Re: [Qemu-devel] [PATCH v4 41/51] qapi: add -i/--include filename.h

2018-02-05 Thread Markus Armbruster
Marc-André Lureau  writes:

> 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 

With my alternative way to split up the generated monolith[*], required
generated headers should be included without the user's help.

We might conceivably need an ability to add includes for other purposes.
As far as I can tell, this is not the case in your series.

If we need the ability, then I'd rather use a directive in the schema
than a command line option.


[*] [PATCH RFC 00/21] Modularize generated QAPI code
Message-Id: <20180202130336.24719-1-arm...@redhat.com>



[Qemu-devel] [PATCH v4 41/51] qapi: add -i/--include filename.h

2018-01-11 Thread Marc-André Lureau
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 
---
 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