Skip to contentSkip to conversation

qapi: Mostly generator cleanups

PATCH In review Markus Armbruster 2 participants 15 messages May 11, 2015 – May 14, 2015 Kbuild

lore
Share & tools
lore
#5 lore raw

PATCH 5/9 qapi: Fix generators to report command line errors decently

In reply to Markus Armbruster

Report to stderr, prefix with the program name. Also reject extra arguments.

---
 scripts/qapi.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
scripts/qapi.py +5 -1
index d90a538..5807476 100644
@@ -971,7 +971,7 @@ def parse_command_line(extra_options = "", extra_long_options = []):
                                         "input-file=", "output-dir="]
                                        + extra_long_options)
     except getopt.GetoptError, err:
-        print str(err)
+        print >>sys.stderr, "%s: %s" % (sys.argv[0], str(err))
         sys.exit(1)
 
     output_dir = ""
@@ -999,4 +999,8 @@ def parse_command_line(extra_options = "", extra_long_options = []):
         do_c = True
         do_h = True
 
+    if len(args) != 0:
+        print >>sys.stderr, "%s: too many arguments"% sys.argv[0]
+        sys.exit(1)
+
     return (input_file, output_dir, do_c, do_h, prefix, extra_opts)
Signature · 1 line
1.9.3
#11 lore raw

PATCH 8/9 qapi: Drop pointless flush() before close()

In reply to Markus Armbruster
---
 scripts/qapi.py | 4 ----
 1 file changed, 4 deletions(-)
scripts/qapi.py +0 -4
index 1f68fa9..784212c 100644
@@ -1046,9 +1046,5 @@ def close_output(fdef, fdecl):
     fdecl.write('''
 #endif
 ''')
-
-    fdecl.flush()
     fdecl.close()
-
-    fdef.flush()
     fdef.close()
Signature · 1 line
1.9.3
#0 lore raw

cover qapi: Mostly generator cleanups

You've seen these patches before, in "[PATCH RFC 00/19] qapi: QMP introspection". Eric has pulled a few into "[PATCH v2 0/3] parse 'null' literal in QMP" and "[PATCH v3 00/14] Fix qapi mangling of downstream names". This series has the remaining ones, except for "[PATCH RFC 19/19] qapi: New QMP command query-schema for QMP schema introspection", which isn't ready.

Based on Luiz's latest pull request plus Eric's "Fix qapi mangling of downstream names".

Changes since RFC:
* Straightforward rebase, R-by retained
* PATCH 06: address Eric's review, R-by dropped

Markus Armbruster (9):
tests: Add missing dependencies on $(qapi-py)
qapi: qapi-event.py option -b does nothing, drop it
qapi: qapi-commands.py option --type is unused, drop it
qapi: Factor parse_command_line() out of the generators
qapi: Fix generators to report command line errors decently
qapi: Turn generators' mandatory option -i into an argument
qapi: Factor open_output(), close_output() out of generators
qapi: Drop pointless flush() before close()
qapi: Inline gen_command_decl_prologue(), gen_command_def_prologue()

 Makefile                 |  14 ++--
 docs/qapi-code-gen.txt   |  10 +--
 scripts/qapi-commands.py | 185 +++++++++++++++--------------------------------
 scripts/qapi-event.py    | 120 +++++++-----------------------
 scripts/qapi-types.py    | 117 ++++++++----------------------
 scripts/qapi-visit.py    | 136 ++++++++++------------------------
 scripts/qapi.py          |  88 ++++++++++++++++++++++
 tests/Makefile           |  16 ++--
 8 files changed, 260 insertions(+), 426 deletions(-)
Signature · 1 line
1.9.3
#1 lore raw

PATCH 1/9 tests: Add missing dependencies on $(qapi-py)

---
 tests/Makefile | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tests/Makefile +4 -4
index 666aee2..6d2f2e5 100644
@@ -301,22 +301,22 @@ tests/test-vmstate$(EXESUF): tests/test-vmstate.o \
 	libqemuutil.a libqemustub.a
 
 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
+$(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-" -i $<, \
 		"  GEN   $@")
 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
+$(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 \
 		$(gen-out-type) -o tests -p "test-" -i $<, \
 		"  GEN   $@")
 tests/test-qmp-commands.h tests/test-qmp-marshal.c :\
-$(SRC_PATH)/tests/qapi-schema/qapi-schema-test.json $(SRC_PATH)/scripts/qapi-commands.py
+$(SRC_PATH)/tests/qapi-schema/qapi-schema-test.json $(SRC_PATH)/scripts/qapi-commands.py $(qapi-py)
 	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py \
 		$(gen-out-type) -o tests -p "test-" -i $<, \
 		"  GEN   $@")
 tests/test-qapi-event.c tests/test-qapi-event.h :\
-$(SRC_PATH)/tests/qapi-schema/qapi-schema-test.json $(SRC_PATH)/scripts/qapi-event.py
+$(SRC_PATH)/tests/qapi-schema/qapi-schema-test.json $(SRC_PATH)/scripts/qapi-event.py $(qapi-py)
 	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-event.py \
 		$(gen-out-type) -o tests -p "test-" -i $<, \
 		"  GEN   $@")
Signature · 1 line
1.9.3
#3 lore raw

PATCH 3/9 qapi: qapi-commands.py option --type is unused, drop it

In reply to Markus Armbruster

Anything but --type sync (which is the default) suppresses output entirely, which makes no sense.

Dates back to the initial commit c17d990. Commit message says "Currently only generators for synchronous qapi/qmp functions are supported", so maybe output other than "synchronous qapi/qmp" was planned at the time, to be selected with --type.

Should other kinds of output ever materialize, we can put the option back.

---
 scripts/qapi-commands.py | 66 +++++++++++++++++++++++-------------------------
 1 file changed, 31 insertions(+), 35 deletions(-)
scripts/qapi-commands.py +31 -35
index 0a1d636..c94a19b 100644
@@ -381,14 +381,13 @@ try:
     opts, args = getopt.gnu_getopt(sys.argv[1:], "chp:i:o:m",
                                    ["source", "header", "prefix=",
                                     "input-file=", "output-dir=",
-                                    "type=", "middle"])
+                                    "middle"])
 except getopt.GetoptError, err:
     print str(err)
     sys.exit(1)
 
 output_dir = ""
 prefix = ""
-dispatch_type = "sync"
 c_file = 'qmp-marshal.c'
 h_file = 'qmp-commands.h'
 middle_mode = False
@@ -403,8 +402,6 @@ for o, a in opts:
         input_file = a
     elif o in ("-o", "--output-dir"):
         output_dir = a + "/"
-    elif o in ("-t", "--type"):
-        dispatch_type = a
     elif o in ("-m", "--middle"):
         middle_mode = True
     elif o in ("-c", "--source"):
@@ -436,40 +433,39 @@ exprs = parse_schema(input_file)
 commands = filter(lambda expr: expr.has_key('command'), exprs)
 commands = filter(lambda expr: not expr.has_key('gen'), commands)
 
-if dispatch_type == "sync":
-    fdecl = maybe_open(do_h, h_file, 'w')
-    fdef = maybe_open(do_c, c_file, 'w')
-    ret = gen_command_decl_prologue(header=basename(h_file), guard=guardname(h_file), prefix=prefix)
+fdecl = maybe_open(do_h, h_file, 'w')
+fdef = maybe_open(do_c, c_file, 'w')
+ret = gen_command_decl_prologue(header=basename(h_file), guard=guardname(h_file), prefix=prefix)
+fdecl.write(ret)
+ret = gen_command_def_prologue(prefix=prefix)
+fdef.write(ret)
+
+for cmd in commands:
+    arglist = []
+    ret_type = None
+    if cmd.has_key('data'):
+        arglist = cmd['data']
+    if cmd.has_key('returns'):
+        ret_type = cmd['returns']
+    ret = generate_command_decl(cmd['command'], arglist, ret_type) + "\n"
     fdecl.write(ret)
-    ret = gen_command_def_prologue(prefix=prefix)
-    fdef.write(ret)
-
-    for cmd in commands:
-        arglist = []
-        ret_type = None
-        if cmd.has_key('data'):
-            arglist = cmd['data']
-        if cmd.has_key('returns'):
-            ret_type = cmd['returns']
-        ret = generate_command_decl(cmd['command'], arglist, ret_type) + "\n"
-        fdecl.write(ret)
-        if ret_type:
-            ret = gen_marshal_output(cmd['command'], arglist, ret_type, middle_mode) + "\n"
-            fdef.write(ret)
+    if ret_type:
+        ret = gen_marshal_output(cmd['command'], arglist, ret_type, middle_mode) + "\n"
+        fdef.write(ret)
 
-        if middle_mode:
-            fdecl.write('%s;\n' % gen_marshal_input_decl(cmd['command'], arglist, ret_type, middle_mode))
+    if middle_mode:
+        fdecl.write('%s;\n' % gen_marshal_input_decl(cmd['command'], arglist, ret_type, middle_mode))
 
-        ret = gen_marshal_input(cmd['command'], arglist, ret_type, middle_mode) + "\n"
-        fdef.write(ret)
+    ret = gen_marshal_input(cmd['command'], arglist, ret_type, middle_mode) + "\n"
+    fdef.write(ret)
 
-    fdecl.write("\n#endif\n");
+fdecl.write("\n#endif\n");
 
-    if not middle_mode:
-        ret = gen_registry(commands)
-        fdef.write(ret)
+if not middle_mode:
+    ret = gen_registry(commands)
+    fdef.write(ret)
 
-    fdef.flush()
-    fdef.close()
-    fdecl.flush()
-    fdecl.close()
+fdef.flush()
+fdef.close()
+fdecl.flush()
+fdecl.close()
Signature · 1 line
1.9.3
#4 lore raw

PATCH 4/9 qapi: Factor parse_command_line() out of the generators

In reply to Markus Armbruster
---
 scripts/qapi-commands.py | 34 +++-------------------------------
 scripts/qapi-event.py    | 32 +-------------------------------
 scripts/qapi-types.py    | 36 ++++--------------------------------
 scripts/qapi-visit.py    | 35 ++++-------------------------------
 scripts/qapi.py          | 40 ++++++++++++++++++++++++++++++++++++++++
 5 files changed, 52 insertions(+), 125 deletions(-)
scripts/qapi-commands.py +3 -31
index c94a19b..2889877 100644
@@ -15,9 +15,7 @@
 from ordereddict import OrderedDict
 from qapi import *
 import re
-import sys
 import os
-import getopt
 import errno
 
 def generate_command_decl(name, args, ret_type):
@@ -376,42 +374,16 @@ def gen_command_def_prologue(prefix="", proxy=False):
         ret += '#include "%sqmp-commands.h"' % prefix
     return ret + "\n\n"
 
-
-try:
-    opts, args = getopt.gnu_getopt(sys.argv[1:], "chp:i:o:m",
-                                   ["source", "header", "prefix=",
-                                    "input-file=", "output-dir=",
-                                    "middle"])
-except getopt.GetoptError, err:
-    print str(err)
-    sys.exit(1)
-
-output_dir = ""
-prefix = ""
 c_file = 'qmp-marshal.c'
 h_file = 'qmp-commands.h'
 middle_mode = False
 
-do_c = False
-do_h = False
+(input_file, output_dir, do_c, do_h, prefix, opts) = \
+    parse_command_line("m", ["middle"])
 
 for o, a in opts:
-    if o in ("-p", "--prefix"):
-        prefix = a
-    elif o in ("-i", "--input-file"):
-        input_file = a
-    elif o in ("-o", "--output-dir"):
-        output_dir = a + "/"
-    elif o in ("-m", "--middle"):
+    if o in ("-m", "--middle"):
         middle_mode = True
-    elif o in ("-c", "--source"):
-        do_c = True
-    elif o in ("-h", "--header"):
-        do_h = True
-
-if not do_c and not do_h:
-    do_c = True
-    do_h = True
 
 c_file = output_dir + prefix + c_file
 h_file = output_dir + prefix + h_file
scripts/qapi-event.py +1 -31
index 3e1f4cf..bc5ca4a 100644
@@ -11,9 +11,7 @@
 
 from ordereddict import OrderedDict
 from qapi import *
-import sys
 import os
-import getopt
 import errno
 
 def _generate_event_api_name(event_name, params):
@@ -219,38 +217,10 @@ const char *%(event_enum_name)s_lookup[] = {
 
 # Start the real job
 
-try:
-    opts, args = getopt.gnu_getopt(sys.argv[1:], "chp:i:o:",
-                                   ["source", "header", "prefix=",
-                                    "input-file=", "output-dir="])
-except getopt.GetoptError, err:
-    print str(err)
-    sys.exit(1)
-
-input_file = ""
-output_dir = ""
-prefix = ""
 c_file = 'qapi-event.c'
 h_file = 'qapi-event.h'
 
-do_c = False
-do_h = False
-
-for o, a in opts:
-    if o in ("-p", "--prefix"):
-        prefix = a
-    elif o in ("-i", "--input-file"):
-        input_file = a
-    elif o in ("-o", "--output-dir"):
-        output_dir = a + "/"
-    elif o in ("-c", "--source"):
-        do_c = True
-    elif o in ("-h", "--header"):
-        do_h = True
-
-if not do_c and not do_h:
-    do_c = True
-    do_h = True
+(input_file, output_dir, do_c, do_h, prefix, dummy) = parse_command_line()
 
 c_file = output_dir + prefix + c_file
 h_file = output_dir + prefix + h_file
scripts/qapi-types.py +4 -32
index 5665145..62044c1 100644
@@ -11,9 +11,7 @@
 
 from ordereddict import OrderedDict
 from qapi import *
-import sys
 import os
-import getopt
 import errno
 
 def generate_fwd_struct(name, members, builtin_type=False):
@@ -275,43 +273,17 @@ void qapi_free_%(name)s(%(c_type)s obj)
                 c_type=c_type(name), name=c_name(name))
     return ret
 
-
-try:
-    opts, args = getopt.gnu_getopt(sys.argv[1:], "chbp:i:o:",
-                                   ["source", "header", "builtins",
-                                    "prefix=", "input-file=", "output-dir="])
-except getopt.GetoptError, err:
-    print str(err)
-    sys.exit(1)
-
-output_dir = ""
-input_file = ""
-prefix = ""
 c_file = 'qapi-types.c'
 h_file = 'qapi-types.h'
-
-do_c = False
-do_h = False
 do_builtins = False
 
+(input_file, output_dir, do_c, do_h, prefix, opts) = \
+    parse_command_line("b", ["builtins"])
+
 for o, a in opts:
-    if o in ("-p", "--prefix"):
-        prefix = a
-    elif o in ("-i", "--input-file"):
-        input_file = a
-    elif o in ("-o", "--output-dir"):
-        output_dir = a + "/"
-    elif o in ("-c", "--source"):
-        do_c = True
-    elif o in ("-h", "--header"):
-        do_h = True
-    elif o in ("-b", "--builtins"):
+    if o in ("-b", "--builtins"):
         do_builtins = True
 
-if not do_c and not do_h:
-    do_c = True
-    do_h = True
-
 c_file = output_dir + prefix + c_file
 h_file = output_dir + prefix + h_file
 
scripts/qapi-visit.py +4 -31
index a16cc54..f3e31cc 100644
@@ -15,9 +15,7 @@
 from ordereddict import OrderedDict
 from qapi import *
 import re
-import sys
 import os
-import getopt
 import errno
 
 implicit_structs = []
@@ -377,42 +375,17 @@ void visit_type_%(name)s(Visitor *m, %(name)s *obj, const char *name, Error **er
 ''',
                  name=c_name(name))
 
-try:
-    opts, args = getopt.gnu_getopt(sys.argv[1:], "chbp:i:o:",
-                                   ["source", "header", "builtins", "prefix=",
-                                    "input-file=", "output-dir="])
-except getopt.GetoptError, err:
-    print str(err)
-    sys.exit(1)
-
-input_file = ""
-output_dir = ""
-prefix = ""
 c_file = 'qapi-visit.c'
 h_file = 'qapi-visit.h'
-
-do_c = False
-do_h = False
 do_builtins = False
 
+(input_file, output_dir, do_c, do_h, prefix, opts) = \
+    parse_command_line("b", ["builtins"])
+
 for o, a in opts:
-    if o in ("-p", "--prefix"):
-        prefix = a
-    elif o in ("-i", "--input-file"):
-        input_file = a
-    elif o in ("-o", "--output-dir"):
-        output_dir = a + "/"
-    elif o in ("-c", "--source"):
-        do_c = True
-    elif o in ("-h", "--header"):
-        do_h = True
-    elif o in ("-b", "--builtins"):
+    if o in ("-b", "--builtins"):
         do_builtins = True
 
-if not do_c and not do_h:
-    do_c = True
-    do_h = True
-
 c_file = output_dir + prefix + c_file
 h_file = output_dir + prefix + h_file
 
scripts/qapi.py +40 -0
index b69600b..d90a538 100644
@@ -13,6 +13,7 @@
 
 import re
 from ordereddict import OrderedDict
+import getopt
 import os
 import sys
 import string
@@ -960,3 +961,42 @@ def guardend(name):
 
 ''',
                  name=guardname(name))
+
+def parse_command_line(extra_options = "", extra_long_options = []):
+
+    try:
+        opts, args = getopt.gnu_getopt(sys.argv[1:],
+                                       "chp:i:o:" + extra_options,
+                                       ["source", "header", "prefix=",
+                                        "input-file=", "output-dir="]
+                                       + extra_long_options)
+    except getopt.GetoptError, err:
+        print str(err)
+        sys.exit(1)
+
+    output_dir = ""
+    prefix = ""
+    do_c = False
+    do_h = False
+    extra_opts = []
+
+    for oa in opts:
+        o, a = oa
+        if o in ("-p", "--prefix"):
+            prefix = a
+        elif o in ("-i", "--input-file"):
+            input_file = a
+        elif o in ("-o", "--output-dir"):
+            output_dir = a + "/"
+        elif o in ("-c", "--source"):
+            do_c = True
+        elif o in ("-h", "--header"):
+            do_h = True
+        else:
+            extra_opts.append(oa)
+
+    if not do_c and not do_h:
+        do_c = True
+        do_h = True
+
+    return (input_file, output_dir, do_c, do_h, prefix, extra_opts)
Signature · 1 line
1.9.3
#12 lore raw

PATCH 9/9 qapi: Inline gen_command_decl_prologue(), gen_command_def_prologue()

In reply to Markus Armbruster
---
 scripts/qapi-commands.py | 58 ++++++++++++++++++++----------------------------
 1 file changed, 24 insertions(+), 34 deletions(-)
scripts/qapi-commands.py +24 -34
index c3e420e..1c1d3aa 100644
@@ -309,36 +309,6 @@ qapi_init(qmp_init_marshal);
                 registry=registry.rstrip())
     return ret
 
-def gen_command_decl_prologue(prefix=""):
-    ret = mcgen('''
-#include "%(prefix)sqapi-types.h"
-#include "qapi/qmp/qdict.h"
-#include "qapi/error.h"
-
-''',
-                 prefix=prefix)
-    return ret
-
-def gen_command_def_prologue(prefix="", proxy=False):
-    ret = mcgen('''
-#include "qemu-common.h"
-#include "qemu/module.h"
-#include "qapi/qmp/qerror.h"
-#include "qapi/qmp/types.h"
-#include "qapi/qmp/dispatch.h"
-#include "qapi/visitor.h"
-#include "qapi/qmp-output-visitor.h"
-#include "qapi/qmp-input-visitor.h"
-#include "qapi/dealloc-visitor.h"
-#include "%(prefix)sqapi-types.h"
-#include "%(prefix)sqapi-visit.h"
-
-''',
-                prefix=prefix)
-    if not proxy:
-        ret += '#include "%sqmp-commands.h"' % prefix
-    return ret + "\n\n"
-
 middle_mode = False
 
 (input_file, output_dir, do_c, do_h, prefix, opts) = \
@@ -385,10 +355,30 @@ h_comment = '''
                             'qmp-marshal.c', 'qmp-commands.h',
                             c_comment, h_comment)
 
-ret = gen_command_decl_prologue(prefix=prefix)
-fdecl.write(ret)
-ret = gen_command_def_prologue(prefix=prefix)
-fdef.write(ret)
+fdef.write(mcgen('''
+#include "qemu-common.h"
+#include "qemu/module.h"
+#include "qapi/qmp/qerror.h"
+#include "qapi/qmp/types.h"
+#include "qapi/qmp/dispatch.h"
+#include "qapi/visitor.h"
+#include "qapi/qmp-output-visitor.h"
+#include "qapi/qmp-input-visitor.h"
+#include "qapi/dealloc-visitor.h"
+#include "%(prefix)sqapi-types.h"
+#include "%(prefix)sqapi-visit.h"
+#include "%(prefix)sqmp-commands.h"
+
+''',
+                prefix=prefix))
+
+fdecl.write(mcgen('''
+#include "%(prefix)sqapi-types.h"
+#include "qapi/qmp/qdict.h"
+#include "qapi/error.h"
+
+''',
+                 prefix=prefix))
 
 for cmd in commands:
     arglist = []
Signature · 1 line
1.9.3
#2 lore raw

PATCH 2/9 qapi: qapi-event.py option -b does nothing, drop it

In reply to Markus Armbruster
---
 Makefile              | 2 +-
 scripts/qapi-event.py | 7 ++-----
 2 files changed, 3 insertions(+), 6 deletions(-)
Makefile +1 -1
index f032158..bfa5dab 100644
@@ -273,7 +273,7 @@ $(qapi-modules) $(SRC_PATH)/scripts/qapi-visit.py $(qapi-py)
 qapi-event.c qapi-event.h :\
 $(qapi-modules) $(SRC_PATH)/scripts/qapi-event.py $(qapi-py)
 	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-event.py \
-		$(gen-out-type) -o "." -b -i $<, \
+		$(gen-out-type) -o "." -i $<, \
 		"  GEN   $@")
 qmp-commands.h qmp-marshal.c :\
 $(qapi-modules) $(SRC_PATH)/scripts/qapi-commands.py $(qapi-py)
scripts/qapi-event.py +2 -5
index a7e0033..3e1f4cf 100644
@@ -220,8 +220,8 @@ const char *%(event_enum_name)s_lookup[] = {
 # Start the real job
 
 try:
-    opts, args = getopt.gnu_getopt(sys.argv[1:], "chbp:i:o:",
-                                   ["source", "header", "builtins", "prefix=",
+    opts, args = getopt.gnu_getopt(sys.argv[1:], "chp:i:o:",
+                                   ["source", "header", "prefix=",
                                     "input-file=", "output-dir="])
 except getopt.GetoptError, err:
     print str(err)
@@ -235,7 +235,6 @@ h_file = 'qapi-event.h'
 
 do_c = False
 do_h = False
-do_builtins = False
 
 for o, a in opts:
     if o in ("-p", "--prefix"):
@@ -248,8 +247,6 @@ for o, a in opts:
         do_c = True
     elif o in ("-h", "--header"):
         do_h = True
-    elif o in ("-b", "--builtins"):
-        do_builtins = True
 
 if not do_c and not do_h:
     do_c = True
Signature · 1 line
1.9.3
#8 lore raw

PATCH 6/9 qapi: Turn generators' mandatory option -i into an argument

In reply to Markus Armbruster

Mandatory option is silly, and the error handling is missing: the programs crash when -i isn't supplied. Make it an argument, and check it properly.

---
 Makefile               | 14 +++++++-------
 docs/qapi-code-gen.txt | 10 +++++-----
 scripts/qapi.py        | 12 +++++-------
 tests/Makefile         |  8 ++++----
 4 files changed, 21 insertions(+), 23 deletions(-)
Makefile +7 -7
index bfa5dab..d945804 100644
@@ -243,17 +243,17 @@ qapi-py = $(SRC_PATH)/scripts/qapi.py $(SRC_PATH)/scripts/ordereddict.py
 qga/qapi-generated/qga-qapi-types.c qga/qapi-generated/qga-qapi-types.h :\
 $(SRC_PATH)/qga/qapi-schema.json $(SRC_PATH)/scripts/qapi-types.py $(qapi-py)
 	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py \
-		$(gen-out-type) -o qga/qapi-generated -p "qga-" -i $<, \
+		$(gen-out-type) -o qga/qapi-generated -p "qga-" $<, \
 		"  GEN   $@")
 qga/qapi-generated/qga-qapi-visit.c qga/qapi-generated/qga-qapi-visit.h :\
 $(SRC_PATH)/qga/qapi-schema.json $(SRC_PATH)/scripts/qapi-visit.py $(qapi-py)
 	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py \
-		$(gen-out-type) -o qga/qapi-generated -p "qga-" -i $<, \
+		$(gen-out-type) -o qga/qapi-generated -p "qga-" $<, \
 		"  GEN   $@")
 qga/qapi-generated/qga-qmp-commands.h qga/qapi-generated/qga-qmp-marshal.c :\
 $(SRC_PATH)/qga/qapi-schema.json $(SRC_PATH)/scripts/qapi-commands.py $(qapi-py)
 	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py \
-		$(gen-out-type) -o qga/qapi-generated -p "qga-" -i $<, \
+		$(gen-out-type) -o qga/qapi-generated -p "qga-" $<, \
 		"  GEN   $@")
 
 qapi-modules = $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi/common.json \
@@ -263,22 +263,22 @@ qapi-modules = $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi/common.json \
 qapi-types.c qapi-types.h :\
 $(qapi-modules) $(SRC_PATH)/scripts/qapi-types.py $(qapi-py)
 	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py \
-		$(gen-out-type) -o "." -b -i $<, \
+		$(gen-out-type) -o "." -b $<, \
 		"  GEN   $@")
 qapi-visit.c qapi-visit.h :\
 $(qapi-modules) $(SRC_PATH)/scripts/qapi-visit.py $(qapi-py)
 	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py \
-		$(gen-out-type) -o "." -b -i $<, \
+		$(gen-out-type) -o "." -b $<, \
 		"  GEN   $@")
 qapi-event.c qapi-event.h :\
 $(qapi-modules) $(SRC_PATH)/scripts/qapi-event.py $(qapi-py)
 	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-event.py \
-		$(gen-out-type) -o "." -i $<, \
+		$(gen-out-type) -o "." $<, \
 		"  GEN   $@")
 qmp-commands.h qmp-marshal.c :\
 $(qapi-modules) $(SRC_PATH)/scripts/qapi-commands.py $(qapi-py)
 	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py \
-		$(gen-out-type) -o "." -m -i $<, \
+		$(gen-out-type) -o "." -m $<, \
 		"  GEN   $@")
 
 QGALIB_GEN=$(addprefix qga/qapi-generated/, qga-qapi-types.h qga-qapi-visit.h qga-qmp-commands.h)
docs/qapi-code-gen.txt +5 -5
index 269a1f3..3f0522e 100644
@@ -536,7 +536,7 @@ created code.
 Example:
 
     $ python scripts/qapi-types.py --output-dir="qapi-generated" \
-    --prefix="example-" --input-file=example-schema.json
+    --prefix="example-" example-schema.json
     $ cat qapi-generated/example-qapi-types.c
 [Uninteresting stuff omitted...]
 
@@ -623,7 +623,7 @@ $(prefix)qapi-visit.h: declarations for previously mentioned visitor
 Example:
 
     $ python scripts/qapi-visit.py --output-dir="qapi-generated"
-    --prefix="example-" --input-file=example-schema.json
+    --prefix="example-" example-schema.json
     $ cat qapi-generated/example-qapi-visit.c
 [Uninteresting stuff omitted...]
 
@@ -681,7 +681,7 @@ Example:
         error_propagate(errp, err);
     }
     $ python scripts/qapi-commands.py --output-dir="qapi-generated" \
-    --prefix="example-" --input-file=example-schema.json
+    --prefix="example-" example-schema.json
     $ cat qapi-generated/example-qapi-visit.h
 [Uninteresting stuff omitted...]
 
@@ -715,7 +715,7 @@ $(prefix)qmp-commands.h: Function prototypes for the QMP commands
 Example:
 
     $ python scripts/qapi-commands.py --output-dir="qapi-generated"
-    --prefix="example-" --input-file=example-schema.json
+    --prefix="example-" example-schema.json
     $ cat qapi-generated/example-qmp-marshal.c
 [Uninteresting stuff omitted...]
 
@@ -806,7 +806,7 @@ $(prefix)qapi-event.c - Implementation of functions to send an event
 Example:
 
     $ python scripts/qapi-event.py --output-dir="qapi-generated"
-    --prefix="example-" --input-file=example-schema.json
+    --prefix="example-" example-schema.json
     $ cat qapi-generated/example-qapi-event.c
 [Uninteresting stuff omitted...]
 
scripts/qapi.py +5 -7
index 5807476..79d1e52 100644
@@ -966,10 +966,9 @@ def parse_command_line(extra_options = "", extra_long_options = []):
 
     try:
         opts, args = getopt.gnu_getopt(sys.argv[1:],
-                                       "chp:i:o:" + extra_options,
+                                       "chp:o:" + extra_options,
                                        ["source", "header", "prefix=",
-                                        "input-file=", "output-dir="]
-                                       + extra_long_options)
+                                        "output-dir="] + extra_long_options)
     except getopt.GetoptError, err:
         print >>sys.stderr, "%s: %s" % (sys.argv[0], str(err))
         sys.exit(1)
@@ -984,8 +983,6 @@ def parse_command_line(extra_options = "", extra_long_options = []):
         o, a = oa
         if o in ("-p", "--prefix"):
             prefix = a
-        elif o in ("-i", "--input-file"):
-            input_file = a
         elif o in ("-o", "--output-dir"):
             output_dir = a + "/"
         elif o in ("-c", "--source"):
@@ -999,8 +996,9 @@ def parse_command_line(extra_options = "", extra_long_options = []):
         do_c = True
         do_h = True
 
-    if len(args) != 0:
-        print >>sys.stderr, "%s: too many arguments"% sys.argv[0]
+    if len(args) != 1:
+        print >>sys.stderr, "%s: need exactly one argument" % sys.argv[0]
         sys.exit(1)
+    input_file = args[0]
 
     return (input_file, output_dir, do_c, do_h, prefix, extra_opts)
tests/Makefile +4 -4
index 6d2f2e5..729b969 100644
@@ -303,22 +303,22 @@ tests/test-vmstate$(EXESUF): tests/test-vmstate.o \
 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-" -i $<, \
+		$(gen-out-type) -o tests -p "test-" $<, \
 		"  GEN   $@")
 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 \
-		$(gen-out-type) -o tests -p "test-" -i $<, \
+		$(gen-out-type) -o tests -p "test-" $<, \
 		"  GEN   $@")
 tests/test-qmp-commands.h tests/test-qmp-marshal.c :\
 $(SRC_PATH)/tests/qapi-schema/qapi-schema-test.json $(SRC_PATH)/scripts/qapi-commands.py $(qapi-py)
 	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py \
-		$(gen-out-type) -o tests -p "test-" -i $<, \
+		$(gen-out-type) -o tests -p "test-" $<, \
 		"  GEN   $@")
 tests/test-qapi-event.c tests/test-qapi-event.h :\
 $(SRC_PATH)/tests/qapi-schema/qapi-schema-test.json $(SRC_PATH)/scripts/qapi-event.py $(qapi-py)
 	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-event.py \
-		$(gen-out-type) -o tests -p "test-" -i $<, \
+		$(gen-out-type) -o tests -p "test-" $<, \
 		"  GEN   $@")
 
 tests/test-string-output-visitor$(EXESUF): tests/test-string-output-visitor.o $(test-qapi-obj-y) libqemuutil.a libqemustub.a
Signature · 1 line
1.9.3
#10 lore raw

PATCH 7/9 qapi: Factor open_output(), close_output() out of generators

In reply to Markus Armbruster
---
 scripts/qapi-commands.py | 101 +++++++++++++++++------------------------------
 scripts/qapi-event.py    |  85 ++++++++++++---------------------------
 scripts/qapi-types.py    |  81 ++++++++++++-------------------------
 scripts/qapi-visit.py    | 101 ++++++++++++++++-------------------------------
 scripts/qapi.py          |  50 +++++++++++++++++++++++
 5 files changed, 172 insertions(+), 246 deletions(-)
scripts/qapi-commands.py +37 -64
index 2889877..c3e420e 100644
@@ -15,8 +15,6 @@
 from ordereddict import OrderedDict
 from qapi import *
 import re
-import os
-import errno
 
 def generate_command_decl(name, args, ret_type):
     arglist=""
@@ -311,51 +309,18 @@ qapi_init(qmp_init_marshal);
                 registry=registry.rstrip())
     return ret
 
-def gen_command_decl_prologue(header, guard, prefix=""):
+def gen_command_decl_prologue(prefix=""):
     ret = mcgen('''
-/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */
-
-/*
- * schema-defined QAPI function prototypes
- *
- * Copyright IBM, Corp. 2011
- *
- * Authors:
- *  Anthony Liguori   <[email protected]>
- *
- * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
- * See the COPYING.LIB file in the top-level directory.
- *
- */
-
-#ifndef %(guard)s
-#define %(guard)s
-
 #include "%(prefix)sqapi-types.h"
 #include "qapi/qmp/qdict.h"
 #include "qapi/error.h"
 
 ''',
-                 header=basename(header), guard=guardname(header), prefix=prefix)
+                 prefix=prefix)
     return ret
 
 def gen_command_def_prologue(prefix="", proxy=False):
     ret = mcgen('''
-/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */
-
-/*
- * schema-defined QMP->QAPI command dispatch
- *
- * Copyright IBM, Corp. 2011
- *
- * Authors:
- *  Anthony Liguori   <[email protected]>
- *
- * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
- * See the COPYING.LIB file in the top-level directory.
- *
- */
-
 #include "qemu-common.h"
 #include "qemu/module.h"
 #include "qapi/qmp/qerror.h"
@@ -374,8 +339,6 @@ def gen_command_def_prologue(prefix="", proxy=False):
         ret += '#include "%sqmp-commands.h"' % prefix
     return ret + "\n\n"
 
-c_file = 'qmp-marshal.c'
-h_file = 'qmp-commands.h'
 middle_mode = False
 
 (input_file, output_dir, do_c, do_h, prefix, opts) = \
@@ -385,29 +348,44 @@ for o, a in opts:
     if o in ("-m", "--middle"):
         middle_mode = True
 
-c_file = output_dir + prefix + c_file
-h_file = output_dir + prefix + h_file
-
-def maybe_open(really, name, opt):
-    if really:
-        return open(name, opt)
-    else:
-        import StringIO
-        return StringIO.StringIO()
-
-try:
-    os.makedirs(output_dir)
-except os.error, e:
-    if e.errno != errno.EEXIST:
-        raise
-
 exprs = parse_schema(input_file)
 commands = filter(lambda expr: expr.has_key('command'), exprs)
 commands = filter(lambda expr: not expr.has_key('gen'), commands)
 
-fdecl = maybe_open(do_h, h_file, 'w')
-fdef = maybe_open(do_c, c_file, 'w')
-ret = gen_command_decl_prologue(header=basename(h_file), guard=guardname(h_file), prefix=prefix)
+c_comment = '''
+/*
+ * schema-defined QMP->QAPI command dispatch
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ *  Anthony Liguori   <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+'''
+h_comment = '''
+/*
+ * schema-defined QAPI function prototypes
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ *  Anthony Liguori   <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+'''
+
+(fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix,
+                            'qmp-marshal.c', 'qmp-commands.h',
+                            c_comment, h_comment)
+
+ret = gen_command_decl_prologue(prefix=prefix)
 fdecl.write(ret)
 ret = gen_command_def_prologue(prefix=prefix)
 fdef.write(ret)
@@ -431,13 +409,8 @@ for cmd in commands:
     ret = gen_marshal_input(cmd['command'], arglist, ret_type, middle_mode) + "\n"
     fdef.write(ret)
 
-fdecl.write("\n#endif\n");
-
 if not middle_mode:
     ret = gen_registry(commands)
     fdef.write(ret)
 
-fdef.flush()
-fdef.close()
-fdecl.flush()
-fdecl.close()
+close_output(fdef, fdecl)
scripts/qapi-event.py +25 -60

122 lines not on this page · raw message

scripts/qapi-types.py +25 -56

118 lines not on this page · raw message

scripts/qapi-visit.py +35 -66

133 lines not on this page · raw message

scripts/qapi.py +50 -0

59 lines not on this page · raw message

Signature · 1 line
1.9.3
#13 lore raw
In reply to Markus Armbruster
Quoted 9 lines · Markus Armbruster

You've seen these patches before, in "[PATCH RFC 00/19] qapi: QMP introspection". Eric has pulled a few into "[PATCH v2 0/3] parse 'null' literal in QMP" and "[PATCH v3 00/14] Fix qapi mangling of downstream names". This series has the remaining ones, except for "[PATCH RFC 19/19] qapi: New QMP command query-schema for QMP schema introspection", which isn't ready.

Based on Luiz's latest pull request plus Eric's "Fix qapi mangling of downstream names".

Now at v4; there might be some rebasing needed, but let's get this in soon.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#6 lore raw

Re: [Qemu-devel] [PATCH 5/9] qapi: Fix generators to report command line errors decently

In reply to Markus Armbruster
Quoted 11 lines · Markus Armbruster

Report to stderr, prefix with the program name. Also reject extra arguments.

---
 scripts/qapi.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

scripts/qapi.py def parse_command_line(extra_options = "", extra_long_options = []): · line 1003

Quoted 5 lines
scripts/qapi.py +2 -0
@@ -999,4 +999,8 @@ def parse_command_line(extra_options = "", extra_long_options = []):
         do_c = True
         do_h = True
 
+    if len(args) != 0:
+        print >>sys.stderr, "%s: too many arguments"% sys.argv[0]

Spacing on both sides of %? Or even:

print >>sys.stderr, sys.argv[0] + ": too many arguments"

but trivial enough to keep R-b whatever you decide.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Reviewed-by on v1 6/9
#9 lore raw

Re: [Qemu-devel] [PATCH 6/9] qapi: Turn generators' mandatory option -i into an argument

In reply to Markus Armbruster
Quoted 14 lines · Markus Armbruster

Mandatory option is silly, and the error handling is missing: the programs crash when -i isn't supplied. Make it an argument, and check it properly.

---
 Makefile               | 14 +++++++-------
 docs/qapi-code-gen.txt | 10 +++++-----
 scripts/qapi.py        | 12 +++++-------
 tests/Makefile         |  8 ++++----
 4 files changed, 21 insertions(+), 23 deletions(-)

scripts/qapi.py def parse_command_line(extra_options = "", extra_long_options = []): · line 1000

Quoted 7 lines
scripts/qapi.py +2 -2
@@ -999,8 +996,9 @@ def parse_command_line(extra_options = "", extra_long_options = []):
         do_c = True
         do_h = True
 
-    if len(args) != 0:
-        print >>sys.stderr, "%s: too many arguments"% sys.argv[0]
+    if len(args) != 1:
+        print >>sys.stderr, "%s: need exactly one argument" % sys.argv[0]

Hmm, might be affected by resolution of my review comments on 5/9; but shouldn't affect the review.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#7 lore raw

Re: [Qemu-devel] [PATCH 5/9] qapi: Fix generators to report command line errors decently

In reply to Eric Blake
Quoted 15 lines · Eric Blake
Quoted 14 lines · Markus Armbruster

Report to stderr, prefix with the program name. Also reject extra arguments.

---
 scripts/qapi.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
scripts/qapi.py +0 -0
@@ -999,4 +999,8 @@ def parse_command_line(extra_options = "", extra_long_options = []):
         do_c = True
         do_h = True
 
Quoted 8 lines

scripts/qapi.py def parse_command_line(extra_options = "", extra_long_options = []): · line 1003

Quoted 2 lines
scripts/qapi.py +2 -0
+    if len(args) != 0:
+        print >>sys.stderr, "%s: too many arguments"% sys.argv[0]

Spacing on both sides of %? Or even:

print >>sys.stderr, sys.argv[0] + ": too many arguments"

but trivial enough to keep R-b whatever you decide.

Spacing tidied up, thanks!

author Applied
#14 lore raw
In reply to Eric Blake
Quoted 8 lines · Eric Blake
Quoted 7 lines · Markus Armbruster

You've seen these patches before, in "[PATCH RFC 00/19] qapi: QMP introspection". Eric has pulled a few into "[PATCH v2 0/3] parse 'null' literal in QMP" and "[PATCH v3 00/14] Fix qapi mangling of downstream names". This series has the remaining ones, except for "[PATCH RFC 19/19] qapi: New QMP command query-schema for QMP schema introspection", which isn't ready.

Quoted 4 lines
Quoted 2 lines

Based on Luiz's latest pull request plus Eric's "Fix qapi mangling of downstream names".

Now at v4; there might be some rebasing needed, but let's get this in soon.

We're in luck, it rebased cleanly.

Applied to my qapi-next branch, thanks for the review!