3 # gen_def.py : Generate the .DEF file for Windows builds
5 # ====================================================================
6 # Copyright 2002-2010 Justin Erenkrantz and Greg Stein
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
12 # http://www.apache.org/licenses/LICENSE-2.0
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 # ====================================================================
22 # Typically, this script is used like:
24 # C:\PATH> python build/gen_def.py serf.h serf_bucket_types.h serf_bucket_util.h > build/serf.def
30 # This regex parses function declarations that look like:
32 # return_type serf_func1(...
33 # return_type *serf_func2(...
35 # Where return_type is a combination of words and "*" each separated by a
36 # SINGLE space. If the function returns a pointer type (like serf_func2),
37 # then a space may exist between the "*" and the function name. Thus,
38 # a more complicated example might be:
39 # const type * const * serf_func3(...
41 _funcs = re.compile(r'^(?:(?:\w+|\*) )+\*?(serf_[a-z][a-z_0-9]*)\(',
44 # This regex parses the bucket type definitions which look like:
46 # extern const serf_bucket_type_t serf_bucket_type_FOO;
48 _types = re.compile(r'^extern const serf_bucket_type_t (serf_[a-z_]*);',
52 def extract_exports(fname):
53 content = open(fname).read()
55 for name in _funcs.findall(content):
57 for name in _types.findall(content):
61 # Blacklist the serf v2 API for now
62 blacklist = ['serf_connection_switch_protocol',
63 'serf_http_protocol_create',
64 'serf_http_request_create',
65 'serf_https_protocol_create']
67 if __name__ == '__main__':
68 # run the extraction over each file mentioned
72 for fname in sys.argv[1:]:
73 funclist = extract_exports(fname)
74 funclist = set(funclist) - set(blacklist)