diff mbox series

[v3,40/50] qapi: add -i/--include filename.h

Message ID 20170911110623.24981-41-marcandre.lureau@redhat.com
State New
Headers show
Series Hi, | expand

Commit Message

Marc-André Lureau Sept. 11, 2017, 11:06 a.m. UTC
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(-)

Comments

Markus Armbruster Dec. 14, 2017, 1:50 p.m. UTC | #1
Marc-André Lureau <marcandre.lureau@redhat.com> 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.
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

If we need to manage includes manually, then this patch is one way to do
it.  But I'm not sure we need to.  Let me review the remainder of the
series before we analyze this further.
diff mbox series

Patch

diff --git a/scripts/qapi.py b/scripts/qapi.py
index 19e48bd4d2..eb4ffdc06d 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -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
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 d6194ff702..f9abd83490 100644
--- a/scripts/qapi-introspect.py
+++ b/scripts/qapi-introspect.py
@@ -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)
diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index 312685c295..2b46a7e17f 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -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()
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index 369e1f927d..1e173d3cd7 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -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()