[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v4 41/51] qapi: add -i/--include filename.h
From: |
Marc-André Lureau |
Subject: |
[Qemu-devel] [PATCH v4 41/51] qapi: add -i/--include filename.h |
Date: |
Thu, 11 Jan 2018 22:32:40 +0100 |
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.
Fix some pycodestyle on the way.
Signed-off-by: Marc-André Lureau <address@hidden>
---
scripts/qapi.py | 15 ++++++++++-----
scripts/qapi-commands.py | 7 +++++--
scripts/qapi-event.py | 6 ++++--
scripts/qapi-introspect.py | 6 ++++--
scripts/qapi-types.py | 7 +++++--
scripts/qapi-visit.py | 6 ++++--
tests/Makefile.include | 4 +++-
7 files changed, 35 insertions(+), 16 deletions(-)
diff --git a/scripts/qapi.py b/scripts/qapi.py
index 1668a6da6c..f56460d028 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -2125,10 +2125,10 @@ def build_params(arg_type, boxed, extra):
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)
+ opts, args = getopt.gnu_getopt(
+ sys.argv[1:], '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)
@@ -2137,6 +2137,7 @@ def parse_command_line(extra_options='',
extra_long_options=[]):
prefix = ''
do_c = False
do_h = False
+ includes = []
extra_opts = []
for oa in opts:
@@ -2155,6 +2156,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)
@@ -2167,7 +2170,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
diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py
index 7455d2b8bb..4841f4d9a1 100644
--- a/scripts/qapi-commands.py
+++ b/scripts/qapi-commands.py
@@ -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()
diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py
index 60c6f7030d..0aba866dc8 100644
--- a/scripts/qapi-event.py
+++ b/scripts/qapi-event.py
@@ -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)
diff --git a/scripts/qapi-introspect.py b/scripts/qapi-introspect.py
index 6a66047243..65277e98fd 100644
--- a/scripts/qapi-introspect.py
+++ b/scripts/qapi-introspect.py
@@ -192,11 +192,12 @@ const QLitObject %(c_name)s = %(c_string)s;
self._gen_qlit(name, 'event', {'arg-type': self._use_type(arg_type)},
ifcond)
+
# Debugging aid: unmask QAPI schema's type names
# 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:
@@ -239,10 +240,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)
diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index 312685c295..cc42447bc4 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -260,13 +260,14 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor):
self._gen_object(name, info, ifcond, None,
[variants.tag_member], variants)
+
# If you link code generated from multiple schemata, you want only one
# instance of the code for built-in types. Generate it only when
# do_builtins, enabled by command line option -b. See also
# 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 +318,9 @@ fdef.write(mcgen('''
fdecl.write(mcgen('''
#include "qapi/util.h"
-'''))
+%(includes)s
+''',
+ includes=includes))
schema = QAPISchema(input_file)
gen = QAPISchemaGenTypeVisitor()
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index 48ac1c9a42..bcbd62b32d 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -332,13 +332,14 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor):
self.decl += gen_visit_decl(name)
self.defn += gen_visit_alternate(name, variants)
+
# If you link code generated from multiple schemata, you want only one
# instance of the code for built-in types. Generate it only when
# do_builtins, enabled by command line option -b. See also
# 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 +388,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()
diff --git a/tests/Makefile.include b/tests/Makefile.include
index 3aec5b0874..2b83f05954 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -648,8 +648,10 @@ tests/test-replication$(EXESUF): tests/test-replication.o
$(test-util-obj-y) \
tests/test-qapi-types.c tests/test-qapi-types.h :\
$(SRC_PATH)/tests/qapi-schema/qapi-schema-test.json
$(SRC_PATH)/scripts/qapi-types.py $(qapi-py)
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py \
- $(gen-out-type) -o tests -p "test-" $<, \
+ $(gen-out-type) -o tests -p "test-" -i tests/test-qapi-types.h
$<, \
"GEN","$@")
+# check that -i includes worked with a silly self-include
+ $(call quiet-command,[ $(gen-out-type) == -c ] || grep -q '#include
"tests/test-qapi-types.h"' $@,"TEST","$@")
tests/test-qapi-visit.c tests/test-qapi-visit.h :\
$(SRC_PATH)/tests/qapi-schema/qapi-schema-test.json
$(SRC_PATH)/scripts/qapi-visit.py $(qapi-py)
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py \
--
2.16.0.rc1.1.gef27df75a1
- [Qemu-devel] [PATCH v4 31/51] qapi: add #if conditions to generated code, (continued)
- [Qemu-devel] [PATCH v4 31/51] qapi: add #if conditions to generated code, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 32/51] docs: document schema configuration, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 33/51] qapi2texi: add 'If:' section to generated documentation, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 34/51] qapi2texi: add 'If:' condition to enum values, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 36/51] qapi2texi: add condition to variants, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 35/51] qapi2texi: add 'If:' condition to struct members, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 37/51] qapi: add conditions to VNC type/commands/events on the schema, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 38/51] qapi: add conditions to SPICE type/commands/events on the schema, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 39/51] qapi: add conditions to REPLICATION type/commands on the schema, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 40/51] qapi-commands: don't initialize command list in qmp_init_marshall(), Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 41/51] qapi: add -i/--include filename.h,
Marc-André Lureau <=
- [Qemu-devel] [PATCH v4 42/51] qapi: add a 'unit' pragma, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 43/51] build-sys: move qmp-introspect per target, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 44/51] build-sys: add a target schema, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 45/51] qapi: make rtc-reset-reinjection depend on TARGET_I386, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 47/51] target.json: add a note about query-cpu* not being s390x-specific, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 46/51] qapi: make s390 commands depend on TARGET_S390X, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 48/51] qapi: make query-gic-capabilities depend on TARGET_ARM, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 49/51] qapi: make query-cpu-model-expansion depend on s390 or x86, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 51/51] qapi: remove qmp_unregister_command(), Marc-André Lureau, 2018/01/11