Re: [Qemu-devel] [PATCH RFC 05/21] qapi: Turn generators into modules

2018-02-05 Thread Marc-Andre Lureau
On Fri, Feb 2, 2018 at 2:03 PM, Markus Armbruster  wrote:
> The next commit will introduce a common driver program for all
> generators.  The generators need to be modules for that.  qapi2texi.py
> already is.  Make the other generators follow suit.
>
> The changes are actually trivial.  Obvious in the diffs once you view
> them with whitespace changes ignored.
>
> Signed-off-by: Markus Armbruster 

Reviewed-by: Marc-André Lureau 


> ---
>  scripts/qapi-commands.py   | 43 ++--
>  scripts/qapi-event.py  | 43 ++--
>  scripts/qapi-introspect.py | 54 ++--
>  scripts/qapi-types.py  | 56 ++---
>  scripts/qapi-visit.py  | 62 
> +-
>  5 files changed, 143 insertions(+), 115 deletions(-)
>
> diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py
> index d229537659..331b58670e 100644
> --- a/scripts/qapi-commands.py
> +++ b/scripts/qapi-commands.py
> @@ -255,16 +255,17 @@ class QAPISchemaGenCommandVisitor(QAPISchemaVisitor):
>  self._regy += gen_register_command(name, success_response)
>
>
> -(input_file, output_dir, do_c, do_h, prefix, opts) = parse_command_line()
> +def main(argv):
> +(input_file, output_dir, do_c, do_h, prefix, opts) = parse_command_line()
>
> -blurb = '''
> +blurb = '''
>   * Schema-defined QAPI/QMP commands
>  '''
>
> -genc = QAPIGenC(blurb, __doc__)
> -genh = QAPIGenH(blurb, __doc__)
> +genc = QAPIGenC(blurb, __doc__)
> +genh = QAPIGenH(blurb, __doc__)
>
> -genc.body(mcgen('''
> +genc.body(mcgen('''
>  #include "qemu/osdep.h"
>  #include "qemu-common.h"
>  #include "qemu/module.h"
> @@ -278,24 +279,28 @@ genc.body(mcgen('''
>  #include "%(prefix)sqmp-commands.h"
>
>  ''',
> -prefix=prefix))
> +prefix=prefix))
>
> -genh.body(mcgen('''
> +genh.body(mcgen('''
>  #include "%(prefix)sqapi-types.h"
>  #include "qapi/qmp/qdict.h"
>  #include "qapi/qmp/dispatch.h"
>
>  void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds);
>  ''',
> -prefix=prefix, c_prefix=c_name(prefix, protect=False)))
> -
> -schema = QAPISchema(input_file)
> -vis = QAPISchemaGenCommandVisitor(prefix)
> -schema.visit(vis)
> -genc.body(vis.defn)
> -genh.body(vis.decl)
> -
> -if do_c:
> -genc.write(output_dir, prefix + 'qmp-marshal.c')
> -if do_h:
> -genh.write(output_dir, prefix + 'qmp-commands.h')
> +prefix=prefix, c_prefix=c_name(prefix, protect=False)))
> +
> +schema = QAPISchema(input_file)
> +vis = QAPISchemaGenCommandVisitor(prefix)
> +schema.visit(vis)
> +genc.body(vis.defn)
> +genh.body(vis.decl)
> +
> +if do_c:
> +genc.write(output_dir, prefix + 'qmp-marshal.c')
> +if do_h:
> +genh.write(output_dir, prefix + 'qmp-commands.h')
> +
> +
> +if __name__ == '__main__':
> +main(sys.argv)
> diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py
> index 1af21b580a..5b33c694d4 100644
> --- a/scripts/qapi-event.py
> +++ b/scripts/qapi-event.py
> @@ -171,16 +171,17 @@ class QAPISchemaGenEventVisitor(QAPISchemaVisitor):
>  self._event_names.append(name)
>
>
> -(input_file, output_dir, do_c, do_h, prefix, dummy) = parse_command_line()
> +def main(argv):
> +(input_file, output_dir, do_c, do_h, prefix, dummy) = 
> parse_command_line()
>
> -blurb = '''
> +blurb = '''
>   * Schema-defined QAPI/QMP events
>  '''
>
> -genc = QAPIGenC(blurb, __doc__)
> -genh = QAPIGenH(blurb, __doc__)
> +genc = QAPIGenC(blurb, __doc__)
> +genh = QAPIGenH(blurb, __doc__)
>
> -genc.body(mcgen('''
> +genc.body(mcgen('''
>  #include "qemu/osdep.h"
>  #include "qemu-common.h"
>  #include "%(prefix)sqapi-event.h"
> @@ -190,23 +191,27 @@ genc.body(mcgen('''
>  #include "qapi/qmp-event.h"
>
>  ''',
> -prefix=prefix))
> +prefix=prefix))
>
> -genh.body(mcgen('''
> +genh.body(mcgen('''
>  #include "qapi/util.h"
>  #include "qapi/qmp/qdict.h"
>  #include "%(prefix)sqapi-types.h"
>
>  ''',
> -prefix=prefix))
> -
> -schema = QAPISchema(input_file)
> -vis = QAPISchemaGenEventVisitor(prefix)
> -schema.visit(vis)
> -genc.body(vis.defn)
> -genh.body(vis.decl)
> -
> -if do_c:
> -genc.write(output_dir, prefix + 'qapi-event.c')
> -if do_h:
> -genh.write(output_dir, prefix + 'qapi-event.h')
> +prefix=prefix))
> +
> +schema = QAPISchema(input_file)
> +vis = QAPISchemaGenEventVisitor(prefix)
> +schema.visit(vis)
> +genc.body(vis.defn)
> +genh.body(vis.decl)
> +
> +if do_c:
> +genc.write(output_dir, prefix + 'qapi-event.c')
> +if do_h:
> +genh.write(output_dir, prefix + 'qapi-event.h')
> +
> +
> +if __name__ == '__main__':
> +main(sys.argv)
> diff --git a/scripts/qapi-introspect.py 

Re: [Qemu-devel] [PATCH RFC 05/21] qapi: Turn generators into modules

2018-02-02 Thread Eric Blake
On 02/02/2018 07:03 AM, Markus Armbruster wrote:
> The next commit will introduce a common driver program for all
> generators.  The generators need to be modules for that.  qapi2texi.py
> already is.  Make the other generators follow suit.
> 
> The changes are actually trivial.  Obvious in the diffs once you view
> them with whitespace changes ignored.
> 
> Signed-off-by: Markus Armbruster 
> ---
>  scripts/qapi-commands.py   | 43 ++--
>  scripts/qapi-event.py  | 43 ++--
>  scripts/qapi-introspect.py | 54 ++--
>  scripts/qapi-types.py  | 56 ++---
>  scripts/qapi-visit.py  | 62 
> +-
>  5 files changed, 143 insertions(+), 115 deletions(-)
> 

Reviewed-by: Eric Blake 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3266
Virtualization:  qemu.org | libvirt.org



signature.asc
Description: OpenPGP digital signature


[Qemu-devel] [PATCH RFC 05/21] qapi: Turn generators into modules

2018-02-02 Thread Markus Armbruster
The next commit will introduce a common driver program for all
generators.  The generators need to be modules for that.  qapi2texi.py
already is.  Make the other generators follow suit.

The changes are actually trivial.  Obvious in the diffs once you view
them with whitespace changes ignored.

Signed-off-by: Markus Armbruster 
---
 scripts/qapi-commands.py   | 43 ++--
 scripts/qapi-event.py  | 43 ++--
 scripts/qapi-introspect.py | 54 ++--
 scripts/qapi-types.py  | 56 ++---
 scripts/qapi-visit.py  | 62 +-
 5 files changed, 143 insertions(+), 115 deletions(-)

diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py
index d229537659..331b58670e 100644
--- a/scripts/qapi-commands.py
+++ b/scripts/qapi-commands.py
@@ -255,16 +255,17 @@ class QAPISchemaGenCommandVisitor(QAPISchemaVisitor):
 self._regy += gen_register_command(name, success_response)
 
 
-(input_file, output_dir, do_c, do_h, prefix, opts) = parse_command_line()
+def main(argv):
+(input_file, output_dir, do_c, do_h, prefix, opts) = parse_command_line()
 
-blurb = '''
+blurb = '''
  * Schema-defined QAPI/QMP commands
 '''
 
-genc = QAPIGenC(blurb, __doc__)
-genh = QAPIGenH(blurb, __doc__)
+genc = QAPIGenC(blurb, __doc__)
+genh = QAPIGenH(blurb, __doc__)
 
-genc.body(mcgen('''
+genc.body(mcgen('''
 #include "qemu/osdep.h"
 #include "qemu-common.h"
 #include "qemu/module.h"
@@ -278,24 +279,28 @@ genc.body(mcgen('''
 #include "%(prefix)sqmp-commands.h"
 
 ''',
-prefix=prefix))
+prefix=prefix))
 
-genh.body(mcgen('''
+genh.body(mcgen('''
 #include "%(prefix)sqapi-types.h"
 #include "qapi/qmp/qdict.h"
 #include "qapi/qmp/dispatch.h"
 
 void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds);
 ''',
-prefix=prefix, c_prefix=c_name(prefix, protect=False)))
-
-schema = QAPISchema(input_file)
-vis = QAPISchemaGenCommandVisitor(prefix)
-schema.visit(vis)
-genc.body(vis.defn)
-genh.body(vis.decl)
-
-if do_c:
-genc.write(output_dir, prefix + 'qmp-marshal.c')
-if do_h:
-genh.write(output_dir, prefix + 'qmp-commands.h')
+prefix=prefix, c_prefix=c_name(prefix, protect=False)))
+
+schema = QAPISchema(input_file)
+vis = QAPISchemaGenCommandVisitor(prefix)
+schema.visit(vis)
+genc.body(vis.defn)
+genh.body(vis.decl)
+
+if do_c:
+genc.write(output_dir, prefix + 'qmp-marshal.c')
+if do_h:
+genh.write(output_dir, prefix + 'qmp-commands.h')
+
+
+if __name__ == '__main__':
+main(sys.argv)
diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py
index 1af21b580a..5b33c694d4 100644
--- a/scripts/qapi-event.py
+++ b/scripts/qapi-event.py
@@ -171,16 +171,17 @@ class QAPISchemaGenEventVisitor(QAPISchemaVisitor):
 self._event_names.append(name)
 
 
-(input_file, output_dir, do_c, do_h, prefix, dummy) = parse_command_line()
+def main(argv):
+(input_file, output_dir, do_c, do_h, prefix, dummy) = parse_command_line()
 
-blurb = '''
+blurb = '''
  * Schema-defined QAPI/QMP events
 '''
 
-genc = QAPIGenC(blurb, __doc__)
-genh = QAPIGenH(blurb, __doc__)
+genc = QAPIGenC(blurb, __doc__)
+genh = QAPIGenH(blurb, __doc__)
 
-genc.body(mcgen('''
+genc.body(mcgen('''
 #include "qemu/osdep.h"
 #include "qemu-common.h"
 #include "%(prefix)sqapi-event.h"
@@ -190,23 +191,27 @@ genc.body(mcgen('''
 #include "qapi/qmp-event.h"
 
 ''',
-prefix=prefix))
+prefix=prefix))
 
-genh.body(mcgen('''
+genh.body(mcgen('''
 #include "qapi/util.h"
 #include "qapi/qmp/qdict.h"
 #include "%(prefix)sqapi-types.h"
 
 ''',
-prefix=prefix))
-
-schema = QAPISchema(input_file)
-vis = QAPISchemaGenEventVisitor(prefix)
-schema.visit(vis)
-genc.body(vis.defn)
-genh.body(vis.decl)
-
-if do_c:
-genc.write(output_dir, prefix + 'qapi-event.c')
-if do_h:
-genh.write(output_dir, prefix + 'qapi-event.h')
+prefix=prefix))
+
+schema = QAPISchema(input_file)
+vis = QAPISchemaGenEventVisitor(prefix)
+schema.visit(vis)
+genc.body(vis.defn)
+genh.body(vis.decl)
+
+if do_c:
+genc.write(output_dir, prefix + 'qapi-event.c')
+if do_h:
+genh.write(output_dir, prefix + 'qapi-event.h')
+
+
+if __name__ == '__main__':
+main(sys.argv)
diff --git a/scripts/qapi-introspect.py b/scripts/qapi-introspect.py
index 8d4e3c1c3a..09e7d1f140 100644
--- a/scripts/qapi-introspect.py
+++ b/scripts/qapi-introspect.py
@@ -167,38 +167,44 @@ const char %(c_name)s[] = %(c_string)s;
 arg_type = arg_type or self._schema.the_empty_object_type
 self._gen_json(name, 'event', {'arg-type': self._use_type(arg_type)})
 
-# Debugging aid: unmask QAPI schema's type names
-# We normally mask them, because they're not QMP wire ABI