@@ -2096,9 +2096,9 @@ def parse_command_line(extra_options='', extra_long_options=[]):
try:
opts, args = getopt.gnu_getopt(sys.argv[1:],
- 'chp:o:' + extra_options,
- ['source', 'header', 'prefix=',
- 'output-dir='] + extra_long_options)
+ 'chp:o:i:' + extra_options,
+ ['source', 'header', 'prefix=', 'output-dir=',
+ 'include='] + extra_long_options)
except getopt.GetoptError as err:
print >>sys.stderr, "%s: %s" % (sys.argv[0], str(err))
sys.exit(1)
@@ -2107,6 +2107,7 @@ def parse_command_line(extra_options='', extra_long_options=[]):
prefix = ''
do_c = False
do_h = False
+ includes = []
extra_opts = []
for oa in opts:
@@ -2125,6 +2126,8 @@ def parse_command_line(extra_options='', extra_long_options=[]):
do_c = True
elif o in ('-h', '--header'):
do_h = True
+ elif o in ('-i', '--include'):
+ includes.append(a)
else:
extra_opts.append(oa)
@@ -2137,7 +2140,9 @@ def parse_command_line(extra_options='', extra_long_options=[]):
sys.exit(1)
fname = args[0]
- return (fname, output_dir, do_c, do_h, prefix, extra_opts)
+ includes = "\n".join(['#include "%s"' % inc for inc in includes])
+
+ return (fname, output_dir, do_c, do_h, prefix, includes, extra_opts)
#
# Generate output files with boilerplate
@@ -253,7 +253,8 @@ class QAPISchemaGenCommandVisitor(QAPISchemaVisitor):
self._regy += gen_register_command(name, success_response)
-(input_file, output_dir, do_c, do_h, prefix, opts) = parse_command_line()
+(input_file, output_dir, do_c, do_h, prefix, includes, opts) = \
+ parse_command_line()
c_comment = '''
/*
@@ -305,6 +306,7 @@ fdef.write(mcgen('''
prefix=prefix))
fdecl.write(mcgen('''
+%(includes)s
#include "%(prefix)sqapi-types.h"
#include "qapi/qmp/qdict.h"
#include "qapi/qmp/dispatch.h"
@@ -312,7 +314,8 @@ fdecl.write(mcgen('''
void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds);
''',
- prefix=prefix, c_prefix=c_name(prefix, protect=False)))
+ includes=includes, prefix=prefix,
+ c_prefix=c_name(prefix, protect=False)))
schema = QAPISchema(input_file)
gen = QAPISchemaGenCommandVisitor()
@@ -171,7 +171,8 @@ class QAPISchemaGenEventVisitor(QAPISchemaVisitor):
self._event_names.append(QAPISchemaMember(name, ifcond))
-(input_file, output_dir, do_c, do_h, prefix, dummy) = parse_command_line()
+(input_file, output_dir, do_c, do_h, prefix, includes, dummy) = \
+ parse_command_line()
c_comment = '''
/*
@@ -218,13 +219,14 @@ fdef.write(mcgen('''
prefix=prefix))
fdecl.write(mcgen('''
+%(includes)s
#include "qapi/error.h"
#include "qapi/util.h"
#include "qapi/qmp/qdict.h"
#include "%(prefix)sqapi-types.h"
''',
- prefix=prefix))
+ includes=includes, prefix=prefix))
event_enum_name = c_name(prefix + 'QAPIEvent', protect=False)
@@ -192,7 +192,7 @@ const QLitObject %(c_name)s = %(c_string)s;
# We normally mask them, because they're not QMP wire ABI
opt_unmask = False
-(input_file, output_dir, do_c, do_h, prefix, opts) = \
+(input_file, output_dir, do_c, do_h, prefix, includes, opts) = \
parse_command_line('u', ['unmask-non-abi-names'])
for o, a in opts:
@@ -235,10 +235,11 @@ fdef.write(mcgen('''
prefix=prefix))
fdecl.write(mcgen('''
+%(includes)s
#include "qemu/osdep.h"
#include "qapi/qmp/qlit.h"
-'''))
+''', includes=includes))
schema = QAPISchema(input_file)
gen = QAPISchemaGenIntrospectVisitor(opt_unmask)
@@ -266,7 +266,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor):
# QAPISchemaGenTypeVisitor.visit_end().
do_builtins = False
-(input_file, output_dir, do_c, do_h, prefix, opts) = \
+(input_file, output_dir, do_c, do_h, prefix, includes, opts) = \
parse_command_line('b', ['builtins'])
for o, a in opts:
@@ -317,7 +317,9 @@ fdef.write(mcgen('''
fdecl.write(mcgen('''
#include "qapi/util.h"
-'''))
+%(includes)s
+''',
+ includes=includes))
schema = QAPISchema(input_file)
gen = QAPISchemaGenTypeVisitor()
@@ -338,7 +338,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor):
# QAPISchemaGenVisitVisitor.visit_end().
do_builtins = False
-(input_file, output_dir, do_c, do_h, prefix, opts) = \
+(input_file, output_dir, do_c, do_h, prefix, includes, opts) = \
parse_command_line('b', ['builtins'])
for o, a in opts:
@@ -387,12 +387,13 @@ fdef.write(mcgen('''
prefix=prefix))
fdecl.write(mcgen('''
+%(includes)s
#include "qapi/visitor.h"
#include "qapi/qmp/qerror.h"
#include "%(prefix)sqapi-types.h"
''',
- prefix=prefix))
+ includes=includes, prefix=prefix))
schema = QAPISchema(input_file)
gen = QAPISchemaGenVisitVisitor()
Add a new option to add user-specified #include lines in the generated headers. This will help to split a schema, where one generated header will depend on another. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- scripts/qapi.py | 13 +++++++++---- scripts/qapi-commands.py | 7 +++++-- scripts/qapi-event.py | 6 ++++-- scripts/qapi-introspect.py | 5 +++-- scripts/qapi-types.py | 6 ++++-- scripts/qapi-visit.py | 5 +++-- 6 files changed, 28 insertions(+), 14 deletions(-)