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