diff options
author | João Valverde <j@v6e.pt> | 2022-06-07 14:27:53 +0100 |
---|---|---|
committer | João Valverde <j@v6e.pt> | 2022-06-07 14:31:08 +0100 |
commit | 104cc42008889a69b15e836cd34103daa7e40d33 (patch) | |
tree | f04b85847e0b9dfc78c72a72f7d39c2c3bf8bf72 | |
parent | e21aa6c36e42224d4d796a16ff3157423f6bf850 (diff) |
Make it easier to call tools/make-enums.py from the source dir
-rw-r--r-- | epan/CMakeLists.txt | 9 | ||||
-rwxr-xr-x | tools/make-enums.py | 33 |
2 files changed, 26 insertions, 16 deletions
diff --git a/epan/CMakeLists.txt b/epan/CMakeLists.txt index ff0a6072c9..1a8a103f23 100644 --- a/epan/CMakeLists.txt +++ b/epan/CMakeLists.txt @@ -429,20 +429,11 @@ set_target_properties(wscbor_test PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD True ) -set(ENUM_FILES - epan/address.h - epan/ipproto.h - epan/proto.h - epan/ftypes/ftypes.h -) - # This tries to parse C headers using Python to extract enums for # introspection. It is slow and has some particular dependencies. # It's also not foolproof. It should not be part of the ALL target. add_custom_target(gen-enums COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/make-enums.py - --outfile ${CMAKE_CURRENT_SOURCE_DIR}/introspection-enums.c - ${ENUM_FILES} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} ) diff --git a/tools/make-enums.py b/tools/make-enums.py index 459fd4a5d8..703fabcffa 100755 --- a/tools/make-enums.py +++ b/tools/make-enums.py @@ -20,12 +20,34 @@ import sys import argparse from pyclibrary import CParser +default_infiles = [ + "epan/address.h", + "epan/ipproto.h", + "epan/proto.h", + "epan/ftypes/ftypes.h", +] + +default_outfile = "epan/introspection-enums.c" + argp = argparse.ArgumentParser() argp.add_argument("-o", "--outfile") argp.add_argument("infiles", nargs="*") args = argp.parse_args() -parser = CParser(args.infiles) +if args.infiles: + infiles = args.infiles +else: + infiles = default_infiles + +if args.outfile: + outfile = args.outfile +else: + outfile = default_outfile + +print("input: {}".format(infiles)) +print("output: {}".format(outfile)) + +parser = CParser(infiles) source = """\ /* @@ -46,7 +68,7 @@ source = """\ */ """ % (os.path.basename(sys.argv[0])) -for f in args.infiles: +for f in infiles: source += '#include <{}>\n'.format(f) source += """ @@ -69,12 +91,9 @@ source += """\ """ try: - if args.outfile: - fh = open(args.outfile, 'w') - else: - fh = sys.stdout + fh = open(outfile, 'w') except OSError: - sys.exit('Unable to write ' + args.outfile + '.\n') + sys.exit('Unable to write ' + outfile + '.\n') fh.write(source) fh.close() |