Make it easier to call tools/make-enums.py from the source dir
This commit is contained in:
parent
e21aa6c36e
commit
104cc42008
@ -429,20 +429,11 @@ set_target_properties(wscbor_test PROPERTIES
|
|||||||
EXCLUDE_FROM_DEFAULT_BUILD True
|
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
|
# This tries to parse C headers using Python to extract enums for
|
||||||
# introspection. It is slow and has some particular dependencies.
|
# introspection. It is slow and has some particular dependencies.
|
||||||
# It's also not foolproof. It should not be part of the ALL target.
|
# It's also not foolproof. It should not be part of the ALL target.
|
||||||
add_custom_target(gen-enums
|
add_custom_target(gen-enums
|
||||||
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/make-enums.py
|
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}
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -20,12 +20,34 @@ import sys
|
|||||||
import argparse
|
import argparse
|
||||||
from pyclibrary import CParser
|
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 = argparse.ArgumentParser()
|
||||||
argp.add_argument("-o", "--outfile")
|
argp.add_argument("-o", "--outfile")
|
||||||
argp.add_argument("infiles", nargs="*")
|
argp.add_argument("infiles", nargs="*")
|
||||||
args = argp.parse_args()
|
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 = """\
|
source = """\
|
||||||
/*
|
/*
|
||||||
@ -46,7 +68,7 @@ source = """\
|
|||||||
*/
|
*/
|
||||||
""" % (os.path.basename(sys.argv[0]))
|
""" % (os.path.basename(sys.argv[0]))
|
||||||
|
|
||||||
for f in args.infiles:
|
for f in infiles:
|
||||||
source += '#include <{}>\n'.format(f)
|
source += '#include <{}>\n'.format(f)
|
||||||
|
|
||||||
source += """
|
source += """
|
||||||
@ -69,12 +91,9 @@ source += """\
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if args.outfile:
|
fh = open(outfile, 'w')
|
||||||
fh = open(args.outfile, 'w')
|
|
||||||
else:
|
|
||||||
fh = sys.stdout
|
|
||||||
except OSError:
|
except OSError:
|
||||||
sys.exit('Unable to write ' + args.outfile + '.\n')
|
sys.exit('Unable to write ' + outfile + '.\n')
|
||||||
|
|
||||||
fh.write(source)
|
fh.write(source)
|
||||||
fh.close()
|
fh.close()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user