1251877Speter#!/usr/bin/env python 2251877Speter# 3251877Speter# gen_def.py : Generate the .DEF file for Windows builds 4251877Speter# 5251877Speter# ==================================================================== 6251877Speter# Copyright 2002-2010 Justin Erenkrantz and Greg Stein 7251877Speter# 8251877Speter# Licensed under the Apache License, Version 2.0 (the "License"); 9251877Speter# you may not use this file except in compliance with the License. 10251877Speter# You may obtain a copy of the License at 11251877Speter# 12251877Speter# http://www.apache.org/licenses/LICENSE-2.0 13251877Speter# 14251877Speter# Unless required by applicable law or agreed to in writing, software 15251877Speter# distributed under the License is distributed on an "AS IS" BASIS, 16251877Speter# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17251877Speter# See the License for the specific language governing permissions and 18251877Speter# limitations under the License. 19251877Speter# ==================================================================== 20251877Speter# 21251877Speter# 22251877Speter# Typically, this script is used like: 23251877Speter# 24251877Speter# C:\PATH> python build/gen_def.py serf.h serf_bucket_types.h serf_bucket_util.h > build/serf.def 25251877Speter# 26251877Speter 27251877Speterimport re 28251877Speterimport sys 29251877Speter 30251877Speter# This regex parses function declarations that look like: 31251877Speter# 32251877Speter# return_type serf_func1(... 33251877Speter# return_type *serf_func2(... 34251877Speter# 35251877Speter# Where return_type is a combination of words and "*" each separated by a 36251877Speter# SINGLE space. If the function returns a pointer type (like serf_func2), 37251877Speter# then a space may exist between the "*" and the function name. Thus, 38251877Speter# a more complicated example might be: 39251877Speter# const type * const * serf_func3(... 40251877Speter# 41251877Speter_funcs = re.compile(r'^(?:(?:\w+|\*) )+\*?(serf_[a-z][a-z_0-9]*)\(', 42251877Speter re.MULTILINE) 43251877Speter 44251877Speter# This regex parses the bucket type definitions which look like: 45251877Speter# 46251877Speter# extern const serf_bucket_type_t serf_bucket_type_FOO; 47251877Speter# 48251877Speter_types = re.compile(r'^extern const serf_bucket_type_t (serf_[a-z_]*);', 49251877Speter re.MULTILINE) 50251877Speter 51251877Speter 52251877Speterdef extract_exports(fname): 53251877Speter content = open(fname).read() 54251877Speter exports = [ ] 55251877Speter for name in _funcs.findall(content): 56251877Speter exports.append(name) 57251877Speter for name in _types.findall(content): 58251877Speter exports.append(name) 59251877Speter return exports 60251877Speter 61253895Speter# Blacklist the serf v2 API for now 62253895Speterblacklist = ['serf_connection_switch_protocol', 63253895Speter 'serf_http_protocol_create', 64253895Speter 'serf_http_request_create', 65253895Speter 'serf_https_protocol_create'] 66251877Speter 67251877Speterif __name__ == '__main__': 68251877Speter # run the extraction over each file mentioned 69251877Speter import sys 70251877Speter print("EXPORTS") 71253895Speter 72251877Speter for fname in sys.argv[1:]: 73253895Speter funclist = extract_exports(fname) 74253895Speter funclist = set(funclist) - set(blacklist) 75253895Speter for func in funclist: 76251877Speter print(func) 77