Command line QAPIfication
cover Command line QAPIfication
This is a prototype to demonstrate where I'm headed. PATCH 01-28 are infrastructure, PATCH 29-32 QAPIfy a few options.
Plenty of infrastrucure work remains. Some of it is marked TODO/FIXME in the patches. I've excluded work to improve backward keyval.c compatibility with QemuOpts quirks for now.
Command line introspection is provided by query-qmp-schema for now. Perhaps it should be separate. See PATCH 25.
Documentation is generated into qemu-qmp-ref.*. Perhaps it should be separate. See PATCH 26.
main() iterates over argv[] twice. The second loop "executes" some options directly. PATCH 29+30 QAPIfy two of them. Other options it converts into a more convenient form, for later execution. PATCH 31+32 QAPIfy two of them: the conversion becomes a no-op, because QAPIfication already produces a convenient data type.
"Later execution" means the command line is executed in some magic order mortal users can't predict. Strict left-to-right would be simpler and cleaner, but backward compatibility may compel us to remain complicated and unclean.
qemu-img already duplicates --option. I suspect we'll end up wanting to QAPIfy that as well, sharing the common part of the QAPI schema.
Based-on: [email protected]
[PULL 0/3] QAPI patches for 2017-10-02 Based-on: [email protected] [PATCH 0/3] hmp-commands-info: Texinfo fixes Based-on: [email protected] [PATCH 0/8] qemu-options: Texinfo and --help fixes
Based-on: [email protected]
[PATCH 00/11] qapi: Cleanups around qapi2texi
Markus Armbruster (32):
tests/qapi-schema: Improve coverage of '@'
texi2pod: Support @verbatim environment
qapi2texi: Fix for examples containing '@'
qapi2texi: Fix for '@' not followed by \w character
qapi2texi: Provide access to Texinfo markup
qapi2texi: Drop | example markup
qapi: Drop superfluous allow_optional=True
qapi: Simplify check_name() parameters
qapi: check_type() parameter allow_optional is now unused, drop
qapi: Don't run generators twice
qapi: Drop the options to generate only .c or .h
qapi: Use argparse to parse command line arguments
qapi: Use argparse to open schema file
qapi: Rework generated code for built-in types tests/qapi-schema: Improve simple union coverage
qapi: Factor out _make_implicit_wrapper_type()
qapi: Fix simple union lowering with multiple schemas docs/devel/qapi-code-gen.txt: Rewrite section on schema syntax
qapi: Accept double-quoted strings
qapi: Frontend for defining command line options
qapi: Define QAPIOptionKind and QAPIOption automatically
qapi: New helper c_string()
qapi-options: Command line option backend
qapi-options: Generate help string
qapi-introspect: Include command line options information
qapi2texi: Include command line options information
os-posix: Drop misleading comment
vl: QAPIfy command line option definition qapi/options: QAPIfy --echr argument type qapi/options: QAPIfy --watchdog-action argument type qapi/options: QAPIfy --blockdev argument type qapi/options: QAPIfy --add-fd argument type
.gitignore | 4 +- Makefile | 101 +- Makefile.objs | 4 +- docs/devel/qapi-code-gen.txt | 83 +- include/qemu-common.h | 2 +- os-posix.c | 27 +- os-win32.c | 3 +- qapi-schema.json | 9 +- qapi/introspect.json | 22 +- qapi/options.json | 4574 ++++++++++++++++++++++++++++++ qemu-doc.texi | 4 +- qemu-options-wrapper.h | 41 - qemu-options.h | 36 - qemu-options.hx | 4256 --------------------------- qga/Makefile.objs | 1 + scripts/qapi-commands.py | 13 +- scripts/qapi-event.py | 12 +- scripts/qapi-introspect.py | 44 +- scripts/qapi-options.py | 212 ++ scripts/qapi-types.py | 78 +- scripts/qapi-visit.py | 74 +- scripts/qapi.py | 350 ++- scripts/qapi2texi.py | 88 +- scripts/texi2pod.pl | 11 +- tests/Makefile.include | 56 +- tests/qapi-schema/builtins.err | 0 tests/qapi-schema/builtins.exit | 1 + tests/qapi-schema/builtins.json | 1 + tests/qapi-schema/builtins.out | 33 + tests/qapi-schema/comments.out | 3 - tests/qapi-schema/doc-bad-section.out | 3 - tests/qapi-schema/doc-good.json | 46 +- tests/qapi-schema/doc-good.out | 70 +- tests/qapi-schema/doc-good.texi | 82 +- tests/qapi-schema/empty.out | 3 - tests/qapi-schema/event-case.out | 3 - tests/qapi-schema/ident-with-escape.out | 3 - tests/qapi-schema/include-relpath.out | 3 - tests/qapi-schema/include-repetition.out | 3 - tests/qapi-schema/include-simple.out | 3 - tests/qapi-schema/indented-expr.out | 3 - tests/qapi-schema/qapi-schema-test.json | 26 +- tests/qapi-schema/qapi-schema-test.out | 64 +- tests/qapi-schema/test-qapi.py | 22 +- tests/test-qapi-options.c | 74 + vl.c | 809 +++--- 46 files changed, 6151 insertions(+), 5209 deletions(-) create mode 100644 qapi/options.json delete mode 100644 qemu-options-wrapper.h delete mode 100644 qemu-options.h delete mode 100644 qemu-options.hx create mode 100644 scripts/qapi-options.py create mode 100644 tests/qapi-schema/builtins.err create mode 100644 tests/qapi-schema/builtins.exit create mode 100644 tests/qapi-schema/builtins.json create mode 100644 tests/qapi-schema/builtins.out create mode 100644 tests/test-qapi-options.c
Signature · 1 line
2.13.6
RFC PATCH 1/32 tests/qapi-schema: Improve coverage of '@'
Demonstrates a qapi2texi.py bug: it can fail to escape '@'.
--- tests/qapi-schema/doc-good.json | 3 +++ tests/qapi-schema/doc-good.out | 3 +++ tests/qapi-schema/doc-good.texi | 4 ++++ 3 files changed, 10 insertions(+)
tests/qapi-schema/doc-good.json +3 -0
@@ -10,6 +10,7 @@ # # *strong* _with emphasis_ # @var {in braces} +# lone @ BUG: gets passed to Texinfo unescaped # * List item one # - Two, multiple # lines
@@ -46,6 +47,7 @@ # <- out # Examples: # - *verbatim* +# - @at sign # - {braces} ##
@@ -115,6 +117,7 @@ # <- out # Examples: # - *verbatim* +# - @at sign BUG: gets passed to Texinfo unescaped # - {braces} # Since: 2.10 ##
tests/qapi-schema/doc-good.out +3 -0
@@ -38,6 +38,7 @@ doc freeform *strong* _with emphasis_ @var {in braces} +lone @ BUG: gets passed to Texinfo unescaped * List item one - Two, multiple lines
@@ -74,6 +75,7 @@ Example: <- out Examples: - *verbatim* +- @at sign - {braces} doc symbol=Enum body=
@@ -136,6 +138,7 @@ Duis aute irure dolor <- out section=Examples - *verbatim* +- @at sign BUG: gets passed to Texinfo unescaped - {braces} section=Since 2.10
tests/qapi-schema/doc-good.texi +4 -0
@@ -4,6 +4,7 @@ @strong{strong} @emph{with emphasis} @code{var} @{in braces@} +lone @ BUG: gets passed to Texinfo unescaped @itemize @bullet @item List item one
@@ -69,6 +70,8 @@ Examples: @item @strong{verbatim} @item +@code{at} sign +@item @{braces@} @end itemize
@@ -206,6 +209,7 @@ Duis aute irure dolor @b{Examples:} @example - *verbatim* +- @at sign BUG: gets passed to Texinfo unescaped - @{braces@} @end example
Signature · 1 line
2.13.6
Re: [Qemu-devel] [RFC PATCH 01/32] tests/qapi-schema: Improve coverage of '@'
Quoted 3 lines · Markus Armbruster
Demonstrates a
qapi2texi.pybug: it can fail to escape '@'.Signed-off-by Markus Armbruster <[email protected]>
Quoted 95 lines
--- tests/qapi-schema/doc-good.json | 3 +++ tests/qapi-schema/doc-good.out | 3 +++ tests/qapi-schema/doc-good.texi | 4 ++++ 3 files changed, 10 insertions(+)tests/qapi-schema/doc-good.json +3
-0@@ -10,6 +10,7 @@ # # *strong* _with emphasis_ # @var {in braces} +# lone @ BUG: gets passed to Texinfo unescaped # * List item one # - Two, multiple # lines@@ -46,6 +47,7 @@ # <- out # Examples: # - *verbatim* +# - @at sign # - {braces} ##@@ -115,6 +117,7 @@ # <- out # Examples: # - *verbatim* +# - @at sign BUG: gets passed to Texinfo unescaped # - {braces} # Since: 2.10 ##tests/qapi-schema/doc-good.out +3
-0@@ -38,6 +38,7 @@ doc freeform *strong* _with emphasis_ @var {in braces} +lone @ BUG: gets passed to Texinfo unescaped * List item one - Two, multiple lines@@ -74,6 +75,7 @@ Example: <- out Examples: - *verbatim* +- @at sign - {braces} doc symbol=Enum body=@@ -136,6 +138,7 @@ Duis aute irure dolor <- out section=Examples - *verbatim* +- @at sign BUG: gets passed to Texinfo unescaped - {braces} section=Since 2.10tests/qapi-schema/doc-good.texi +4
-1@@ -4,6 +4,7 @@ @strong{strong} @emph{with emphasis} @code{var} @{in braces@} +lone @ BUG: gets passed to Texinfo unescaped @itemize @bullet @item List item one@@ -69,6 +70,8 @@ Examples: @item @strong{verbatim} @item +@code{at} sign +@item @{braces@} @end itemize@@ -206,6 +209,7 @@ Duis aute irure dolor @b{Examples:} @example - *verbatim* +- @at sign BUG: gets passed to Texinfo unescaped - @{braces@} @end example --2.13.6
Signature · 1 line
Marc-André Lureau
RFC PATCH 2/32 texi2pod: Support @verbatim environment
In reply to Markus Armbruster--- scripts/texi2pod.pl | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
scripts/texi2pod.pl +9 -2
@@ -85,6 +85,13 @@ if (defined $out) { while(defined $inf) { while(<$inf>) { + # Verbatim environment + if (defined $endw and $endw eq "verbatim" + and not (/^\@end\s+([a-z]+)/ and $1 eq $endw)) { + $section .= "\t".$_; + next; + } + # Certain commands are discarded without further processing. /^\@(?: [a-z]+index # @*index: useful only in complete manual
@@ -165,7 +172,7 @@ while(<$inf>) { if ($ended =~ /^(?:ifset|ifclear|ignore|menu|iftex)$/) { $skipping = pop @skstack; next; - } elsif ($ended =~ /^(?:example|smallexample|display + } elsif ($ended =~ /^(?:example|smallexample|display|verbatim |quotation|deftp|deftypefn)$/x) { $shift = ""; $_ = ""; # need a paragraph break
@@ -311,7 +318,7 @@ while(<$inf>) { $_ = "\n=over 4\n"; }; - /^\@((?:small)?example|display)/ and do { + /^\@((?:small)?example|display|verbatim)/ and do { push @endwstack, $endw; $endw = $1; $shift = "\t";
Signature · 1 line
2.13.6
Re: [Qemu-devel] [RFC PATCH 02/32] texi2pod: Support @verbatim environment
Quoted 4 lines · Markus Armbruster
Signed-off-by Markus Armbruster <[email protected]>--- scripts/texi2pod.pl | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
My perl is a bit rusty, but I think I can handle this one.
scripts/texi2pod.pl if (defined $out) { · line 90
Quoted 12 lines
scripts/texi2pod.pl +3
-0@@ -85,6 +85,13 @@ if (defined $out) { while(defined $inf) { while(<$inf>) { + # Verbatim environment + if (defined $endw and $endw eq "verbatim" + and not (/^\@end\s+([a-z]+)/ and $1 eq $endw)) {
You anchored to the beginning, but not the end, of the line; that means you accept '@end verbatim garbage' as an end marker. Worth adding $?
If that's the only change, I'm okay with adding:
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [RFC PATCH 02/32] texi2pod: Support @verbatim environment
Quoted 15 lines · Eric Blake
Quoted 4 lines · Markus Armbruster
Signed-off-by Markus Armbruster <[email protected]>--- scripts/texi2pod.pl | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)My perl is a bit rusty, but I think I can handle this one.
Quoted 7 lines
scripts/texi2pod.pl +0
-0@@ -85,6 +85,13 @@ if (defined $out) {
Quoted 8 lines
scripts/texi2pod.pl if (defined $out) { · line 90
Quoted 5 lines
scripts/texi2pod.pl +3
-0while(defined $inf) { while(<$inf>) { + # Verbatim environment + if (defined $endw and $endw eq "verbatim" + and not (/^\@end\s+([a-z]+)/ and $1 eq $endw)) {You anchored to the beginning, but not the end, of the line; that means you accept '@end verbatim garbage' as an end marker. Worth adding $?
Cribbed from
# End-block handler goes up here because it needs to operate even
# if we are skipping.
/^\@end\s+([a-z]+)/ and do {
# Ignore @end foo, where foo is not an operation which may
# cause us to skip, if we are presently skipping.
my $ended = $1;
next if $skipping && $ended !~ /^(?:ifset|ifclear|ignore|menu|iftex|copying)$/;
die "\@end $ended without \@$ended at line $.\n" unless defined $endw;
die "\@$endw ended by \@end $ended at line $.\n" unless $ended eq $endw;
$endw = pop @endwstack;I'd prefer to stick to this regexp.
texi2pod.pl parses quite sloppily in general.
Quoted 3 lines
If that's the only change, I'm okay with adding:
Reviewed-by Eric Blake <[email protected]>
Does this apply to the unchanged patch, too?
Re: [Qemu-devel] [RFC PATCH 02/32] texi2pod: Support @verbatim environment
Quoted 29 lines · Markus Armbruster
Quoted 11 lines · Eric Blake
scripts/texi2pod.pl if (defined $out) { · line 90
Quoted 7 lines · Markus Armbruster
Signed-off-by Markus Armbruster <[email protected]>--- scripts/texi2pod.pl | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)scripts/texi2pod.pl +1
-0+ and not (/^\@end\s+([a-z]+)/ and $1 eq $endw)) {You anchored to the beginning, but not the end, of the line; that means you accept '@end verbatim garbage' as an end marker. Worth adding $?
Cribbed from
# End-block handler goes up here because it needs to operate even # if we are skipping. /^\@end\s+([a-z]+)/ and do { # Ignore @end foo, where foo is not an operation which may # cause us to skip, if we are presently skipping. my $ended = $1; next if $skipping && $ended !~ /^(?:ifset|ifclear|ignore|menu|iftex|copying)$/; die "\@end $ended without \@$ended at line $.\n" unless defined $endw; die "\@$endw ended by \@end $ended at line $.\n" unless $ended eq $endw; $endw = pop @endwstack;
Quoted 1 line
I'd prefer to stick to this regexp.
Consistency makes sense.
Quoted 8 lines
texi2pod.pl parses quite sloppily in general.
Quoted 3 lines
If that's the only change, I'm okay with adding:
Reviewed-by Eric Blake <[email protected]>Does this apply to the unchanged patch, too?
Yes.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
RFC PATCH 3/32 qapi2texi: Fix for examples containing '@'
In reply to Markus ArmbrusterInstead of quoting example text so that the @example environment shows it verbatim, simply use the @verbatim environment.
Examples are no longer indented in output, because makeinfo doesn't indent @verbatim, unlike @example.
TODO keep indentation somehow?
--- scripts/qapi2texi.py | 12 +++++------- tests/qapi-schema/doc-good.json | 2 +- tests/qapi-schema/doc-good.out | 2 +- tests/qapi-schema/doc-good.texi | 16 ++++++++-------- 4 files changed, 15 insertions(+), 17 deletions(-)
scripts/qapi2texi.py +5 -7
@@ -52,13 +52,11 @@ def subst_braces(doc): def texi_example(doc): - """Format @example""" - # TODO: Neglects to escape @ characters. - # We should probably escape them in subst_braces(), and rename the - # function to subst_special() or subs_texi_special(). If we do that, we - # need to delay it until after subst_vars() in texi_format(). - doc = subst_braces(doc).strip('\n') - return EXAMPLE_FMT(code=doc) + """Format example text""" + return """@verbatim +{code} +@end verbatim +""".format(code=doc.strip('\n')) def texi_format(doc):
tests/qapi-schema/doc-good.json +1 -1
@@ -117,7 +117,7 @@ # <- out # Examples: # - *verbatim* -# - @at sign BUG: gets passed to Texinfo unescaped +# - @at sign # - {braces} # Since: 2.10 ##
tests/qapi-schema/doc-good.out +1 -1
@@ -138,7 +138,7 @@ Duis aute irure dolor <- out section=Examples - *verbatim* -- @at sign BUG: gets passed to Texinfo unescaped +- @at sign - {braces} section=Since 2.10
tests/qapi-schema/doc-good.texi +8 -8
@@ -201,17 +201,17 @@ Ut enim ad minim veniam Duis aute irure dolor @b{Example:} -@example +@verbatim -> in <- out -@end example +@end verbatim @b{Examples:} -@example +@verbatim - *verbatim* -- @at sign BUG: gets passed to Texinfo unescaped -- @{braces@} -@end example +- @at sign +- {braces} +@end verbatim @b{Since:} 2.10
@@ -227,11 +227,11 @@ If you're bored enough to read this, go see a video of boxed cats @b{Arguments:} the members of @code{Object} @b{Example:} -@example +@verbatim -> in <- out -@end example +@end verbatim @end deftypefn
Signature · 1 line
2.13.6
Re: [Qemu-devel] [RFC PATCH 03/32] qapi2texi: Fix for examples containing '@'
Hi
Quoted 3 lines · Markus Armbruster
Instead of quoting example text so that the @example environment shows it verbatim, simply use the @verbatim environment.
Not sure if this is really worth it, unless we have a real use-case of @ in examples.
Quoted 107 lines
Examples are no longer indented in output, because makeinfo doesn't indent @verbatim, unlike @example.
TODO keep indentation somehow?Signed-off-by Markus Armbruster <[email protected]>--- scripts/qapi2texi.py | 12 +++++------- tests/qapi-schema/doc-good.json | 2 +- tests/qapi-schema/doc-good.out | 2 +- tests/qapi-schema/doc-good.texi | 16 ++++++++-------- 4 files changed, 15 insertions(+), 17 deletions(-)scripts/qapi2texi.py +5
-7@@ -52,13 +52,11 @@ def subst_braces(doc): def texi_example(doc): - """Format @example""" - # TODO: Neglects to escape @ characters. - # We should probably escape them in subst_braces(), and rename the - # function to subst_special() or subs_texi_special(). If we do that, we - # need to delay it until after subst_vars() in texi_format(). - doc = subst_braces(doc).strip('\n') - return EXAMPLE_FMT(code=doc) + """Format example text""" + return """@verbatim +{code} +@end verbatim +""".format(code=doc.strip('\n')) def texi_format(doc):tests/qapi-schema/doc-good.json +1
-1@@ -117,7 +117,7 @@ # <- out # Examples: # - *verbatim* -# - @at sign BUG: gets passed to Texinfo unescaped +# - @at sign # - {braces} # Since: 2.10 ##tests/qapi-schema/doc-good.out +1
-1@@ -138,7 +138,7 @@ Duis aute irure dolor <- out section=Examples - *verbatim* -- @at sign BUG: gets passed to Texinfo unescaped +- @at sign - {braces} section=Since 2.10tests/qapi-schema/doc-good.texi +8
-9@@ -201,17 +201,17 @@ Ut enim ad minim veniam Duis aute irure dolor @b{Example:} -@example +@verbatim -> in <- out -@end example +@end verbatim @b{Examples:} -@example +@verbatim - *verbatim* -- @at sign BUG: gets passed to Texinfo unescaped -- @{braces@} -@end example +- @at sign +- {braces} +@end verbatim @b{Since:} 2.10@@ -227,11 +227,11 @@ If you're bored enough to read this, go see a video of boxed cats @b{Arguments:} the members of @code{Object} @b{Example:} -@example +@verbatim -> in <- out -@end example +@end verbatim @end deftypefn --2.13.6
Signature · 1 line
Marc-André Lureau
RFC PATCH 4/32 qapi2texi: Fix for '@' not followed by \w character
In reply to Markus Armbruster--- scripts/qapi2texi.py | 22 ++++++++++++---------- tests/qapi-schema/doc-good.json | 2 +- tests/qapi-schema/doc-good.out | 2 +- tests/qapi-schema/doc-good.texi | 2 +- 4 files changed, 15 insertions(+), 13 deletions(-)
scripts/qapi2texi.py +12 -10
@@ -41,14 +41,17 @@ def subst_emph(doc): return re.sub(r'\b_([^_\n]+)_\b', r'@emph{\1}', doc) -def subst_vars(doc): - """Replaces @var by @code{var}""" - return re.sub(r'@([\w-]+)', r'@code{\1}', doc) - - -def subst_braces(doc): - """Replaces {} with @{ @}""" - return doc.replace('{', '@{').replace('}', '@}') +def subst_special(doc): + ret = '' + for m in re.finditer(r'([^@{}]*)(@([-\w]*)|[{}])?', doc): + ret += m.group(1) + if m.group(3): + # format @NAME as @code{NAME} + ret += '@code{' + m.group(3) + '}' + elif m.group(2): + # escape Texinfo's special characters + ret += '@' + m.group(2) + return ret def texi_example(doc):
@@ -71,8 +74,7 @@ def texi_format(doc): - */-: generates an @itemize list """ ret = '' - doc = subst_braces(doc) - doc = subst_vars(doc) + doc = subst_special(doc) doc = subst_emph(doc) doc = subst_strong(doc) inlist = ''
tests/qapi-schema/doc-good.json +1 -1
@@ -10,7 +10,7 @@ # # *strong* _with emphasis_ # @var {in braces} -# lone @ BUG: gets passed to Texinfo unescaped +# lone @ # * List item one # - Two, multiple # lines
tests/qapi-schema/doc-good.out +1 -1
@@ -38,7 +38,7 @@ doc freeform *strong* _with emphasis_ @var {in braces} -lone @ BUG: gets passed to Texinfo unescaped +lone @ * List item one - Two, multiple lines
tests/qapi-schema/doc-good.texi +1 -1
@@ -4,7 +4,7 @@ @strong{strong} @emph{with emphasis} @code{var} @{in braces@} -lone @ BUG: gets passed to Texinfo unescaped +lone @@ @itemize @bullet @item List item one
Signature · 1 line
2.13.6
Re: [Qemu-devel] [RFC PATCH 04/32] qapi2texi: Fix for '@' not followed by \w character
Quoted 1 line · Markus Armbruster
Signed-off-by Markus Armbruster <[email protected]>
Quoted 90 lines
--- scripts/qapi2texi.py | 22 ++++++++++++---------- tests/qapi-schema/doc-good.json | 2 +- tests/qapi-schema/doc-good.out | 2 +- tests/qapi-schema/doc-good.texi | 2 +- 4 files changed, 15 insertions(+), 13 deletions(-)scripts/qapi2texi.py +12
-10@@ -41,14 +41,17 @@ def subst_emph(doc): return re.sub(r'\b_([^_\n]+)_\b', r'@emph{\1}', doc) -def subst_vars(doc): - """Replaces @var by @code{var}""" - return re.sub(r'@([\w-]+)', r'@code{\1}', doc) - - -def subst_braces(doc): - """Replaces {} with @{ @}""" - return doc.replace('{', '@{').replace('}', '@}') +def subst_special(doc): + ret = '' + for m in re.finditer(r'([^@{}]*)(@([-\w]*)|[{}])?', doc): + ret += m.group(1) + if m.group(3): + # format @NAME as @code{NAME} + ret += '@code{' + m.group(3) + '}' + elif m.group(2): + # escape Texinfo's special characters + ret += '@' + m.group(2) + return ret def texi_example(doc):@@ -71,8 +74,7 @@ def texi_format(doc): - */-: generates an @itemize list """ ret = '' - doc = subst_braces(doc) - doc = subst_vars(doc) + doc = subst_special(doc) doc = subst_emph(doc) doc = subst_strong(doc) inlist = ''tests/qapi-schema/doc-good.json +1
-1@@ -10,7 +10,7 @@ # # *strong* _with emphasis_ # @var {in braces} -# lone @ BUG: gets passed to Texinfo unescaped +# lone @ # * List item one # - Two, multiple # linestests/qapi-schema/doc-good.out +1
-1@@ -38,7 +38,7 @@ doc freeform *strong* _with emphasis_ @var {in braces} -lone @ BUG: gets passed to Texinfo unescaped +lone @ * List item one - Two, multiple linestests/qapi-schema/doc-good.texi +1
-2@@ -4,7 +4,7 @@ @strong{strong} @emph{with emphasis} @code{var} @{in braces@} -lone @ BUG: gets passed to Texinfo unescaped +lone @@ @itemize @bullet @item List item one --2.13.6
Signature · 1 line
Marc-André Lureau
RFC PATCH 5/32 qapi2texi: Provide access to Texinfo markup
In reply to Markus Armbrusterqapi2texi supports very limited formatting markup reminiscent of MarkDown, which it translates to Texinfo. It's basically defined by example, and has multiple issues, in particular with lists. Nevertheless, it has served our (modest) needs so far.
However, our needs are about to grow: I'm going to move command line documentation from qemu-options.hx into schema doc comments, similar to how we moved QMP documentation in merge commit 23eb9e6. The QMP documentation was plain text, and the markup was created to make it look decent in generated Texinfo with minimal change. The command line documentation is already in Texinfo. Dumbing it down to what qapi2texi supports would be a lot of work, for a sad result. Making qapi2texi sufficiently powerful for a non-sad result would also be a lot of work, and stupid; the world doesn't need more text markup languages. Not even more text markup language implementations.
Supporting Texinfo in doc comments would be ideal. Can't do, since we blew the '@' character on schema name references. Instead, let's try the stupidest solution that could possibly work: provide an escape to Texinfo. Looks like this:
# !texinfo
# @c This is Texinfo
# @appendix Tips and Tricks
# !end texinfo
--- docs/devel/qapi-code-gen.txt | 13 +++++++++++++ scripts/qapi2texi.py | 19 ++++++++++++++++--- tests/qapi-schema/doc-good.json | 11 +++++++++++ tests/qapi-schema/doc-good.out | 11 +++++++++++ tests/qapi-schema/doc-good.texi | 9 +++++++++ 5 files changed, 60 insertions(+), 3 deletions(-)
docs/devel/qapi-code-gen.txt +13 -0
@@ -97,6 +97,9 @@ permitted. do not work over multiple lines). @foo is used to reference a name in the schema. +You can also embed Texinfo markup. '!texinfo' switches to Texinfo, +and '!end texinfo' switches back. + Example: ##
@@ -112,6 +115,16 @@ Example: # | -> do this # | <- get that # +# Texinfo markup: +# !texinfo +# @table @samp +# @item foo +# This is the text for +# @samp{foo}. +# @item bar +# Text for @samp{bar}. +# @end table +# !end texinfo ##
scripts/qapi2texi.py +16 -3
@@ -74,14 +74,27 @@ def texi_format(doc): - */-: generates an @itemize list """ ret = '' - doc = subst_special(doc) - doc = subst_emph(doc) - doc = subst_strong(doc) inlist = '' + intexi = False lastempty = False + for line in doc.split('\n'): empty = line == '' + if not intexi and line == '!texinfo': + intexi = True + continue + if intexi and line == '!end texinfo': + intexi = False + continue + if intexi: + ret += line + '\n' + continue + + line = subst_special(line) + line = subst_emph(line) + line = subst_strong(line) + # FIXME: Doing this in a single if / elif chain is # problematic. For instance, a line without markup terminates # a list if it follows a blank line (reaches the final elif),
tests/qapi-schema/doc-good.json +11 -0
@@ -31,6 +31,17 @@ # | example # | multiple lines # +# !texinfo +# @table @samp +# @item foo +# This is the text for +# @samp{foo}. +# +# @item bar +# Text for @samp{bar}. +# @end table +# !end texinfo +# # Returns: the King # Since: the first age # Notes:
tests/qapi-schema/doc-good.out +11 -0
@@ -59,6 +59,17 @@ is numbered | example | multiple lines +!texinfo +@table @samp +@item foo +This is the text for +@samp{foo}. + +@item bar +Text for @samp{bar}. +@end table +!end texinfo + Returns: the King Since: the first age Notes:
tests/qapi-schema/doc-good.texi +9 -0
@@ -44,8 +44,17 @@ multiple lines @end example +@table @samp +@item foo +This is the text for +@samp{foo}. + +@item bar +Text for @samp{bar}. +@end table @end enumerate + Returns: the King Since: the first age Notes:
Signature · 1 line
2.13.6
RFC PATCH 6/32 qapi2texi: Drop | example markup
In reply to Markus ArmbrusterDoc comment lines starting with '|' are examples. qapi2texi.py puts each line in its own @example environment, which is wrong. Fortunately, this kind of example markup is used in just one place outside tests. Replace it by Texinfo markup, and drop the '|' feature.
tests/qapi-schema/doc-good.texi changes, because unlike the '|' markup, !texinfo terminates lists. See the FIXME in texi_format().
--- docs/devel/qapi-code-gen.txt | 10 ---------- qapi-schema.json | 8 ++++++-- scripts/qapi2texi.py | 9 +-------- tests/qapi-schema/doc-good.json | 8 ++++++-- tests/qapi-schema/doc-good.out | 8 ++++++-- tests/qapi-schema/doc-good.texi | 10 +++------- 6 files changed, 22 insertions(+), 31 deletions(-)
docs/devel/qapi-code-gen.txt +0 -10
@@ -65,11 +65,6 @@ Double the '=' for a subsection title: # == Subection title -'|' denotes examples: - - # | Text of the example, may span - # | multiple lines - '*' starts an itemized list: # * First item, may span
@@ -110,11 +105,6 @@ Example: # 1. with a list # 2. like that # -# And some code: -# | $ echo foo -# | -> do this -# | <- get that -# # Texinfo markup: # !texinfo # @table @samp
qapi-schema.json +6 -2
@@ -20,8 +20,12 @@ # # Example: # -# | -> data issued by the Client -# | <- Server data response +# !texinfo +# @verbatim +# -> data issued by the Client +# <- Server data response +# @end verbatim +# !end texinfo # # Please, refer to the QMP specification (docs/interop/qmp-spec.txt) for # detailed information on the Server command and response formats.
scripts/qapi2texi.py +1 -8
@@ -25,11 +25,6 @@ TYPE_FMT = """ """.format -EXAMPLE_FMT = """@example -{code} -@end example -""".format - def subst_strong(doc): """Replaces *foo* by @strong{foo}"""
@@ -103,9 +98,7 @@ def texi_format(doc): # # Make sure to update section "Documentation markup" in # docs/devel/qapi-code-gen.txt when fixing this. - if line.startswith('| '): - line = EXAMPLE_FMT(code=line[2:]) - elif line.startswith('= '): + if line.startswith('= '): line = '@section ' + line[2:] elif line.startswith('== '): line = '@subsection ' + line[3:]
tests/qapi-schema/doc-good.json +6 -2
@@ -28,8 +28,12 @@ # # - another item # -# | example -# | multiple lines +# !texinfo +# @verbatim +# example +# multiple lines +# @end verbatim +# !end texinfo # # !texinfo # @table @samp
tests/qapi-schema/doc-good.out +6 -2
@@ -56,8 +56,12 @@ is numbered - another item -| example -| multiple lines +!texinfo +@verbatim +example +multiple lines +@end verbatim +!end texinfo !texinfo @table @samp
tests/qapi-schema/doc-good.texi +3 -7
@@ -35,13 +35,11 @@ is numbered @item another item -@example +@verbatim example -@end example - -@example multiple lines -@end example +@end verbatim +@end enumerate @table @samp
@@ -52,8 +50,6 @@ This is the text for @item bar Text for @samp{bar}. @end table -@end enumerate - Returns: the King Since: the first age
Signature · 1 line
2.13.6
RFC PATCH 7/32 qapi: Drop superfluous allow_optional=True
In reply to Markus Armbrustercheck_command() passes allow_optional=True to check_type(). Useless unless you also pass allow_dict=True, which check_command() doesn't. Drop the superfluous argument.
--- scripts/qapi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/qapi.py +1 -1
@@ -695,7 +695,7 @@ def check_command(expr, info): returns_meta += ['built-in', 'alternate', 'enum'] check_type(info, "'returns' for command '%s'" % name, expr.get('returns'), allow_array=True, - allow_optional=True, allow_metas=returns_meta) + allow_metas=returns_meta) def check_event(expr, info):
Signature · 1 line
2.13.6
Re: [Qemu-devel] [RFC PATCH 07/32] qapi: Drop superfluous allow_optional=True
Quoted 5 lines · Markus Armbruster
check_command()passes allow_optional=True tocheck_type(). Useless unless you also pass allow_dict=True, whichcheck_command()doesn't. Drop the superfluous argument.Signed-off-by Markus Armbruster <[email protected]>
Quoted 21 lines
--- scripts/qapi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/qapi.py +1
-2@@ -695,7 +695,7 @@ def check_command(expr, info): returns_meta += ['built-in', 'alternate', 'enum'] check_type(info, "'returns' for command '%s'" % name, expr.get('returns'), allow_array=True, - allow_optional=True, allow_metas=returns_meta) + allow_metas=returns_meta) def check_event(expr, info): --2.13.6
Signature · 1 line
Marc-André Lureau
RFC PATCH 8/32 qapi: Simplify check_name() parameters
In reply to Markus ArmbrusterReplace flags @enum_member, @allow_optional by string @meta:
'member-enum' implies @enum_member, 'member-struct' implies @allow_optional.
--- scripts/qapi.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-)
scripts/qapi.py +10 -12
@@ -593,8 +593,7 @@ valid_name = re.compile(r'^(__[a-zA-Z0-9.-]+_)?' '[a-zA-Z][a-zA-Z0-9_-]*$') -def check_name(info, source, name, allow_optional=False, - enum_member=False): +def check_name(info, source, name, meta): global valid_name membername = name
@@ -602,12 +601,12 @@ def check_name(info, source, name, allow_optional=False, raise QAPISemError(info, "%s requires a string name" % source) if name.startswith('*'): membername = name[1:] - if not allow_optional: + if meta != 'member-struct': raise QAPISemError(info, "%s does not allow optional name '%s'" % (source, name)) # Enum members can start with a digit, because the generated C # code always prefixes it with the enum name - if enum_member and membername[0].isdigit(): + if meta == 'member-enum' and membername[0].isdigit(): membername = 'D' + membername # Reserve the entire 'q_' namespace for c_name(), and for 'q_empty' # and 'q_obj_*' implicit type names.
@@ -618,7 +617,7 @@ def check_name(info, source, name, allow_optional=False, def add_name(name, info, meta, implicit=False): global all_names - check_name(info, "'%s'" % meta, name) + check_name(info, "'%s'" % meta, name, meta) # FIXME should reject names that differ only in '_' vs. '.' # vs. '-', because they're liable to clash in generated C. if name in all_names:
@@ -667,8 +666,7 @@ def check_type(info, source, value, allow_array=False, # value is a dictionary, check that each member is okay for (key, arg) in value.items(): - check_name(info, "Member of %s" % source, key, - allow_optional=allow_optional) + check_name(info, "Member of %s" % source, key, 'member-struct') if c_name(key, False) == 'u' or c_name(key, False).startswith('has_'): raise QAPISemError(info, "Member of %s uses reserved name '%s'" % (source, key))
@@ -741,7 +739,7 @@ def check_union(expr, info): # The value of member 'discriminator' must name a non-optional # member of the base struct. check_name(info, "Discriminator of flat union '%s'" % name, - discriminator) + discriminator, 'member-union') discriminator_type = base_members.get(discriminator) if not discriminator_type: raise QAPISemError(info,
@@ -760,7 +758,7 @@ def check_union(expr, info): if len(members) == 0: raise QAPISemError(info, "Union '%s' cannot have empty 'data'" % name) for (key, value) in members.items(): - check_name(info, "Member of union '%s'" % name, key) + check_name(info, "Member of union '%s'" % name, key, 'member-union') # Each value must name a known type check_type(info, "Member '%s' of union '%s'" % (key, name),
@@ -794,7 +792,8 @@ def check_alternate(expr, info): "Alternate '%s' should have at least two branches " "in 'data'" % name) for (key, value) in members.items(): - check_name(info, "Member of alternate '%s'" % name, key) + check_name(info, "Member of alternate '%s'" % name, key, + 'member-alternate') # Ensure alternates have no type conflicts. check_type(info, "Member '%s' of alternate '%s'" % (key, name),
@@ -836,8 +835,7 @@ def check_enum(expr, info): raise QAPISemError(info, "Enum '%s' requires a string for 'prefix'" % name) for member in members: - check_name(info, "Member of enum '%s'" % name, member, - enum_member=True) + check_name(info, "Member of enum '%s'" % name, member, 'member-enum') def check_struct(expr, info):
Signature · 1 line
2.13.6
Re: [Qemu-devel] [RFC PATCH 08/32] qapi: Simplify check_name() parameters
Quoted 5 lines · Markus Armbruster
Replace flags @enum_member, @allow_optional by string @meta:
'member-enum' implies @enum_member, 'member-struct' implies @allow_optional.Signed-off-by Markus Armbruster <[email protected]>
Quoted 94 lines
--- scripts/qapi.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-)scripts/qapi.py +10
-13@@ -593,8 +593,7 @@ valid_name = re.compile(r'^(__[a-zA-Z0-9.-]+_)?' '[a-zA-Z][a-zA-Z0-9_-]*$') -def check_name(info, source, name, allow_optional=False, - enum_member=False): +def check_name(info, source, name, meta): global valid_name membername = name@@ -602,12 +601,12 @@ def check_name(info, source, name, allow_optional=False, raise QAPISemError(info, "%s requires a string name" % source) if name.startswith('*'): membername = name[1:] - if not allow_optional: + if meta != 'member-struct': raise QAPISemError(info, "%s does not allow optional name '%s'" % (source, name)) # Enum members can start with a digit, because the generated C # code always prefixes it with the enum name - if enum_member and membername[0].isdigit(): + if meta == 'member-enum' and membername[0].isdigit(): membername = 'D' + membername # Reserve the entire 'q_' namespace for c_name(), and for 'q_empty' # and 'q_obj_*' implicit type names.@@ -618,7 +617,7 @@ def check_name(info, source, name, allow_optional=False, def add_name(name, info, meta, implicit=False): global all_names - check_name(info, "'%s'" % meta, name) + check_name(info, "'%s'" % meta, name, meta) # FIXME should reject names that differ only in '_' vs. '.' # vs. '-', because they're liable to clash in generated C. if name in all_names:@@ -667,8 +666,7 @@ def check_type(info, source, value, allow_array=False, # value is a dictionary, check that each member is okay for (key, arg) in value.items(): - check_name(info, "Member of %s" % source, key, - allow_optional=allow_optional) + check_name(info, "Member of %s" % source, key, 'member-struct') if c_name(key, False) == 'u' or c_name(key, False).startswith('has_'): raise QAPISemError(info, "Member of %s uses reserved name '%s'" % (source, key))@@ -741,7 +739,7 @@ def check_union(expr, info): # The value of member 'discriminator' must name a non-optional # member of the base struct. check_name(info, "Discriminator of flat union '%s'" % name, - discriminator) + discriminator, 'member-union') discriminator_type = base_members.get(discriminator) if not discriminator_type: raise QAPISemError(info,@@ -760,7 +758,7 @@ def check_union(expr, info): if len(members) == 0: raise QAPISemError(info, "Union '%s' cannot have empty 'data'" % name) for (key, value) in members.items(): - check_name(info, "Member of union '%s'" % name, key) + check_name(info, "Member of union '%s'" % name, key, 'member-union') # Each value must name a known type check_type(info, "Member '%s' of union '%s'" % (key, name),@@ -794,7 +792,8 @@ def check_alternate(expr, info): "Alternate '%s' should have at least two branches " "in 'data'" % name) for (key, value) in members.items(): - check_name(info, "Member of alternate '%s'" % name, key) + check_name(info, "Member of alternate '%s'" % name, key, + 'member-alternate') # Ensure alternates have no type conflicts. check_type(info, "Member '%s' of alternate '%s'" % (key, name),@@ -836,8 +835,7 @@ def check_enum(expr, info): raise QAPISemError(info, "Enum '%s' requires a string for 'prefix'" % name) for member in members: - check_name(info, "Member of enum '%s'" % name, member, - enum_member=True) + check_name(info, "Member of enum '%s'" % name, member, 'member-enum') def check_struct(expr, info): --2.13.6
Signature · 1 line
Marc-André Lureau
Re: [Qemu-devel] [RFC PATCH 08/32] qapi: Simplify check_name() parameters
In reply to Markus ArmbrusterQuoted 5 lines · Markus Armbruster
Replace flags @enum_member, @allow_optional by string @meta:
'member-enum' implies @enum_member, 'member-struct' implies @allow_optional.Signed-off-by Markus Armbruster <[email protected]>
Quoted 94 lines
--- scripts/qapi.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-)scripts/qapi.py +10
-13@@ -593,8 +593,7 @@ valid_name = re.compile(r'^(__[a-zA-Z0-9.-]+_)?' '[a-zA-Z][a-zA-Z0-9_-]*$') -def check_name(info, source, name, allow_optional=False, - enum_member=False): +def check_name(info, source, name, meta): global valid_name membername = name@@ -602,12 +601,12 @@ def check_name(info, source, name, allow_optional=False, raise QAPISemError(info, "%s requires a string name" % source) if name.startswith('*'): membername = name[1:] - if not allow_optional: + if meta != 'member-struct': raise QAPISemError(info, "%s does not allow optional name '%s'" % (source, name)) # Enum members can start with a digit, because the generated C # code always prefixes it with the enum name - if enum_member and membername[0].isdigit(): + if meta == 'member-enum' and membername[0].isdigit(): membername = 'D' + membername # Reserve the entire 'q_' namespace for c_name(), and for 'q_empty' # and 'q_obj_*' implicit type names.@@ -618,7 +617,7 @@ def check_name(info, source, name, allow_optional=False, def add_name(name, info, meta, implicit=False): global all_names - check_name(info, "'%s'" % meta, name) + check_name(info, "'%s'" % meta, name, meta) # FIXME should reject names that differ only in '_' vs. '.' # vs. '-', because they're liable to clash in generated C. if name in all_names:@@ -667,8 +666,7 @@ def check_type(info, source, value, allow_array=False, # value is a dictionary, check that each member is okay for (key, arg) in value.items(): - check_name(info, "Member of %s" % source, key, - allow_optional=allow_optional) + check_name(info, "Member of %s" % source, key, 'member-struct') if c_name(key, False) == 'u' or c_name(key, False).startswith('has_'): raise QAPISemError(info, "Member of %s uses reserved name '%s'" % (source, key))@@ -741,7 +739,7 @@ def check_union(expr, info): # The value of member 'discriminator' must name a non-optional # member of the base struct. check_name(info, "Discriminator of flat union '%s'" % name, - discriminator) + discriminator, 'member-union') discriminator_type = base_members.get(discriminator) if not discriminator_type: raise QAPISemError(info,@@ -760,7 +758,7 @@ def check_union(expr, info): if len(members) == 0: raise QAPISemError(info, "Union '%s' cannot have empty 'data'" % name) for (key, value) in members.items(): - check_name(info, "Member of union '%s'" % name, key) + check_name(info, "Member of union '%s'" % name, key, 'member-union') # Each value must name a known type check_type(info, "Member '%s' of union '%s'" % (key, name),@@ -794,7 +792,8 @@ def check_alternate(expr, info): "Alternate '%s' should have at least two branches " "in 'data'" % name) for (key, value) in members.items(): - check_name(info, "Member of alternate '%s'" % name, key) + check_name(info, "Member of alternate '%s'" % name, key, + 'member-alternate') # Ensure alternates have no type conflicts. check_type(info, "Member '%s' of alternate '%s'" % (key, name),@@ -836,8 +835,7 @@ def check_enum(expr, info): raise QAPISemError(info, "Enum '%s' requires a string for 'prefix'" % name) for member in members: - check_name(info, "Member of enum '%s'" % name, member, - enum_member=True) + check_name(info, "Member of enum '%s'" % name, member, 'member-enum') def check_struct(expr, info): --2.13.6
Signature · 1 line
Marc-André Lureau
RFC PATCH 9/32 qapi: check_type() parameter allow_optional is now unused, drop
In reply to Markus Armbruster--- scripts/qapi.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
scripts/qapi.py +5 -8
@@ -629,8 +629,7 @@ def add_name(name, info, meta, implicit=False): all_names[name] = meta -def check_type(info, source, value, allow_array=False, - allow_dict=False, allow_optional=False, +def check_type(info, source, value, allow_array=False, allow_dict=False, allow_metas=[]): global all_names
@@ -686,7 +685,7 @@ def check_command(expr, info): if boxed: args_meta += ['union', 'alternate'] check_type(info, "'data' for command '%s'" % name, - expr.get('data'), allow_dict=not boxed, allow_optional=True, + expr.get('data'), allow_dict=not boxed, allow_metas=args_meta) returns_meta = ['union', 'struct'] if name in returns_whitelist:
@@ -704,8 +703,7 @@ def check_event(expr, info): if boxed: meta += ['union', 'alternate'] check_type(info, "'data' for event '%s'" % name, - expr.get('data'), allow_dict=not boxed, allow_optional=True, - allow_metas=meta) + expr.get('data'), allow_dict=not boxed, allow_metas=meta) def check_union(expr, info):
@@ -728,8 +726,7 @@ def check_union(expr, info): else: # The object must have a string or dictionary 'base'. check_type(info, "'base' for union '%s'" % name, - base, allow_dict=True, allow_optional=True, - allow_metas=['struct']) + base, allow_dict=True, allow_metas=['struct']) if not base: raise QAPISemError(info, "Flat union '%s' must have a base" % name)
@@ -843,7 +840,7 @@ def check_struct(expr, info): members = expr['data'] check_type(info, "'data' for struct '%s'" % name, members, - allow_dict=True, allow_optional=True) + allow_dict=True) check_type(info, "'base' for struct '%s'" % name, expr.get('base'), allow_metas=['struct'])
Signature · 1 line
2.13.6
Re: [Qemu-devel] [RFC PATCH 09/32] qapi: check_type() parameter allow_optional is now unused, drop
Quoted 1 line · Markus Armbruster
Signed-off-by Markus Armbruster <[email protected]>
Quoted 60 lines
--- scripts/qapi.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)scripts/qapi.py +5
-9@@ -629,8 +629,7 @@ def add_name(name, info, meta, implicit=False): all_names[name] = meta -def check_type(info, source, value, allow_array=False, - allow_dict=False, allow_optional=False, +def check_type(info, source, value, allow_array=False, allow_dict=False, allow_metas=[]): global all_names@@ -686,7 +685,7 @@ def check_command(expr, info): if boxed: args_meta += ['union', 'alternate'] check_type(info, "'data' for command '%s'" % name, - expr.get('data'), allow_dict=not boxed, allow_optional=True, + expr.get('data'), allow_dict=not boxed, allow_metas=args_meta) returns_meta = ['union', 'struct'] if name in returns_whitelist:@@ -704,8 +703,7 @@ def check_event(expr, info): if boxed: meta += ['union', 'alternate'] check_type(info, "'data' for event '%s'" % name, - expr.get('data'), allow_dict=not boxed, allow_optional=True, - allow_metas=meta) + expr.get('data'), allow_dict=not boxed, allow_metas=meta) def check_union(expr, info):@@ -728,8 +726,7 @@ def check_union(expr, info): else: # The object must have a string or dictionary 'base'. check_type(info, "'base' for union '%s'" % name, - base, allow_dict=True, allow_optional=True, - allow_metas=['struct']) + base, allow_dict=True, allow_metas=['struct']) if not base: raise QAPISemError(info, "Flat union '%s' must have a base" % name)@@ -843,7 +840,7 @@ def check_struct(expr, info): members = expr['data'] check_type(info, "'data' for struct '%s'" % name, members, - allow_dict=True, allow_optional=True) + allow_dict=True) check_type(info, "'base' for struct '%s'" % name, expr.get('base'), allow_metas=['struct']) --2.13.6
Signature · 1 line
Marc-André Lureau
RFC PATCH 10/32 qapi: Don't run generators twice
In reply to Markus ArmbrusterThe generators always generate both .c and .h, but they can route one of them to the bit bucket. We run them twice, once to generate .c, and once to generate .h. Probably because the naive make rule
FOO.c FOO.h: qapi-schema.json
RECIPE
runs RECIPE twice, once to generate FOO.c and once to generate FOO.h.
Employ the usual make trick to generate multiple files in one rule:
.INTERMEDIATE: FOO-gen
FOO.c FOO.h: FOO-gen ;
FOO-gen: qapi-schema.json
RECIPEWhen make needs FOO.c or FOO.h, it runs RECIPE once to generate intermediate target FOO-gen, then considers both FOO.c and FOO.h updated.
--- Makefile | 58 +++++++++++++++++++++++++++++++++----------------- Makefile.objs | 2 +- tests/Makefile.include | 36 +++++++++++++++++++++---------- 3 files changed, 64 insertions(+), 32 deletions(-)
Makefile +38 -20
@@ -384,24 +384,33 @@ qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx $(SRC_PATH)/scripts/hxtool qemu-ga$(EXESUF): LIBS = $(LIBS_QGA) qemu-ga$(EXESUF): QEMU_CFLAGS += -I qga/qapi-generated -gen-out-type = $(subst .,-,$(suffix $@)) - qapi-py = $(SRC_PATH)/scripts/qapi.py $(SRC_PATH)/scripts/ordereddict.py +.INTERMEDIATE: qga/qapi-generated/qga-qapi-types-gen qga/qapi-generated/qga-qapi-types.c qga/qapi-generated/qga-qapi-types.h :\ +qga/qapi-generated/qga-qapi-types-gen ; +qga/qapi-generated/qga-qapi-types-gen: \ $(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-" $<, \ + -o $(dir $@) -p "qga-" $<, \ "GEN","$@") + +.INTERMEDIATE: qga/qapi-generated/qga-qapi-visit-gen qga/qapi-generated/qga-qapi-visit.c qga/qapi-generated/qga-qapi-visit.h :\ +qga/qapi-generated/qga-qapi-visit-gen ; +qga/qapi-generated/qga-qapi-visit-gen: \ $(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-" $<, \ + -o $(dir $@) -p "qga-" $<, \ "GEN","$@") + +.INTERMEDIATE: qga/qapi-generated/qga-qapi-commands-gen qga/qapi-generated/qga-qmp-commands.h qga/qapi-generated/qga-qmp-marshal.c :\ +qga/qapi-generated/qga-qapi-commands-gen ; +qga/qapi-generated/qga-qapi-commands-gen: \ $(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-" $<, \ + -o $(dir $@) -p "qga-" $<, \ "GEN","$@") qapi-modules = $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi/common.json \
@@ -419,30 +428,39 @@ qapi-modules = $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi/common.json \ $(SRC_PATH)/qapi/transaction.json \ $(SRC_PATH)/qapi/ui.json -qapi-types.c qapi-types.h :\ -$(qapi-modules) $(SRC_PATH)/scripts/qapi-types.py $(qapi-py) +.INTERMEDIATE: qapi-types-gen +qapi-types.c qapi-types.h: qapi-types-gen ; +qapi-types-gen: $(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 $<, \ + -b $<, \ "GEN","$@") -qapi-visit.c qapi-visit.h :\ -$(qapi-modules) $(SRC_PATH)/scripts/qapi-visit.py $(qapi-py) + +.INTERMEDIATE: qapi-visit-gen +qapi-visit.c qapi-visit.h: qapi-visit-gen ; +qapi-visit-gen: $(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 $<, \ + -b $<, \ "GEN","$@") -qapi-event.c qapi-event.h :\ -$(qapi-modules) $(SRC_PATH)/scripts/qapi-event.py $(qapi-py) + +.INTERMEDIATE: qapi-event-gen +qapi-event.c qapi-event.h: qapi-event-gen +qapi-event-gen: $(qapi-modules) $(SRC_PATH)/scripts/qapi-event.py $(qapi-py) $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-event.py \ - $(gen-out-type) -o "." $<, \ + $<, \ "GEN","$@") -qmp-commands.h qmp-marshal.c :\ -$(qapi-modules) $(SRC_PATH)/scripts/qapi-commands.py $(qapi-py) + +.INTERMEDIATE: qapi-commands-gen +qmp-commands.h qmp-marshal.c: qapi-commands-gen +qapi-commands-gen: $(qapi-modules) $(SRC_PATH)/scripts/qapi-commands.py $(qapi-py) $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py \ - $(gen-out-type) -o "." $<, \ + $<, \ "GEN","$@") -qmp-introspect.h qmp-introspect.c :\ -$(qapi-modules) $(SRC_PATH)/scripts/qapi-introspect.py $(qapi-py) + +.INTERMEDIATE: qapi-introspect-gen +qmp-introspect.h qmp-introspect.c: qapi-introspect-gen +qapi-introspect-gen: $(qapi-modules) $(SRC_PATH)/scripts/qapi-introspect.py $(qapi-py) $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-introspect.py \ - $(gen-out-type) -o "." $<, \ + $<, \ "GEN","$@") QGALIB_GEN=$(addprefix qga/qapi-generated/, qga-qapi-types.h qga-qapi-visit.h qga-qmp-commands.h)
Makefile.objs +1 -1
@@ -2,7 +2,7 @@ # Common libraries for tools and emulators stub-obj-y = stubs/ crypto/ util-obj-y = util/ qobject/ qapi/ -util-obj-y += qmp-introspect.o qapi-types.o qapi-visit.o qapi-event.o +util-obj-y += qapi-types.o qapi-visit.o qapi-event.o chardev-obj-y = chardev/
tests/Makefile.include +25 -11
@@ -626,30 +626,44 @@ tests/test-logging$(EXESUF): tests/test-logging.o $(test-util-obj-y) tests/test-replication$(EXESUF): tests/test-replication.o $(test-util-obj-y) \ $(test-block-obj-y) -tests/test-qapi-types.c tests/test-qapi-types.h :\ +.INTERMEDIATE: tests/test-qapi-types-gen +tests/test-qapi-types.c tests/test-qapi-types.h: tests/test-qapi-types-gen ; +tests/test-qapi-types-gen: \ $(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-" $<, \ + -o tests -p "test-" $<, \ "GEN","$@") -tests/test-qapi-visit.c tests/test-qapi-visit.h :\ + +.INTERMEDIATE: tests/test-qapi-visit-gen +tests/test-qapi-visit.c tests/test-qapi-visit.h: tests/test-qapi-visit-gen ; +tests/test-qapi-visit-gen: \ $(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-" $<, \ + -o tests -p "test-" $<, \ "GEN","$@") -tests/test-qmp-commands.h tests/test-qmp-marshal.c :\ + +.INTERMEDIATE: tests/test-qapi-commands-gen +tests/test-qmp-commands.h tests/test-qmp-marshal.c: tests/test-qapi-commands-gen ; +tests/test-qapi-commands-gen: \ $(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-" $<, \ + -o tests -p "test-" $<, \ "GEN","$@") -tests/test-qapi-event.c tests/test-qapi-event.h :\ + +.INTERMEDIATE: tests/test-qapi-event-gen +tests/test-qapi-event.c tests/test-qapi-event.h: tests/test-qapi-event-gen ; +tests/test-qapi-event-gen: \ $(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-" $<, \ + -o tests -p "test-" $<, \ "GEN","$@") -tests/test-qmp-introspect.c tests/test-qmp-introspect.h :\ + +.INTERMEDIATE: tests/test-qapi-introspect-gen +tests/test-qmp-introspect.c tests/test-qmp-introspect.h: tests/test-qapi-introspect-gen ; +tests/test-qapi-introspect-gen: \ $(SRC_PATH)/tests/qapi-schema/qapi-schema-test.json $(SRC_PATH)/scripts/qapi-introspect.py $(qapi-py) $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-introspect.py \ - $(gen-out-type) -o tests -p "test-" $<, \ + -o tests -p "test-" $<, \ "GEN","$@") tests/qapi-schema/doc-good.test.texi: $(SRC_PATH)/tests/qapi-schema/doc-good.json $(SRC_PATH)/scripts/qapi2texi.py $(qapi-py)
@@ -660,7 +674,7 @@ tests/test-string-input-visitor$(EXESUF): tests/test-string-input-visitor.o $(te tests/test-qmp-event$(EXESUF): tests/test-qmp-event.o $(test-qapi-obj-y) tests/test-qobject-output-visitor$(EXESUF): tests/test-qobject-output-visitor.o $(test-qapi-obj-y) tests/test-clone-visitor$(EXESUF): tests/test-clone-visitor.o $(test-qapi-obj-y) -tests/test-qobject-input-visitor$(EXESUF): tests/test-qobject-input-visitor.o $(test-qapi-obj-y) +tests/test-qobject-input-visitor$(EXESUF): tests/test-qobject-input-visitor.o $(test-qapi-obj-y) qmp-introspect.o tests/test-qmp-commands$(EXESUF): tests/test-qmp-commands.o tests/test-qmp-marshal.o $(test-qapi-obj-y) tests/test-visitor-serialization$(EXESUF): tests/test-visitor-serialization.o $(test-qapi-obj-y) tests/test-opts-visitor$(EXESUF): tests/test-opts-visitor.o $(test-qapi-obj-y)
Signature · 1 line
2.13.6
Re: [Qemu-devel] [RFC PATCH 10/32] qapi: Don't run generators twice
Quoted 16 lines · Markus Armbruster
The generators always generate both .c and .h, but they can route one of them to the bit bucket. We run them twice, once to generate .c, and once to generate .h. Probably because the naive make rule
FOO.cFOO.h: qapi-schema.json
RECIPEruns RECIPE twice, once to generate
FOO.cand once to generateFOO.h.Employ the usual make trick to generate multiple files in one rule:
.INTERMEDIATE: FOO-gen FOO.c FOO.h: FOO-gen ; FOO-gen: qapi-schema.json RECIPE
Quoted 5 lines
When make needs
FOO.corFOO.h, it runs RECIPE once to generate intermediate target FOO-gen, then considers bothFOO.candFOO.hupdated.Signed-off-by Markus Armbruster <[email protected]>
As explained in the following stackoverflow answer:
https://stackoverflow.com/a/10609434/1277510
Nice
Quoted 189 lines
--- Makefile | 58 +++++++++++++++++++++++++++++++++----------------- Makefile.objs | 2 +- tests/Makefile.include | 36 +++++++++++++++++++++---------- 3 files changed, 64 insertions(+), 32 deletions(-)Makefile +38
-20@@ -384,24 +384,33 @@ qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx $(SRC_PATH)/scripts/hxtool qemu-ga$(EXESUF): LIBS = $(LIBS_QGA) qemu-ga$(EXESUF): QEMU_CFLAGS += -I qga/qapi-generated -gen-out-type = $(subst .,-,$(suffix $@)) - qapi-py = $(SRC_PATH)/scripts/qapi.py $(SRC_PATH)/scripts/ordereddict.py +.INTERMEDIATE: qga/qapi-generated/qga-qapi-types-gen qga/qapi-generated/qga-qapi-types.c qga/qapi-generated/qga-qapi-types.h :\ +qga/qapi-generated/qga-qapi-types-gen ; +qga/qapi-generated/qga-qapi-types-gen: \ $(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-" $<, \ + -o $(dir $@) -p "qga-" $<, \ "GEN","$@") + +.INTERMEDIATE: qga/qapi-generated/qga-qapi-visit-gen qga/qapi-generated/qga-qapi-visit.c qga/qapi-generated/qga-qapi-visit.h :\ +qga/qapi-generated/qga-qapi-visit-gen ; +qga/qapi-generated/qga-qapi-visit-gen: \ $(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-" $<, \ + -o $(dir $@) -p "qga-" $<, \ "GEN","$@") + +.INTERMEDIATE: qga/qapi-generated/qga-qapi-commands-gen qga/qapi-generated/qga-qmp-commands.h qga/qapi-generated/qga-qmp-marshal.c :\ +qga/qapi-generated/qga-qapi-commands-gen ; +qga/qapi-generated/qga-qapi-commands-gen: \ $(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-" $<, \ + -o $(dir $@) -p "qga-" $<, \ "GEN","$@") qapi-modules = $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi/common.json \@@ -419,30 +428,39 @@ qapi-modules = $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi/common.json \ $(SRC_PATH)/qapi/transaction.json \ $(SRC_PATH)/qapi/ui.json -qapi-types.c qapi-types.h :\ -$(qapi-modules) $(SRC_PATH)/scripts/qapi-types.py $(qapi-py) +.INTERMEDIATE: qapi-types-gen +qapi-types.c qapi-types.h: qapi-types-gen ; +qapi-types-gen: $(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 $<, \ + -b $<, \ "GEN","$@") -qapi-visit.c qapi-visit.h :\ -$(qapi-modules) $(SRC_PATH)/scripts/qapi-visit.py $(qapi-py) + +.INTERMEDIATE: qapi-visit-gen +qapi-visit.c qapi-visit.h: qapi-visit-gen ; +qapi-visit-gen: $(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 $<, \ + -b $<, \ "GEN","$@") -qapi-event.c qapi-event.h :\ -$(qapi-modules) $(SRC_PATH)/scripts/qapi-event.py $(qapi-py) + +.INTERMEDIATE: qapi-event-gen +qapi-event.c qapi-event.h: qapi-event-gen +qapi-event-gen: $(qapi-modules) $(SRC_PATH)/scripts/qapi-event.py $(qapi-py) $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-event.py \ - $(gen-out-type) -o "." $<, \ + $<, \ "GEN","$@") -qmp-commands.h qmp-marshal.c :\ -$(qapi-modules) $(SRC_PATH)/scripts/qapi-commands.py $(qapi-py) + +.INTERMEDIATE: qapi-commands-gen +qmp-commands.h qmp-marshal.c: qapi-commands-gen +qapi-commands-gen: $(qapi-modules) $(SRC_PATH)/scripts/qapi-commands.py $(qapi-py) $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py \ - $(gen-out-type) -o "." $<, \ + $<, \ "GEN","$@") -qmp-introspect.h qmp-introspect.c :\ -$(qapi-modules) $(SRC_PATH)/scripts/qapi-introspect.py $(qapi-py) + +.INTERMEDIATE: qapi-introspect-gen +qmp-introspect.h qmp-introspect.c: qapi-introspect-gen +qapi-introspect-gen: $(qapi-modules) $(SRC_PATH)/scripts/qapi-introspect.py $(qapi-py) $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-introspect.py \ - $(gen-out-type) -o "." $<, \ + $<, \ "GEN","$@") QGALIB_GEN=$(addprefix qga/qapi-generated/, qga-qapi-types.h qga-qapi-visit.h qga-qmp-commands.h)Makefile.objs +1
-1@@ -2,7 +2,7 @@ # Common libraries for tools and emulators stub-obj-y = stubs/ crypto/ util-obj-y = util/ qobject/ qapi/ -util-obj-y += qmp-introspect.o qapi-types.o qapi-visit.o qapi-event.o +util-obj-y += qapi-types.o qapi-visit.o qapi-event.o chardev-obj-y = chardev/tests/Makefile.include +25
-12@@ -626,30 +626,44 @@ tests/test-logging$(EXESUF): tests/test-logging.o $(test-util-obj-y) tests/test-replication$(EXESUF): tests/test-replication.o $(test-util-obj-y) \ $(test-block-obj-y) -tests/test-qapi-types.c tests/test-qapi-types.h :\ +.INTERMEDIATE: tests/test-qapi-types-gen +tests/test-qapi-types.c tests/test-qapi-types.h: tests/test-qapi-types-gen ; +tests/test-qapi-types-gen: \ $(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-" $<, \ + -o tests -p "test-" $<, \ "GEN","$@") -tests/test-qapi-visit.c tests/test-qapi-visit.h :\ + +.INTERMEDIATE: tests/test-qapi-visit-gen +tests/test-qapi-visit.c tests/test-qapi-visit.h: tests/test-qapi-visit-gen ; +tests/test-qapi-visit-gen: \ $(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-" $<, \ + -o tests -p "test-" $<, \ "GEN","$@") -tests/test-qmp-commands.h tests/test-qmp-marshal.c :\ + +.INTERMEDIATE: tests/test-qapi-commands-gen +tests/test-qmp-commands.h tests/test-qmp-marshal.c: tests/test-qapi-commands-gen ; +tests/test-qapi-commands-gen: \ $(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-" $<, \ + -o tests -p "test-" $<, \ "GEN","$@") -tests/test-qapi-event.c tests/test-qapi-event.h :\ + +.INTERMEDIATE: tests/test-qapi-event-gen +tests/test-qapi-event.c tests/test-qapi-event.h: tests/test-qapi-event-gen ; +tests/test-qapi-event-gen: \ $(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-" $<, \ + -o tests -p "test-" $<, \ "GEN","$@") -tests/test-qmp-introspect.c tests/test-qmp-introspect.h :\ + +.INTERMEDIATE: tests/test-qapi-introspect-gen +tests/test-qmp-introspect.c tests/test-qmp-introspect.h: tests/test-qapi-introspect-gen ; +tests/test-qapi-introspect-gen: \ $(SRC_PATH)/tests/qapi-schema/qapi-schema-test.json $(SRC_PATH)/scripts/qapi-introspect.py $(qapi-py) $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-introspect.py \ - $(gen-out-type) -o tests -p "test-" $<, \ + -o tests -p "test-" $<, \ "GEN","$@") tests/qapi-schema/doc-good.test.texi: $(SRC_PATH)/tests/qapi-schema/doc-good.json $(SRC_PATH)/scripts/qapi2texi.py $(qapi-py)@@ -660,7 +674,7 @@ tests/test-string-input-visitor$(EXESUF): tests/test-string-input-visitor.o $(te tests/test-qmp-event$(EXESUF): tests/test-qmp-event.o $(test-qapi-obj-y) tests/test-qobject-output-visitor$(EXESUF): tests/test-qobject-output-visitor.o $(test-qapi-obj-y) tests/test-clone-visitor$(EXESUF): tests/test-clone-visitor.o $(test-qapi-obj-y) -tests/test-qobject-input-visitor$(EXESUF): tests/test-qobject-input-visitor.o $(test-qapi-obj-y) +tests/test-qobject-input-visitor$(EXESUF): tests/test-qobject-input-visitor.o $(test-qapi-obj-y) qmp-introspect.o tests/test-qmp-commands$(EXESUF): tests/test-qmp-commands.o tests/test-qmp-marshal.o $(test-qapi-obj-y) tests/test-visitor-serialization$(EXESUF): tests/test-visitor-serialization.o $(test-qapi-obj-y) tests/test-opts-visitor$(EXESUF): tests/test-opts-visitor.o $(test-qapi-obj-y) --2.13.6
Signature · 1 line
Marc-André Lureau
RFC PATCH 11/32 qapi: Drop the options to generate only .c or .h
In reply to Markus Armbruster--- scripts/qapi-commands.py | 4 ++-- scripts/qapi-event.py | 4 ++-- scripts/qapi-introspect.py | 4 ++-- scripts/qapi-types.py | 4 ++-- scripts/qapi-visit.py | 4 ++-- scripts/qapi.py | 25 ++++--------------------- 6 files changed, 14 insertions(+), 31 deletions(-)
scripts/qapi-commands.py +2 -2
@@ -253,7 +253,7 @@ class QAPISchemaGenCommandVisitor(QAPISchemaVisitor): self._regy += gen_register_command(name, success_response) -(input_file, output_dir, do_c, do_h, prefix, opts) = parse_command_line() +(input_file, output_dir, prefix, opts) = parse_command_line() c_comment = ''' /*
@@ -284,7 +284,7 @@ h_comment = ''' */ ''' -(fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix, +(fdef, fdecl) = open_output(output_dir, prefix, 'qmp-marshal.c', 'qmp-commands.h', c_comment, h_comment)
scripts/qapi-event.py +2 -2
@@ -169,7 +169,7 @@ class QAPISchemaGenEventVisitor(QAPISchemaVisitor): self._event_names.append(name) -(input_file, output_dir, do_c, do_h, prefix, dummy) = parse_command_line() +(input_file, output_dir, prefix, dummy) = parse_command_line() c_comment = ''' /*
@@ -200,7 +200,7 @@ h_comment = ''' */ ''' -(fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix, +(fdef, fdecl) = open_output(output_dir, prefix, 'qapi-event.c', 'qapi-event.h', c_comment, h_comment)
scripts/qapi-introspect.py +2 -2
@@ -169,7 +169,7 @@ const char %(c_name)s[] = %(c_string)s; # We normally mask them, because they're not QMP wire ABI opt_unmask = False -(input_file, output_dir, do_c, do_h, prefix, opts) = \ +(input_file, output_dir, prefix, opts) = \ parse_command_line('u', ['unmask-non-abi-names']) for o, a in opts:
@@ -199,7 +199,7 @@ h_comment = ''' */ ''' -(fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix, +(fdef, fdecl) = open_output(output_dir, prefix, 'qmp-introspect.c', 'qmp-introspect.h', c_comment, h_comment)
scripts/qapi-types.py +2 -2
@@ -243,7 +243,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): # QAPISchemaGenTypeVisitor.visit_end(). do_builtins = False -(input_file, output_dir, do_c, do_h, prefix, opts) = \ +(input_file, output_dir, prefix, opts) = \ parse_command_line('b', ['builtins']) for o, a in opts:
@@ -280,7 +280,7 @@ h_comment = ''' */ ''' -(fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix, +(fdef, fdecl) = open_output(output_dir, prefix, 'qapi-types.c', 'qapi-types.h', c_comment, h_comment)
scripts/qapi-visit.py +2 -2
@@ -327,7 +327,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor): # QAPISchemaGenVisitVisitor.visit_end(). do_builtins = False -(input_file, output_dir, do_c, do_h, prefix, opts) = \ +(input_file, output_dir, prefix, opts) = \ parse_command_line('b', ['builtins']) for o, a in opts:
@@ -363,7 +363,7 @@ h_comment = ''' */ ''' -(fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix, +(fdef, fdecl) = open_output(output_dir, prefix, 'qapi-visit.c', 'qapi-visit.h', c_comment, h_comment)
scripts/qapi.py +4 -21
@@ -1931,8 +1931,6 @@ def parse_command_line(extra_options='', extra_long_options=[]): output_dir = '' prefix = '' - do_c = False - do_h = False extra_opts = [] for oa in opts:
@@ -1947,30 +1945,22 @@ def parse_command_line(extra_options='', extra_long_options=[]): prefix = 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 - if len(args) != 1: print >>sys.stderr, "%s: need exactly one argument" % sys.argv[0] sys.exit(1) fname = args[0] - return (fname, output_dir, do_c, do_h, prefix, extra_opts) + return (fname, output_dir, prefix, extra_opts) # # Generate output files with boilerplate # -def open_output(output_dir, do_c, do_h, prefix, c_file, h_file, +def open_output(output_dir, prefix, c_file, h_file, c_comment, h_comment): guard = guardname(prefix + h_file) c_file = output_dir + prefix + c_file
@@ -1983,15 +1973,8 @@ def open_output(output_dir, do_c, do_h, prefix, c_file, h_file, 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 = open(c_file, 'w') + fdecl = open(h_file, 'w') fdef.write(mcgen(''' /* AUTOMATICALLY GENERATED, DO NOT MODIFY */
Signature · 1 line
2.13.6
Re: [Qemu-devel] [RFC PATCH 11/32] qapi: Drop the options to generate only .c or .h
Quoted 1 line · Markus Armbruster
Signed-off-by Markus Armbruster <[email protected]>
Quoted 187 lines
--- scripts/qapi-commands.py | 4 ++-- scripts/qapi-event.py | 4 ++-- scripts/qapi-introspect.py | 4 ++-- scripts/qapi-types.py | 4 ++-- scripts/qapi-visit.py | 4 ++-- scripts/qapi.py | 25 ++++--------------------- 6 files changed, 14 insertions(+), 31 deletions(-)scripts/qapi-commands.py +2
-2@@ -253,7 +253,7 @@ class QAPISchemaGenCommandVisitor(QAPISchemaVisitor): self._regy += gen_register_command(name, success_response) -(input_file, output_dir, do_c, do_h, prefix, opts) = parse_command_line() +(input_file, output_dir, prefix, opts) = parse_command_line() c_comment = ''' /*@@ -284,7 +284,7 @@ h_comment = ''' */ ''' -(fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix, +(fdef, fdecl) = open_output(output_dir, prefix, 'qmp-marshal.c', 'qmp-commands.h', c_comment, h_comment)scripts/qapi-event.py +2
-2@@ -169,7 +169,7 @@ class QAPISchemaGenEventVisitor(QAPISchemaVisitor): self._event_names.append(name) -(input_file, output_dir, do_c, do_h, prefix, dummy) = parse_command_line() +(input_file, output_dir, prefix, dummy) = parse_command_line() c_comment = ''' /*@@ -200,7 +200,7 @@ h_comment = ''' */ ''' -(fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix, +(fdef, fdecl) = open_output(output_dir, prefix, 'qapi-event.c', 'qapi-event.h', c_comment, h_comment)scripts/qapi-introspect.py +2
-2@@ -169,7 +169,7 @@ const char %(c_name)s[] = %(c_string)s; # We normally mask them, because they're not QMP wire ABI opt_unmask = False -(input_file, output_dir, do_c, do_h, prefix, opts) = \ +(input_file, output_dir, prefix, opts) = \ parse_command_line('u', ['unmask-non-abi-names']) for o, a in opts:@@ -199,7 +199,7 @@ h_comment = ''' */ ''' -(fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix, +(fdef, fdecl) = open_output(output_dir, prefix, 'qmp-introspect.c', 'qmp-introspect.h', c_comment, h_comment)scripts/qapi-types.py +2
-2@@ -243,7 +243,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): # QAPISchemaGenTypeVisitor.visit_end(). do_builtins = False -(input_file, output_dir, do_c, do_h, prefix, opts) = \ +(input_file, output_dir, prefix, opts) = \ parse_command_line('b', ['builtins']) for o, a in opts:@@ -280,7 +280,7 @@ h_comment = ''' */ ''' -(fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix, +(fdef, fdecl) = open_output(output_dir, prefix, 'qapi-types.c', 'qapi-types.h', c_comment, h_comment)scripts/qapi-visit.py +2
-2@@ -327,7 +327,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor): # QAPISchemaGenVisitVisitor.visit_end(). do_builtins = False -(input_file, output_dir, do_c, do_h, prefix, opts) = \ +(input_file, output_dir, prefix, opts) = \ parse_command_line('b', ['builtins']) for o, a in opts:@@ -363,7 +363,7 @@ h_comment = ''' */ ''' -(fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix, +(fdef, fdecl) = open_output(output_dir, prefix, 'qapi-visit.c', 'qapi-visit.h', c_comment, h_comment)scripts/qapi.py +4
-22@@ -1931,8 +1931,6 @@ def parse_command_line(extra_options='', extra_long_options=[]): output_dir = '' prefix = '' - do_c = False - do_h = False extra_opts = [] for oa in opts:@@ -1947,30 +1945,22 @@ def parse_command_line(extra_options='', extra_long_options=[]): prefix = 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 - if len(args) != 1: print >>sys.stderr, "%s: need exactly one argument" % sys.argv[0] sys.exit(1) fname = args[0] - return (fname, output_dir, do_c, do_h, prefix, extra_opts) + return (fname, output_dir, prefix, extra_opts) # # Generate output files with boilerplate # -def open_output(output_dir, do_c, do_h, prefix, c_file, h_file, +def open_output(output_dir, prefix, c_file, h_file, c_comment, h_comment): guard = guardname(prefix + h_file) c_file = output_dir + prefix + c_file@@ -1983,15 +1973,8 @@ def open_output(output_dir, do_c, do_h, prefix, c_file, h_file, 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 = open(c_file, 'w') + fdecl = open(h_file, 'w') fdef.write(mcgen(''' /* AUTOMATICALLY GENERATED, DO NOT MODIFY */ --2.13.6
Signature · 1 line
Marc-André Lureau
RFC PATCH 12/32 qapi: Use argparse to parse command line arguments
In reply to Markus ArmbrusterLess code than with getopt, and we get --help for free.
--- scripts/qapi-commands.py | 13 +++++----- scripts/qapi-event.py | 12 ++++----- scripts/qapi-introspect.py | 22 +++++++--------- scripts/qapi-types.py | 22 ++++++---------- scripts/qapi-visit.py | 24 +++++++---------- scripts/qapi.py | 58 +++++++++++++++--------------------------- scripts/qapi2texi.py | 11 +++++--- tests/qapi-schema/test-qapi.py | 10 +++++--- 8 files changed, 74 insertions(+), 98 deletions(-)
scripts/qapi-commands.py +7 -6
@@ -214,7 +214,7 @@ void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds) QTAILQ_INIT(cmds); ''', - c_prefix=c_name(prefix, protect=False)) + c_prefix=c_name(args.prefix, protect=False)) ret += registry ret += mcgen(''' }
@@ -253,7 +253,7 @@ class QAPISchemaGenCommandVisitor(QAPISchemaVisitor): self._regy += gen_register_command(name, success_response) -(input_file, output_dir, prefix, opts) = parse_command_line() +args = common_argument_parser().parse_args() c_comment = ''' /*
@@ -284,7 +284,7 @@ h_comment = ''' */ ''' -(fdef, fdecl) = open_output(output_dir, prefix, +(fdef, fdecl) = open_output(args.output_dir, args.prefix, 'qmp-marshal.c', 'qmp-commands.h', c_comment, h_comment)
@@ -302,7 +302,7 @@ fdef.write(mcgen(''' #include "%(prefix)sqmp-commands.h" ''', - prefix=prefix)) + prefix=args.prefix)) fdecl.write(mcgen(''' #include "%(prefix)sqapi-types.h"
@@ -312,9 +312,10 @@ fdecl.write(mcgen(''' void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds); ''', - prefix=prefix, c_prefix=c_name(prefix, protect=False))) + prefix=args.prefix, + c_prefix=c_name(args.prefix, protect=False))) -schema = QAPISchema(input_file) +schema = QAPISchema(args.schema) gen = QAPISchemaGenCommandVisitor() schema.visit(gen) fdef.write(gen.defn)
scripts/qapi-event.py +6 -6
@@ -169,7 +169,7 @@ class QAPISchemaGenEventVisitor(QAPISchemaVisitor): self._event_names.append(name) -(input_file, output_dir, prefix, dummy) = parse_command_line() +args = common_argument_parser().parse_args() c_comment = ''' /*
@@ -200,7 +200,7 @@ h_comment = ''' */ ''' -(fdef, fdecl) = open_output(output_dir, prefix, +(fdef, fdecl) = open_output(args.output_dir, args.prefix, 'qapi-event.c', 'qapi-event.h', c_comment, h_comment)
@@ -213,7 +213,7 @@ fdef.write(mcgen(''' #include "qapi/qmp-event.h" ''', - prefix=prefix)) + prefix=args.prefix)) fdecl.write(mcgen(''' #include "qapi/error.h"
@@ -222,11 +222,11 @@ fdecl.write(mcgen(''' #include "%(prefix)sqapi-types.h" ''', - prefix=prefix)) + prefix=args.prefix)) -event_enum_name = c_name(prefix + 'QAPIEvent', protect=False) +event_enum_name = c_name(args.prefix + 'QAPIEvent', protect=False) -schema = QAPISchema(input_file) +schema = QAPISchema(args.schema) gen = QAPISchemaGenEventVisitor() schema.visit(gen) fdef.write(gen.defn)
scripts/qapi-introspect.py +9 -13
@@ -64,7 +64,7 @@ class QAPISchemaGenIntrospectVisitor(QAPISchemaVisitor): # generate C # TODO can generate awfully long lines jsons.extend(self._jsons) - name = c_name(prefix, protect=False) + 'qmp_schema_json' + name = c_name(args.prefix, protect=False) + 'qmp_schema_json' self.decl = mcgen(''' extern const char %(c_name)s[]; ''',
@@ -165,16 +165,12 @@ 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)}) +parser = common_argument_parser() # Debugging aid: unmask QAPI schema's type names # We normally mask them, because they're not QMP wire ABI -opt_unmask = False - -(input_file, output_dir, prefix, opts) = \ - parse_command_line('u', ['unmask-non-abi-names']) - -for o, a in opts: - if o in ('-u', '--unmask-non-abi-names'): - opt_unmask = True +parser.add_argument('-u', '--unmask-non-abi-names', action='store_true', + help='unmask non-ABI names') +args = parser.parse_args() c_comment = ''' /*
@@ -199,7 +195,7 @@ h_comment = ''' */ ''' -(fdef, fdecl) = open_output(output_dir, prefix, +(fdef, fdecl) = open_output(args.output_dir, args.prefix, 'qmp-introspect.c', 'qmp-introspect.h', c_comment, h_comment)
@@ -208,10 +204,10 @@ fdef.write(mcgen(''' #include "%(prefix)sqmp-introspect.h" ''', - prefix=prefix)) + prefix=args.prefix)) -schema = QAPISchema(input_file) -gen = QAPISchemaGenIntrospectVisitor(opt_unmask) +schema = QAPISchema(args.schema) +gen = QAPISchemaGenIntrospectVisitor(args.unmask_non_abi_names) schema.visit(gen) fdef.write(gen.defn) fdecl.write(gen.decl)
scripts/qapi-types.py +8 -14
@@ -185,7 +185,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): self._fwdecl = None # To avoid header dependency hell, we always generate # declarations for built-in types in our header files and - # simply guard them. See also do_builtins (command line + # simply guard them. See also args.builtins (command line # option -b). self._btin += guardend('QAPI_TYPES_BUILTIN') self.decl = self._btin + self.decl
@@ -200,7 +200,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): # TODO use something cleaner than existence of info if not info: self._btin += gen_enum(name, values, prefix) - if do_builtins: + if args.builtins: self.defn += gen_enum_lookup(name, values, prefix) else: self._fwdecl += gen_enum(name, values, prefix)
@@ -211,7 +211,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): self._btin += gen_fwd_object_or_array(name) self._btin += gen_array(name, element_type) self._btin += gen_type_cleanup_decl(name) - if do_builtins: + if args.builtins: self.defn += gen_type_cleanup(name) else: self._fwdecl += gen_fwd_object_or_array(name)
@@ -239,16 +239,10 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): # If you link code generated from multiple schemata, you want only one # instance of the code for built-in types. Generate it only when -# do_builtins, enabled by command line option -b. See also +# args.builtins, enabled by command line option -b. See also # QAPISchemaGenTypeVisitor.visit_end(). -do_builtins = False -(input_file, output_dir, prefix, opts) = \ - parse_command_line('b', ['builtins']) - -for o, a in opts: - if o in ('-b', '--builtins'): - do_builtins = True +args = common_argument_parser(builtins=True).parse_args() c_comment = ''' /*
@@ -280,7 +274,7 @@ h_comment = ''' */ ''' -(fdef, fdecl) = open_output(output_dir, prefix, +(fdef, fdecl) = open_output(args.output_dir, args.prefix, 'qapi-types.c', 'qapi-types.h', c_comment, h_comment)
@@ -290,13 +284,13 @@ fdef.write(mcgen(''' #include "%(prefix)sqapi-types.h" #include "%(prefix)sqapi-visit.h" ''', - prefix=prefix)) + prefix=args.prefix)) fdecl.write(mcgen(''' #include "qapi/util.h" ''')) -schema = QAPISchema(input_file) +schema = QAPISchema(args.schema) gen = QAPISchemaGenTypeVisitor() schema.visit(gen) fdef.write(gen.defn)
scripts/qapi-visit.py +9 -15
@@ -276,7 +276,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor): def visit_end(self): # To avoid header dependency hell, we always generate # declarations for built-in types in our header files and - # simply guard them. See also do_builtins (command line + # simply guard them. See also args.builtins (command line # option -b). self._btin += guardend('QAPI_VISIT_BUILTIN') self.decl = self._btin + self.decl
@@ -287,7 +287,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor): # TODO use something cleaner than existence of info if not info: self._btin += gen_visit_decl(name, scalar=True) - if do_builtins: + if args.builtins: self.defn += gen_visit_enum(name) else: self.decl += gen_visit_decl(name, scalar=True)
@@ -298,7 +298,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor): defn = gen_visit_list(name, element_type) if isinstance(element_type, QAPISchemaBuiltinType): self._btin += decl - if do_builtins: + if args.builtins: self.defn += defn else: self.decl += decl
@@ -323,16 +323,10 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor): # If you link code generated from multiple schemata, you want only one # instance of the code for built-in types. Generate it only when -# do_builtins, enabled by command line option -b. See also +# args.builtins, enabled by command line option -b. See also # QAPISchemaGenVisitVisitor.visit_end(). -do_builtins = False -(input_file, output_dir, prefix, opts) = \ - parse_command_line('b', ['builtins']) - -for o, a in opts: - if o in ('-b', '--builtins'): - do_builtins = True +args = common_argument_parser(builtins=True).parse_args() c_comment = ''' /*
@@ -363,7 +357,7 @@ h_comment = ''' */ ''' -(fdef, fdecl) = open_output(output_dir, prefix, +(fdef, fdecl) = open_output(args.output_dir, args.prefix, 'qapi-visit.c', 'qapi-visit.h', c_comment, h_comment)
@@ -373,7 +367,7 @@ fdef.write(mcgen(''' #include "qapi/error.h" #include "%(prefix)sqapi-visit.h" ''', - prefix=prefix)) + prefix=args.prefix)) fdecl.write(mcgen(''' #include "qapi/visitor.h"
@@ -381,9 +375,9 @@ fdecl.write(mcgen(''' #include "%(prefix)sqapi-types.h" ''', - prefix=prefix)) + prefix=args.prefix)) -schema = QAPISchema(input_file) +schema = QAPISchema(args.schema) gen = QAPISchemaGenVisitVisitor() schema.visit(gen) fdef.write(gen.defn)
scripts/qapi.py +21 -37
80 lines not on this page · raw message
scripts/qapi2texi.py +7 -4
@@ -4,6 +4,8 @@ # This work is licensed under the terms of the GNU LGPL, version 2+. # See the COPYING file in the top-level directory. """This script produces the documentation of a qapi schema in texinfo format""" + +import argparse import re import sys
@@ -279,11 +281,12 @@ def texi_schema(schema): def main(argv): """Takes schema argument, prints result to stdout""" - if len(argv) != 2: - print >>sys.stderr, "%s: need exactly 1 argument: SCHEMA" % argv[0] - sys.exit(1) + parser = argparse.ArgumentParser() + parser.add_argument('schema', + help='QAPI schema source file') + args = parser.parse_args() - schema = qapi.QAPISchema(argv[1]) + schema = qapi.QAPISchema(args.schema) if not qapi.doc_required: print >>sys.stderr, ("%s: need pragma 'doc-required' " "to generate documentation" % argv[0])
tests/qapi-schema/test-qapi.py +7 -3
@@ -12,8 +12,7 @@ from qapi import * from pprint import pprint -import os -import sys +import argparse class QAPISchemaTestVisitor(QAPISchemaVisitor):
@@ -53,7 +52,12 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): for v in variants.variants: print ' case %s: %s' % (v.name, v.type.name) -schema = QAPISchema(sys.argv[1]) +parser = argparse.ArgumentParser() +parser.add_argument('schema', + help='QAPI schema source file') +args = parser.parse_args() + +schema = QAPISchema(args.schema) schema.visit(QAPISchemaTestVisitor()) for doc in schema.docs:
Signature · 1 line
2.13.6
Re: [Qemu-devel] [RFC PATCH 12/32] qapi: Use argparse to parse command line arguments
Quoted 3 lines · Markus Armbruster
Less code than with getopt, and we get --help for free.
Signed-off-by Markus Armbruster <[email protected]>
Quoted 471 lines
--- scripts/qapi-commands.py | 13 +++++----- scripts/qapi-event.py | 12 ++++----- scripts/qapi-introspect.py | 22 +++++++--------- scripts/qapi-types.py | 22 ++++++---------- scripts/qapi-visit.py | 24 +++++++---------- scripts/qapi.py | 58 +++++++++++++++--------------------------- scripts/qapi2texi.py | 11 +++++--- tests/qapi-schema/test-qapi.py | 10 +++++--- 8 files changed, 74 insertions(+), 98 deletions(-)scripts/qapi-commands.py +7
-6@@ -214,7 +214,7 @@ void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds) QTAILQ_INIT(cmds); ''', - c_prefix=c_name(prefix, protect=False)) + c_prefix=c_name(args.prefix, protect=False)) ret += registry ret += mcgen(''' }@@ -253,7 +253,7 @@ class QAPISchemaGenCommandVisitor(QAPISchemaVisitor): self._regy += gen_register_command(name, success_response) -(input_file, output_dir, prefix, opts) = parse_command_line() +args = common_argument_parser().parse_args() c_comment = ''' /*@@ -284,7 +284,7 @@ h_comment = ''' */ ''' -(fdef, fdecl) = open_output(output_dir, prefix, +(fdef, fdecl) = open_output(args.output_dir, args.prefix, 'qmp-marshal.c', 'qmp-commands.h', c_comment, h_comment)@@ -302,7 +302,7 @@ fdef.write(mcgen(''' #include "%(prefix)sqmp-commands.h" ''', - prefix=prefix)) + prefix=args.prefix)) fdecl.write(mcgen(''' #include "%(prefix)sqapi-types.h"@@ -312,9 +312,10 @@ fdecl.write(mcgen(''' void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds); ''', - prefix=prefix, c_prefix=c_name(prefix, protect=False))) + prefix=args.prefix, + c_prefix=c_name(args.prefix, protect=False))) -schema = QAPISchema(input_file) +schema = QAPISchema(args.schema) gen = QAPISchemaGenCommandVisitor() schema.visit(gen) fdef.write(gen.defn)scripts/qapi-event.py +6
-6@@ -169,7 +169,7 @@ class QAPISchemaGenEventVisitor(QAPISchemaVisitor): self._event_names.append(name) -(input_file, output_dir, prefix, dummy) = parse_command_line() +args = common_argument_parser().parse_args() c_comment = ''' /*@@ -200,7 +200,7 @@ h_comment = ''' */ ''' -(fdef, fdecl) = open_output(output_dir, prefix, +(fdef, fdecl) = open_output(args.output_dir, args.prefix, 'qapi-event.c', 'qapi-event.h', c_comment, h_comment)@@ -213,7 +213,7 @@ fdef.write(mcgen(''' #include "qapi/qmp-event.h" ''', - prefix=prefix)) + prefix=args.prefix)) fdecl.write(mcgen(''' #include "qapi/error.h"@@ -222,11 +222,11 @@ fdecl.write(mcgen(''' #include "%(prefix)sqapi-types.h" ''', - prefix=prefix)) + prefix=args.prefix)) -event_enum_name = c_name(prefix + 'QAPIEvent', protect=False) +event_enum_name = c_name(args.prefix + 'QAPIEvent', protect=False) -schema = QAPISchema(input_file) +schema = QAPISchema(args.schema) gen = QAPISchemaGenEventVisitor() schema.visit(gen) fdef.write(gen.defn)scripts/qapi-introspect.py +9
-13@@ -64,7 +64,7 @@ class QAPISchemaGenIntrospectVisitor(QAPISchemaVisitor): # generate C # TODO can generate awfully long lines jsons.extend(self._jsons) - name = c_name(prefix, protect=False) + 'qmp_schema_json' + name = c_name(args.prefix, protect=False) + 'qmp_schema_json' self.decl = mcgen(''' extern const char %(c_name)s[]; ''',@@ -165,16 +165,12 @@ 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)}) +parser = common_argument_parser() # Debugging aid: unmask QAPI schema's type names # We normally mask them, because they're not QMP wire ABI -opt_unmask = False - -(input_file, output_dir, prefix, opts) = \ - parse_command_line('u', ['unmask-non-abi-names']) - -for o, a in opts: - if o in ('-u', '--unmask-non-abi-names'): - opt_unmask = True +parser.add_argument('-u', '--unmask-non-abi-names', action='store_true', + help='unmask non-ABI names') +args = parser.parse_args() c_comment = ''' /*@@ -199,7 +195,7 @@ h_comment = ''' */ ''' -(fdef, fdecl) = open_output(output_dir, prefix, +(fdef, fdecl) = open_output(args.output_dir, args.prefix, 'qmp-introspect.c', 'qmp-introspect.h', c_comment, h_comment)@@ -208,10 +204,10 @@ fdef.write(mcgen(''' #include "%(prefix)sqmp-introspect.h" ''', - prefix=prefix)) + prefix=args.prefix)) -schema = QAPISchema(input_file) -gen = QAPISchemaGenIntrospectVisitor(opt_unmask) +schema = QAPISchema(args.schema) +gen = QAPISchemaGenIntrospectVisitor(args.unmask_non_abi_names) schema.visit(gen) fdef.write(gen.defn) fdecl.write(gen.decl)scripts/qapi-types.py +8
-14@@ -185,7 +185,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): self._fwdecl = None # To avoid header dependency hell, we always generate # declarations for built-in types in our header files and - # simply guard them. See also do_builtins (command line + # simply guard them. See also args.builtins (command line # option -b). self._btin += guardend('QAPI_TYPES_BUILTIN') self.decl = self._btin + self.decl@@ -200,7 +200,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): # TODO use something cleaner than existence of info if not info: self._btin += gen_enum(name, values, prefix) - if do_builtins: + if args.builtins: self.defn += gen_enum_lookup(name, values, prefix) else: self._fwdecl += gen_enum(name, values, prefix)@@ -211,7 +211,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): self._btin += gen_fwd_object_or_array(name) self._btin += gen_array(name, element_type) self._btin += gen_type_cleanup_decl(name) - if do_builtins: + if args.builtins: self.defn += gen_type_cleanup(name) else: self._fwdecl += gen_fwd_object_or_array(name)@@ -239,16 +239,10 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): # If you link code generated from multiple schemata, you want only one # instance of the code for built-in types. Generate it only when -# do_builtins, enabled by command line option -b. See also +# args.builtins, enabled by command line option -b. See also # QAPISchemaGenTypeVisitor.visit_end(). -do_builtins = False -(input_file, output_dir, prefix, opts) = \ - parse_command_line('b', ['builtins']) - -for o, a in opts: - if o in ('-b', '--builtins'): - do_builtins = True +args = common_argument_parser(builtins=True).parse_args() c_comment = ''' /*@@ -280,7 +274,7 @@ h_comment = ''' */ ''' -(fdef, fdecl) = open_output(output_dir, prefix, +(fdef, fdecl) = open_output(args.output_dir, args.prefix, 'qapi-types.c', 'qapi-types.h', c_comment, h_comment)@@ -290,13 +284,13 @@ fdef.write(mcgen(''' #include "%(prefix)sqapi-types.h" #include "%(prefix)sqapi-visit.h" ''', - prefix=prefix)) + prefix=args.prefix)) fdecl.write(mcgen(''' #include "qapi/util.h" ''')) -schema = QAPISchema(input_file) +schema = QAPISchema(args.schema) gen = QAPISchemaGenTypeVisitor() schema.visit(gen) fdef.write(gen.defn)scripts/qapi-visit.py +9
-15@@ -276,7 +276,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor): def visit_end(self): # To avoid header dependency hell, we always generate # declarations for built-in types in our header files and - # simply guard them. See also do_builtins (command line + # simply guard them. See also args.builtins (command line # option -b). self._btin += guardend('QAPI_VISIT_BUILTIN') self.decl = self._btin + self.decl@@ -287,7 +287,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor): # TODO use something cleaner than existence of info if not info: self._btin += gen_visit_decl(name, scalar=True) - if do_builtins: + if args.builtins: self.defn += gen_visit_enum(name) else: self.decl += gen_visit_decl(name, scalar=True)@@ -298,7 +298,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor): defn = gen_visit_list(name, element_type) if isinstance(element_type, QAPISchemaBuiltinType): self._btin += decl - if do_builtins: + if args.builtins: self.defn += defn else: self.decl += decl@@ -323,16 +323,10 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor): # If you link code generated from multiple schemata, you want only one # instance of the code for built-in types. Generate it only when -# do_builtins, enabled by command line option -b. See also +# args.builtins, enabled by command line option -b. See also # QAPISchemaGenVisitVisitor.visit_end(). -do_builtins = False -(input_file, output_dir, prefix, opts) = \ - parse_command_line('b', ['builtins']) - -for o, a in opts: - if o in ('-b', '--builtins'): - do_builtins = True +args = common_argument_parser(builtins=True).parse_args() c_comment = ''' /*@@ -363,7 +357,7 @@ h_comment = ''' */ ''' -(fdef, fdecl) = open_output(output_dir, prefix, +(fdef, fdecl) = open_output(args.output_dir, args.prefix, 'qapi-visit.c', 'qapi-visit.h', c_comment, h_comment)@@ -373,7 +367,7 @@ fdef.write(mcgen(''' #include "qapi/error.h" #include "%(prefix)sqapi-visit.h" ''', - prefix=prefix)) + prefix=args.prefix)) fdecl.write(mcgen(''' #include "qapi/visitor.h"@@ -381,9 +375,9 @@ fdecl.write(mcgen(''' #include "%(prefix)sqapi-types.h" ''', - prefix=prefix)) + prefix=args.prefix)) -schema = QAPISchema(input_file) +schema = QAPISchema(args.schema) gen = QAPISchemaGenVisitVisitor() schema.visit(gen) fdef.write(gen.defn)scripts/qapi.py +21
-37@@ -11,8 +11,8 @@ # This work is licensed under the terms of the GNU GPL, version 2. # See the COPYING file in the top-level directory. +import argparse import errno -import getopt import os import re import string@@ -1917,43 +1917,27 @@ def build_params(arg_type, boxed, extra): # Common command line parsing # +def common_argument_parser(builtins=False): -def parse_command_line(extra_options='', extra_long_options=[]): + def prefix(string): + match = re.match(r'([a-z_.-][a-z0-9_.-]*)?', string, re.I) + if match.end() != len(string): + raise argparse.ArgumentTypeError("funny character '%s'" + % string[match.end()]) + return string - try: - opts, args = getopt.gnu_getopt(sys.argv[1:], - 'chp:o:' + extra_options, - ['source', 'header', 'prefix=', - 'output-dir='] + extra_long_options) - except getopt.GetoptError as err: - print >>sys.stderr, "%s: %s" % (sys.argv[0], str(err)) - sys.exit(1) + parser = argparse.ArgumentParser(conflict_handler='resolve') + if builtins: + parser.add_argument('-b', '--builtins', action='store_true', + help='generate builtins') + parser.add_argument('-o', '--output-dir', default='', + help='output directory') + parser.add_argument('-p', '--prefix', default='', type=prefix, + help='prefix to add to output files') + parser.add_argument('schema', + help='QAPI schema source file') + return parser - output_dir = '' - prefix = '' - extra_opts = [] - - for oa in opts: - o, a = oa - if o in ('-p', '--prefix'): - match = re.match(r'([A-Za-z_.-][A-Za-z0-9_.-]*)?', a) - if match.end() != len(a): - print >>sys.stderr, \ - "%s: 'funny character '%s' in argument of --prefix" \ - % (sys.argv[0], a[match.end()]) - sys.exit(1) - prefix = a - elif o in ('-o', '--output-dir'): - output_dir = a + '/' - else: - extra_opts.append(oa) - - if len(args) != 1: - print >>sys.stderr, "%s: need exactly one argument" % sys.argv[0] - sys.exit(1) - fname = args[0] - - return (fname, output_dir, prefix, extra_opts) # # Generate output files with boilerplate@@ -1963,8 +1947,8 @@ def parse_command_line(extra_options='', extra_long_options=[]): def open_output(output_dir, prefix, c_file, h_file, c_comment, h_comment): guard = guardname(prefix + h_file) - c_file = output_dir + prefix + c_file - h_file = output_dir + prefix + h_file + c_file = os.path.join(output_dir, prefix + c_file) + h_file = os.path.join(output_dir, prefix + h_file) if output_dir: try:scripts/qapi2texi.py +7
-4@@ -4,6 +4,8 @@ # This work is licensed under the terms of the GNU LGPL, version 2+. # See the COPYING file in the top-level directory. """This script produces the documentation of a qapi schema in texinfo format""" + +import argparse import re import sys@@ -279,11 +281,12 @@ def texi_schema(schema): def main(argv): """Takes schema argument, prints result to stdout""" - if len(argv) != 2: - print >>sys.stderr, "%s: need exactly 1 argument: SCHEMA" % argv[0] - sys.exit(1) + parser = argparse.ArgumentParser() + parser.add_argument('schema', + help='QAPI schema source file') + args = parser.parse_args() - schema = qapi.QAPISchema(argv[1]) + schema = qapi.QAPISchema(args.schema) if not qapi.doc_required: print >>sys.stderr, ("%s: need pragma 'doc-required' " "to generate documentation" % argv[0])tests/qapi-schema/test-qapi.py +7
-4@@ -12,8 +12,7 @@ from qapi import * from pprint import pprint -import os -import sys +import argparse class QAPISchemaTestVisitor(QAPISchemaVisitor):@@ -53,7 +52,12 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): for v in variants.variants: print ' case %s: %s' % (v.name, v.type.name) -schema = QAPISchema(sys.argv[1]) +parser = argparse.ArgumentParser() +parser.add_argument('schema', + help='QAPI schema source file') +args = parser.parse_args() + +schema = QAPISchema(args.schema) schema.visit(QAPISchemaTestVisitor()) for doc in schema.docs: --2.13.6
Signature · 1 line
Marc-André Lureau
RFC PATCH 13/32 qapi: Use argparse to open schema file
In reply to Markus ArmbrusterQAPISchema.__init__() opens the schema file. Since it doesn't bother to catch exceptions, an invalid schema argument is reported like this:
Traceback (most recent call last):
File "../scripts/qapi-commands.py", line 318, in <module>
schema = QAPISchema(args.schema)
File "/work/armbru/qemu/scripts/qapi.py", line 1464, in __init__
parser = QAPISchemaParser(open(fname, 'r'))
IOError: [Errno 2] No such file or directory: 'nonexistent'
Leave it to argparse, which handles the exception like this:
usage: qapi-commands.py [-h] [-o OUTPUT_DIR] [-p PREFIX] schema
qapi-commands.py: error: argument schema: can't open 'nonexistent': [Errno 2] No such file or directory: 'nonexistent'
Too verbose for my taste, but let's not second-guess the standard library.
--- scripts/qapi.py | 6 +++--- scripts/qapi2texi.py | 2 +- tests/qapi-schema/test-qapi.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)
scripts/qapi.py +3 -3
@@ -1450,9 +1450,9 @@ class QAPISchemaEvent(QAPISchemaEntity): class QAPISchema(object): - def __init__(self, fname): + def __init__(self, file): try: - parser = QAPISchemaParser(open(fname, 'r')) + parser = QAPISchemaParser(file) self.exprs = check_exprs(parser.exprs) self.docs = parser.docs self._entity_dict = {}
@@ -1934,7 +1934,7 @@ def common_argument_parser(builtins=False): help='output directory') parser.add_argument('-p', '--prefix', default='', type=prefix, help='prefix to add to output files') - parser.add_argument('schema', + parser.add_argument('schema', type=argparse.FileType('r'), help='QAPI schema source file') return parser
scripts/qapi2texi.py +1 -1
@@ -282,7 +282,7 @@ def texi_schema(schema): def main(argv): """Takes schema argument, prints result to stdout""" parser = argparse.ArgumentParser() - parser.add_argument('schema', + parser.add_argument('schema', type=argparse.FileType('r'), help='QAPI schema source file') args = parser.parse_args()
tests/qapi-schema/test-qapi.py +1 -1
@@ -53,7 +53,7 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): print ' case %s: %s' % (v.name, v.type.name) parser = argparse.ArgumentParser() -parser.add_argument('schema', +parser.add_argument('schema', type=argparse.FileType('r'), help='QAPI schema source file') args = parser.parse_args()
Signature · 1 line
2.13.6
Re: [Qemu-devel] [RFC PATCH 13/32] qapi: Use argparse to open schema file
Quoted 10 lines · Markus Armbruster
QAPISchema.__init__()opens the schema file. Since it doesn't bother to catch exceptions, an invalid schema argument is reported like this:Traceback (most recent call last):
File "../scripts/qapi-commands.py", line 318, in <module>
schema = QAPISchema(args.schema)
File "/work/armbru/qemu/scripts/qapi.py", line 1464, in__init__
parser =QAPISchemaParser(open(fname, 'r'))
IOError: [Errno 2] No such file or directory: 'nonexistent'
Quoted 7 lines
Leave it to argparse, which handles the exception like this:
usage:
qapi-commands.py[-h] [-oOUTPUT_DIR] [-p PREFIX] schema
qapi-commands.py: error: argument schema: can't open 'nonexistent': [Errno 2] No such file or directory: 'nonexistent'Too verbose for my taste, but let's not second-guess the standard library.
indeed :)
Quoted 2 lines
Signed-off-by Markus Armbruster <[email protected]>
Quoted 61 lines
--- scripts/qapi.py | 6 +++--- scripts/qapi2texi.py | 2 +- tests/qapi-schema/test-qapi.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)scripts/qapi.py +3
-3@@ -1450,9 +1450,9 @@ class QAPISchemaEvent(QAPISchemaEntity): class QAPISchema(object): - def __init__(self, fname): + def __init__(self, file): try: - parser = QAPISchemaParser(open(fname, 'r')) + parser = QAPISchemaParser(file) self.exprs = check_exprs(parser.exprs) self.docs = parser.docs self._entity_dict = {}@@ -1934,7 +1934,7 @@ def common_argument_parser(builtins=False): help='output directory') parser.add_argument('-p', '--prefix', default='', type=prefix, help='prefix to add to output files') - parser.add_argument('schema', + parser.add_argument('schema', type=argparse.FileType('r'), help='QAPI schema source file') return parserscripts/qapi2texi.py +1
-1@@ -282,7 +282,7 @@ def texi_schema(schema): def main(argv): """Takes schema argument, prints result to stdout""" parser = argparse.ArgumentParser() - parser.add_argument('schema', + parser.add_argument('schema', type=argparse.FileType('r'), help='QAPI schema source file') args = parser.parse_args()tests/qapi-schema/test-qapi.py +1
-2@@ -53,7 +53,7 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): print ' case %s: %s' % (v.name, v.type.name) parser = argparse.ArgumentParser() -parser.add_argument('schema', +parser.add_argument('schema', type=argparse.FileType('r'), help='QAPI schema source file') args = parser.parse_args() --2.13.6
Signature · 1 line
Marc-André Lureau
RFC PATCH 14/32 qapi: Rework generated code for built-in types
In reply to Markus Armbrusterqapi-types.py and qapi-visit.py generate some C code for built-in types. To make this work with multiple schemas, we generate code for built-ins into .c files only when the user asks for it with -b. The user is responsible for linking exactly one set of files generated with -b per program. We generate code for built-ins into .h regardless of -b, but guard it with a preprocessor symbol.
This is cumbersome and inflexible. Move the code generated for built-in types into separate files builtin-qapi-{types,visit}.{c,h}. Run qapi-types.py and qapi-visit.py without a schema argument to generate them. Drop their option -b.
--- .gitignore | 2 ++ Makefile | 18 ++++++++-- Makefile.objs | 1 + docs/devel/qapi-code-gen.txt | 24 +++++++++++-- qga/Makefile.objs | 1 + scripts/qapi-introspect.py | 4 +-- scripts/qapi-types.py | 54 ++++++++++------------------ scripts/qapi-visit.py | 62 ++++++++++++-------------------- scripts/qapi.py | 57 ++++++++++++++++------------- scripts/qapi2texi.py | 2 +- tests/Makefile.include | 4 ++- tests/qapi-schema/builtins.err | 0 tests/qapi-schema/builtins.exit | 1 + tests/qapi-schema/builtins.json | 1 + tests/qapi-schema/builtins.out | 3 ++ tests/qapi-schema/comments.out | 3 -- tests/qapi-schema/doc-bad-section.out | 3 -- tests/qapi-schema/doc-good.out | 3 -- tests/qapi-schema/empty.out | 3 -- tests/qapi-schema/event-case.out | 3 -- tests/qapi-schema/ident-with-escape.out | 3 -- tests/qapi-schema/include-relpath.out | 3 -- tests/qapi-schema/include-repetition.out | 3 -- tests/qapi-schema/include-simple.out | 3 -- tests/qapi-schema/indented-expr.out | 3 -- tests/qapi-schema/qapi-schema-test.out | 3 -- tests/qapi-schema/test-qapi.py | 4 +-- 27 files changed, 127 insertions(+), 144 deletions(-) create mode 100644 tests/qapi-schema/builtins.err create mode 100644 tests/qapi-schema/builtins.exit create mode 100644 tests/qapi-schema/builtins.json create mode 100644 tests/qapi-schema/builtins.out
.gitignore +2 -0
@@ -1,3 +1,5 @@ +/builtin-qapi-types.[ch] +/builtin-qapi-visit.[ch] /config-devices.* /config-all-devices.* /config-all-disas.*
Makefile +16 -2
@@ -52,6 +52,8 @@ endif include $(SRC_PATH)/rules.mak GENERATED_FILES = qemu-version.h config-host.h qemu-options.def +GENERATED_FILES += builtin-qapi-types.h builtin-qapi-types.c +GENERATED_FILES += builtin-qapi-visit.h builtin-qapi-visit.c GENERATED_FILES += qmp-commands.h qapi-types.h qapi-visit.h qapi-event.h GENERATED_FILES += qmp-marshal.c qapi-types.c qapi-visit.c qapi-event.c GENERATED_FILES += qmp-introspect.h
@@ -428,18 +430,30 @@ qapi-modules = $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi/common.json \ $(SRC_PATH)/qapi/transaction.json \ $(SRC_PATH)/qapi/ui.json +.INTERMEDIATE: builtin-qapi-types-gen +builtin-qapi-types.c builtin-qapi-types.h: builtin-qapi-types-gen ; +builtin-qapi-types-gen: $(SRC_PATH)/scripts/qapi-types.py $(qapi-py) + $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py, \ + "GEN","$@") + +.INTERMEDIATE: builtin-qapi-visit-gen +builtin-qapi-visit.c builtin-qapi-visit.h: builtin-qapi-visit-gen ; +builtin-qapi-visit-gen: $(SRC_PATH)/scripts/qapi-visit.py $(qapi-py) + $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py, \ + "GEN","$@") + .INTERMEDIATE: qapi-types-gen qapi-types.c qapi-types.h: qapi-types-gen ; qapi-types-gen: $(qapi-modules) $(SRC_PATH)/scripts/qapi-types.py $(qapi-py) $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py \ - -b $<, \ + $<, \ "GEN","$@") .INTERMEDIATE: qapi-visit-gen qapi-visit.c qapi-visit.h: qapi-visit-gen ; qapi-visit-gen: $(qapi-modules) $(SRC_PATH)/scripts/qapi-visit.py $(qapi-py) $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py \ - -b $<, \ + $<, \ "GEN","$@") .INTERMEDIATE: qapi-event-gen
Makefile.objs +1 -0
@@ -2,6 +2,7 @@ # Common libraries for tools and emulators stub-obj-y = stubs/ crypto/ util-obj-y = util/ qobject/ qapi/ +util-obj-y += builtin-qapi-types.o builtin-qapi-visit.o util-obj-y += qapi-types.o qapi-visit.o qapi-event.o chardev-obj-y = chardev/
docs/devel/qapi-code-gen.txt +21 -3
@@ -937,7 +937,7 @@ supporting code. The following files are created: $(prefix)qapi-types.h - C types corresponding to types defined in the schema you pass in -$(prefix)qapi-types.c - Cleanup functions for the above C types +$(prefix)qapi-types.c - Support code for the above C types The $(prefix) is an optional parameter used as a namespace to keep the generated code from one schema/code-generation separated from others so code
@@ -954,7 +954,7 @@ Example: #ifndef EXAMPLE_QAPI_TYPES_H #define EXAMPLE_QAPI_TYPES_H -[Built-in types omitted...] + #include "builtin-qapi-types.h" typedef struct UserDefOne UserDefOne;
@@ -1011,6 +1011,14 @@ Example: visit_free(v); } +Type definitions for the built-in types are generated separately, into +builtin-qapi-types.h and builtin-qapi-types.c. These are independent +of the schema. + +Example: + + $ python scripts/qapi-types.py --output-dir="qapi-generated" + === scripts/qapi-visit.py === Used to generate the visitor functions used to walk through and
@@ -1039,7 +1047,9 @@ Example: #ifndef EXAMPLE_QAPI_VISIT_H #define EXAMPLE_QAPI_VISIT_H -[Visitors for built-in types omitted...] + #include "builtin-qapi-visit.h" + #include "example-qapi-types.h" + void visit_type_UserDefOne_members(Visitor *v, UserDefOne *obj, Error **errp); void visit_type_UserDefOne(Visitor *v, const char *name, UserDefOne **obj, Error **errp);
@@ -1140,6 +1150,14 @@ Example: error_propagate(errp, err); } +Visitor functions for the built-in types are generated separately, +into builtin-qapi-visit.h and builtin-qapi-visit.c. These are +independent of the schema. + +Example: + + $ python scripts/qapi-visit.py --output-dir="qapi-generated" + === scripts/qapi-commands.py === Used to generate the marshaling/dispatch functions for the commands
qga/Makefile.objs +1 -0
@@ -2,6 +2,7 @@ qga-obj-y = commands.o guest-agent-command-state.o main.o qga-obj-$(CONFIG_POSIX) += commands-posix.o channel-posix.o qga-obj-$(CONFIG_WIN32) += commands-win32.o channel-win32.o service-win32.o qga-obj-$(CONFIG_WIN32) += vss-win32.o +qga-obj-y += ../builtin-qapi-types.o ../builtin-qapi-visit.o qga-obj-y += qapi-generated/qga-qapi-types.o qapi-generated/qga-qapi-visit.o qga-obj-y += qapi-generated/qga-qmp-marshal.o
scripts/qapi-introspect.py +2 -2
@@ -60,7 +60,7 @@ class QAPISchemaGenIntrospectVisitor(QAPISchemaVisitor): jsons = self._jsons self._jsons = [] for typ in self._used_types: - typ.visit(self) + typ.visit(self, builtins=True) # generate C # TODO can generate awfully long lines jsons.extend(self._jsons)
@@ -208,7 +208,7 @@ fdef.write(mcgen(''' schema = QAPISchema(args.schema) gen = QAPISchemaGenIntrospectVisitor(args.unmask_non_abi_names) -schema.visit(gen) +schema.visit(gen, builtins=True) fdef.write(gen.defn) fdecl.write(gen.decl)
scripts/qapi-types.py +18 -36
95 lines not on this page · raw message
scripts/qapi-visit.py +22 -40
94 lines not on this page · raw message
scripts/qapi.py +33 -24
131 lines not on this page · raw message
scripts/qapi2texi.py +1 -1
@@ -257,7 +257,7 @@ class QAPISchemaGenDocVisitor(qapi.QAPISchemaVisitor): if self.out: self.out += '\n' self.cur_doc = doc - entity.visit(self) + entity.visit(self, builtins=False) self.cur_doc = None def freeform(self, doc):
tests/Makefile.include +3 -1
@@ -371,6 +371,7 @@ check-qtest-s390x-y += tests/drive_del-test$(EXESUF) check-qtest-generic-y += tests/qom-test$(EXESUF) check-qtest-generic-y += tests/test-hmp$(EXESUF) +qapi-schema += builtins.json qapi-schema += alternate-any.json qapi-schema += alternate-array.json qapi-schema += alternate-base.json
@@ -910,7 +911,8 @@ check-tests/qemu-iotests-quick.sh: tests/qemu-iotests-quick.sh qemu-img$(EXESUF) $(patsubst %, check-%, $(check-qapi-schema-y)): check-%.json: $(SRC_PATH)/%.json $(call quiet-command, PYTHONPATH=$(SRC_PATH)/scripts \ $(PYTHON) $(SRC_PATH)/tests/qapi-schema/test-qapi.py \ - $^ >$*.test.out 2>$*.test.err; \ + `echo "$^" | sed '/builtins/d'` \ + >$*.test.out 2>$*.test.err; \ echo $$? >$*.test.exit, \ "TEST","$*.out") @diff -q $(SRC_PATH)/$*.out $*.test.out
tests/qapi-schema/builtins.err new file +0 -0
tests/qapi-schema/builtins.exit new file +1 -0
@@ -0,0 +1 @@ +0
tests/qapi-schema/builtins.json new file +1 -0
@@ -0,0 +1 @@ +# This file exists to simplify make's job, it's not actually read
tests/qapi-schema/builtins.out new file +3 -0
@@ -0,0 +1,3 @@ +enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] + prefix QTYPE +object q_empty
tests/qapi-schema/comments.out +0 -3
@@ -1,4 +1 @@ -enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] - prefix QTYPE enum Status ['good', 'bad', 'ugly'] -object q_empty
tests/qapi-schema/doc-bad-section.out +0 -3
@@ -1,7 +1,4 @@ enum Enum ['one', 'two'] -enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] - prefix QTYPE -object q_empty doc symbol=Enum body= == Produces *invalid* texinfo
tests/qapi-schema/doc-good.out +0 -3
@@ -6,8 +6,6 @@ object Object tag base1 case one: Variant1 case two: Variant2 -enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] - prefix QTYPE object SugaredUnion member type: SugaredUnionKind optional=False tag type
@@ -21,7 +19,6 @@ command cmd q_obj_cmd-arg -> Object gen=True success_response=True boxed=False command cmd-boxed Object -> None gen=True success_response=True boxed=True -object q_empty object q_obj_Variant1-wrapper member data: Variant1 optional=False object q_obj_Variant2-wrapper
tests/qapi-schema/empty.out +0 -3
@@ -1,3 +0,0 @@ -enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] - prefix QTYPE -object q_empty
tests/qapi-schema/event-case.out +0 -3
@@ -1,5 +1,2 @@ -enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] - prefix QTYPE event oops None boxed=False -object q_empty
tests/qapi-schema/ident-with-escape.out +0 -3
@@ -1,7 +1,4 @@ -enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] - prefix QTYPE command fooA q_obj_fooA-arg -> None gen=True success_response=True boxed=False -object q_empty object q_obj_fooA-arg member bar1: str optional=False
tests/qapi-schema/include-relpath.out +0 -3
@@ -1,4 +1 @@ -enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] - prefix QTYPE enum Status ['good', 'bad', 'ugly'] -object q_empty
tests/qapi-schema/include-repetition.out +0 -3
@@ -1,4 +1 @@ -enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] - prefix QTYPE enum Status ['good', 'bad', 'ugly'] -object q_empty
tests/qapi-schema/include-simple.out +0 -3
@@ -1,4 +1 @@ -enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] - prefix QTYPE enum Status ['good', 'bad', 'ugly'] -object q_empty
tests/qapi-schema/indented-expr.out +0 -3
@@ -1,7 +1,4 @@ -enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] - prefix QTYPE command eins None -> None gen=True success_response=True boxed=False -object q_empty command zwei None -> None gen=True success_response=True boxed=False
tests/qapi-schema/qapi-schema-test.out +0 -3
@@ -50,8 +50,6 @@ object NestedEnumsOne member enum4: EnumOne optional=True enum QEnumTwo ['value1', 'value2'] prefix QENUM_TWO -enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] - prefix QTYPE object TestStruct member integer: int optional=False member boolean: bool optional=False
@@ -162,7 +160,6 @@ command guest-get-time q_obj_guest-get-time-arg -> int gen=True success_response=True boxed=False command guest-sync q_obj_guest-sync-arg -> any gen=True success_response=True boxed=False -object q_empty object q_obj_EVENT_C-arg member a: int optional=True member b: UserDefOne optional=True
tests/qapi-schema/test-qapi.py +2 -2
@@ -53,12 +53,12 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): print ' case %s: %s' % (v.name, v.type.name) parser = argparse.ArgumentParser() -parser.add_argument('schema', type=argparse.FileType('r'), +parser.add_argument('schema', type=argparse.FileType('r'), nargs='?', help='QAPI schema source file') args = parser.parse_args() schema = QAPISchema(args.schema) -schema.visit(QAPISchemaTestVisitor()) +schema.visit(QAPISchemaTestVisitor(), builtins=not args.schema) for doc in schema.docs: if doc.symbol:
Signature · 1 line
2.13.6
Re: [Qemu-devel] [RFC PATCH 14/32] qapi: Rework generated code for built-in types
Hi
Quoted 7 lines · Markus Armbruster
qapi-types.pyandqapi-visit.pygenerate some C code for built-in types. To make this work with multiple schemas, we generate code for built-ins into .c files only when the user asks for it with -b. The user is responsible for linking exactly one set of files generated with -b per program. We generate code for built-ins into .h regardless of -b, but guard it with a preprocessor symbol.
Quoted 6 lines
This is cumbersome and inflexible. Move the code generated for built-in types into separate files builtin-qapi-{types,visit}.{c,h}. Run
qapi-types.pyandqapi-visit.pywithout a schema argument to generate them. Drop their option -b.Signed-off-by Markus Armbruster <[email protected]>
Good idea!
I think I would still prefer to see a seperate argument to generate builtin files (rather than absence of schema), but this is minor detail.
Quoted 764 lines
--- .gitignore | 2 ++ Makefile | 18 ++++++++-- Makefile.objs | 1 + docs/devel/qapi-code-gen.txt | 24 +++++++++++-- qga/Makefile.objs | 1 + scripts/qapi-introspect.py | 4 +-- scripts/qapi-types.py | 54 ++++++++++------------------ scripts/qapi-visit.py | 62 ++++++++++++-------------------- scripts/qapi.py | 57 ++++++++++++++++------------- scripts/qapi2texi.py | 2 +- tests/Makefile.include | 4 ++- tests/qapi-schema/builtins.err | 0 tests/qapi-schema/builtins.exit | 1 + tests/qapi-schema/builtins.json | 1 + tests/qapi-schema/builtins.out | 3 ++ tests/qapi-schema/comments.out | 3 -- tests/qapi-schema/doc-bad-section.out | 3 -- tests/qapi-schema/doc-good.out | 3 -- tests/qapi-schema/empty.out | 3 -- tests/qapi-schema/event-case.out | 3 -- tests/qapi-schema/ident-with-escape.out | 3 -- tests/qapi-schema/include-relpath.out | 3 -- tests/qapi-schema/include-repetition.out | 3 -- tests/qapi-schema/include-simple.out | 3 -- tests/qapi-schema/indented-expr.out | 3 -- tests/qapi-schema/qapi-schema-test.out | 3 -- tests/qapi-schema/test-qapi.py | 4 +-- 27 files changed, 127 insertions(+), 144 deletions(-) create mode 100644 tests/qapi-schema/builtins.err create mode 100644 tests/qapi-schema/builtins.exit create mode 100644 tests/qapi-schema/builtins.json create mode 100644 tests/qapi-schema/builtins.out.gitignore +2
-0@@ -1,3 +1,5 @@ +/builtin-qapi-types.[ch] +/builtin-qapi-visit.[ch] /config-devices.* /config-all-devices.* /config-all-disas.*Makefile +16
-2@@ -52,6 +52,8 @@ endif include $(SRC_PATH)/rules.mak GENERATED_FILES = qemu-version.h config-host.h qemu-options.def +GENERATED_FILES += builtin-qapi-types.h builtin-qapi-types.c +GENERATED_FILES += builtin-qapi-visit.h builtin-qapi-visit.c GENERATED_FILES += qmp-commands.h qapi-types.h qapi-visit.h qapi-event.h GENERATED_FILES += qmp-marshal.c qapi-types.c qapi-visit.c qapi-event.c GENERATED_FILES += qmp-introspect.h@@ -428,18 +430,30 @@ qapi-modules = $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi/common.json \ $(SRC_PATH)/qapi/transaction.json \ $(SRC_PATH)/qapi/ui.json +.INTERMEDIATE: builtin-qapi-types-gen +builtin-qapi-types.c builtin-qapi-types.h: builtin-qapi-types-gen ; +builtin-qapi-types-gen: $(SRC_PATH)/scripts/qapi-types.py $(qapi-py) + $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py, \ + "GEN","$@") + +.INTERMEDIATE: builtin-qapi-visit-gen +builtin-qapi-visit.c builtin-qapi-visit.h: builtin-qapi-visit-gen ; +builtin-qapi-visit-gen: $(SRC_PATH)/scripts/qapi-visit.py $(qapi-py) + $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py, \ + "GEN","$@") + .INTERMEDIATE: qapi-types-gen qapi-types.c qapi-types.h: qapi-types-gen ; qapi-types-gen: $(qapi-modules) $(SRC_PATH)/scripts/qapi-types.py $(qapi-py) $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py \ - -b $<, \ + $<, \ "GEN","$@") .INTERMEDIATE: qapi-visit-gen qapi-visit.c qapi-visit.h: qapi-visit-gen ; qapi-visit-gen: $(qapi-modules) $(SRC_PATH)/scripts/qapi-visit.py $(qapi-py) $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py \ - -b $<, \ + $<, \ "GEN","$@") .INTERMEDIATE: qapi-event-genMakefile.objs +1
-0@@ -2,6 +2,7 @@ # Common libraries for tools and emulators stub-obj-y = stubs/ crypto/ util-obj-y = util/ qobject/ qapi/ +util-obj-y += builtin-qapi-types.o builtin-qapi-visit.o util-obj-y += qapi-types.o qapi-visit.o qapi-event.o chardev-obj-y = chardev/docs/devel/qapi-code-gen.txt +21
-3@@ -937,7 +937,7 @@ supporting code. The following files are created: $(prefix)qapi-types.h - C types corresponding to types defined in the schema you pass in -$(prefix)qapi-types.c - Cleanup functions for the above C types +$(prefix)qapi-types.c - Support code for the above C types The $(prefix) is an optional parameter used as a namespace to keep the generated code from one schema/code-generation separated from others so code@@ -954,7 +954,7 @@ Example: #ifndef EXAMPLE_QAPI_TYPES_H #define EXAMPLE_QAPI_TYPES_H -[Built-in types omitted...] + #include "builtin-qapi-types.h" typedef struct UserDefOne UserDefOne;@@ -1011,6 +1011,14 @@ Example: visit_free(v); } +Type definitions for the built-in types are generated separately, into +builtin-qapi-types.h and builtin-qapi-types.c. These are independent +of the schema. + +Example: + + $ python scripts/qapi-types.py --output-dir="qapi-generated" + === scripts/qapi-visit.py === Used to generate the visitor functions used to walk through and@@ -1039,7 +1047,9 @@ Example: #ifndef EXAMPLE_QAPI_VISIT_H #define EXAMPLE_QAPI_VISIT_H -[Visitors for built-in types omitted...] + #include "builtin-qapi-visit.h" + #include "example-qapi-types.h" + void visit_type_UserDefOne_members(Visitor *v, UserDefOne *obj, Error **errp); void visit_type_UserDefOne(Visitor *v, const char *name, UserDefOne **obj, Error **errp);@@ -1140,6 +1150,14 @@ Example: error_propagate(errp, err); } +Visitor functions for the built-in types are generated separately, +into builtin-qapi-visit.h and builtin-qapi-visit.c. These are +independent of the schema. + +Example: + + $ python scripts/qapi-visit.py --output-dir="qapi-generated" + === scripts/qapi-commands.py === Used to generate the marshaling/dispatch functions for the commandsqga/Makefile.objs +1
-0@@ -2,6 +2,7 @@ qga-obj-y = commands.o guest-agent-command-state.o main.o qga-obj-$(CONFIG_POSIX) += commands-posix.o channel-posix.o qga-obj-$(CONFIG_WIN32) += commands-win32.o channel-win32.o service-win32.o qga-obj-$(CONFIG_WIN32) += vss-win32.o +qga-obj-y += ../builtin-qapi-types.o ../builtin-qapi-visit.o qga-obj-y += qapi-generated/qga-qapi-types.o qapi-generated/qga-qapi-visit.o qga-obj-y += qapi-generated/qga-qmp-marshal.oscripts/qapi-introspect.py +2
-2@@ -60,7 +60,7 @@ class QAPISchemaGenIntrospectVisitor(QAPISchemaVisitor): jsons = self._jsons self._jsons = [] for typ in self._used_types: - typ.visit(self) + typ.visit(self, builtins=True) # generate C # TODO can generate awfully long lines jsons.extend(self._jsons)@@ -208,7 +208,7 @@ fdef.write(mcgen(''' schema = QAPISchema(args.schema) gen = QAPISchemaGenIntrospectVisitor(args.unmask_non_abi_names) -schema.visit(gen) +schema.visit(gen, builtins=True) fdef.write(gen.defn) fdecl.write(gen.decl)scripts/qapi-types.py +18
-36@@ -170,7 +170,6 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): self.decl = None self.defn = None self._fwdecl = None - self._btin = None def visit_begin(self, schema): # gen_object() is recursive, ensure it doesn't visit the empty type@@ -178,45 +177,23 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): self.decl = '' self.defn = '' self._fwdecl = '' - self._btin = guardstart('QAPI_TYPES_BUILTIN') def visit_end(self): self.decl = self._fwdecl + self.decl self._fwdecl = None - # To avoid header dependency hell, we always generate - # declarations for built-in types in our header files and - # simply guard them. See also args.builtins (command line - # option -b). - self._btin += guardend('QAPI_TYPES_BUILTIN') - self.decl = self._btin + self.decl - self._btin = None def _gen_type_cleanup(self, name): self.decl += gen_type_cleanup_decl(name) self.defn += gen_type_cleanup(name) def visit_enum_type(self, name, info, values, prefix): - # Special case for our lone builtin enum type - # TODO use something cleaner than existence of info - if not info: - self._btin += gen_enum(name, values, prefix) - if args.builtins: - self.defn += gen_enum_lookup(name, values, prefix) - else: - self._fwdecl += gen_enum(name, values, prefix) - self.defn += gen_enum_lookup(name, values, prefix) + self._fwdecl += gen_enum(name, values, prefix) + self.defn += gen_enum_lookup(name, values, prefix) def visit_array_type(self, name, info, element_type): - if isinstance(element_type, QAPISchemaBuiltinType): - self._btin += gen_fwd_object_or_array(name) - self._btin += gen_array(name, element_type) - self._btin += gen_type_cleanup_decl(name) - if args.builtins: - self.defn += gen_type_cleanup(name) - else: - self._fwdecl += gen_fwd_object_or_array(name) - self.decl += gen_array(name, element_type) - self._gen_type_cleanup(name) + self._fwdecl += gen_fwd_object_or_array(name) + self.decl += gen_array(name, element_type) + self._gen_type_cleanup(name) def visit_object_type(self, name, info, base, members, variants): # Nothing to do for the special empty builtin@@ -237,12 +214,12 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): self.decl += gen_object(name, None, [variants.tag_member], variants) self._gen_type_cleanup(name) -# If you link code generated from multiple schemata, you want only one -# instance of the code for built-in types. Generate it only when -# args.builtins, enabled by command line option -b. See also -# QAPISchemaGenTypeVisitor.visit_end(). - -args = common_argument_parser(builtins=True).parse_args() +argparser = common_argument_parser(builtins=True) +args = argparser.parse_args() +if not args.schema: + if args.prefix: + argparser.error('schema required with -p') + args.prefix = 'builtin-' c_comment = ''' /*@@ -286,13 +263,18 @@ fdef.write(mcgen(''' ''', prefix=args.prefix)) -fdecl.write(mcgen(''' +if args.schema: + fdecl.write(mcgen(''' +#include "builtin-qapi-types.h" +''')) +else: + fdecl.write(mcgen(''' #include "qapi/util.h" ''')) schema = QAPISchema(args.schema) gen = QAPISchemaGenTypeVisitor() -schema.visit(gen) +schema.visit(gen, builtins=not args.schema) fdef.write(gen.defn) fdecl.write(gen.decl)scripts/qapi-visit.py +22
-40@@ -266,43 +266,18 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor): def __init__(self): self.decl = None self.defn = None - self._btin = None def visit_begin(self, schema): self.decl = '' self.defn = '' - self._btin = guardstart('QAPI_VISIT_BUILTIN') - - def visit_end(self): - # To avoid header dependency hell, we always generate - # declarations for built-in types in our header files and - # simply guard them. See also args.builtins (command line - # option -b). - self._btin += guardend('QAPI_VISIT_BUILTIN') - self.decl = self._btin + self.decl - self._btin = None def visit_enum_type(self, name, info, values, prefix): - # Special case for our lone builtin enum type - # TODO use something cleaner than existence of info - if not info: - self._btin += gen_visit_decl(name, scalar=True) - if args.builtins: - self.defn += gen_visit_enum(name) - else: - self.decl += gen_visit_decl(name, scalar=True) - self.defn += gen_visit_enum(name) + self.decl += gen_visit_decl(name, scalar=True) + self.defn += gen_visit_enum(name) def visit_array_type(self, name, info, element_type): - decl = gen_visit_decl(name) - defn = gen_visit_list(name, element_type) - if isinstance(element_type, QAPISchemaBuiltinType): - self._btin += decl - if args.builtins: - self.defn += defn - else: - self.decl += decl - self.defn += defn + self.decl += gen_visit_decl(name) + self.defn += gen_visit_list(name, element_type) def visit_object_type(self, name, info, base, members, variants): # Nothing to do for the special empty builtin@@ -321,12 +296,12 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor): self.decl += gen_visit_decl(name) self.defn += gen_visit_alternate(name, variants) -# If you link code generated from multiple schemata, you want only one -# instance of the code for built-in types. Generate it only when -# args.builtins, enabled by command line option -b. See also -# QAPISchemaGenVisitVisitor.visit_end(). - -args = common_argument_parser(builtins=True).parse_args() +argparser = common_argument_parser(builtins=True) +args = argparser.parse_args() +if not args.schema: + if args.prefix: + argparser.error('schema required with -p') + args.prefix = 'builtin-' c_comment = ''' /*@@ -369,17 +344,24 @@ fdef.write(mcgen(''' ''', prefix=args.prefix)) -fdecl.write(mcgen(''' +if args.schema: + fdecl.write(mcgen(''' +#include "builtin-qapi-visit.h" +#include "%(prefix)sqapi-types.h" + +''', + prefix=args.prefix)) +else: + fdecl.write(mcgen(''' #include "qapi/visitor.h" #include "qapi/qmp/qerror.h" -#include "%(prefix)sqapi-types.h" +#include "builtin-qapi-types.h" -''', - prefix=args.prefix)) +''')) schema = QAPISchema(args.schema) gen = QAPISchemaGenVisitVisitor() -schema.visit(gen) +schema.visit(gen, builtins=not args.schema) fdef.write(gen.defn) fdecl.write(gen.decl)scripts/qapi.py +33
-24@@ -983,7 +983,7 @@ class QAPISchemaEntity(object): def is_implicit(self): return not self.info - def visit(self, visitor): + def visit(self, visitor, builtins): pass@@ -1084,8 +1084,9 @@ class QAPISchemaBuiltinType(QAPISchemaType): def doc_type(self): return self.json_type() - def visit(self, visitor): - visitor.visit_builtin_type(self.name, self.info, self.json_type()) + def visit(self, visitor, builtins): + if builtins: + visitor.visit_builtin_type(self.name, self.info, self.json_type()) class QAPISchemaEnumType(QAPISchemaType):@@ -1118,9 +1119,11 @@ class QAPISchemaEnumType(QAPISchemaType): def json_type(self): return 'string' - def visit(self, visitor): - visitor.visit_enum_type(self.name, self.info, - self.member_names(), self.prefix) + def visit(self, visitor, builtins): + # TODO use something cleaner than existence of info + if builtins or self.info: + visitor.visit_enum_type(self.name, self.info, + self.member_names(), self.prefix) class QAPISchemaArrayType(QAPISchemaType):@@ -1149,8 +1152,10 @@ class QAPISchemaArrayType(QAPISchemaType): return None return 'array of ' + elt_doc_type - def visit(self, visitor): - visitor.visit_array_type(self.name, self.info, self.element_type) + def visit(self, visitor, builtins): + if builtins or not isinstance(self.element_type, + QAPISchemaBuiltinType): + visitor.visit_array_type(self.name, self.info, self.element_type) class QAPISchemaObjectType(QAPISchemaType):@@ -1229,11 +1234,13 @@ class QAPISchemaObjectType(QAPISchemaType): def json_type(self): return 'object' - def visit(self, visitor): - visitor.visit_object_type(self.name, self.info, - self.base, self.local_members, self.variants) - visitor.visit_object_type_flat(self.name, self.info, - self.members, self.variants) + def visit(self, visitor, builtins): + # TODO use something cleaner than existence of info + if builtins or self.info: + visitor.visit_object_type(self.name, self.info, self.base, + self.local_members, self.variants) + visitor.visit_object_type_flat(self.name, self.info, + self.members, self.variants) class QAPISchemaMember(object):@@ -1375,7 +1382,7 @@ class QAPISchemaAlternateType(QAPISchemaType): def json_type(self): return 'value' - def visit(self, visitor): + def visit(self, visitor, builtins): visitor.visit_alternate_type(self.name, self.info, self.variants) def is_empty(self):@@ -1415,7 +1422,7 @@ class QAPISchemaCommand(QAPISchemaEntity): self.ret_type = schema.lookup_type(self._ret_type_name) assert isinstance(self.ret_type, QAPISchemaType) - def visit(self, visitor): + def visit(self, visitor, builtins): visitor.visit_command(self.name, self.info, self.arg_type, self.ret_type, self.gen, self.success_response, self.boxed)@@ -1445,16 +1452,20 @@ class QAPISchemaEvent(QAPISchemaEntity): elif self.boxed: raise QAPISemError(self.info, "Use of 'boxed' requires 'data'") - def visit(self, visitor): + def visit(self, visitor, builtins): visitor.visit_event(self.name, self.info, self.arg_type, self.boxed) class QAPISchema(object): def __init__(self, file): try: - parser = QAPISchemaParser(file) - self.exprs = check_exprs(parser.exprs) - self.docs = parser.docs + if file: + parser = QAPISchemaParser(file) + self.exprs = check_exprs(parser.exprs) + self.docs = parser.docs + else: + self.exprs = [] + self.docs = [] self._entity_dict = {} self._predefining = True self._def_predefineds()@@ -1668,11 +1679,11 @@ class QAPISchema(object): for ent in self._entity_dict.values(): ent.check(self) - def visit(self, visitor): + def visit(self, visitor, builtins=False): visitor.visit_begin(self) for (name, entity) in sorted(self._entity_dict.items()): if visitor.visit_needed(entity): - entity.visit(visitor) + entity.visit(visitor, builtins) visitor.visit_end()@@ -1927,14 +1938,12 @@ def common_argument_parser(builtins=False): return string parser = argparse.ArgumentParser(conflict_handler='resolve') - if builtins: - parser.add_argument('-b', '--builtins', action='store_true', - help='generate builtins') parser.add_argument('-o', '--output-dir', default='', help='output directory') parser.add_argument('-p', '--prefix', default='', type=prefix, help='prefix to add to output files') parser.add_argument('schema', type=argparse.FileType('r'), + nargs='?' if builtins else None, help='QAPI schema source file') return parserscripts/qapi2texi.py +1
-1@@ -257,7 +257,7 @@ class QAPISchemaGenDocVisitor(qapi.QAPISchemaVisitor): if self.out: self.out += '\n' self.cur_doc = doc - entity.visit(self) + entity.visit(self, builtins=False) self.cur_doc = None def freeform(self, doc):tests/Makefile.include +3
-1@@ -371,6 +371,7 @@ check-qtest-s390x-y += tests/drive_del-test$(EXESUF) check-qtest-generic-y += tests/qom-test$(EXESUF) check-qtest-generic-y += tests/test-hmp$(EXESUF) +qapi-schema += builtins.json qapi-schema += alternate-any.json qapi-schema += alternate-array.json qapi-schema += alternate-base.json@@ -910,7 +911,8 @@ check-tests/qemu-iotests-quick.sh: tests/qemu-iotests-quick.sh qemu-img$(EXESUF) $(patsubst %, check-%, $(check-qapi-schema-y)): check-%.json: $(SRC_PATH)/%.json $(call quiet-command, PYTHONPATH=$(SRC_PATH)/scripts \ $(PYTHON) $(SRC_PATH)/tests/qapi-schema/test-qapi.py \ - $^ >$*.test.out 2>$*.test.err; \ + `echo "$^" | sed '/builtins/d'` \ + >$*.test.out 2>$*.test.err; \ echo $$? >$*.test.exit, \ "TEST","$*.out") @diff -q $(SRC_PATH)/$*.out $*.test.outtests/qapi-schema/builtins.err new file +0
-0tests/qapi-schema/builtins.exit new file +1
-0@@ -0,0 +1 @@ +0tests/qapi-schema/builtins.json new file +1
-0@@ -0,0 +1 @@ +# This file exists to simplify make's job, it's not actually readtests/qapi-schema/builtins.out new file +3
-0@@ -0,0 +1,3 @@ +enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] + prefix QTYPE +object q_emptytests/qapi-schema/comments.out +0
-3@@ -1,4 +1 @@ -enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] - prefix QTYPE enum Status ['good', 'bad', 'ugly'] -object q_emptytests/qapi-schema/doc-bad-section.out +0
-3@@ -1,7 +1,4 @@ enum Enum ['one', 'two'] -enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] - prefix QTYPE -object q_empty doc symbol=Enum body= == Produces *invalid* texinfotests/qapi-schema/doc-good.out +0
-3@@ -6,8 +6,6 @@ object Object tag base1 case one: Variant1 case two: Variant2 -enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] - prefix QTYPE object SugaredUnion member type: SugaredUnionKind optional=False tag type@@ -21,7 +19,6 @@ command cmd q_obj_cmd-arg -> Object gen=True success_response=True boxed=False command cmd-boxed Object -> None gen=True success_response=True boxed=True -object q_empty object q_obj_Variant1-wrapper member data: Variant1 optional=False object q_obj_Variant2-wrappertests/qapi-schema/empty.out +0
-3@@ -1,3 +0,0 @@ -enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] - prefix QTYPE -object q_emptytests/qapi-schema/event-case.out +0
-3@@ -1,5 +1,2 @@ -enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] - prefix QTYPE event oops None boxed=False -object q_emptytests/qapi-schema/ident-with-escape.out +0
-3@@ -1,7 +1,4 @@ -enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] - prefix QTYPE command fooA q_obj_fooA-arg -> None gen=True success_response=True boxed=False -object q_empty object q_obj_fooA-arg member bar1: str optional=Falsetests/qapi-schema/include-relpath.out +0
-3@@ -1,4 +1 @@ -enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] - prefix QTYPE enum Status ['good', 'bad', 'ugly'] -object q_emptytests/qapi-schema/include-repetition.out +0
-3@@ -1,4 +1 @@ -enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] - prefix QTYPE enum Status ['good', 'bad', 'ugly'] -object q_emptytests/qapi-schema/include-simple.out +0
-3@@ -1,4 +1 @@ -enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] - prefix QTYPE enum Status ['good', 'bad', 'ugly'] -object q_emptytests/qapi-schema/indented-expr.out +0
-3@@ -1,7 +1,4 @@ -enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] - prefix QTYPE command eins None -> None gen=True success_response=True boxed=False -object q_empty command zwei None -> None gen=True success_response=True boxed=Falsetests/qapi-schema/qapi-schema-test.out +0
-3@@ -50,8 +50,6 @@ object NestedEnumsOne member enum4: EnumOne optional=True enum QEnumTwo ['value1', 'value2'] prefix QENUM_TWO -enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] - prefix QTYPE object TestStruct member integer: int optional=False member boolean: bool optional=False@@ -162,7 +160,6 @@ command guest-get-time q_obj_guest-get-time-arg -> int gen=True success_response=True boxed=False command guest-sync q_obj_guest-sync-arg -> any gen=True success_response=True boxed=False -object q_empty object q_obj_EVENT_C-arg member a: int optional=True member b: UserDefOne optional=Truetests/qapi-schema/test-qapi.py +2
-3@@ -53,12 +53,12 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): print ' case %s: %s' % (v.name, v.type.name) parser = argparse.ArgumentParser() -parser.add_argument('schema', type=argparse.FileType('r'), +parser.add_argument('schema', type=argparse.FileType('r'), nargs='?', help='QAPI schema source file') args = parser.parse_args() schema = QAPISchema(args.schema) -schema.visit(QAPISchemaTestVisitor()) +schema.visit(QAPISchemaTestVisitor(), builtins=not args.schema) for doc in schema.docs: if doc.symbol: --2.13.6
Signature · 1 line
Marc-André Lureau
Re: [Qemu-devel] [RFC PATCH 14/32] qapi: Rework generated code for built-in types
Quoted 15 lines · Marc-André Lureau
Hi
Quoted 12 lines · Markus Armbruster
qapi-types.pyandqapi-visit.pygenerate some C code for built-in types. To make this work with multiple schemas, we generate code for built-ins into .c files only when the user asks for it with -b. The user is responsible for linking exactly one set of files generated with -b per program. We generate code for built-ins into .h regardless of -b, but guard it with a preprocessor symbol.This is cumbersome and inflexible. Move the code generated for built-in types into separate files builtin-qapi-{types,visit}.{c,h}. Run
qapi-types.pyandqapi-visit.pywithout a schema argument to generate them. Drop their option -b.
Quoted 7 lines
Quoted 1 line
Signed-off-by Markus Armbruster <[email protected]>Good idea!
I think I would still prefer to see a seperate argument to generate builtin files (rather than absence of schema), but this is minor detail.
An option to generate built-ins would have to conflict with -p and the positional argument. I tried the stupidest solution that could possibly work first.
Quoted 1 line
Reviewed-by Marc-André Lureau <[email protected]>
Thanks!
RFC PATCH 15/32 tests/qapi-schema: Improve simple union coverage
In reply to Markus ArmbrusterThis demonstrates a bug in the lowering of simple unions: if more than one schema uses the same built-in type T for a simple union member, they all generate the same q_obj_T_wrapper into their qapi-types.h. They clash when you include more than one schema's qapi-types.h.
--- tests/qapi-schema/qapi-schema-test.json | 6 ++++++ tests/qapi-schema/qapi-schema-test.out | 10 ++++++++++ 2 files changed, 16 insertions(+)
tests/qapi-schema/qapi-schema-test.json +6 -0
@@ -82,6 +82,12 @@ 'base': 'UserDefZero', 'data': { 'string': 'str', 'enum1': 'EnumOne' } } +{ 'union': 'UserDefSimpleUnion', + 'data': { 'value1': 'UserDefA', +# FIXME generated q_obj_int_wrapper clashes with qapi-schema.json's +# 'value2': 'int', + 'value3': 'UserDefB' } } + # this variant of UserDefFlatUnion defaults to a union that uses members with # allocated types to test corner cases in the cleanup/dealloc visitor { 'union': 'UserDefFlatUnion2',
tests/qapi-schema/qapi-schema-test.out +10 -0
@@ -108,6 +108,12 @@ object UserDefOptions member u16: uint16List optional=True member i64x: int optional=True member u64x: uint64 optional=True +object UserDefSimpleUnion + member type: UserDefSimpleUnionKind optional=False + tag type + case value1: q_obj_UserDefA-wrapper + case value3: q_obj_UserDefB-wrapper +enum UserDefSimpleUnionKind ['value1', 'value3'] object UserDefTwo member string0: str optional=False member dict1: UserDefTwoDict optional=False
@@ -169,6 +175,10 @@ object q_obj_EVENT_D-arg member b: str optional=False member c: str optional=True member enum3: EnumOne optional=True +object q_obj_UserDefA-wrapper + member data: UserDefA optional=False +object q_obj_UserDefB-wrapper + member data: UserDefB optional=False object q_obj_UserDefFlatUnion2-base member integer: int optional=True member string: str optional=False
Signature · 1 line
2.13.6
Re: [Qemu-devel] [RFC PATCH 15/32] tests/qapi-schema: Improve simple union coverage
Quoted 4 lines · Markus Armbruster
This demonstrates a bug in the lowering of simple unions: if more than one schema uses the same built-in type T for a simple union member, they all generate the same
q_obj_T_wrapperinto theirqapi-types.h. They clash when you include more than one schema'sqapi-types.h.
Ah, I don't remember seeing that when I splitted the schema in my qapi-if / conditional series.
Could it happen with non-built-in types ?
Quoted 1 line
Signed-off-by Markus Armbruster <[email protected]>
Quoted 54 lines
--- tests/qapi-schema/qapi-schema-test.json | 6 ++++++ tests/qapi-schema/qapi-schema-test.out | 10 ++++++++++ 2 files changed, 16 insertions(+)tests/qapi-schema/qapi-schema-test.json +6
-0@@ -82,6 +82,12 @@ 'base': 'UserDefZero', 'data': { 'string': 'str', 'enum1': 'EnumOne' } } +{ 'union': 'UserDefSimpleUnion', + 'data': { 'value1': 'UserDefA', +# FIXME generated q_obj_int_wrapper clashes with qapi-schema.json's +# 'value2': 'int', + 'value3': 'UserDefB' } } + # this variant of UserDefFlatUnion defaults to a union that uses members with # allocated types to test corner cases in the cleanup/dealloc visitor { 'union': 'UserDefFlatUnion2',tests/qapi-schema/qapi-schema-test.out +10
-1@@ -108,6 +108,12 @@ object UserDefOptions member u16: uint16List optional=True member i64x: int optional=True member u64x: uint64 optional=True +object UserDefSimpleUnion + member type: UserDefSimpleUnionKind optional=False + tag type + case value1: q_obj_UserDefA-wrapper + case value3: q_obj_UserDefB-wrapper +enum UserDefSimpleUnionKind ['value1', 'value3'] object UserDefTwo member string0: str optional=False member dict1: UserDefTwoDict optional=False@@ -169,6 +175,10 @@ object q_obj_EVENT_D-arg member b: str optional=False member c: str optional=True member enum3: EnumOne optional=True +object q_obj_UserDefA-wrapper + member data: UserDefA optional=False +object q_obj_UserDefB-wrapper + member data: UserDefB optional=False object q_obj_UserDefFlatUnion2-base member integer: int optional=True member string: str optional=False --2.13.6
Signature · 1 line
Marc-André Lureau
Re: [Qemu-devel] [RFC PATCH 15/32] tests/qapi-schema: Improve simple union coverage
Quoted 8 lines · Marc-André Lureau
Quoted 4 lines · Markus Armbruster
This demonstrates a bug in the lowering of simple unions: if more than one schema uses the same built-in type T for a simple union member, they all generate the same
q_obj_T_wrapperinto theirqapi-types.h. They clash when you include more than one schema'sqapi-types.h.Ah, I don't remember seeing that when I splitted the schema in my qapi-if / conditional series.
Simple union members of built-in type are rare. I spotted the problem with options, then realized it's already possible with simple unions.
Quoted 1 line
Could it happen with non-built-in types ?
Yes, but multiple q_obj_T_wrapper can clash only when their T also clash. Name your types more wisely then.
Quoted 3 lines
Quoted 1 line
Signed-off-by Markus Armbruster <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>
Thanks!
RFC PATCH 16/32 qapi: Factor out _make_implicit_wrapper_type()
In reply to Markus Armbruster--- scripts/qapi.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
scripts/qapi.py +6 -2
@@ -1552,6 +1552,11 @@ class QAPISchema(object): members, None)) return name + def _make_implicit_wrapper_type(self, typ, info): + return self._make_implicit_object_type( + typ, info, None, 'wrapper', + [self._make_member('data', typ, info)]) + def _def_enum_type(self, expr, info, doc): name = expr['enum'] data = expr['data']
@@ -1588,8 +1593,7 @@ class QAPISchema(object): if isinstance(typ, list): assert len(typ) == 1 typ = self._make_array_type(typ[0], info) - typ = self._make_implicit_object_type( - typ, info, None, 'wrapper', [self._make_member('data', typ, info)]) + typ = self._make_implicit_wrapper_type(typ, info) return QAPISchemaObjectTypeVariant(case, typ) def _def_union_type(self, expr, info, doc):
Signature · 1 line
2.13.6
Re: [Qemu-devel] [RFC PATCH 16/32] qapi: Factor out _make_implicit_wrapper_type()
Quoted 1 line · Markus Armbruster
Signed-off-by Markus Armbruster <[email protected]>
Quoted 34 lines
--- scripts/qapi.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)scripts/qapi.py +6
-3@@ -1552,6 +1552,11 @@ class QAPISchema(object): members, None)) return name + def _make_implicit_wrapper_type(self, typ, info): + return self._make_implicit_object_type( + typ, info, None, 'wrapper', + [self._make_member('data', typ, info)]) + def _def_enum_type(self, expr, info, doc): name = expr['enum'] data = expr['data']@@ -1588,8 +1593,7 @@ class QAPISchema(object): if isinstance(typ, list): assert len(typ) == 1 typ = self._make_array_type(typ[0], info) - typ = self._make_implicit_object_type( - typ, info, None, 'wrapper', [self._make_member('data', typ, info)]) + typ = self._make_implicit_wrapper_type(typ, info) return QAPISchemaObjectTypeVariant(case, typ) def _def_union_type(self, expr, info, doc): --2.13.6
Signature · 1 line
Marc-André Lureau
RFC PATCH 17/32 qapi: Fix simple union lowering with multiple schemas
In reply to Markus ArmbrusterIf more than one schema uses the same built-in type T for a simple union member, they all generate the same q_obj_T_wrapper into their qapi-types.h. They clash when you include more than one schema's qapi-types.h.
Fix by generating them into builtin-qapi-types.h instead.
--- scripts/qapi-types.py | 12 ++++++++---- scripts/qapi.py | 2 ++ tests/qapi-schema/builtins.out | 30 ++++++++++++++++++++++++++++++ tests/qapi-schema/qapi-schema-test.json | 3 +-- tests/qapi-schema/qapi-schema-test.out | 5 ++--- 5 files changed, 43 insertions(+), 9 deletions(-)
scripts/qapi-types.py +8 -4
@@ -53,7 +53,10 @@ def gen_struct_members(members): return ret -def gen_object(name, base, members, variants): +def gen_object(name, info, base, members, variants): + # TODO use something cleaner than existence of info + if not info and args.schema: + return '' # suppress built-in if name in objects_seen: return '' objects_seen.add(name)
@@ -62,7 +65,7 @@ def gen_object(name, base, members, variants): if variants: for v in variants.variants: if isinstance(v.type, QAPISchemaObjectType): - ret += gen_object(v.type.name, v.type.base, + ret += gen_object(v.type.name, v.type.info, v.type.base, v.type.local_members, v.type.variants) ret += mcgen('''
@@ -200,7 +203,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): if name == 'q_empty': return self._fwdecl += gen_fwd_object_or_array(name) - self.decl += gen_object(name, base, members, variants) + self.decl += gen_object(name, info, base, members, variants) if base and not base.is_implicit(): self.decl += gen_upcast(name, base) # TODO Worth changing the visitor signature, so we could
@@ -211,7 +214,8 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): def visit_alternate_type(self, name, info, variants): self._fwdecl += gen_fwd_object_or_array(name) - self.decl += gen_object(name, None, [variants.tag_member], variants) + self.decl += gen_object(name, info, None, + [variants.tag_member], variants) self._gen_type_cleanup(name) argparser = common_argument_parser(builtins=True)
scripts/qapi.py +2 -0
@@ -1499,6 +1499,8 @@ class QAPISchema(object): # would be to use lazy instantiation, while figuring out how to # avoid compilation issues with multiple qapi-types.h. self._make_array_type(name, None) + # TODO same for wrapper types + self._make_implicit_wrapper_type(name, None) def _def_predefineds(self): for t in [('str', 'string', 'char' + pointer_suffix),
tests/qapi-schema/builtins.out +30 -0
@@ -1,3 +1,33 @@ enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] prefix QTYPE object q_empty +object q_obj_any-wrapper + member data: any optional=False +object q_obj_bool-wrapper + member data: bool optional=False +object q_obj_int-wrapper + member data: int optional=False +object q_obj_int16-wrapper + member data: int16 optional=False +object q_obj_int32-wrapper + member data: int32 optional=False +object q_obj_int64-wrapper + member data: int64 optional=False +object q_obj_int8-wrapper + member data: int8 optional=False +object q_obj_null-wrapper + member data: null optional=False +object q_obj_number-wrapper + member data: number optional=False +object q_obj_size-wrapper + member data: size optional=False +object q_obj_str-wrapper + member data: str optional=False +object q_obj_uint16-wrapper + member data: uint16 optional=False +object q_obj_uint32-wrapper + member data: uint32 optional=False +object q_obj_uint64-wrapper + member data: uint64 optional=False +object q_obj_uint8-wrapper + member data: uint8 optional=False
tests/qapi-schema/qapi-schema-test.json +1 -2
@@ -84,8 +84,7 @@ { 'union': 'UserDefSimpleUnion', 'data': { 'value1': 'UserDefA', -# FIXME generated q_obj_int_wrapper clashes with qapi-schema.json's -# 'value2': 'int', + 'value2': 'int', 'value3': 'UserDefB' } } # this variant of UserDefFlatUnion defaults to a union that uses members with
tests/qapi-schema/qapi-schema-test.out +2 -3
@@ -112,8 +112,9 @@ object UserDefSimpleUnion member type: UserDefSimpleUnionKind optional=False tag type case value1: q_obj_UserDefA-wrapper + case value2: q_obj_int-wrapper case value3: q_obj_UserDefB-wrapper -enum UserDefSimpleUnionKind ['value1', 'value3'] +enum UserDefSimpleUnionKind ['value1', 'value2', 'value3'] object UserDefTwo member string0: str optional=False member dict1: UserDefTwoDict optional=False
@@ -211,8 +212,6 @@ object q_obj_numberList-wrapper member data: numberList optional=False object q_obj_sizeList-wrapper member data: sizeList optional=False -object q_obj_str-wrapper - member data: str optional=False object q_obj_strList-wrapper member data: strList optional=False object q_obj_uint16List-wrapper
Signature · 1 line
2.13.6
Re: [Qemu-devel] [RFC PATCH 17/32] qapi: Fix simple union lowering with multiple schemas
Quoted 8 lines · Markus Armbruster
If more than one schema uses the same built-in type T for a simple union member, they all generate the same
q_obj_T_wrapperinto theirqapi-types.h. They clash when you include more than one schema'sqapi-types.h.Fix by generating them into
builtin-qapi-types.hinstead.Signed-off-by Markus Armbruster <[email protected]>
Quoted 145 lines
--- scripts/qapi-types.py | 12 ++++++++---- scripts/qapi.py | 2 ++ tests/qapi-schema/builtins.out | 30 ++++++++++++++++++++++++++++++ tests/qapi-schema/qapi-schema-test.json | 3 +-- tests/qapi-schema/qapi-schema-test.out | 5 ++--- 5 files changed, 43 insertions(+), 9 deletions(-)scripts/qapi-types.py +8
-4@@ -53,7 +53,10 @@ def gen_struct_members(members): return ret -def gen_object(name, base, members, variants): +def gen_object(name, info, base, members, variants): + # TODO use something cleaner than existence of info + if not info and args.schema: + return '' # suppress built-in if name in objects_seen: return '' objects_seen.add(name)@@ -62,7 +65,7 @@ def gen_object(name, base, members, variants): if variants: for v in variants.variants: if isinstance(v.type, QAPISchemaObjectType): - ret += gen_object(v.type.name, v.type.base, + ret += gen_object(v.type.name, v.type.info, v.type.base, v.type.local_members, v.type.variants) ret += mcgen('''@@ -200,7 +203,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): if name == 'q_empty': return self._fwdecl += gen_fwd_object_or_array(name) - self.decl += gen_object(name, base, members, variants) + self.decl += gen_object(name, info, base, members, variants) if base and not base.is_implicit(): self.decl += gen_upcast(name, base) # TODO Worth changing the visitor signature, so we could@@ -211,7 +214,8 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): def visit_alternate_type(self, name, info, variants): self._fwdecl += gen_fwd_object_or_array(name) - self.decl += gen_object(name, None, [variants.tag_member], variants) + self.decl += gen_object(name, info, None, + [variants.tag_member], variants) self._gen_type_cleanup(name) argparser = common_argument_parser(builtins=True)scripts/qapi.py +2
-0@@ -1499,6 +1499,8 @@ class QAPISchema(object): # would be to use lazy instantiation, while figuring out how to # avoid compilation issues with multiple qapi-types.h. self._make_array_type(name, None) + # TODO same for wrapper types + self._make_implicit_wrapper_type(name, None) def _def_predefineds(self): for t in [('str', 'string', 'char' + pointer_suffix),tests/qapi-schema/builtins.out +30
-0@@ -1,3 +1,33 @@ enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] prefix QTYPE object q_empty +object q_obj_any-wrapper + member data: any optional=False +object q_obj_bool-wrapper + member data: bool optional=False +object q_obj_int-wrapper + member data: int optional=False +object q_obj_int16-wrapper + member data: int16 optional=False +object q_obj_int32-wrapper + member data: int32 optional=False +object q_obj_int64-wrapper + member data: int64 optional=False +object q_obj_int8-wrapper + member data: int8 optional=False +object q_obj_null-wrapper + member data: null optional=False +object q_obj_number-wrapper + member data: number optional=False +object q_obj_size-wrapper + member data: size optional=False +object q_obj_str-wrapper + member data: str optional=False +object q_obj_uint16-wrapper + member data: uint16 optional=False +object q_obj_uint32-wrapper + member data: uint32 optional=False +object q_obj_uint64-wrapper + member data: uint64 optional=False +object q_obj_uint8-wrapper + member data: uint8 optional=Falsetests/qapi-schema/qapi-schema-test.json +1
-2@@ -84,8 +84,7 @@ { 'union': 'UserDefSimpleUnion', 'data': { 'value1': 'UserDefA', -# FIXME generated q_obj_int_wrapper clashes with qapi-schema.json's -# 'value2': 'int', + 'value2': 'int', 'value3': 'UserDefB' } } # this variant of UserDefFlatUnion defaults to a union that uses members withtests/qapi-schema/qapi-schema-test.out +2
-4@@ -112,8 +112,9 @@ object UserDefSimpleUnion member type: UserDefSimpleUnionKind optional=False tag type case value1: q_obj_UserDefA-wrapper + case value2: q_obj_int-wrapper case value3: q_obj_UserDefB-wrapper -enum UserDefSimpleUnionKind ['value1', 'value3'] +enum UserDefSimpleUnionKind ['value1', 'value2', 'value3'] object UserDefTwo member string0: str optional=False member dict1: UserDefTwoDict optional=False@@ -211,8 +212,6 @@ object q_obj_numberList-wrapper member data: numberList optional=False object q_obj_sizeList-wrapper member data: sizeList optional=False -object q_obj_str-wrapper - member data: str optional=False object q_obj_strList-wrapper member data: strList optional=False object q_obj_uint16List-wrapper --2.13.6
Signature · 1 line
Marc-André Lureau
RFC PATCH 18/32 docs/devel/qapi-code-gen.txt: Rewrite section on schema syntax
In reply to Markus ArmbrusterSection "QMP/Guest agent schema" is one big paragraph, encumbered with more detail than necessary. It also claims JSON null isn't supported, which is untrue since commit e53188a, v2.4.0. Rewrite it.
--- docs/devel/qapi-code-gen.txt | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-)
docs/devel/qapi-code-gen.txt +18 -18
@@ -25,24 +25,24 @@ how the schemas, scripts, and resulting code are used. == QMP/Guest agent schema == -A QAPI schema file is designed to be loosely based on JSON -(http://www.ietf.org/rfc/rfc7159.txt) with changes for quoting style -and the use of comments; a QAPI schema file is then parsed by a python -code generation program. A valid QAPI schema consists of a series of -top-level expressions, with no commas between them. Where -dictionaries (JSON objects) are used, they are parsed as python -OrderedDicts so that ordering is preserved (for predictable layout of -generated C structs and parameter lists). Ordering doesn't matter -between top-level expressions or the keys within an expression, but -does matter within dictionary values for 'data' and 'returns' members -of a single expression. QAPI schema input is written using 'single -quotes' instead of JSON's "double quotes" (in contrast, Client JSON -Protocol uses no comments, and while input accepts 'single quotes' as -an extension, output is strict JSON using only "double quotes"). As -in JSON, trailing commas are not permitted in arrays or dictionaries. -Input must be ASCII (although QMP supports full Unicode strings, the -QAPI parser does not). At present, there is no place where a QAPI -schema requires the use of JSON numbers or null. +Schema syntax is based on JSON (RFC 7159), with the following +differences: + +* Comments (see below) + +* No JSON numbers + +* Strings use 'single quotes' instead of "double quotes" + +* The input character set is plain ASCII + + Unicode characters need to be escaped. In contrast, the Client JSON + Protocol uses UTF-8. + +A QAPI schema consists of a sequence of JSON values (top-level +expressions), with no commas between them. The order of top-level +expressions doesn't matter. The order of keys in JSON objects is +generally relevant. === Comments ===
Signature · 1 line
2.13.6
Re: [Qemu-devel] [RFC PATCH 18/32] docs/devel/qapi-code-gen.txt: Rewrite section on schema syntax
Quoted 5 lines · Markus Armbruster
Section "QMP/Guest agent schema" is one big paragraph, encumbered with more detail than necessary. It also claims JSON null isn't supported, which is untrue since commit e53188a, v2.4.0. Rewrite it.
Signed-off-by Markus Armbruster <[email protected]>
Quoted 55 lines
--- docs/devel/qapi-code-gen.txt | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-)docs/devel/qapi-code-gen.txt +18
-19@@ -25,24 +25,24 @@ how the schemas, scripts, and resulting code are used. == QMP/Guest agent schema == -A QAPI schema file is designed to be loosely based on JSON -(http://www.ietf.org/rfc/rfc7159.txt) with changes for quoting style -and the use of comments; a QAPI schema file is then parsed by a python -code generation program. A valid QAPI schema consists of a series of -top-level expressions, with no commas between them. Where -dictionaries (JSON objects) are used, they are parsed as python -OrderedDicts so that ordering is preserved (for predictable layout of -generated C structs and parameter lists). Ordering doesn't matter -between top-level expressions or the keys within an expression, but -does matter within dictionary values for 'data' and 'returns' members -of a single expression. QAPI schema input is written using 'single -quotes' instead of JSON's "double quotes" (in contrast, Client JSON -Protocol uses no comments, and while input accepts 'single quotes' as -an extension, output is strict JSON using only "double quotes"). As -in JSON, trailing commas are not permitted in arrays or dictionaries. -Input must be ASCII (although QMP supports full Unicode strings, the -QAPI parser does not). At present, there is no place where a QAPI -schema requires the use of JSON numbers or null. +Schema syntax is based on JSON (RFC 7159), with the following +differences: + +* Comments (see below) + +* No JSON numbers + +* Strings use 'single quotes' instead of "double quotes" + +* The input character set is plain ASCII + + Unicode characters need to be escaped. In contrast, the Client JSON + Protocol uses UTF-8. + +A QAPI schema consists of a sequence of JSON values (top-level +expressions), with no commas between them. The order of top-level +expressions doesn't matter. The order of keys in JSON objects is +generally relevant. === Comments === --2.13.6
Signature · 1 line
Marc-André Lureau
RFC PATCH 19/32 qapi: Accept double-quoted strings
In reply to Markus ArmbrusterThe QAPI schema parser has always accepted only single-quoted strings, even though JSON strings are double-quoted. Accept double-quoted strings as well, so you can write strings containing single quotes without backslash escapes.
--- docs/devel/qapi-code-gen.txt | 2 +- scripts/qapi.py | 8 +++++--- tests/qapi-schema/qapi-schema-test.json | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-)
docs/devel/qapi-code-gen.txt +1 -1
@@ -32,7 +32,7 @@ differences: * No JSON numbers -* Strings use 'single quotes' instead of "double quotes" +* Strings can use 'single quotes' in addition to "double quotes" * The input character set is plain ASCII
scripts/qapi.py +5 -3
@@ -382,14 +382,15 @@ class QAPISchemaParser(object): return elif self.tok in '{}:,[]': return - elif self.tok == "'": + elif self.tok == "'" or self.tok == '"': string = '' esc = False while True: ch = self.src[self.cursor] self.cursor += 1 if ch == '\n': - raise QAPIParseError(self, 'Missing terminating "\'"') + raise QAPIParseError( + self, 'Missing terminating %r' % self.tok) if esc: if ch == 'b': string += '\b'
@@ -429,8 +430,9 @@ class QAPISchemaParser(object): esc = False elif ch == '\\': esc = True - elif ch == "'": + elif ch == self.tok: self.val = string + self.tok = "'" return else: string += ch
tests/qapi-schema/qapi-schema-test.json +1 -1
@@ -11,7 +11,7 @@ 'guest-sync' ] } } { 'struct': 'TestStruct', - 'data': { 'integer': 'int', 'boolean': 'bool', 'string': 'str' } } + 'data': { 'integer': 'int', 'boolean': 'bool', 'string': "str" } } # for testing enums { 'struct': 'NestedEnumsOne',
Signature · 1 line
2.13.6
Re: [Qemu-devel] [RFC PATCH 19/32] qapi: Accept double-quoted strings
Quoted 6 lines · Markus Armbruster
The QAPI schema parser has always accepted only single-quoted strings, even though JSON strings are double-quoted. Accept double-quoted strings as well, so you can write strings containing single quotes without backslash escapes.
Signed-off-by Markus Armbruster <[email protected]>
What's the motivation to allow both? If we were to switch from single to double quote only, that would make more sense. otherwise, patch looks good
Quoted 69 lines
--- docs/devel/qapi-code-gen.txt | 2 +- scripts/qapi.py | 8 +++++--- tests/qapi-schema/qapi-schema-test.json | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-)docs/devel/qapi-code-gen.txt +1
-1@@ -32,7 +32,7 @@ differences: * No JSON numbers -* Strings use 'single quotes' instead of "double quotes" +* Strings can use 'single quotes' in addition to "double quotes" * The input character set is plain ASCIIscripts/qapi.py +5
-3@@ -382,14 +382,15 @@ class QAPISchemaParser(object): return elif self.tok in '{}:,[]': return - elif self.tok == "'": + elif self.tok == "'" or self.tok == '"': string = '' esc = False while True: ch = self.src[self.cursor] self.cursor += 1 if ch == '\n': - raise QAPIParseError(self, 'Missing terminating "\'"') + raise QAPIParseError( + self, 'Missing terminating %r' % self.tok) if esc: if ch == 'b': string += '\b'@@ -429,8 +430,9 @@ class QAPISchemaParser(object): esc = False elif ch == '\\': esc = True - elif ch == "'": + elif ch == self.tok: self.val = string + self.tok = "'" return else: string += chtests/qapi-schema/qapi-schema-test.json +1
-2@@ -11,7 +11,7 @@ 'guest-sync' ] } } { 'struct': 'TestStruct', - 'data': { 'integer': 'int', 'boolean': 'bool', 'string': 'str' } } + 'data': { 'integer': 'int', 'boolean': 'bool', 'string': "str" } } # for testing enums { 'struct': 'NestedEnumsOne', --2.13.6
Signature · 1 line
Marc-André Lureau
Re: [Qemu-devel] [RFC PATCH 19/32] qapi: Accept double-quoted strings
Quoted 10 lines · Marc-André Lureau
Quoted 6 lines · Markus Armbruster
The QAPI schema parser has always accepted only single-quoted strings, even though JSON strings are double-quoted. Accept double-quoted strings as well, so you can write strings containing single quotes without backslash escapes.
Signed-off-by Markus Armbruster <[email protected]>What's the motivation to allow both? If we were to switch from single to double quote only, that would make more sense.
Abandoning single quotes now would require us to touch pretty much every line of code in the schemas. I don't think correcting quotes is worth wrecking git-blame.
Sadly, the schema language is neither JSON, nor an established extension of JSON, nor Python. This commit brings the schema language one step closer to a superset of JSON. I feel "homegrown superset" is a slightly less bad idea than "homegrown with large overlap".
Naming the schema files .json was in bad taste.
Quoted 1 line
otherwise, patch looks good
Ready to upgrade to R-by now?
Want me to work more of my rationale into the commit message?
Re: [Qemu-devel] [RFC PATCH 19/32] qapi: Accept double-quoted strings
Quoted 8 lines · Markus Armbruster
Quoted 6 lines · Marc-André Lureau
Quoted 5 lines · Markus Armbruster
The QAPI schema parser has always accepted only single-quoted strings, even though JSON strings are double-quoted. Accept double-quoted strings as well, so you can write strings containing single quotes without backslash escapes.
Quoted 9 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Markus Armbruster <[email protected]>What's the motivation to allow both? If we were to switch from single to double quote only, that would make more sense.
Abandoning single quotes now would require us to touch pretty much every line of code in the schemas. I don't think correcting quotes is worth wrecking git-blame.
Recent (and upcoming) changes to the schema are already quite invasive. I think we could do it, convert all strings to double-quote, and it would help with getting the schema closer to a valid json.
Fwiw, there are tools like
https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/git-hyper-blame.html
to skip commits in git-blame. It's also fairly easy to run git blame before the reformatting commit.
Quoted 12 lines
Sadly, the schema language is neither JSON, nor an established extension of JSON, nor Python. This commit brings the schema language one step closer to a superset of JSON. I feel "homegrown superset" is a slightly less bad idea than "homegrown with large overlap".
Naming the schema files .json was in bad taste.
Quoted 1 line
otherwise, patch looks good
Ready to upgrade to R-by now?
Want me to work more of my rationale into the commit message?
Signature · 1 line
Marc-André Lureau
Re: [Qemu-devel] [RFC PATCH 19/32] qapi: Accept double-quoted strings
Quoted 14 lines · Marc-André Lureau
Quoted 13 lines · Markus Armbruster
Quoted 10 lines · Marc-André Lureau
Quoted 6 lines · Markus Armbruster
The QAPI schema parser has always accepted only single-quoted strings, even though JSON strings are double-quoted. Accept double-quoted strings as well, so you can write strings containing single quotes without backslash escapes.
Signed-off-by Markus Armbruster <[email protected]>What's the motivation to allow both? If we were to switch from single to double quote only, that would make more sense.
Quoted 8 lines
Quoted 4 lines
Abandoning single quotes now would require us to touch pretty much every line of code in the schemas. I don't think correcting quotes is worth wrecking git-blame.
Recent (and upcoming) changes to the schema are already quite invasive. I think we could do it, convert all strings to double-quote, and it would help with getting the schema closer to a valid json.
Is the recent (and upcoming) churn *that* bad? Got numbers?
Quoted 4 lines
Fwiw, there are tools like
https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/git-hyper-blame.html
to skip commits in git-blame. It's also fairly easy to run git blame before the reformatting commit.
Both techniques add friction...
Quoted 12 lines
Quoted 12 lines
Sadly, the schema language is neither JSON, nor an established extension of JSON, nor Python. This commit brings the schema language one step closer to a superset of JSON. I feel "homegrown superset" is a slightly less bad idea than "homegrown with large overlap".
Naming the schema files .json was in bad taste.
Quoted 1 line
otherwise, patch looks good
Ready to upgrade to R-by now?
Want me to work more of my rationale into the commit message?
Re: [Qemu-devel] [RFC PATCH 19/32] qapi: Accept double-quoted strings
In reply to Markus ArmbrusterQuoted 6 lines · Markus Armbruster
Sadly, the schema language is neither JSON, nor an established extension of JSON, nor Python. This commit brings the schema language one step closer to a superset of JSON. I feel "homegrown superset" is a slightly less bad idea than "homegrown with large overlap".
Naming the schema files .json was in bad taste.
Would it make sense to rename all of our files from .json to .qapi? Then it is obvious that we are using a homegrown syntax; and it is also easy enough to tweak things like .dir-locals.el to recognize that suffix as triggering specific formatting rules. Git rename detection means it is still reasonable to blame across file renames.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [RFC PATCH 19/32] qapi: Accept double-quoted strings
Quoted 7 lines · Eric Blake
Quoted 5 lines · Markus Armbruster
Sadly, the schema language is neither JSON, nor an established extension of JSON, nor Python. This commit brings the schema language one step closer to a superset of JSON. I feel "homegrown superset" is a slightly less bad idea than "homegrown with large overlap".
Quoted 7 lines
Quoted 1 line
Naming the schema files .json was in bad taste.
Would it make sense to rename all of our files from .json to .qapi? Then it is obvious that we are using a homegrown syntax; and it is also easy enough to tweak things like .dir-locals.el to recognize that suffix as triggering specific formatting rules. Git rename detection means it is still reasonable to blame across file renames.
I don't know. I'm always reluctant to rename files. Probably too reluctant. Opinions?
RFC PATCH 20/32 qapi: Frontend for defining command line options
In reply to Markus ArmbrusterTODO explain why
TODO update qapi-code-gen.txt
TODO negative tests
--- scripts/qapi.py | 91 +++++++++++++++++++++++++++++++++ tests/qapi-schema/qapi-schema-test.json | 19 +++++++ tests/qapi-schema/qapi-schema-test.out | 34 ++++++++++++ tests/qapi-schema/test-qapi.py | 10 ++++ 4 files changed, 154 insertions(+)
scripts/qapi.py +91 -0
@@ -606,6 +606,11 @@ def check_name(info, source, name, meta): if meta != 'member-struct': raise QAPISemError(info, "%s does not allow optional name '%s'" % (source, name)) + # Options start with '--' + if meta == 'option': + if not name.startswith('--'): + raise QAPISemError(info, "%s must start with '--'" % source) + membername = name[2:] # Enum members can start with a digit, because the generated C # code always prefixes it with the enum name if meta == 'member-enum' and membername[0].isdigit():
@@ -708,6 +713,17 @@ def check_event(expr, info): expr.get('data'), allow_dict=not boxed, allow_metas=meta) +def check_option(expr, info): + name = expr['option'] + boxed = expr.get('boxed', False) + + meta = ['built-in', 'struct', 'enum'] + if boxed: + meta += ['union', 'alternate'] + check_type(info, "'data' for option '%s'" % name, + expr.get('data'), allow_dict=not boxed, allow_metas=meta) + + def check_union(expr, info): name = expr['union'] base = expr.get('base')
@@ -912,6 +928,10 @@ def check_exprs(exprs): elif 'event' in expr: meta = 'event' check_keys(expr_elem, 'event', [], ['data', 'boxed']) + elif 'option' in expr: + meta = 'option' + check_keys(expr_elem, 'option', ['help'], + ['data', 'short', 'implied-key', 'boxed']) else: raise QAPISemError(expr_elem['info'], "Expression is missing metatype")
@@ -951,6 +971,8 @@ def check_exprs(exprs): check_command(expr, info) elif 'event' in expr: check_event(expr, info) + elif 'option' in expr: + check_option(expr, info) else: assert False, 'unexpected meta type'
@@ -1025,6 +1047,10 @@ class QAPISchemaVisitor(object): def visit_event(self, name, info, arg_type, boxed): pass + def visit_option(self, name, info, arg_type, short, implied_key, + boxed, help_): + pass + class QAPISchemaType(QAPISchemaEntity): # Return the C type for common use.
@@ -1458,6 +1484,56 @@ class QAPISchemaEvent(QAPISchemaEntity): visitor.visit_event(self.name, self.info, self.arg_type, self.boxed) +class QAPISchemaOption(QAPISchemaEntity): + def __init__(self, name, info, doc, arg_type, short, implied_key, + boxed, help_): + QAPISchemaEntity.__init__(self, name, info, doc) + assert not arg_type or isinstance(arg_type, str) + self._arg_type_name = arg_type + self.arg_type = None + self.short = short + self.implied_key = implied_key + self.boxed = boxed + self.help = help_ + + def check(self, schema): + if self._arg_type_name: + self.arg_type = schema.lookup_type(self._arg_type_name) + assert (isinstance(self.arg_type, QAPISchemaType) + and not isinstance(self.arg_type, QAPISchemaArrayType)) + self.arg_type.check(schema) + if self.boxed: + if self.arg_type.is_empty(): + raise QAPISemError(self.info, + "Cannot use 'boxed' with empty type") + else: + assert not isinstance(self.arg_type, QAPISchemaAlternateType) + assert (not isinstance(self.arg_type, QAPISchemaObjectType) + or not self.arg_type.variants) + elif self.boxed: + raise QAPISemError(self.info, "Use of 'boxed' requires 'data'") + if self.short and not (isinstance(self.short, str) + and len(self.short) == 1): + raise QAPISemError(self.info, + "Value of 'short' must be a character") + if self.implied_key and not isinstance(self.implied_key, str): + raise QAPISemError(self.info, + "Value of 'implied-key' must be a string") + if self.help is None: + self.help = [] + if not isinstance(self.help, list): + self.help = [self.help] + if not all([isinstance(elt, str) for elt in self.help]): + raise QAPISemError( + self.info, + "Value of 'help' must be a string or a list of strings") + + def visit(self, visitor, builtins): + visitor.visit_option(self.name, self.info, self.arg_type, + self.short, self.implied_key, + self.boxed, self.help) + + class QAPISchema(object): def __init__(self, file): try:
@@ -1663,6 +1739,19 @@ class QAPISchema(object): name, info, doc, 'arg', self._make_members(data, info)) self._def_entity(QAPISchemaEvent(name, info, doc, data, boxed)) + def _def_option(self, expr, info, doc): + name = expr['option'] + data = expr.get('data') + short = expr.get('short') + implied_key = expr.get('implied-key') + boxed = expr.get('boxed', False) + help_ = expr.get('help') + if isinstance(data, OrderedDict): + data = self._make_implicit_object_type( + name[2:], info, doc, 'optarg', self._make_members(data, info)) + self._def_entity(QAPISchemaOption(name, info, doc, data, + short, implied_key, boxed, help_)) + def _def_exprs(self): for expr_elem in self.exprs: expr = expr_elem['expr']
@@ -1680,6 +1769,8 @@ class QAPISchema(object): self._def_command(expr, info, doc) elif 'event' in expr: self._def_event(expr, info, doc) + elif 'option' in expr: + self._def_option(expr, info, doc) else: assert False
tests/qapi-schema/qapi-schema-test.json +19 -0
@@ -193,3 +193,22 @@ 'data': { 'a': ['__org.qemu_x-Enum'], 'b': ['__org.qemu_x-Struct'], 'c': '__org.qemu_x-Union2', 'd': '__org.qemu_x-Alt' }, 'returns': '__org.qemu_x-Union1' } + +# testing option +{ 'option': '--help', 'short': 'h', + 'help': "option without an argument" } +{ 'option': '--opt-str', 'data': 'str', + 'help': "option's argument is a string" } +{ 'option': '--opt-int', 'data': 'int', + 'help': "option's argument is an integer" } +{ 'option': '--opt-enum', 'data': 'EnumOne', + 'help': "option's argument is an enumeration" } +{ 'option': '--opt-any', 'data': 'any', + 'help': "--opt-any INT option's argument is an integer" } +{ 'option': '--opt-struct', 'data': { 's': 'str', '*i': 'int' }, + 'implied-key': 's', + 'help': [ + "an option with a complex argument", + "and multi-line help" ] } +{ 'option': '--opt-boxed', 'data': 'UserDefZero', 'boxed': true, + 'help': null }
tests/qapi-schema/qapi-schema-test.out +34 -0
@@ -1,3 +1,34 @@ +option --help None + short=h + boxed=False + help= +option without an argument +option --opt-any any + boxed=False + help= +--opt-any INT option's argument is an integer +option --opt-boxed UserDefZero + boxed=True + help= + +option --opt-enum EnumOne + boxed=False + help= +option's argument is an enumeration +option --opt-int int + boxed=False + help= +option's argument is an integer +option --opt-str str + boxed=False + help= +option's argument is a string +option --opt-struct q_obj_opt-struct-optarg + implied-key=s + boxed=False + help= +an option with a complex argument +and multi-line help alternate AltEnumBool tag type case e: EnumOne
@@ -210,6 +241,9 @@ object q_obj_intList-wrapper member data: intList optional=False object q_obj_numberList-wrapper member data: numberList optional=False +object q_obj_opt-struct-optarg + member s: str optional=False + member i: int optional=True object q_obj_sizeList-wrapper member data: sizeList optional=False object q_obj_strList-wrapper
tests/qapi-schema/test-qapi.py +10 -0
@@ -45,6 +45,16 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): print 'event %s %s' % (name, arg_type and arg_type.name) print ' boxed=%s' % boxed + def visit_option(self, name, info, arg_type, short, implied_key, + boxed, help): + print 'option %s %s' % (name, arg_type and arg_type.name) + if short: + print ' short=%s' % short + if implied_key: + print ' implied-key=%s' % implied_key + print ' boxed=%s' % boxed + print ' help=\n%s' % '\n'.join(help) + @staticmethod def _print_variants(variants): if variants:
Signature · 1 line
2.13.6
RFC PATCH 21/32 qapi: Define QAPIOptionKind and QAPIOption automatically
In reply to Markus ArmbrusterEnumeration type QAPIOptionKind enumerates the command line options.
Flat union QAPIOption captures a single command line option. Its tag is QAPIOptionKind, and the variants are the option argument types.
FIXME implement missing clash checking in QAPISchemaObjectType.check_clash() FIXME potential clash in QAPISchema._def_autos()
FIXME made up info in QAPISchema._def_autos()
TODO can we avoid the wrappers around non-object option argument types?
--- scripts/qapi-commands.py | 2 +- scripts/qapi-event.py | 2 +- scripts/qapi-introspect.py | 2 +- scripts/qapi-types.py | 2 +- scripts/qapi-visit.py | 2 +- scripts/qapi.py | 42 ++++++++++++++++++++++++++++++++-- scripts/qapi2texi.py | 2 +- tests/qapi-schema/qapi-schema-test.out | 14 ++++++++++++ tests/qapi-schema/test-qapi.py | 2 +- 9 files changed, 61 insertions(+), 9 deletions(-)
scripts/qapi-commands.py +1 -1
@@ -315,7 +315,7 @@ void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds); prefix=args.prefix, c_prefix=c_name(args.prefix, protect=False))) -schema = QAPISchema(args.schema) +schema = QAPISchema(args.schema, args.prefix) gen = QAPISchemaGenCommandVisitor() schema.visit(gen) fdef.write(gen.defn)
scripts/qapi-event.py +1 -1
@@ -226,7 +226,7 @@ fdecl.write(mcgen(''' event_enum_name = c_name(args.prefix + 'QAPIEvent', protect=False) -schema = QAPISchema(args.schema) +schema = QAPISchema(args.schema, args.prefix) gen = QAPISchemaGenEventVisitor() schema.visit(gen) fdef.write(gen.defn)
scripts/qapi-introspect.py +1 -1
@@ -206,7 +206,7 @@ fdef.write(mcgen(''' ''', prefix=args.prefix)) -schema = QAPISchema(args.schema) +schema = QAPISchema(args.schema, args.prefix) gen = QAPISchemaGenIntrospectVisitor(args.unmask_non_abi_names) schema.visit(gen, builtins=True) fdef.write(gen.defn)
scripts/qapi-types.py +1 -1
@@ -276,7 +276,7 @@ else: #include "qapi/util.h" ''')) -schema = QAPISchema(args.schema) +schema = QAPISchema(args.schema, args.prefix) gen = QAPISchemaGenTypeVisitor() schema.visit(gen, builtins=not args.schema) fdef.write(gen.defn)
scripts/qapi-visit.py +1 -1
@@ -359,7 +359,7 @@ else: ''')) -schema = QAPISchema(args.schema) +schema = QAPISchema(args.schema, args.prefix) gen = QAPISchemaGenVisitVisitor() schema.visit(gen, builtins=not args.schema) fdef.write(gen.defn)
scripts/qapi.py +40 -2
77 lines not on this page · raw message
scripts/qapi2texi.py +1 -1
@@ -286,7 +286,7 @@ def main(argv): help='QAPI schema source file') args = parser.parse_args() - schema = qapi.QAPISchema(args.schema) + schema = qapi.QAPISchema(args.schema, '') if not qapi.doc_required: print >>sys.stderr, ("%s: need pragma 'doc-required' " "to generate documentation" % argv[0])
tests/qapi-schema/qapi-schema-test.out +14 -0
@@ -79,6 +79,18 @@ object NestedEnumsOne member enum2: EnumOne optional=True member enum3: EnumOne optional=False member enum4: EnumOne optional=True +object QAPIOption + member type: QAPIOptionKind optional=False + member idx: int32 optional=False + member cnt: int32 optional=False + tag type + case opt-any: q_obj_any-wrapper + case opt-boxed: UserDefZero + case opt-enum: q_obj_EnumOne-wrapper + case opt-int: q_obj_int-wrapper + case opt-str: q_obj_str-wrapper + case opt-struct: q_obj_opt-struct-optarg +enum QAPIOptionKind ['help', 'opt-any', 'opt-boxed', 'opt-enum', 'opt-int', 'opt-str', 'opt-struct'] enum QEnumTwo ['value1', 'value2'] prefix QENUM_TWO object TestStruct
@@ -207,6 +219,8 @@ object q_obj_EVENT_D-arg member b: str optional=False member c: str optional=True member enum3: EnumOne optional=True +object q_obj_EnumOne-wrapper + member data: EnumOne optional=False object q_obj_UserDefA-wrapper member data: UserDefA optional=False object q_obj_UserDefB-wrapper
tests/qapi-schema/test-qapi.py +1 -1
@@ -67,7 +67,7 @@ parser.add_argument('schema', type=argparse.FileType('r'), nargs='?', help='QAPI schema source file') args = parser.parse_args() -schema = QAPISchema(args.schema) +schema = QAPISchema(args.schema, '') schema.visit(QAPISchemaTestVisitor(), builtins=not args.schema) for doc in schema.docs:
Signature · 1 line
2.13.6
RFC PATCH 22/32 qapi: New helper c_string()
In reply to Markus ArmbrusterUse new c_string() to replace qapi-introspect's more limited to_c_string().
--- scripts/qapi-introspect.py | 8 ++------ scripts/qapi.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-)
scripts/qapi-introspect.py +2 -6
@@ -35,10 +35,6 @@ def to_json(obj, level=0): return ret -def to_c_string(string): - return '"' + string.replace('\\', r'\\').replace('"', r'\"') + '"' - - class QAPISchemaGenIntrospectVisitor(QAPISchemaVisitor): def __init__(self, unmask): self._unmask = unmask
@@ -70,12 +66,12 @@ extern const char %(c_name)s[]; ''', c_name=c_name(name)) lines = to_json(jsons).split('\n') - c_string = '\n '.join([to_c_string(line) for line in lines]) self.defn = mcgen(''' const char %(c_name)s[] = %(c_string)s; ''', c_name=c_name(name), - c_string=c_string) + c_string='\n '.join([c_string(line) + for line in lines])) self._schema = None self._jsons = None self._used_types = None
scripts/qapi.py +15 -0
@@ -1915,6 +1915,21 @@ def c_name(name, protect=True): return 'q_' + name return name + +def c_string(string): + def escape_ch(match): + ch = match.group(0) + esc = {'\a': 'a', '\b': 'b', '\f': 'f', '\n': 'n', '\r': 'r', + '\t': 't', '\v': 'v', '"': r'"', '\\': '\\'}.get(ch) + if not esc: + esc = 'x%02x' % ord(ch) + return '\\' + esc + + if string is None: + return "NULL" + return '"' + re.sub(r'[\0-\37"\\\177]', escape_ch, string) + '"' + + eatspace = '\033EATSPACE.' pointer_suffix = ' *' + eatspace
Signature · 1 line
2.13.6
RFC PATCH 23/32 qapi-options: Command line option backend
In reply to Markus ArmbrusterNew qapi generator qapi-options.py generates code for parsing command line options into an array of QAPIOption.
TODO negative tests
--- Makefile | 11 ++- Makefile.objs | 1 + scripts/qapi-options.py | 199 ++++++++++++++++++++++++++++++++++++++++++++++ tests/Makefile.include | 16 +++- tests/test-qapi-options.c | 74 +++++++++++++++++ 5 files changed, 297 insertions(+), 4 deletions(-) create mode 100644 scripts/qapi-options.py create mode 100644 tests/test-qapi-options.c
Makefile +9 -2
@@ -56,8 +56,8 @@ GENERATED_FILES += builtin-qapi-types.h builtin-qapi-types.c GENERATED_FILES += builtin-qapi-visit.h builtin-qapi-visit.c GENERATED_FILES += qmp-commands.h qapi-types.h qapi-visit.h qapi-event.h GENERATED_FILES += qmp-marshal.c qapi-types.c qapi-visit.c qapi-event.c -GENERATED_FILES += qmp-introspect.h -GENERATED_FILES += qmp-introspect.c +GENERATED_FILES += qapi-options.h qmp-introspect.h +GENERATED_FILES += qapi-options.c qmp-introspect.c GENERATED_FILES += trace/generated-tcg-tracers.h
@@ -470,6 +470,13 @@ qapi-commands-gen: $(qapi-modules) $(SRC_PATH)/scripts/qapi-commands.py $(qapi-p $<, \ "GEN","$@") +.INTERMEDIATE: qapi-options-gen +qapi-options.h qapi-options.c: qapi-options-gen +qapi-options-gen: $(qapi-modules) $(SRC_PATH)/scripts/qapi-options.py $(qapi-py) + $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-options.py \ + $<, \ + "GEN","$@") + .INTERMEDIATE: qapi-introspect-gen qmp-introspect.h qmp-introspect.c: qapi-introspect-gen qapi-introspect-gen: $(qapi-modules) $(SRC_PATH)/scripts/qapi-introspect.py $(qapi-py)
Makefile.objs +1 -0
@@ -80,6 +80,7 @@ common-obj-$(CONFIG_FDT) += device_tree.o # qapi common-obj-y += qmp-marshal.o +common-obj-y += qapi-options.o common-obj-y += qmp-introspect.o common-obj-y += qmp.o hmp.o endif
scripts/qapi-options.py new file +199 -0
199 lines not on this page · raw message
tests/Makefile.include +14 -2
@@ -59,6 +59,7 @@ check-unit-y += tests/test-string-output-visitor$(EXESUF) gcov-files-test-string-output-visitor-y = qapi/string-output-visitor.c check-unit-y += tests/test-qmp-event$(EXESUF) gcov-files-test-qmp-event-y += qapi/qmp-event.c +check-unit-y += tests/test-qapi-options(EXESUF) check-unit-y += tests/test-opts-visitor$(EXESUF) gcov-files-test-opts-visitor-y = qapi/opts-visitor.c check-unit-y += tests/test-coroutine$(EXESUF)
@@ -542,7 +543,7 @@ check-qapi-schema-y := $(addprefix tests/qapi-schema/, $(qapi-schema)) GENERATED_FILES += tests/test-qapi-types.h tests/test-qapi-visit.h \ tests/test-qmp-commands.h tests/test-qapi-event.h \ - tests/test-qmp-introspect.h + tests/test-qapi-options.h tests/test-qmp-introspect.h test-obj-y = tests/check-qnum.o tests/check-qstring.o tests/check-qdict.o \ tests/check-qlist.o tests/check-qnull.o \
@@ -567,7 +568,8 @@ QEMU_CFLAGS += -I$(SRC_PATH)/tests test-util-obj-y = libqemuutil.a test-qom-obj-y = $(qom-obj-y) $(test-util-obj-y) test-qapi-obj-y = tests/test-qapi-visit.o tests/test-qapi-types.o \ - tests/test-qapi-event.o tests/test-qmp-introspect.o \ + tests/test-qapi-event.o tests/test-qapi-options.o \ + tests/test-qmp-introspect.o \ $(test-qom-obj-y) benchmark-crypto-obj-y = $(crypto-obj-y) $(test-qom-obj-y) test-crypto-obj-y = $(crypto-obj-y) $(test-qom-obj-y)
@@ -651,6 +653,15 @@ $(SRC_PATH)/tests/qapi-schema/qapi-schema-test.json $(SRC_PATH)/scripts/qapi-com -o tests -p "test-" $<, \ "GEN","$@") +.INTERMEDIATE: tests/test-qapi-options-gen +tests/test-qapi-options.c tests/test-qapi-options.h: tests/test-qapi-options-gen +tests/test-qapi-options-gen: \ +$(SRC_PATH)/tests/qapi-schema/qapi-schema-test.json $(SRC_PATH)/scripts/qapi-options.py $(qapi-py) + $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-options.py \ + -o tests -p "test-" $<, \ + "GEN","$@") +tests/test-qmp-introspect.c tests/test-qmp-introspect.h :\ + .INTERMEDIATE: tests/test-qapi-event-gen tests/test-qapi-event.c tests/test-qapi-event.h: tests/test-qapi-event-gen ; tests/test-qapi-event-gen: \
@@ -673,6 +684,7 @@ tests/qapi-schema/doc-good.test.texi: $(SRC_PATH)/tests/qapi-schema/doc-good.jso tests/test-string-output-visitor$(EXESUF): tests/test-string-output-visitor.o $(test-qapi-obj-y) tests/test-string-input-visitor$(EXESUF): tests/test-string-input-visitor.o $(test-qapi-obj-y) tests/test-qmp-event$(EXESUF): tests/test-qmp-event.o $(test-qapi-obj-y) +tests/test-qapi-options(EXESUF): tests/test-qapi-options.o $(test-qapi-obj-y) tests/test-qobject-output-visitor$(EXESUF): tests/test-qobject-output-visitor.o $(test-qapi-obj-y) tests/test-clone-visitor$(EXESUF): tests/test-clone-visitor.o $(test-qapi-obj-y) tests/test-qobject-input-visitor$(EXESUF): tests/test-qobject-input-visitor.o $(test-qapi-obj-y) qmp-introspect.o
tests/test-qapi-options.c new file +74 -0
74 lines not on this page · raw message
Signature · 1 line
2.13.6
RFC PATCH 24/32 qapi-options: Generate help string
In reply to Markus Armbruster--- scripts/qapi-options.py | 13 +++++++++++++ 1 file changed, 13 insertions(+)
scripts/qapi-options.py +13 -0
@@ -13,12 +13,15 @@ from qapi import * class QAPISchemaGenOptionVisitor(QAPISchemaVisitor): + # TODO keep help in source order + # TODO generate the part of help that shows syntax def __init__(self): self.decl = None self.defn = None self._shortopts = None self._longopts = None self._cases = None + self._help = None def visit_begin(self, schema): self.decl = ''
@@ -26,15 +29,22 @@ class QAPISchemaGenOptionVisitor(QAPISchemaVisitor): self._shortopts = '' self._longopts = '' self._cases = '' + self._help = [] def visit_end(self): if self._cases: c_max = c_enum_const(args.prefix + 'QAPIOptionKind', '_MAX') + c_help = '\n '.join([c_string(h) for h in self._help]) self.decl += mcgen(''' +extern const char %(c_prefix)sqapi_options_help[]; + %(c_prefix)sQAPIOption *%(c_prefix)sqapi_options_parse(int argc, char *argv[]); ''', c_prefix=c_name(args.prefix, protect=False)) self.defn += mcgen(''' +const char %(c_prefix)sqapi_options_help[] = + %(c_help)s; + %(c_prefix)sQAPIOption *%(c_prefix)sqapi_options_parse(int argc, char *argv[]) { static const struct option longopts[] = {
@@ -72,6 +82,7 @@ class QAPISchemaGenOptionVisitor(QAPISchemaVisitor): } ''', c_prefix=c_name(args.prefix, protect=False), + c_help=c_help, c_shortopts=c_string(self._shortopts), longopts=self._longopts, cases=self._cases,
@@ -79,6 +90,7 @@ class QAPISchemaGenOptionVisitor(QAPISchemaVisitor): self._shortopts = None self._longopts = None self._cases = None + self._help = None def visit_option(self, name, info, arg_type, short, implied_key, boxed, help_):
@@ -140,6 +152,7 @@ case 256 + %(case)s: ''') pop_indent(8) + self._help += help_ args = common_argument_parser().parse_args()
Signature · 1 line
2.13.6
RFC PATCH 25/32 qapi-introspect: Include command line options information
In reply to Markus ArmbrusterMake query-qmp-schema describe command line options in addition to QMP commands and events. Simple, but it pushes query-qmp-schema beyond QMP. Perhaps options introspection should be separate. Perhaps not for the same reason QMP and command line are defined in the same
schema: they share many types.
--- qapi/introspect.json | 22 ++++++++++++++++++++-- scripts/qapi-introspect.py | 10 +++++++++- 2 files changed, 29 insertions(+), 3 deletions(-)
qapi/introspect.json +20 -2
@@ -70,11 +70,13 @@ # # @event: a QMP event # +# @option: a command line option (since 2.11) +# # Since: 2.5 ## { 'enum': 'SchemaMetaType', 'data': [ 'builtin', 'enum', 'array', 'object', 'alternate', - 'command', 'event' ] } + 'command', 'event', 'option' ] } ## # @SchemaInfo:
@@ -103,7 +105,8 @@ 'object': 'SchemaInfoObject', 'alternate': 'SchemaInfoAlternate', 'command': 'SchemaInfoCommand', - 'event': 'SchemaInfoEvent' } } + 'event': 'SchemaInfoEvent', + 'option': 'SchemaInfoOption' } } ## # @SchemaInfoBuiltin:
@@ -278,3 +281,18 @@ ## { 'struct': 'SchemaInfoEvent', 'data': { 'arg-type': 'str' } } + +## +# @SchemaInfoOption: +# +# Additional SchemaInfo members for meta-type 'option'. +# +# @arg-type: the name of the object type that provides the option's +# parameters. +# +# @short: the option character, if any. +# +# Since: 2.11 +## +{ 'struct': 'SchemaInfoOption', + 'data': { 'arg-type': 'str', '*short': 'str' } }
scripts/qapi-introspect.py +9 -1
@@ -108,7 +108,7 @@ const char %(c_name)s[] = %(c_string)s; return self._name(typ.name) def _gen_json(self, name, mtype, obj): - if mtype not in ('command', 'event', 'builtin', 'array'): + if mtype not in ('command', 'event', 'option', 'builtin', 'array'): name = self._name(name) obj['name'] = name obj['meta-type'] = mtype
@@ -161,6 +161,14 @@ 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)}) + def visit_option(self, name, info, arg_type, short, implied_key, + boxed, help_): + arg_type = arg_type or self._schema.the_empty_object_type + obj = {'arg-type': self._use_type(arg_type)} + if short: + obj['short'] = short + self._gen_json(name, 'option', obj) + parser = common_argument_parser() # Debugging aid: unmask QAPI schema's type names # We normally mask them, because they're not QMP wire ABI
Signature · 1 line
2.13.6
RFC PATCH 26/32 qapi2texi: Include command line options information
In reply to Markus ArmbrusterMake generated QEMU QMP reference cover command line options in addition to QMP commands and events. Simple, but pushes the QMP reference beyond QMP. Perhaps options documentation should be separate. Perhaps not for the same reason QMP and command line are defined in the same schema: they share many types.
--- scripts/qapi2texi.py | 15 ++++++++++++++ tests/qapi-schema/doc-good.json | 24 ++++++++++++++++++++++ tests/qapi-schema/doc-good.out | 45 +++++++++++++++++++++++++++++++++++++++++ tests/qapi-schema/doc-good.texi | 45 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 129 insertions(+)
scripts/qapi2texi.py +15 -0
@@ -253,6 +253,21 @@ class QAPISchemaGenDocVisitor(qapi.QAPISchemaVisitor): name=doc.symbol, body=texi_entity(doc, 'Arguments')) + def visit_option(self, name, info, arg_type, short, implied_key, + boxed, help): + doc = self.cur_doc + if self.out: + self.out += '\n' + if boxed: + body = texi_body(doc) + body += '\n@b{Arguments:} the members of @code{%s}' % arg_type.name + body += texi_sections(doc) + else: + body = texi_entity(doc, 'Arguments') + self.out += MSG_FMT(type='Option', + name=doc.symbol, + body=body) + def symbol(self, doc, entity): if self.out: self.out += '\n'
tests/qapi-schema/doc-good.json +24 -0
@@ -151,3 +151,27 @@ ## { 'command': 'cmd-boxed', 'boxed': true, 'data': 'Object' } + +## +# @--help: +# Display help and exit. +## +{ 'option': '--help', 'short': 'h' , 'help': null } + +## +# @--opt-arg-str: +# TODO support documenting simple option argument +## +{ 'option': '--opt-arg-str', 'data': 'str' , 'help': null } + +## +# @--opt-arg-struct: +# @s: a string +# @i: an integer +## +{ 'option': '--opt-arg-struct', 'data': { 's': 'str', '*i': 'int' } , 'help': null } + +## +# @--opt-arg-boxed: +## +{ 'option': '--opt-arg-boxed', 'data': 'Base', 'boxed': true , 'help': null }
tests/qapi-schema/doc-good.out +45 -0
63 lines not on this page · raw message
tests/qapi-schema/doc-good.texi +45 -0
48 lines not on this page · raw message
Signature · 1 line
2.13.6
RFC PATCH 27/32 os-posix: Drop misleading comment
In reply to Markus ArmbrusterComments explaining why we include a header tend to go bad. This one's almost comical: not only doesn't qemu-options.hx use MAP_POPULATE anymore (since commit ef36fa1, v2.0.0, 2013), even the include it applies to got moved away in commit 02d0e09 (v2.7.0).
--- os-posix.c | 1 - 1 file changed, 1 deletion(-)
os-posix.c +0 -1
@@ -25,7 +25,6 @@#include "qemu/osdep.h" #include <sys/wait.h> -/*needed for MAP_POPULATE before including qemu-options.h */ #include <pwd.h> #include <grp.h> #include <libgen.h>
Signature · 1 line
2.13.6
Re: [Qemu-devel] [RFC PATCH 27/32] os-posix: Drop misleading comment
CC qemu-trivial
Quoted 6 lines · Markus Armbruster
Comments explaining why we include a header tend to go bad. This one's almost comical: not only doesn't qemu-options.hx use
MAP_POPULATEanymore (since commit ef36fa1, v2.0.0, 2013), even the include it applies to got moved away in commit 02d0e09 (v2.7.0).Signed-off-by Markus Armbruster <[email protected]>
Quoted 20 lines
--- os-posix.c | 1 - 1 file changed, 1 deletion(-)os-posix.c +0
-2@@ -25,7 +25,6 @@#include "qemu/osdep.h" #include <sys/wait.h> -/*needed for MAP_POPULATE before including qemu-options.h */ #include <pwd.h> #include <grp.h> #include <libgen.h> --2.13.6
Signature · 1 line
Marc-André Lureau
RFC PATCH 28/32 vl: QAPIfy command line option definition
In reply to Markus ArmbrusterMove options definition from qemu-options.hx to the QAPI schema.
Schema deficiencies:
* TODO rework doc strings into QAPIDoc format
* TODO generate (parts of) 'help' from 'data'?
* FIXME many 'str' option arguments (marked FIXME/TODO) need to be QAPIfied, anything that can't be QAPIfied needs to be replaced & deprecated
* FIXME conditionals (marked #if in qapi/options.json)
* TODO move the non-miscellaneous options next to their subsystem's
* schema definitions
qemu-doc breakage:
* FIXME need to include options part of
docs/interop/qemu-qmp-qapi.texi into qemu-doc
* FIXME several references in qemu-doc
vl.c TODOs:
* Drop conditionals hackery once we have schema conditionals
* Read and write .json config files
* How can we port -set from QemuOpts to QAPI?
The next few commits QAPIfy a few easy 'str' option arguments, to demonstrate how. Many more remain, and some of them are going to be harder.
QAPIfication switches from the QemuOpts parser to keyval_parse(), which isn't 100% backward compatible. We need to decide how far to push reproducing QemuOpts parsing quirks.
QemuOpts also serves as configuration repository. QAPIfication gets rid of that. Code relying on the configuration repository features will need updates.
--- .gitignore | 2 - Makefile | 18 +- include/qemu-common.h | 2 +- os-posix.c | 26 +- os-win32.c | 3 +- qapi-schema.json | 1 + qapi/options.json | 4574 ++++++++++++++++++++++++++++++++++++++++++++++++ qemu-doc.texi | 4 +- qemu-options-wrapper.h | 41 - qemu-options.h | 36 - qemu-options.hx | 4256 -------------------------------------------- scripts/qapi.py | 15 +- vl.c | 694 ++++---- 13 files changed, 4961 insertions(+), 4711 deletions(-) create mode 100644 qapi/options.json delete mode 100644 qemu-options-wrapper.h delete mode 100644 qemu-options.h delete mode 100644 qemu-options.hx
.gitignore +0 -2
@@ -39,8 +39,6 @@ /qemu-doc.txt /qemu-img /qemu-nbd -/qemu-options.def -/qemu-options.texi /qemu-img-cmds.texi /qemu-img-cmds.h /qemu-io
Makefile +6 -12
@@ -51,7 +51,7 @@ endif include $(SRC_PATH)/rules.mak -GENERATED_FILES = qemu-version.h config-host.h qemu-options.def +GENERATED_FILES = qemu-version.h config-host.h GENERATED_FILES += builtin-qapi-types.h builtin-qapi-types.c GENERATED_FILES += builtin-qapi-visit.h builtin-qapi-visit.c GENERATED_FILES += qmp-commands.h qapi-types.h qapi-visit.h qapi-event.h
@@ -314,8 +314,6 @@ qemu-version.h: FORCE config-host.h: config-host.h-timestamp config-host.h-timestamp: config-host.mak -qemu-options.def: $(SRC_PATH)/qemu-options.hx $(SRC_PATH)/scripts/hxtool - $(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@,"GEN","$@") SUBDIR_RULES=$(patsubst %,subdir-%, $(TARGET_DIRS)) SOFTMMU_SUBDIR_RULES=$(filter %-softmmu,$(SUBDIR_RULES))
@@ -422,6 +420,7 @@ qapi-modules = $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi/common.json \ $(SRC_PATH)/qapi/introspect.json \ $(SRC_PATH)/qapi/migration.json \ $(SRC_PATH)/qapi/net.json \ + $(SRC_PATH)/qapi/options.json \ $(SRC_PATH)/qapi/rocker.json \ $(SRC_PATH)/qapi/run-state.json \ $(SRC_PATH)/qapi/sockets.json \
@@ -529,7 +528,6 @@ module_block.h: $(SRC_PATH)/scripts/modules/module_block.py config-host.mak clean: # avoid old build problems by removing potentially incorrect old files rm -f config.mak op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h gen-op-arm.h - rm -f qemu-options.def rm -f *.msi find . \( -name '*.so' -o -name '*.dll' -o -name '*.mo' -o -name '*.[oda]' \) -type f -exec rm {} + rm -f $(filter-out %.tlb,$(TOOLS)) $(HELPERS-y) qemu-ga TAGS cscope.* *.pod *~ */*~
@@ -544,7 +542,6 @@ clean: rm -rf qga/qapi-generated for d in $(ALL_SUBDIRS); do \ if test -d $$d; then $(MAKE) -C $$d $@ || exit 1; fi; \ - rm -f $$d/qemu-options.def; \ done rm -f $(SUBDIR_DEVICES_MAK) config-all-devices.mak
@@ -556,7 +553,7 @@ qemu-%.tar.bz2: $(SRC_PATH)/scripts/make-release "$(SRC_PATH)" "$(patsubst qemu-%.tar.bz2,%,$@)" distclean: clean - rm -f config-host.mak config-host.h* config-host.ld $(DOCS) qemu-options.texi qemu-img-cmds.texi qemu-monitor.texi qemu-monitor-info.texi + rm -f config-host.mak config-host.h* config-host.ld $(DOCS) qemu-img-cmds.texi qemu-monitor.texi qemu-monitor-info.texi rm -f config-all-devices.mak config-all-disas.mak config.status rm -f po/*.mo tests/qemu-iotests/common.env rm -f roms/seabios/config.mak roms/vgabios/config.mak
@@ -715,7 +712,7 @@ ui/console-gl.o: $(SRC_PATH)/ui/console-gl.c \ # documentation MAKEINFO=makeinfo -MAKEINFOINCLUDES= -I docs -I $(<D) -I $(@D) +MAKEINFOINCLUDES= -I docs -I $(<D) -I $(@D) -I $(SRC_PATH) MAKEINFOFLAGS=--no-split --number-sections $(MAKEINFOINCLUDES) TEXI2PODFLAGS=$(MAKEINFOINCLUDES) "-DVERSION=$(VERSION)" TEXI2PDFFLAGS=$(if $(V),,--quiet) -I $(SRC_PATH) $(MAKEINFOINCLUDES)
@@ -737,9 +734,6 @@ docs/version.texi: $(SRC_PATH)/VERSION %.pdf: %.texi docs/version.texi $(call quiet-command,texi2pdf $(TEXI2PDFFLAGS) $< -o $@,"GEN","$@") -qemu-options.texi: $(SRC_PATH)/qemu-options.hx $(SRC_PATH)/scripts/hxtool - $(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -t < $< > $@,"GEN","$@") - qemu-monitor.texi: $(SRC_PATH)/hmp-commands.hx $(SRC_PATH)/scripts/hxtool $(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -t < $< > $@,"GEN","$@")
@@ -757,7 +751,7 @@ docs/interop/qemu-qmp-qapi.texi: $(qapi-modules) docs/interop/qemu-ga-qapi.texi: $(SRC_PATH)/qga/qapi-schema.json $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi2texi.py $< > $@,"GEN","$@") -qemu.1: qemu-doc.texi qemu-options.texi qemu-monitor.texi qemu-monitor-info.texi +qemu.1: qemu-doc.texi docs/interop/qemu-qmp-ref.texi qemu-monitor.texi qemu-monitor-info.texi qemu.1: qemu-option-trace.texi qemu-img.1: qemu-img.texi qemu-option-trace.texi qemu-img-cmds.texi fsdev/virtfs-proxy-helper.1: fsdev/virtfs-proxy-helper.texi
@@ -771,7 +765,7 @@ pdf: qemu-doc.pdf docs/interop/qemu-qmp-ref.pdf docs/interop/qemu-ga-ref.pdf txt: qemu-doc.txt docs/interop/qemu-qmp-ref.txt docs/interop/qemu-ga-ref.txt qemu-doc.html qemu-doc.info qemu-doc.pdf qemu-doc.txt: \ - qemu-img.texi qemu-nbd.texi qemu-options.texi qemu-option-trace.texi \ + qemu-img.texi qemu-nbd.texi docs/interop/qemu-qmp-ref.texi qemu-option-trace.texi \ qemu-monitor.texi qemu-img-cmds.texi qemu-ga.texi \ qemu-monitor-info.texi docs/qemu-block-drivers.texi
include/qemu-common.h +1 -1
@@ -139,7 +139,7 @@ char *qemu_find_file(int type, const char *name);/* OS specific functions */ void os_setup_early_signal_handling (void );char *os_find_datadir (void ); -void os_parse_cmd_args (int index,const char *optarg); +void os_parse_cmd_args (const QAPIOption *opt);#include "qemu/module.h"
os-posix.c +14 -12
@@ -32,7 +32,6 @@/* Needed early for CONFIG_BSD etc. */ #include "sysemu/sysemu.h" #include "net/slirp.h" -#include "qemu-options.h" #include "qemu/error-report.h" #include "qemu/log.h" #include "qemu/cutils.h"
@@ -131,35 +130,38 @@ void os_set_proc_name(const char *s)* Parse OS specific command line options. * return 0 if option handled, -1 otherwise */ -void os_parse_cmd_args (int index,const char *optarg) +void os_parse_cmd_args (const QAPIOption *opt) { -switch (index) { +switch (opt->type) {#ifdef CONFIG_SLIRP -case QEMU_OPTION_smb: +case QAPI_OPTION_KIND_SMB :error_report ("The -smb option is deprecated. " "Please use '-netdev user,smb=...' instead." ); -if (net_slirp_smb (optarg) <0 ) +if (net_slirp_smb (opt->u.smb.data) <0 ) {exit (1 ); + }break ;#endif -case QEMU_OPTION_runas: - user_pwd =getpwnam (optarg); +case QAPI_OPTION_KIND_RUNAS : + user_pwd =getpwnam (opt->u.runas.data);if (!user_pwd) { -fprintf (stderr,"User \"%s\" doesn't exist\n" , optarg); +fprintf (stderr,"User \"%s\" doesn't exist\n" , opt->u.runas.data);exit (1 ); }break ; -case QEMU_OPTION_chroot: - chroot_dir = optarg; +case QAPI_OPTION_KIND_CHROOT : + chroot_dir = opt->u.chroot.data;break ; -case QEMU_OPTION_daemonize: +case QAPI_OPTION_KIND_DAEMONIZE : daemonize =1 ;break ;#if defined(CONFIG_LINUX ) -case QEMU_OPTION_enablefips: +case QAPI_OPTION_KIND_ENABLE_FIPS :fips_set_state (true);break ;#endif +default : + ; } }
os-win32.c +1 -2
@@ -26,7 +26,6 @@#include <windows.h> #include <mmsystem.h> #include "sysemu/sysemu.h" -#include "qemu-options.h" /***********************************************************/ /* Functions missing in mingw */
@@ -93,7 +92,7 @@ void os_set_line_buffering(void)* Parse OS specific command line options. * return 0 if option handled, -1 otherwise */ -void os_parse_cmd_args (int index,const char *optarg) +void os_parse_cmd_args (const QEMUOption *opt) {return ; }
qapi-schema.json +1 -0
@@ -96,6 +96,7 @@ { 'include': 'qapi/transaction.json' } { 'include': 'qapi/trace.json' } { 'include': 'qapi/introspect.json' } +{ 'include': 'qapi/options.json' } ## # = Miscellanea
qapi/options.json new file +4574 -0
2,828 lines not on this page · raw message
qemu-options-wrapper.h deleted +0 -41
41 lines not on this page · raw message
qemu-options.hx deleted +0 -4256
4,256 lines not on this page · raw message
vl.c +350 -344
694 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.13.6
Part of the diff is not shown here. View the raw message.
RFC PATCH 29/32 qapi/options: QAPIfy --echr argument type
In reply to Markus ArmbrusterBonus: more rigorous error checking. Crap like '-echar 666' and '-echar 0x' are now rejected.
FIXME the error messages are crap:
qemu-system-x86_64: -echr 666: Parameter 'null' expects int8_t
qemu-system-x86_64: -echr 0x: Parameter '<anonymous>' expects integer
--- qapi/options.json | 2 +- vl.c | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-)
qapi/options.json +1 -1
@@ -3892,7 +3892,7 @@ # !end texinfo ## { 'option': '--echr', - 'data': 'str', # FIXME int + 'data': 'int8', 'help': "-echr chr set terminal escape character instead of ctrl-a" } ##
vl.c +2 -8
@@ -3574,14 +3574,8 @@ int main(int argc, char **argv, char **envp) }break ;case QAPI_OPTION_KIND_ECHR : - { -char *r; - term_escape_char =strtol (qopt[i].u.echr.data, &r,0 ); -if (r == qopt[i].u.echr.data) { -printf ("Bad argument to echr\n" ); - } -break ; - } + term_escape_char = qopt[i].u.echr.data; +break ;case QAPI_OPTION_KIND_MONITOR : default_monitor =0 ;if (strncmp (qopt[i].u.monitor.data,"none" ,4 )) {
Signature · 1 line
2.13.6
RFC PATCH 30/32 qapi/options: QAPIfy --watchdog-action argument type
In reply to Markus Armbruster--- qapi/options.json | 2 +- vl.c | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-)
qapi/options.json +1 -1
@@ -3868,7 +3868,7 @@ # !end texinfo ## { 'option': '--watchdog-action', - 'data': 'str', # FIXME enum + 'data': 'WatchdogAction', 'help': [ "-watchdog-action reset|shutdown|poweroff|inject-nmi|pause|debug|none", " action when watchdog fires [default=reset]"] }
vl.c +2 -5
@@ -3724,11 +3724,8 @@ int main(int argc, char **argv, char **envp) watchdog = qopt[i].u.watchdog.data;break ;case QAPI_OPTION_KIND_WATCHDOG_ACTION : -if (select_watchdog_action (qopt[i].u.watchdog_action.data) - ==-1 ) { -error_report ("unknown -watchdog-action parameter" ); -exit (1 ); - } +qmp_watchdog_set_action (qopt[i].u.watchdog_action.data, + &error_abort);break ;case QAPI_OPTION_KIND_VIRTIOCONSOLE :add_device_config (DEV_VIRTCON , qopt[i].u.virtioconsole.data);
Signature · 1 line
2.13.6
RFC PATCH 31/32 qapi/options: QAPIfy --blockdev argument type
In reply to Markus Armbruster--- qapi/options.json | 2 +- vl.c | 42 +++++++----------------------------------- 2 files changed, 8 insertions(+), 36 deletions(-)
qapi/options.json +1 -1
@@ -877,7 +877,7 @@ # !end texinfo ## { 'option': '--blockdev', - 'data': 'str', # FIXME BlockdevOptions + 'data': 'BlockdevOptions', 'boxed': true, 'help': [ "-blockdev [driver=]driver[,node-name=N][,discard=ignore|unmap]", " [,cache.direct=on|off][,cache.no-flush=on|off]",
vl.c +7 -35
60 lines not on this page · raw message
Signature · 1 line
2.13.6
RFC PATCH 32/32 qapi/options: QAPIfy --add-fd argument type
In reply to Markus Armbruster--- qapi/options.json | 2 +- vl.c | 70 +++++++++++++------------------------------------------ 2 files changed, 17 insertions(+), 55 deletions(-)
qapi/options.json +1 -1
@@ -285,7 +285,7 @@ # !end texinfo ## { 'option': '--add-fd', - 'data': 'str', # FIXME QAPIfy qemu_add_fd_opts + 'data': { 'fd': 'int', 'set': 'int', '*opaque': 'str' }, 'help': [ "-add-fd fd=fd,set=set[,opaque=opaque]", " Add 'fd' to fd 'set'"] }
vl.c +16 -54
117 lines not on this page · raw message
Signature · 1 line
2.13.6