Blame build/gen_def.py

Packit 3adb1e
#!/usr/bin/env python
Packit 3adb1e
#
Packit 3adb1e
# gen_def.py :  Generate the .DEF file for Windows builds
Packit 3adb1e
#
Packit 3adb1e
# ===================================================================
Packit 3adb1e
#   Licensed to the Apache Software Foundation (ASF) under one
Packit 3adb1e
#   or more contributor license agreements.  See the NOTICE file
Packit 3adb1e
#   distributed with this work for additional information
Packit 3adb1e
#   regarding copyright ownership.  The ASF licenses this file
Packit 3adb1e
#   to you under the Apache License, Version 2.0 (the
Packit 3adb1e
#   "License"); you may not use this file except in compliance
Packit 3adb1e
#   with the License.  You may obtain a copy of the License at
Packit 3adb1e
# 
Packit 3adb1e
#     http://www.apache.org/licenses/LICENSE-2.0
Packit 3adb1e
# 
Packit 3adb1e
#   Unless required by applicable law or agreed to in writing,
Packit 3adb1e
#   software distributed under the License is distributed on an
Packit 3adb1e
#   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
Packit 3adb1e
#   KIND, either express or implied.  See the License for the
Packit 3adb1e
#   specific language governing permissions and limitations
Packit 3adb1e
#   under the License.
Packit 3adb1e
# ===================================================================
Packit 3adb1e
#
Packit 3adb1e
# Typically, this script is used like:
Packit 3adb1e
#
Packit 3adb1e
#    C:\PATH> python build/gen_def.py serf.h serf_bucket_types.h serf_bucket_util.h > build/serf.def
Packit 3adb1e
#
Packit 3adb1e
Packit 3adb1e
import re
Packit 3adb1e
import sys
Packit 3adb1e
Packit 3adb1e
# This regex parses function declarations that look like:
Packit 3adb1e
#
Packit 3adb1e
#    return_type serf_func1(...
Packit 3adb1e
#    return_type *serf_func2(...
Packit 3adb1e
#
Packit 3adb1e
# Where return_type is a combination of words and "*" each separated by a
Packit 3adb1e
# SINGLE space. If the function returns a pointer type (like serf_func2),
Packit 3adb1e
# then a space may exist between the "*" and the function name. Thus,
Packit 3adb1e
# a more complicated example might be:
Packit 3adb1e
#    const type * const * serf_func3(...
Packit 3adb1e
#
Packit 3adb1e
_funcs = re.compile(r'^(?:(?:\w+|\*) )+\*?(serf_[a-z][a-zA-Z_0-9]*)\(',
Packit 3adb1e
                    re.MULTILINE)
Packit 3adb1e
Packit 3adb1e
# This regex parses the bucket type definitions which look like:
Packit 3adb1e
#
Packit 3adb1e
#    extern const serf_bucket_type_t serf_bucket_type_FOO;
Packit 3adb1e
#
Packit 3adb1e
_types = re.compile(r'^extern const serf_bucket_type_t (serf_[a-z_]*);',
Packit 3adb1e
                    re.MULTILINE)
Packit 3adb1e
Packit 3adb1e
Packit 3adb1e
def extract_exports(fname):
Packit 3adb1e
  content = open(fname).read()
Packit 3adb1e
  exports = [ ]
Packit 3adb1e
  for name in _funcs.findall(content):
Packit 3adb1e
    exports.append(name)
Packit 3adb1e
  for name in _types.findall(content):
Packit 3adb1e
    exports.append(name)
Packit 3adb1e
  return exports
Packit 3adb1e
Packit 3adb1e
# Blacklist the serf v2 API for now
Packit 3adb1e
blacklist = ['serf_connection_switch_protocol',
Packit 3adb1e
             'serf_http_protocol_create',
Packit 3adb1e
             'serf_http_request_create',
Packit 3adb1e
             'serf_https_protocol_create']
Packit 3adb1e
Packit 3adb1e
if __name__ == '__main__':
Packit 3adb1e
  # run the extraction over each file mentioned
Packit 3adb1e
  import sys
Packit 3adb1e
  print("EXPORTS")
Packit 3adb1e
Packit 3adb1e
  for fname in sys.argv[1:]:
Packit 3adb1e
    funclist = extract_exports(fname)
Packit 3adb1e
    funclist = set(funclist) - set(blacklist)
Packit 3adb1e
    for func in funclist:
Packit 3adb1e
      print(func)