* [Qemu-devel] [PATCH 1/9] tests: Add missing dependencies on $(qapi-py)
2015-05-11 7:24 [Qemu-devel] [PATCH 0/9] qapi: Mostly generator cleanups Markus Armbruster
@ 2015-05-11 7:24 ` Markus Armbruster
2015-05-11 7:24 ` [Qemu-devel] [PATCH 2/9] qapi: qapi-event.py option -b does nothing, drop it Markus Armbruster
` (8 subsequent siblings)
9 siblings, 0 replies; 15+ messages in thread
From: Markus Armbruster @ 2015-05-11 7:24 UTC (permalink / raw)
To: qemu-devel; +Cc: mdroth
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
tests/Makefile | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/tests/Makefile b/tests/Makefile
index 666aee2..6d2f2e5 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -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 $@")
--
1.9.3
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [Qemu-devel] [PATCH 2/9] qapi: qapi-event.py option -b does nothing, drop it
2015-05-11 7:24 [Qemu-devel] [PATCH 0/9] qapi: Mostly generator cleanups Markus Armbruster
2015-05-11 7:24 ` [Qemu-devel] [PATCH 1/9] tests: Add missing dependencies on $(qapi-py) Markus Armbruster
@ 2015-05-11 7:24 ` Markus Armbruster
2015-05-11 7:24 ` [Qemu-devel] [PATCH 3/9] qapi: qapi-commands.py option --type is unused, " Markus Armbruster
` (7 subsequent siblings)
9 siblings, 0 replies; 15+ messages in thread
From: Markus Armbruster @ 2015-05-11 7:24 UTC (permalink / raw)
To: qemu-devel; +Cc: mdroth
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
Makefile | 2 +-
scripts/qapi-event.py | 7 ++-----
2 files changed, 3 insertions(+), 6 deletions(-)
diff --git a/Makefile b/Makefile
index f032158..bfa5dab 100644
--- a/Makefile
+++ b/Makefile
@@ -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)
diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py
index a7e0033..3e1f4cf 100644
--- a/scripts/qapi-event.py
+++ b/scripts/qapi-event.py
@@ -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
--
1.9.3
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [Qemu-devel] [PATCH 3/9] qapi: qapi-commands.py option --type is unused, drop it
2015-05-11 7:24 [Qemu-devel] [PATCH 0/9] qapi: Mostly generator cleanups Markus Armbruster
2015-05-11 7:24 ` [Qemu-devel] [PATCH 1/9] tests: Add missing dependencies on $(qapi-py) Markus Armbruster
2015-05-11 7:24 ` [Qemu-devel] [PATCH 2/9] qapi: qapi-event.py option -b does nothing, drop it Markus Armbruster
@ 2015-05-11 7:24 ` Markus Armbruster
2015-05-11 7:24 ` [Qemu-devel] [PATCH 4/9] qapi: Factor parse_command_line() out of the generators Markus Armbruster
` (6 subsequent siblings)
9 siblings, 0 replies; 15+ messages in thread
From: Markus Armbruster @ 2015-05-11 7:24 UTC (permalink / raw)
To: qemu-devel; +Cc: mdroth
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.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
scripts/qapi-commands.py | 66 +++++++++++++++++++++++-------------------------
1 file changed, 31 insertions(+), 35 deletions(-)
diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py
index 0a1d636..c94a19b 100644
--- a/scripts/qapi-commands.py
+++ b/scripts/qapi-commands.py
@@ -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()
--
1.9.3
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [Qemu-devel] [PATCH 4/9] qapi: Factor parse_command_line() out of the generators
2015-05-11 7:24 [Qemu-devel] [PATCH 0/9] qapi: Mostly generator cleanups Markus Armbruster
` (2 preceding siblings ...)
2015-05-11 7:24 ` [Qemu-devel] [PATCH 3/9] qapi: qapi-commands.py option --type is unused, " Markus Armbruster
@ 2015-05-11 7:24 ` Markus Armbruster
2015-05-11 7:24 ` [Qemu-devel] [PATCH 5/9] qapi: Fix generators to report command line errors decently Markus Armbruster
` (5 subsequent siblings)
9 siblings, 0 replies; 15+ messages in thread
From: Markus Armbruster @ 2015-05-11 7:24 UTC (permalink / raw)
To: qemu-devel; +Cc: mdroth
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
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(-)
diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py
index c94a19b..2889877 100644
--- a/scripts/qapi-commands.py
+++ b/scripts/qapi-commands.py
@@ -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
diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py
index 3e1f4cf..bc5ca4a 100644
--- a/scripts/qapi-event.py
+++ b/scripts/qapi-event.py
@@ -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
diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index 5665145..62044c1 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -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
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index a16cc54..f3e31cc 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -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
diff --git a/scripts/qapi.py b/scripts/qapi.py
index b69600b..d90a538 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -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)
--
1.9.3
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [Qemu-devel] [PATCH 5/9] qapi: Fix generators to report command line errors decently
2015-05-11 7:24 [Qemu-devel] [PATCH 0/9] qapi: Mostly generator cleanups Markus Armbruster
` (3 preceding siblings ...)
2015-05-11 7:24 ` [Qemu-devel] [PATCH 4/9] qapi: Factor parse_command_line() out of the generators Markus Armbruster
@ 2015-05-11 7:24 ` Markus Armbruster
2015-05-14 15:16 ` Eric Blake
2015-05-11 7:24 ` [Qemu-devel] [PATCH 6/9] qapi: Turn generators' mandatory option -i into an argument Markus Armbruster
` (4 subsequent siblings)
9 siblings, 1 reply; 15+ messages in thread
From: Markus Armbruster @ 2015-05-11 7:24 UTC (permalink / raw)
To: qemu-devel; +Cc: mdroth
Report to stderr, prefix with the program name. Also reject
extra arguments.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
scripts/qapi.py | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/scripts/qapi.py b/scripts/qapi.py
index d90a538..5807476 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -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)
--
1.9.3
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [Qemu-devel] [PATCH 5/9] qapi: Fix generators to report command line errors decently
2015-05-11 7:24 ` [Qemu-devel] [PATCH 5/9] qapi: Fix generators to report command line errors decently Markus Armbruster
@ 2015-05-14 15:16 ` Eric Blake
2015-05-14 16:40 ` Markus Armbruster
0 siblings, 1 reply; 15+ messages in thread
From: Eric Blake @ 2015-05-14 15:16 UTC (permalink / raw)
To: Markus Armbruster, qemu-devel; +Cc: mdroth
[-- Attachment #1: Type: text/plain, Size: 845 bytes --]
On 05/11/2015 01:24 AM, Markus Armbruster wrote:
> Report to stderr, prefix with the program name. Also reject
> extra arguments.
>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> Reviewed-by: Eric Blake <eblake@redhat.com>
> ---
> scripts/qapi.py | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> @@ -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.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [Qemu-devel] [PATCH 5/9] qapi: Fix generators to report command line errors decently
2015-05-14 15:16 ` Eric Blake
@ 2015-05-14 16:40 ` Markus Armbruster
0 siblings, 0 replies; 15+ messages in thread
From: Markus Armbruster @ 2015-05-14 16:40 UTC (permalink / raw)
To: Eric Blake; +Cc: qemu-devel, mdroth
Eric Blake <eblake@redhat.com> writes:
> On 05/11/2015 01:24 AM, Markus Armbruster wrote:
>> Report to stderr, prefix with the program name. Also reject
>> extra arguments.
>>
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> Reviewed-by: Eric Blake <eblake@redhat.com>
>> ---
>> scripts/qapi.py | 6 +++++-
>> 1 file changed, 5 insertions(+), 1 deletion(-)
>>
>
>> @@ -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.
Spacing tidied up, thanks!
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Qemu-devel] [PATCH 6/9] qapi: Turn generators' mandatory option -i into an argument
2015-05-11 7:24 [Qemu-devel] [PATCH 0/9] qapi: Mostly generator cleanups Markus Armbruster
` (4 preceding siblings ...)
2015-05-11 7:24 ` [Qemu-devel] [PATCH 5/9] qapi: Fix generators to report command line errors decently Markus Armbruster
@ 2015-05-11 7:24 ` Markus Armbruster
2015-05-14 15:22 ` Eric Blake
2015-05-11 7:24 ` [Qemu-devel] [PATCH 7/9] qapi: Factor open_output(), close_output() out of generators Markus Armbruster
` (3 subsequent siblings)
9 siblings, 1 reply; 15+ messages in thread
From: Markus Armbruster @ 2015-05-11 7:24 UTC (permalink / raw)
To: qemu-devel; +Cc: mdroth
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.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
Makefile | 14 +++++++-------
docs/qapi-code-gen.txt | 10 +++++-----
scripts/qapi.py | 12 +++++-------
tests/Makefile | 8 ++++----
4 files changed, 21 insertions(+), 23 deletions(-)
diff --git a/Makefile b/Makefile
index bfa5dab..d945804 100644
--- a/Makefile
+++ b/Makefile
@@ -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)
diff --git a/docs/qapi-code-gen.txt b/docs/qapi-code-gen.txt
index 269a1f3..3f0522e 100644
--- a/docs/qapi-code-gen.txt
+++ b/docs/qapi-code-gen.txt
@@ -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...]
diff --git a/scripts/qapi.py b/scripts/qapi.py
index 5807476..79d1e52 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -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)
diff --git a/tests/Makefile b/tests/Makefile
index 6d2f2e5..729b969 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -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
--
1.9.3
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [Qemu-devel] [PATCH 6/9] qapi: Turn generators' mandatory option -i into an argument
2015-05-11 7:24 ` [Qemu-devel] [PATCH 6/9] qapi: Turn generators' mandatory option -i into an argument Markus Armbruster
@ 2015-05-14 15:22 ` Eric Blake
0 siblings, 0 replies; 15+ messages in thread
From: Eric Blake @ 2015-05-14 15:22 UTC (permalink / raw)
To: Markus Armbruster, qemu-devel; +Cc: mdroth
[-- Attachment #1: Type: text/plain, Size: 1122 bytes --]
On 05/11/2015 01:24 AM, Markus Armbruster wrote:
> 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.
>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
> Makefile | 14 +++++++-------
> docs/qapi-code-gen.txt | 10 +++++-----
> scripts/qapi.py | 12 +++++-------
> tests/Makefile | 8 ++++----
> 4 files changed, 21 insertions(+), 23 deletions(-)
>
> @@ -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.
Reviewed-by: Eric Blake <eblake@redhat.com>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Qemu-devel] [PATCH 7/9] qapi: Factor open_output(), close_output() out of generators
2015-05-11 7:24 [Qemu-devel] [PATCH 0/9] qapi: Mostly generator cleanups Markus Armbruster
` (5 preceding siblings ...)
2015-05-11 7:24 ` [Qemu-devel] [PATCH 6/9] qapi: Turn generators' mandatory option -i into an argument Markus Armbruster
@ 2015-05-11 7:24 ` Markus Armbruster
2015-05-11 7:24 ` [Qemu-devel] [PATCH 8/9] qapi: Drop pointless flush() before close() Markus Armbruster
` (2 subsequent siblings)
9 siblings, 0 replies; 15+ messages in thread
From: Markus Armbruster @ 2015-05-11 7:24 UTC (permalink / raw)
To: qemu-devel; +Cc: mdroth
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
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(-)
diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py
index 2889877..c3e420e 100644
--- a/scripts/qapi-commands.py
+++ b/scripts/qapi-commands.py
@@ -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 <aliguori@us.ibm.com>
- *
- * 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 <aliguori@us.ibm.com>
- *
- * 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 <aliguori@us.ibm.com>
+ *
+ * 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 <aliguori@us.ibm.com>
+ *
+ * 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)
diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py
index bc5ca4a..56bc602 100644
--- a/scripts/qapi-event.py
+++ b/scripts/qapi-event.py
@@ -11,8 +11,6 @@
from ordereddict import OrderedDict
from qapi import *
-import os
-import errno
def _generate_event_api_name(event_name, params):
api_name = "void qapi_event_send_%s(" % c_name(event_name).lower();
@@ -214,36 +212,9 @@ const char *%(event_enum_name)s_lookup[] = {
''')
return ret
-
-# Start the real job
-
-c_file = 'qapi-event.c'
-h_file = 'qapi-event.h'
-
(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
-
-try:
- os.makedirs(output_dir)
-except os.error, e:
- if e.errno != errno.EEXIST:
- raise
-
-def maybe_open(really, name, opt):
- if really:
- return open(name, opt)
- else:
- import StringIO
- return StringIO.StringIO()
-
-fdef = maybe_open(do_c, c_file, 'w')
-fdecl = maybe_open(do_h, h_file, 'w')
-
-fdef.write(mcgen('''
-/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */
-
+c_comment = '''
/*
* schema-defined QAPI event functions
*
@@ -256,41 +227,43 @@ fdef.write(mcgen('''
* See the COPYING.LIB file in the top-level directory.
*
*/
+'''
+h_comment = '''
+/*
+ * schema-defined QAPI event functions
+ *
+ * Copyright (c) 2014 Wenchao Xia
+ *
+ * Authors:
+ * Wenchao Xia <wenchaoqemu@gmail.com>
+ *
+ * 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,
+ 'qapi-event.c', 'qapi-event.h',
+ c_comment, h_comment)
+
+fdef.write(mcgen('''
#include "qemu-common.h"
-#include "%(header)s"
+#include "%(prefix)sqapi-event.h"
#include "%(prefix)sqapi-visit.h"
#include "qapi/qmp-output-visitor.h"
#include "qapi/qmp-event.h"
''',
- prefix=prefix, header=basename(h_file)))
+ prefix=prefix))
fdecl.write(mcgen('''
-/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */
-
-/*
- * schema-defined QAPI event functions
- *
- * Copyright (c) 2014 Wenchao Xia
- *
- * Authors:
- * Wenchao Xia <wenchaoqemu@gmail.com>
- *
- * 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 "qapi/error.h"
#include "qapi/qmp/qdict.h"
#include "%(prefix)sqapi-types.h"
''',
- prefix=prefix, guard=guardname(h_file)))
+ prefix=prefix))
exprs = parse_schema(input_file)
@@ -323,12 +296,4 @@ fdecl.write(ret)
ret = generate_event_enum_lookup(event_enum_name, event_enum_strings)
fdef.write(ret)
-fdecl.write('''
-#endif
-''')
-
-fdecl.flush()
-fdecl.close()
-
-fdef.flush()
-fdef.close()
+close_output(fdef, fdecl)
diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index 62044c1..6bd0b13 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -11,8 +11,6 @@
from ordereddict import OrderedDict
from qapi import *
-import os
-import errno
def generate_fwd_struct(name, members, builtin_type=False):
if builtin_type:
@@ -273,8 +271,6 @@ void qapi_free_%(name)s(%(c_type)s obj)
c_type=c_type(name), name=c_name(name))
return ret
-c_file = 'qapi-types.c'
-h_file = 'qapi-types.h'
do_builtins = False
(input_file, output_dir, do_c, do_h, prefix, opts) = \
@@ -284,28 +280,7 @@ for o, a in opts:
if o in ("-b", "--builtins"):
do_builtins = True
-c_file = output_dir + prefix + c_file
-h_file = output_dir + prefix + h_file
-
-try:
- os.makedirs(output_dir)
-except os.error, e:
- if e.errno != errno.EEXIST:
- raise
-
-def maybe_open(really, name, opt):
- if really:
- return open(name, opt)
- else:
- import StringIO
- return StringIO.StringIO()
-
-fdef = maybe_open(do_c, c_file, 'w')
-fdecl = maybe_open(do_h, h_file, 'w')
-
-fdef.write(mcgen('''
-/* AUTOMATICALLY GENERATED, DO NOT MODIFY */
-
+c_comment = '''
/*
* deallocation functions for schema-defined QAPI types
*
@@ -319,37 +294,39 @@ fdef.write(mcgen('''
* See the COPYING.LIB file in the top-level directory.
*
*/
+'''
+h_comment = '''
+/*
+ * schema-defined QAPI types
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ * Anthony Liguori <aliguori@us.ibm.com>
+ *
+ * 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,
+ 'qapi-types.c', 'qapi-types.h',
+ c_comment, h_comment)
+
+fdef.write(mcgen('''
#include "qapi/dealloc-visitor.h"
#include "%(prefix)sqapi-types.h"
#include "%(prefix)sqapi-visit.h"
-''', prefix=prefix))
+''',
+ prefix=prefix))
fdecl.write(mcgen('''
-/* AUTOMATICALLY GENERATED, DO NOT MODIFY */
-
-/*
- * schema-defined QAPI types
- *
- * Copyright IBM, Corp. 2011
- *
- * Authors:
- * Anthony Liguori <aliguori@us.ibm.com>
- *
- * 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 <stdbool.h>
#include <stdint.h>
-''',
- guard=guardname(h_file)))
+'''))
exprs = parse_schema(input_file)
exprs = filter(lambda expr: not expr.has_key('gen'), exprs)
@@ -427,12 +404,4 @@ for expr in exprs:
continue
fdecl.write(ret)
-fdecl.write('''
-#endif
-''')
-
-fdecl.flush()
-fdecl.close()
-
-fdef.flush()
-fdef.close()
+close_output(fdef, fdecl)
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index f3e31cc..ba4be8d 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -15,8 +15,6 @@
from ordereddict import OrderedDict
from qapi import *
import re
-import os
-import errno
implicit_structs = []
@@ -375,8 +373,6 @@ void visit_type_%(name)s(Visitor *m, %(name)s *obj, const char *name, Error **er
''',
name=c_name(name))
-c_file = 'qapi-visit.c'
-h_file = 'qapi-visit.h'
do_builtins = False
(input_file, output_dir, do_c, do_h, prefix, opts) = \
@@ -386,70 +382,51 @@ for o, a in opts:
if o in ("-b", "--builtins"):
do_builtins = True
-c_file = output_dir + prefix + c_file
-h_file = output_dir + prefix + h_file
+c_comment = '''
+/*
+ * schema-defined QAPI visitor functions
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ * Anthony Liguori <aliguori@us.ibm.com>
+ *
+ * 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 visitor functions
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ * Anthony Liguori <aliguori@us.ibm.com>
+ *
+ * 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.
+ *
+ */
+'''
-try:
- os.makedirs(output_dir)
-except os.error, e:
- if e.errno != errno.EEXIST:
- raise
-
-def maybe_open(really, name, opt):
- if really:
- return open(name, opt)
- else:
- import StringIO
- return StringIO.StringIO()
-
-fdef = maybe_open(do_c, c_file, 'w')
-fdecl = maybe_open(do_h, h_file, 'w')
+(fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix,
+ 'qapi-visit.c', 'qapi-visit.h',
+ c_comment, h_comment)
fdef.write(mcgen('''
-/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */
-
-/*
- * schema-defined QAPI visitor functions
- *
- * Copyright IBM, Corp. 2011
- *
- * Authors:
- * Anthony Liguori <aliguori@us.ibm.com>
- *
- * 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 "%(header)s"
+#include "%(prefix)sqapi-visit.h"
''',
- header=basename(h_file)))
+ prefix = prefix))
fdecl.write(mcgen('''
-/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */
-
-/*
- * schema-defined QAPI visitor functions
- *
- * Copyright IBM, Corp. 2011
- *
- * Authors:
- * Anthony Liguori <aliguori@us.ibm.com>
- *
- * 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 "qapi/visitor.h"
#include "%(prefix)sqapi-types.h"
''',
- prefix=prefix, guard=guardname(h_file)))
+ prefix=prefix))
exprs = parse_schema(input_file)
@@ -505,12 +482,4 @@ for expr in exprs:
ret += generate_enum_declaration(expr['enum'], expr['data'])
fdecl.write(ret)
-fdecl.write('''
-#endif
-''')
-
-fdecl.flush()
-fdecl.close()
-
-fdef.flush()
-fdef.close()
+close_output(fdef, fdecl)
diff --git a/scripts/qapi.py b/scripts/qapi.py
index 79d1e52..1f68fa9 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -13,6 +13,7 @@
import re
from ordereddict import OrderedDict
+import errno
import getopt
import os
import sys
@@ -1002,3 +1003,52 @@ def parse_command_line(extra_options = "", extra_long_options = []):
input_file = args[0]
return (input_file, output_dir, do_c, do_h, prefix, extra_opts)
+
+def open_output(output_dir, do_c, do_h, prefix, c_file, h_file,
+ c_comment, h_comment):
+ c_file = output_dir + prefix + c_file
+ h_file = output_dir + prefix + h_file
+
+ try:
+ os.makedirs(output_dir)
+ except os.error, e:
+ if e.errno != errno.EEXIST:
+ raise
+
+ def maybe_open(really, name, opt):
+ if really:
+ return open(name, opt)
+ else:
+ import StringIO
+ return StringIO.StringIO()
+
+ fdef = maybe_open(do_c, c_file, 'w')
+ fdecl = maybe_open(do_h, h_file, 'w')
+
+ fdef.write(mcgen('''
+/* AUTOMATICALLY GENERATED, DO NOT MODIFY */
+%(comment)s
+''',
+ comment = c_comment))
+
+ fdecl.write(mcgen('''
+/* AUTOMATICALLY GENERATED, DO NOT MODIFY */
+%(comment)s
+#ifndef %(guard)s
+#define %(guard)s
+
+''',
+ comment = h_comment, guard = guardname(h_file)))
+
+ return (fdef, fdecl)
+
+def close_output(fdef, fdecl):
+ fdecl.write('''
+#endif
+''')
+
+ fdecl.flush()
+ fdecl.close()
+
+ fdef.flush()
+ fdef.close()
--
1.9.3
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [Qemu-devel] [PATCH 8/9] qapi: Drop pointless flush() before close()
2015-05-11 7:24 [Qemu-devel] [PATCH 0/9] qapi: Mostly generator cleanups Markus Armbruster
` (6 preceding siblings ...)
2015-05-11 7:24 ` [Qemu-devel] [PATCH 7/9] qapi: Factor open_output(), close_output() out of generators Markus Armbruster
@ 2015-05-11 7:24 ` Markus Armbruster
2015-05-11 7:24 ` [Qemu-devel] [PATCH 9/9] qapi: Inline gen_command_decl_prologue(), gen_command_def_prologue() Markus Armbruster
2015-05-14 15:14 ` [Qemu-devel] [PATCH 0/9] qapi: Mostly generator cleanups Eric Blake
9 siblings, 0 replies; 15+ messages in thread
From: Markus Armbruster @ 2015-05-11 7:24 UTC (permalink / raw)
To: qemu-devel; +Cc: mdroth
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
scripts/qapi.py | 4 ----
1 file changed, 4 deletions(-)
diff --git a/scripts/qapi.py b/scripts/qapi.py
index 1f68fa9..784212c 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -1046,9 +1046,5 @@ def close_output(fdef, fdecl):
fdecl.write('''
#endif
''')
-
- fdecl.flush()
fdecl.close()
-
- fdef.flush()
fdef.close()
--
1.9.3
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [Qemu-devel] [PATCH 9/9] qapi: Inline gen_command_decl_prologue(), gen_command_def_prologue()
2015-05-11 7:24 [Qemu-devel] [PATCH 0/9] qapi: Mostly generator cleanups Markus Armbruster
` (7 preceding siblings ...)
2015-05-11 7:24 ` [Qemu-devel] [PATCH 8/9] qapi: Drop pointless flush() before close() Markus Armbruster
@ 2015-05-11 7:24 ` Markus Armbruster
2015-05-14 15:14 ` [Qemu-devel] [PATCH 0/9] qapi: Mostly generator cleanups Eric Blake
9 siblings, 0 replies; 15+ messages in thread
From: Markus Armbruster @ 2015-05-11 7:24 UTC (permalink / raw)
To: qemu-devel; +Cc: mdroth
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
scripts/qapi-commands.py | 58 ++++++++++++++++++++----------------------------
1 file changed, 24 insertions(+), 34 deletions(-)
diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py
index c3e420e..1c1d3aa 100644
--- a/scripts/qapi-commands.py
+++ b/scripts/qapi-commands.py
@@ -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 = []
--
1.9.3
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [Qemu-devel] [PATCH 0/9] qapi: Mostly generator cleanups
2015-05-11 7:24 [Qemu-devel] [PATCH 0/9] qapi: Mostly generator cleanups Markus Armbruster
` (8 preceding siblings ...)
2015-05-11 7:24 ` [Qemu-devel] [PATCH 9/9] qapi: Inline gen_command_decl_prologue(), gen_command_def_prologue() Markus Armbruster
@ 2015-05-14 15:14 ` Eric Blake
2015-05-14 16:46 ` Markus Armbruster
9 siblings, 1 reply; 15+ messages in thread
From: Eric Blake @ 2015-05-14 15:14 UTC (permalink / raw)
To: Markus Armbruster, qemu-devel; +Cc: mdroth
[-- Attachment #1: Type: text/plain, Size: 726 bytes --]
On 05/11/2015 01:24 AM, Markus Armbruster wrote:
> 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.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [Qemu-devel] [PATCH 0/9] qapi: Mostly generator cleanups
2015-05-14 15:14 ` [Qemu-devel] [PATCH 0/9] qapi: Mostly generator cleanups Eric Blake
@ 2015-05-14 16:46 ` Markus Armbruster
0 siblings, 0 replies; 15+ messages in thread
From: Markus Armbruster @ 2015-05-14 16:46 UTC (permalink / raw)
To: Eric Blake; +Cc: qemu-devel, mdroth
Eric Blake <eblake@redhat.com> writes:
> On 05/11/2015 01:24 AM, Markus Armbruster wrote:
>> 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.
We're in luck, it rebased cleanly.
Applied to my qapi-next branch, thanks for the review!
^ permalink raw reply [flat|nested] 15+ messages in thread