qapi doc generation (whole version, squashed)
v7 cover qapi doc generation (whole version, squashed)
Add a qapi2texi script to generate the documentation from the qapi schemas.
The SQUASHED patch in this series is a squashed version of the documentation move from qmp-commands.txt to the schemas. The whole version (not sent on the ML to avoid spamming) is in the following git
branch: https://github.com/elmarco/qemu/commits/qapi-doc
PDF preview:
https://fedorapeople.org/~elmarco/qemu-qmp-ref.pdf (v7 without type info)
v7: after Markus review of v6
- removed type information, doc and syntax (post-poned)
- keep original documentation order (consequently, tests/qapi-schema/doc-bad-section.json is now accepted)
- removed "qapi: use a QAPIParseError in parser" patch
- removed "reorder documentation body" patch
- removed 'o' support for list items
- added several TODOs
- added a few preliminary patches for the new changes
- improved some error messages
- updated tests corresponding to the changes above
- added r-b tags
v6:
- rebased on top of armbru/qapi-next branch
- add a few patches to improve Exception subclasses and usage in qapi.py as suggested during review
- parser and generator fixes and improvements after v5 review:
- various union improvements, hopefully with a better syntax
- improve error messages
- improve docs/qapi-code-gen.txt documentation section
- do not allow interleaved body documentation between sections
- more tests for new cases
- make expression documentation mandatory, fix the tests
- replace bad usage of @var{} with @t{} in texi, fix texi2pod to handle it
- renaming, reordering etc..
- add docs/qapi-syntax.texi to describe the API syntax used in the texi documentation
- fix interleaved body and section documentation
- improve documentation sections name
- many build-sys improvements after review
- fix and improve commit messages, update R-b tags
v5:
- many parser and generator fixes and improvements after v4 review:
- simplified current section handling by using a Section object
- adding a line is more stateful: either freeform or symbol comment
- always check_docs() when parsing with QAPISchema
- simplified some code and comments
- do not break current section on empty line, but break after a non indented paragraph in an argument section. This seems to reflects the way documentation is written:
##
# @foo:
# @arg: fluctuat nec mergitur
# - continues here
#
# Since: 1853
#
# Body
#
##
Other sections (Note/Examples etc) are not indented (it seems), but could use a similar rule. I prefer to keep this only for args, for styling reasons (bikeshedding?).
- better handling of flat-union in generator
- list all enum values (even when not documented)
- added qapi-doc parsing tests and more error checking
- pep8/pylint fixes
- some more schema doc fixes
- do not move logo to docs/
v4:
- more device_add schema fixes
- do not merge docs/qmp-intro.txt in qemu-qmp-ref.texi
- remove needless @ifinfo, add GPL copying text
- added qemu logo to pdf
- added some r-b tags
v3:
- many improvements to the doc parser:
- throws an error in various malformated conditions
- allows multiple meta-sections, except for "Since:" and "Return:"
- build a list of docs, instead of attaching docs to expressions
- accept() breaks on new doc block, and get_doc() returns a QAPIDoc
- fix more documentation to fit the new parser
- use a master texi file that includes the generated file, instead of templated texi file
- texi fixes after Markus review
- only build and install html and man pages by default
- fix .gitignore
v2:
- change licence to be lgpl2+
- fix some comments & commit message
- add more code comments
- improve the doc parsing to treat only "Since" as a special case not requiring ":" (common notation in the doc)
- include some early schema doc fixes (to fix generated doc)
- include the squashed version of the doc move
- include the man page and installation build changes
Marc-André Lureau (21):
qapi: replace 'o' for list items
qapi: move QKeyCode doc body at the top
qapi: make TODOs named-sections
qapi: improve device_add schema
qapi: improve TransactionAction doc qga/schema: improve guest-set-vcpus Returns: section
qapi: avoid interleaving sections and parameters
qapi: move experimental note down
qapi: add some sections in docs
docs: add master qapi texi files
qapi: rework qapi Exception
qapi.py: fix line break before binary operator pep8
texi2pod: learn quotation, deftp and deftypefn (SQUASHED) move doc to schema
qapi: add qapi2texi script
docs: add qemu logo to pdf
build-sys: use --no-split for info
build-sys: remove dvi doc generation
build-sys: use a generic TEXI2MAN rule
build-sys: add txt documentation rules
build-sys: add qapi doc generation targets
qapi-schema.json | 1338 ++++++- qapi/block-core.json | 700 +++- qapi/block.json | 66 +- qapi/common.json | 38 +- qapi/crypto.json | 5 +- qapi/event.json | 248 +- qapi/introspect.json | 5 +- qapi/rocker.json | 61 +- qapi/trace.json | 17 + scripts/qapi.py | 583 ++- scripts/qapi2texi.py | 266 ++ .gitignore | 11 +- Makefile | 94 +- configure | 2 +- docs/qapi-code-gen.txt | 174 +- docs/qemu-ga-ref.texi | 78 + docs/qemu-qmp-ref.texi | 78 + docs/qemu_logo.pdf | Bin 0 -> 9117 bytes docs/qmp-commands.txt | 3824 -------------------- docs/qmp-events.txt | 731 ---- docs/qmp-intro.txt | 3 +- qga/qapi-schema.json | 11 +- rules.mak | 12 + scripts/texi2pod.pl | 54 +- tests/Makefile.include | 20 + tests/qapi-schema/alternate-any.err | 2 +- tests/qapi-schema/alternate-any.json | 4 + tests/qapi-schema/alternate-array.err | 2 +- tests/qapi-schema/alternate-array.json | 7 + tests/qapi-schema/alternate-base.err | 2 +- tests/qapi-schema/alternate-base.json | 7 + tests/qapi-schema/alternate-clash.err | 2 +- tests/qapi-schema/alternate-clash.json | 4 + tests/qapi-schema/alternate-conflict-dict.err | 2 +- tests/qapi-schema/alternate-conflict-dict.json | 10 + tests/qapi-schema/alternate-conflict-string.err | 2 +- tests/qapi-schema/alternate-conflict-string.json | 7 + tests/qapi-schema/alternate-empty.err | 2 +- tests/qapi-schema/alternate-empty.json | 4 + tests/qapi-schema/alternate-nested.err | 2 +- tests/qapi-schema/alternate-nested.json | 7 + tests/qapi-schema/alternate-unknown.err | 2 +- tests/qapi-schema/alternate-unknown.json | 4 + tests/qapi-schema/args-alternate.err | 2 +- tests/qapi-schema/args-alternate.json | 8 + tests/qapi-schema/args-any.err | 2 +- tests/qapi-schema/args-any.json | 4 + tests/qapi-schema/args-array-empty.err | 2 +- tests/qapi-schema/args-array-empty.json | 4 + tests/qapi-schema/args-array-unknown.err | 2 +- tests/qapi-schema/args-array-unknown.json | 4 + tests/qapi-schema/args-bad-boxed.err | 2 +- tests/qapi-schema/args-bad-boxed.json | 4 + tests/qapi-schema/args-boxed-anon.err | 2 +- tests/qapi-schema/args-boxed-anon.json | 4 + tests/qapi-schema/args-boxed-empty.err | 2 +- tests/qapi-schema/args-boxed-empty.json | 8 + tests/qapi-schema/args-boxed-string.err | 2 +- tests/qapi-schema/args-boxed-string.json | 4 + tests/qapi-schema/args-int.err | 2 +- tests/qapi-schema/args-int.json | 4 + tests/qapi-schema/args-invalid.err | 2 +- tests/qapi-schema/args-invalid.json | 3 + tests/qapi-schema/args-member-array-bad.err | 2 +- tests/qapi-schema/args-member-array-bad.json | 4 + tests/qapi-schema/args-member-case.err | 2 +- tests/qapi-schema/args-member-case.json | 4 + tests/qapi-schema/args-member-unknown.err | 2 +- tests/qapi-schema/args-member-unknown.json | 4 + tests/qapi-schema/args-name-clash.err | 2 +- tests/qapi-schema/args-name-clash.json | 4 + tests/qapi-schema/args-union.err | 2 +- tests/qapi-schema/args-union.json | 7 + tests/qapi-schema/args-unknown.err | 2 +- tests/qapi-schema/args-unknown.json | 4 + tests/qapi-schema/bad-base.err | 2 +- tests/qapi-schema/bad-base.json | 7 + tests/qapi-schema/bad-data.err | 2 +- tests/qapi-schema/bad-data.json | 4 + tests/qapi-schema/bad-ident.err | 2 +- tests/qapi-schema/bad-ident.json | 4 + tests/qapi-schema/bad-type-bool.err | 2 +- tests/qapi-schema/bad-type-bool.json | 4 + tests/qapi-schema/bad-type-dict.err | 2 +- tests/qapi-schema/bad-type-dict.json | 4 + tests/qapi-schema/base-cycle-direct.err | 2 +- tests/qapi-schema/base-cycle-direct.json | 4 + tests/qapi-schema/base-cycle-indirect.err | 2 +- tests/qapi-schema/base-cycle-indirect.json | 7 + tests/qapi-schema/command-int.err | 2 +- tests/qapi-schema/command-int.json | 4 + tests/qapi-schema/comments.json | 4 + tests/qapi-schema/comments.out | 3 + tests/qapi-schema/doc-bad-args.err | 1 + tests/qapi-schema/doc-bad-args.exit | 1 + tests/qapi-schema/doc-bad-args.json | 8 + tests/qapi-schema/doc-bad-args.out | 0 tests/qapi-schema/doc-bad-symbol.err | 1 + tests/qapi-schema/doc-bad-symbol.exit | 1 + tests/qapi-schema/doc-bad-symbol.json | 6 + tests/qapi-schema/doc-bad-symbol.out | 0 tests/qapi-schema/doc-duplicated-arg.err | 1 + tests/qapi-schema/doc-duplicated-arg.exit | 1 + tests/qapi-schema/doc-duplicated-arg.json | 7 + tests/qapi-schema/doc-duplicated-arg.out | 0 tests/qapi-schema/doc-duplicated-return.err | 1 + tests/qapi-schema/doc-duplicated-return.exit | 1 + tests/qapi-schema/doc-duplicated-return.json | 8 + tests/qapi-schema/doc-duplicated-return.out | 0 tests/qapi-schema/doc-duplicated-since.err | 1 + tests/qapi-schema/doc-duplicated-since.exit | 1 + tests/qapi-schema/doc-duplicated-since.json | 8 + tests/qapi-schema/doc-duplicated-since.out | 0 tests/qapi-schema/doc-empty-arg.err | 1 + tests/qapi-schema/doc-empty-arg.exit | 1 + tests/qapi-schema/doc-empty-arg.json | 6 + tests/qapi-schema/doc-empty-arg.out | 0 tests/qapi-schema/doc-empty-section.err | 1 + tests/qapi-schema/doc-empty-section.exit | 1 + tests/qapi-schema/doc-empty-section.json | 8 + tests/qapi-schema/doc-empty-section.out | 0 tests/qapi-schema/doc-empty-symbol.err | 1 + tests/qapi-schema/doc-empty-symbol.exit | 1 + tests/qapi-schema/doc-empty-symbol.json | 5 + tests/qapi-schema/doc-empty-symbol.out | 0 tests/qapi-schema/doc-interleaved-section.err | 1 + tests/qapi-schema/doc-interleaved-section.exit | 1 + tests/qapi-schema/doc-interleaved-section.json | 21 + tests/qapi-schema/doc-interleaved-section.out | 0 tests/qapi-schema/doc-invalid-end.err | 1 + tests/qapi-schema/doc-invalid-end.exit | 1 + tests/qapi-schema/doc-invalid-end.json | 5 + tests/qapi-schema/doc-invalid-end.out | 0 tests/qapi-schema/doc-invalid-end2.err | 1 + tests/qapi-schema/doc-invalid-end2.exit | 1 + tests/qapi-schema/doc-invalid-end2.json | 5 + tests/qapi-schema/doc-invalid-end2.out | 0 tests/qapi-schema/doc-invalid-return.err | 1 + tests/qapi-schema/doc-invalid-return.exit | 1 + tests/qapi-schema/doc-invalid-return.json | 7 + tests/qapi-schema/doc-invalid-return.out | 0 tests/qapi-schema/doc-invalid-section.err | 1 + tests/qapi-schema/doc-invalid-section.exit | 1 + tests/qapi-schema/doc-invalid-section.json | 6 + tests/qapi-schema/doc-invalid-section.out | 0 tests/qapi-schema/doc-invalid-start.err | 1 + tests/qapi-schema/doc-invalid-start.exit | 1 + tests/qapi-schema/doc-invalid-start.json | 5 + tests/qapi-schema/doc-invalid-start.out | 0 tests/qapi-schema/doc-missing-colon.err | 1 + tests/qapi-schema/doc-missing-colon.exit | 1 + tests/qapi-schema/doc-missing-colon.json | 5 + tests/qapi-schema/doc-missing-colon.out | 0 tests/qapi-schema/doc-missing-expr.err | 1 + tests/qapi-schema/doc-missing-expr.exit | 1 + tests/qapi-schema/doc-missing-expr.json | 5 + tests/qapi-schema/doc-missing-expr.out | 0 tests/qapi-schema/doc-missing-space.err | 1 + tests/qapi-schema/doc-missing-space.exit | 1 + tests/qapi-schema/doc-missing-space.json | 6 + tests/qapi-schema/doc-missing-space.out | 0 tests/qapi-schema/doc-optional.err | 1 + tests/qapi-schema/doc-optional.exit | 1 + tests/qapi-schema/doc-optional.json | 7 + tests/qapi-schema/doc-optional.out | 0 tests/qapi-schema/double-type.err | 2 +- tests/qapi-schema/double-type.json | 4 + tests/qapi-schema/enum-bad-name.err | 2 +- tests/qapi-schema/enum-bad-name.json | 4 + tests/qapi-schema/enum-bad-prefix.err | 2 +- tests/qapi-schema/enum-bad-prefix.json | 4 + tests/qapi-schema/enum-clash-member.err | 2 +- tests/qapi-schema/enum-clash-member.json | 4 + tests/qapi-schema/enum-dict-member.err | 2 +- tests/qapi-schema/enum-dict-member.json | 4 + tests/qapi-schema/enum-member-case.err | 2 +- tests/qapi-schema/enum-member-case.json | 7 + tests/qapi-schema/enum-missing-data.err | 2 +- tests/qapi-schema/enum-missing-data.json | 4 + tests/qapi-schema/enum-wrong-data.err | 2 +- tests/qapi-schema/enum-wrong-data.json | 4 + tests/qapi-schema/event-boxed-empty.err | 2 +- tests/qapi-schema/event-boxed-empty.json | 4 + tests/qapi-schema/event-case.json | 4 + tests/qapi-schema/event-case.out | 3 + tests/qapi-schema/event-nest-struct.err | 2 +- tests/qapi-schema/event-nest-struct.json | 4 + tests/qapi-schema/flat-union-array-branch.err | 2 +- tests/qapi-schema/flat-union-array-branch.json | 12 + tests/qapi-schema/flat-union-bad-base.err | 2 +- tests/qapi-schema/flat-union-bad-base.json | 13 + tests/qapi-schema/flat-union-bad-discriminator.err | 2 +- .../qapi-schema/flat-union-bad-discriminator.json | 16 + tests/qapi-schema/flat-union-base-any.err | 2 +- tests/qapi-schema/flat-union-base-any.json | 13 + tests/qapi-schema/flat-union-base-union.err | 2 +- tests/qapi-schema/flat-union-base-union.json | 16 + tests/qapi-schema/flat-union-clash-member.err | 2 +- tests/qapi-schema/flat-union-clash-member.json | 16 + tests/qapi-schema/flat-union-empty.err | 2 +- tests/qapi-schema/flat-union-empty.json | 10 + tests/qapi-schema/flat-union-incomplete-branch.err | 2 +- .../qapi-schema/flat-union-incomplete-branch.json | 10 + tests/qapi-schema/flat-union-inline.err | 2 +- tests/qapi-schema/flat-union-inline.json | 10 + tests/qapi-schema/flat-union-int-branch.err | 2 +- tests/qapi-schema/flat-union-int-branch.json | 13 + .../qapi-schema/flat-union-invalid-branch-key.err | 2 +- .../qapi-schema/flat-union-invalid-branch-key.json | 15 + .../flat-union-invalid-discriminator.err | 2 +- .../flat-union-invalid-discriminator.json | 15 + tests/qapi-schema/flat-union-no-base.err | 2 +- tests/qapi-schema/flat-union-no-base.json | 13 + .../flat-union-optional-discriminator.err | 2 +- .../flat-union-optional-discriminator.json | 13 + .../flat-union-string-discriminator.err | 2 +- .../flat-union-string-discriminator.json | 15 + tests/qapi-schema/ident-with-escape.json | 4 + tests/qapi-schema/ident-with-escape.out | 3 + tests/qapi-schema/include-relpath-sub.json | 3 + tests/qapi-schema/include-relpath.out | 3 + tests/qapi-schema/include-repetition.out | 3 + tests/qapi-schema/include-simple-sub.json | 3 + tests/qapi-schema/include-simple.out | 3 + tests/qapi-schema/indented-expr.json | 6 + tests/qapi-schema/indented-expr.out | 6 + tests/qapi-schema/missing-type.err | 2 +- tests/qapi-schema/missing-type.json | 4 + tests/qapi-schema/nested-struct-data.err | 2 +- tests/qapi-schema/nested-struct-data.json | 4 + tests/qapi-schema/qapi-schema-test.json | 213 ++ tests/qapi-schema/qapi-schema-test.out | 212 ++ tests/qapi-schema/redefined-builtin.err | 2 +- tests/qapi-schema/redefined-builtin.json | 4 + tests/qapi-schema/redefined-command.err | 2 +- tests/qapi-schema/redefined-command.json | 7 + tests/qapi-schema/redefined-event.err | 2 +- tests/qapi-schema/redefined-event.json | 7 + tests/qapi-schema/redefined-type.err | 2 +- tests/qapi-schema/redefined-type.json | 7 + tests/qapi-schema/reserved-command-q.err | 2 +- tests/qapi-schema/reserved-command-q.json | 7 + tests/qapi-schema/reserved-enum-q.err | 2 +- tests/qapi-schema/reserved-enum-q.json | 4 + tests/qapi-schema/reserved-member-has.err | 2 +- tests/qapi-schema/reserved-member-has.json | 4 + tests/qapi-schema/reserved-member-q.err | 2 +- tests/qapi-schema/reserved-member-q.json | 4 + tests/qapi-schema/reserved-member-u.err | 2 +- tests/qapi-schema/reserved-member-u.json | 4 + tests/qapi-schema/reserved-member-underscore.err | 2 +- tests/qapi-schema/reserved-member-underscore.json | 4 + tests/qapi-schema/reserved-type-kind.err | 2 +- tests/qapi-schema/reserved-type-kind.json | 4 + tests/qapi-schema/reserved-type-list.err | 2 +- tests/qapi-schema/reserved-type-list.json | 4 + tests/qapi-schema/returns-alternate.err | 2 +- tests/qapi-schema/returns-alternate.json | 7 + tests/qapi-schema/returns-array-bad.err | 2 +- tests/qapi-schema/returns-array-bad.json | 4 + tests/qapi-schema/returns-dict.err | 2 +- tests/qapi-schema/returns-dict.json | 4 + tests/qapi-schema/returns-unknown.err | 2 +- tests/qapi-schema/returns-unknown.json | 4 + tests/qapi-schema/returns-whitelist.err | 2 +- tests/qapi-schema/returns-whitelist.json | 16 + tests/qapi-schema/struct-base-clash-deep.err | 2 +- tests/qapi-schema/struct-base-clash-deep.json | 10 + tests/qapi-schema/struct-base-clash.err | 2 +- tests/qapi-schema/struct-base-clash.json | 7 + tests/qapi-schema/struct-data-invalid.err | 2 +- tests/qapi-schema/struct-data-invalid.json | 3 + tests/qapi-schema/struct-member-invalid.err | 2 +- tests/qapi-schema/struct-member-invalid.json | 3 + tests/qapi-schema/test-qapi.py | 12 + tests/qapi-schema/type-bypass-bad-gen.err | 2 +- tests/qapi-schema/type-bypass-bad-gen.json | 4 + tests/qapi-schema/unicode-str.err | 2 +- tests/qapi-schema/unicode-str.json | 4 + tests/qapi-schema/union-base-no-discriminator.err | 2 +- tests/qapi-schema/union-base-no-discriminator.json | 12 + tests/qapi-schema/union-branch-case.err | 2 +- tests/qapi-schema/union-branch-case.json | 4 + tests/qapi-schema/union-clash-branches.err | 2 +- tests/qapi-schema/union-clash-branches.json | 4 + tests/qapi-schema/union-empty.err | 2 +- tests/qapi-schema/union-empty.json | 4 + tests/qapi-schema/union-invalid-base.err | 2 +- tests/qapi-schema/union-invalid-base.json | 10 + tests/qapi-schema/union-optional-branch.err | 2 +- tests/qapi-schema/union-optional-branch.json | 4 + tests/qapi-schema/union-unknown.err | 2 +- tests/qapi-schema/union-unknown.json | 4 + tests/qapi-schema/unknown-escape.err | 2 +- tests/qapi-schema/unknown-escape.json | 4 + tests/qapi-schema/unknown-expr-key.err | 2 +- tests/qapi-schema/unknown-expr-key.json | 4 + 297 files changed, 4832 insertions(+), 5013 deletions(-) create mode 100755 scripts/qapi2texi.py create mode 100644 docs/qemu-ga-ref.texi create mode 100644 docs/qemu-qmp-ref.texi create mode 100644 docs/qemu_logo.pdf delete mode 100644 docs/qmp-commands.txt delete mode 100644 docs/qmp-events.txt create mode 100644 tests/qapi-schema/doc-bad-args.err create mode 100644 tests/qapi-schema/doc-bad-args.exit create mode 100644 tests/qapi-schema/doc-bad-args.json create mode 100644 tests/qapi-schema/doc-bad-args.out create mode 100644 tests/qapi-schema/doc-bad-symbol.err create mode 100644 tests/qapi-schema/doc-bad-symbol.exit create mode 100644 tests/qapi-schema/doc-bad-symbol.json create mode 100644 tests/qapi-schema/doc-bad-symbol.out create mode 100644 tests/qapi-schema/doc-duplicated-arg.err create mode 100644 tests/qapi-schema/doc-duplicated-arg.exit create mode 100644 tests/qapi-schema/doc-duplicated-arg.json create mode 100644 tests/qapi-schema/doc-duplicated-arg.out create mode 100644 tests/qapi-schema/doc-duplicated-return.err create mode 100644 tests/qapi-schema/doc-duplicated-return.exit create mode 100644 tests/qapi-schema/doc-duplicated-return.json create mode 100644 tests/qapi-schema/doc-duplicated-return.out create mode 100644 tests/qapi-schema/doc-duplicated-since.err create mode 100644 tests/qapi-schema/doc-duplicated-since.exit create mode 100644 tests/qapi-schema/doc-duplicated-since.json create mode 100644 tests/qapi-schema/doc-duplicated-since.out create mode 100644 tests/qapi-schema/doc-empty-arg.err create mode 100644 tests/qapi-schema/doc-empty-arg.exit create mode 100644 tests/qapi-schema/doc-empty-arg.json create mode 100644 tests/qapi-schema/doc-empty-arg.out create mode 100644 tests/qapi-schema/doc-empty-section.err create mode 100644 tests/qapi-schema/doc-empty-section.exit create mode 100644 tests/qapi-schema/doc-empty-section.json create mode 100644 tests/qapi-schema/doc-empty-section.out create mode 100644 tests/qapi-schema/doc-empty-symbol.err create mode 100644 tests/qapi-schema/doc-empty-symbol.exit create mode 100644 tests/qapi-schema/doc-empty-symbol.json create mode 100644 tests/qapi-schema/doc-empty-symbol.out create mode 100644 tests/qapi-schema/doc-interleaved-section.err create mode 100644 tests/qapi-schema/doc-interleaved-section.exit create mode 100644 tests/qapi-schema/doc-interleaved-section.json create mode 100644 tests/qapi-schema/doc-interleaved-section.out create mode 100644 tests/qapi-schema/doc-invalid-end.err create mode 100644 tests/qapi-schema/doc-invalid-end.exit create mode 100644 tests/qapi-schema/doc-invalid-end.json create mode 100644 tests/qapi-schema/doc-invalid-end.out create mode 100644 tests/qapi-schema/doc-invalid-end2.err create mode 100644 tests/qapi-schema/doc-invalid-end2.exit create mode 100644 tests/qapi-schema/doc-invalid-end2.json create mode 100644 tests/qapi-schema/doc-invalid-end2.out create mode 100644 tests/qapi-schema/doc-invalid-return.err create mode 100644 tests/qapi-schema/doc-invalid-return.exit create mode 100644 tests/qapi-schema/doc-invalid-return.json create mode 100644 tests/qapi-schema/doc-invalid-return.out create mode 100644 tests/qapi-schema/doc-invalid-section.err create mode 100644 tests/qapi-schema/doc-invalid-section.exit create mode 100644 tests/qapi-schema/doc-invalid-section.json create mode 100644 tests/qapi-schema/doc-invalid-section.out create mode 100644 tests/qapi-schema/doc-invalid-start.err create mode 100644 tests/qapi-schema/doc-invalid-start.exit create mode 100644 tests/qapi-schema/doc-invalid-start.json create mode 100644 tests/qapi-schema/doc-invalid-start.out create mode 100644 tests/qapi-schema/doc-missing-colon.err create mode 100644 tests/qapi-schema/doc-missing-colon.exit create mode 100644 tests/qapi-schema/doc-missing-colon.json create mode 100644 tests/qapi-schema/doc-missing-colon.out create mode 100644 tests/qapi-schema/doc-missing-expr.err create mode 100644 tests/qapi-schema/doc-missing-expr.exit create mode 100644 tests/qapi-schema/doc-missing-expr.json create mode 100644 tests/qapi-schema/doc-missing-expr.out create mode 100644 tests/qapi-schema/doc-missing-space.err create mode 100644 tests/qapi-schema/doc-missing-space.exit create mode 100644 tests/qapi-schema/doc-missing-space.json create mode 100644 tests/qapi-schema/doc-missing-space.out create mode 100644 tests/qapi-schema/doc-optional.err create mode 100644 tests/qapi-schema/doc-optional.exit create mode 100644 tests/qapi-schema/doc-optional.json create mode 100644 tests/qapi-schema/doc-optional.out
Signature · 1 line
2.11.0
PATCH v7 1/21 qapi: replace 'o' for list items
Replace with '*', the common form for list items.
--- qapi-schema.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
qapi-schema.json +3 -3
@@ -1883,11 +1883,11 @@ # # Known limitations: # -# o This command is stateless, this means that commands that depend +# * This command is stateless, this means that commands that depend # on state information (such as getfd) might not work # -# o Commands that prompt the user for data (eg. 'cont' when the block -# device is encrypted) don't currently work +# * Commands that prompt the user for data (eg. 'cont' when the block +# device is encrypted) don't currently work ## { 'command': 'human-monitor-command', 'data': {'command-line': 'str', '*cpu-index': 'int'},
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH v7 01/21] qapi: replace 'o' for list items
Quoted 3 lines · Marc-André Lureau
Replace with '*', the common form for list items.
Signed-off-by Marc-André Lureau <[email protected]>
PATCH v7 2/21 qapi: move QKeyCode doc body at the top
In reply to Marc-André LureauFollowing documentation guidelines.
--- qapi-schema.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
qapi-schema.json +4 -4
@@ -3612,6 +3612,10 @@ ## # @QKeyCode: # +# An enumeration of key name. +# +# This is used by the @send-key command. +# # @unmapped: since 2.0 # @pause: since 2.0 # @ro: since 2.4
@@ -3619,10 +3623,6 @@ # @kp_equals: since 2.6 # @power: since 2.6 # -# An enumeration of key name. -# -# This is used by the send-key command. -# # Since: 1.3.0 # ##
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH v7 02/21] qapi: move QKeyCode doc body at the top
Quoted 3 lines · Marc-André Lureau
Following documentation guidelines.
Signed-off-by Marc-André Lureau <[email protected]>
PATCH v7 3/21 qapi: make TODOs named-sections
In reply to Marc-André LureauHave the TODO in the TAG: format, so they will stand out in the generated documentation.
--- qapi-schema.json | 4 ++-- qapi/introspect.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
qapi-schema.json +2 -2
@@ -2314,7 +2314,7 @@ # "mac": "52:54:00:12:34:56" } } # <- { "return": {} } # -# TODO This command effectively bypasses QAPI completely due to its +# TODO: This command effectively bypasses QAPI completely due to its # "additional arguments" business. It shouldn't have been added to # the schema in this form. It should be qapified properly, or # replaced by a properly qapified command.
@@ -2515,7 +2515,7 @@ # # Additional arguments depend on the type. # -# TODO This command effectively bypasses QAPI completely due to its +# TODO: This command effectively bypasses QAPI completely due to its # "additional arguments" business. It shouldn't have been added to # the schema in this form. It should be qapified properly, or # replaced by a properly qapified command.
qapi/introspect.json +1 -1
@@ -258,7 +258,7 @@ # # @ret-type: the name of the command's result type. # -# TODO @success-response (currently irrelevant, because it's QGA, not QMP) +# TODO: @success-response (currently irrelevant, because it's QGA, not QMP) # # Since: 2.5 ##
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH v7 03/21] qapi: make TODOs named-sections
Quoted 2 lines · Marc-André Lureau
Have the TODO in the TAG: format, so they will stand out in the generated documentation.
I expect TODO without colon to creep back. Right now, we have three with and three without colon. Whack-a-mole is a stupid game, but since these moles are fairly harmless, I don't care.
The commit message is sub-optimal, though. At this point, there is no generated documentation, and we have no concept of "named-sections". Let's instead say
qapi: Format TODO comments more consistently
Consistently put a colon after TODO. This will make the TODOs stand out in the documentation we're going to generate.
With that
Alternatively, delay the patch until after we generate documentation.
PATCH v7 4/21 qapi: improve device_add schema
In reply to Marc-André Lureau'device_add' is still incomplete for now, but we can fix a few arguments:
- 'bus' is a common argument, regardless of the device
- 'id' is an optional argument
--- qapi-schema.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
qapi-schema.json +2 -2
@@ -2292,7 +2292,7 @@ # # @bus: #optional the device's parent bus (device tree path) # -# @id: the device's ID, must be unique +# @id: #optional the device's ID, must be unique # # Additional arguments depend on the type. #
@@ -2322,7 +2322,7 @@ # Since: 0.13 ## { 'command': 'device_add', - 'data': {'driver': 'str', 'id': 'str'}, + 'data': {'driver': 'str', '*bus': 'str', '*id': 'str'}, 'gen': false } # so we can get the additional arguments ##
Signature · 1 line
2.11.0
PATCH v7 5/21 qapi: improve TransactionAction doc
In reply to Marc-André LureauTransactionAction is a flat union, document 'type' versions exhaustively, and sort the members.
--- qapi-schema.json | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-)
qapi-schema.json +16 -15
@@ -1795,28 +1795,29 @@ # @TransactionAction: # # A discriminated record of operations that can be performed with -# @transaction. +# @transaction. Action @type can be: # -# Since: 1.1 +# - @abort: since 1.6 +# - @block-dirty-bitmap-add: since 2.5 +# - @block-dirty-bitmap-clear: since 2.5 +# - @blockdev-backup: since 2.3 +# - @blockdev-snapshot: since 2.5 +# - @blockdev-snapshot-internal-sync: since 1.7 +# - @blockdev-snapshot-sync: since 1.1 +# - @drive-backup: since 1.6 # -# drive-backup since 1.6 -# abort since 1.6 -# blockdev-snapshot-internal-sync since 1.7 -# blockdev-backup since 2.3 -# blockdev-snapshot since 2.5 -# block-dirty-bitmap-add since 2.5 -# block-dirty-bitmap-clear since 2.5 +# Since: 1.1 ## { 'union': 'TransactionAction', 'data': { - 'blockdev-snapshot': 'BlockdevSnapshot', - 'blockdev-snapshot-sync': 'BlockdevSnapshotSync', - 'drive-backup': 'DriveBackup', - 'blockdev-backup': 'BlockdevBackup', 'abort': 'Abort', - 'blockdev-snapshot-internal-sync': 'BlockdevSnapshotInternal', 'block-dirty-bitmap-add': 'BlockDirtyBitmapAdd', - 'block-dirty-bitmap-clear': 'BlockDirtyBitmap' + 'block-dirty-bitmap-clear': 'BlockDirtyBitmap', + 'blockdev-backup': 'BlockdevBackup', + 'blockdev-snapshot': 'BlockdevSnapshot', + 'blockdev-snapshot-internal-sync': 'BlockdevSnapshotInternal', + 'blockdev-snapshot-sync': 'BlockdevSnapshotSync', + 'drive-backup': 'DriveBackup' } } ##
Signature · 1 line
2.11.0
PATCH v7 6/21 qga/schema: improve guest-set-vcpus Returns: section
In reply to Marc-André LureauItemize the possible return values of guest-set-vcpus.
Drop the blank lines for consistency with itemized lists elsewhere.
--- qga/qapi-schema.json | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
qga/qapi-schema.json +4 -7
@@ -697,21 +697,18 @@ # Returns: The length of the initial sublist that has been successfully # processed. The guest agent maximizes this value. Possible cases: # -# 0: if the @vcpus list was empty on input. Guest state +# - 0: if the @vcpus list was empty on input. Guest state # has not been changed. Otherwise, -# -# Error: processing the first node of @vcpus failed for the +# - Error: processing the first node of @vcpus failed for the # reason returned. Guest state has not been changed. # Otherwise, -# -# < length(@vcpus): more than zero initial nodes have been processed, +# - < length(@vcpus): more than zero initial nodes have been processed, # but not the entire @vcpus list. Guest state has # changed accordingly. To retrieve the error # (assuming it persists), repeat the call with the # successfully processed initial sublist removed. # Otherwise, -# -# length(@vcpus): call successful. +# - length(@vcpus): call successful. # # Since: 1.5 ##
Signature · 1 line
2.11.0
PATCH v7 7/21 qapi: avoid interleaving sections and parameters
In reply to Marc-André LureauFollow documentation guideline, body, parameters then additional sections.
--- qapi-schema.json | 10 +++++----- qapi/event.json | 4 ++-- qapi/introspect.json | 3 +-- 3 files changed, 8 insertions(+), 9 deletions(-)
qapi-schema.json +5 -5
@@ -4729,17 +4729,17 @@ # it should be passed by management with device_add command when # a CPU is being hotplugged. # +# @node-id: #optional NUMA node ID the CPU belongs to +# @socket-id: #optional socket number within node/board the CPU belongs to +# @core-id: #optional core number within socket the CPU belongs to +# @thread-id: #optional thread number within core the CPU belongs to +# # Note: currently there are 4 properties that could be present # but management should be prepared to pass through other # properties with device_add command to allow for future # interface extension. This also requires the filed names to be kept in # sync with the properties passed to -device/device_add. # -# @node-id: #optional NUMA node ID the CPU belongs to -# @socket-id: #optional socket number within node/board the CPU belongs to -# @core-id: #optional core number within socket the CPU belongs to -# @thread-id: #optional thread number within core the CPU belongs to -# # Since: 2.7 ## { 'struct': 'CpuInstanceProperties',
qapi/event.json +2 -2
@@ -272,9 +272,9 @@ # # Emitted when guest executes ACPI _OST method. # -# Since: 2.1 -# # @info: ACPIOSTInfo type as described in qapi-schema.json +# +# Since: 2.1 ## { 'event': 'ACPI_DEVICE_OST', 'data': { 'info': 'ACPIOSTInfo' } }
qapi/introspect.json +1 -2
@@ -78,14 +78,13 @@ # @SchemaInfo: # # @name: the entity's name, inherited from @base. +# The SchemaInfo is always referenced by this name. # Commands and events have the name defined in the QAPI schema. # Unlike command and event names, type names are not part of # the wire ABI. Consequently, type names are meaningless # strings here, although they are still guaranteed unique # regardless of @meta-type. # -# All references to other SchemaInfo are by name. -# # @meta-type: the entity's meta type, inherited from @base. # # Additional members depend on the value of @meta-type.
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH v7 07/21] qapi: avoid interleaving sections and parameters
Quoted 2 lines · Marc-André Lureau
Follow documentation guideline, body, parameters then additional sections.
Commit message wording nit: we don't have a concept of "sections", yet.
I don't think the guidelines demand such an order at this point. Here's the applicable paragraph from docs/qapi-code-gen.txt:
Comments are allowed; anything between an unquoted # and the following newline is ignored. Although there is not yet a documentation generator, a form of stylized comments has developed for consistently documenting details about an expression and when it was added to the schema. The documentation is delimited between two lines of ##, then the first line names the expression, an optional overview is provided, then individual documentation about each member of 'data' is provided, and finally, a 'Since: x.y.z' tag lists the release that introduced the expression. Optional members are tagged with the phrase '#optional', often with their default value; and extensions added after the expression was first released are also given a '(since x.y.z)' comment. For example:
A pedantical reader would conclude only "Since" can follow the "members of 'data'".
I'm feeling less pedantical, and conclude that additional information not mentioned in this paragraph can be stuck wherever it reads well. Matches existing practice.
That said, I don't mind moving stuff around if it helps the doc generator later on, and doesn't make things less readable.
Quoted 24 lines
Signed-off-by Marc-André Lureau <[email protected]>--- qapi-schema.json | 10 +++++----- qapi/event.json | 4 ++-- qapi/introspect.json | 3 +-- 3 files changed, 8 insertions(+), 9 deletions(-)qapi-schema.json +5
-0@@ -4729,17 +4729,17 @@ # it should be passed by management with device_add command when # a CPU is being hotplugged. # +# @node-id: #optional NUMA node ID the CPU belongs to +# @socket-id: #optional socket number within node/board the CPU belongs to +# @core-id: #optional core number within socket the CPU belongs to +# @thread-id: #optional thread number within core the CPU belongs to +# # Note: currently there are 4 properties that could be present # but management should be prepared to pass through other # properties with device_add command to allow for future # interface extension. This also requires the filed names to be kept in
qapi-schema.json line 4745
Quoted 10 lines
qapi-schema.json +0
-5# sync with the properties passed to -device/device_add. # -# @node-id: #optional NUMA node ID the CPU belongs to -# @socket-id: #optional socket number within node/board the CPU belongs to -# @core-id: #optional core number within socket the CPU belongs to -# @thread-id: #optional thread number within core the CPU belongs to -# # Since: 2.7 ## { 'struct': 'CpuInstanceProperties',
No objection.
Quoted 6 lines
qapi/event.json +0
-0@@ -272,9 +272,9 @@ #
qapi/event.json line 280
Quoted 10 lines
qapi/event.json +2
-2# Emitted when guest executes ACPI _OST method. # -# Since: 2.1 -# # @info: ACPIOSTInfo type as described in qapi-schema.json +# +# Since: 2.1 ## { 'event': 'ACPI_DEVICE_OST', 'data': { 'info': 'ACPIOSTInfo' } }
Consistency improvement.
Quoted 10 lines
qapi/introspect.json +1
-0@@ -78,14 +78,13 @@ # @SchemaInfo: # # @name: the entity's name, inherited from @base. +# The SchemaInfo is always referenced by this name. # Commands and events have the name defined in the QAPI schema.
qapi/introspect.json line 90
Quoted 10 lines
qapi/introspect.json +0
-2# Unlike command and event names, type names are not part of # the wire ABI. Consequently, type names are meaningless # strings here, although they are still guaranteed unique # regardless of @meta-type. # -# All references to other SchemaInfo are by name. -# # @meta-type: the entity's meta type, inherited from @base. # # Additional members depend on the value of @meta-type.
Okay.
PATCH 02 "qapi: move QKeyCode doc body at the top" could be squashed into this one, I think.
Overall, no objections, except the commit message's first line forward-references the "sections" concept, and its rationale is a bit weak.
What about this:
qapi: Reorder doc comments for future doc generator
The doc generator we're going to add expects a fairly rigid doc comment structure. Reorder / rephrase some to please it.
To be clear: I still doubt this rigid order is a good idea. But as long as I can't point to actual harm, I'm willing to accept it, in the interest of getting stuff done.
PATCH v7 8/21 qapi: move experimental note down
In reply to Marc-André LureauUse a better 'Note:' section, move it below parameters following guidelines.
--- qapi/block-core.json | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
qapi/block-core.json +12 -12
@@ -2440,12 +2440,12 @@ # BlockBackend will be created; otherwise, @node-name is mandatory at the top # level and no BlockBackend will be created. # -# This command is still a work in progress. It doesn't support all +# For the arguments, see the documentation of BlockdevOptions. +# +# Note: This command is still a work in progress. It doesn't support all # block drivers among other things. Stay away from it unless you want # to help with its development. # -# For the arguments, see the documentation of BlockdevOptions. -# # Since: 1.7 ## { 'command': 'blockdev-add', 'data': 'BlockdevOptions', 'boxed': true }
@@ -2457,12 +2457,12 @@ # The command will fail if the node is attached to a device or is # otherwise being used. # -# This command is still a work in progress and is considered +# @node-name: Name of the graph node to delete. +# +# Note: This command is still a work in progress and is considered # experimental. Stay away from it unless you want to help with its # development. # -# @node-name: Name of the graph node to delete. -# # Since: 2.5 ## { 'command': 'x-blockdev-del', 'data': { 'node-name': 'str' } }
@@ -2529,13 +2529,13 @@ # # If the tray is open and there is no medium inserted, this will be a no-op. # -# This command is still a work in progress and is considered experimental. -# Stay away from it unless you want to help with its development. -# # @device: #optional Block device name (deprecated, use @id instead) # # @id: #optional The name or QOM path of the guest device (since: 2.8) # +# Note: This command is still a work in progress and is considered experimental. +# Stay away from it unless you want to help with its development. +# # Since: 2.5 ## { 'command': 'x-blockdev-remove-medium',
@@ -2549,15 +2549,15 @@ # device's tray must currently be open (unless there is no attached guest # device) and there must be no medium inserted already. # -# This command is still a work in progress and is considered experimental. -# Stay away from it unless you want to help with its development. -# # @device: #optional Block device name (deprecated, use @id instead) # # @id: #optional The name or QOM path of the guest device (since: 2.8) # # @node-name: name of a node in the block driver state graph # +# Note: This command is still a work in progress and is considered experimental. +# Stay away from it unless you want to help with its development. +# # Since: 2.5 ## { 'command': 'x-blockdev-insert-medium',
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH v7 08/21] qapi: move experimental note down
Quoted 4 lines · Marc-André Lureau
Use a better 'Note:' section, move it below parameters following guidelines.
Signed-off-by Marc-André Lureau <[email protected]>
Again, I don't mind moving stuff around if it helps getting this series wrapped, and doesn't make things less readable. My only nit is the commit message's claim about the guidelines. Let's sidestep it:
Move these notes down and prefix with "Note:", to please the doc generator we're going to add.
Okay?
Re: [Qemu-devel] [PATCH v7 08/21] qapi: move experimental note down
Hi
----- Original Message -----
Quoted 7 lines
Quoted 4 lines · Marc-André Lureau
Use a better 'Note:' section, move it below parameters following guidelines.
Signed-off-by Marc-André Lureau <[email protected]>
Quoted 9 lines
Again, I don't mind moving stuff around if it helps getting this series wrapped, and doesn't make things less readable. My only nit is the commit message's claim about the guidelines. Let's sidestep it:
Move these notes down and prefix with "Note:", to please the doc generator we're going to add.
Okay?
ok, thanks
PATCH v7 9/21 qapi: add some sections in docs
In reply to Marc-André LureauAdd some more section titles to organize the documentation we're going to generate.
--- qapi-schema.json | 4 ++++ qapi/block-core.json | 6 ++++-- qapi/block.json | 10 ++++++++-- qapi/common.json | 6 ++++-- qapi/crypto.json | 5 ++++- qapi/event.json | 6 ++++++ qapi/rocker.json | 4 ++++ qapi/trace.json | 3 +++ 8 files changed, 37 insertions(+), 7 deletions(-)
qapi-schema.json +4 -0
@@ -20,6 +20,10 @@ # QAPI introspection { 'include': 'qapi/introspect.json' } +## +# = QMP commands +## + ## # @qmp_capabilities: #
qapi/block-core.json +4 -2
@@ -1,6 +1,8 @@ # -*- Mode: Python -*- -# -# QAPI block core definitions (vm unrelated) + +## +# == QAPI block core definitions (vm unrelated) +## # QAPI common definitions { 'include': 'common.json' }
qapi/block.json +8 -2
@@ -1,10 +1,16 @@ # -*- Mode: Python -*- -# -# QAPI block definitions (vm related) + +## +# = QAPI block definitions +## # QAPI block core definitions { 'include': 'block-core.json' } +## +# == QAPI block definitions (vm unrelated) +## + ## # @BiosAtaTranslation: #
qapi/common.json +4 -2
@@ -1,6 +1,8 @@ # -*- Mode: Python -*- -# -# QAPI common definitions + +## +# = QAPI common definitions +## ## # @QapiErrorClass:
qapi/crypto.json +4 -1
@@ -1,6 +1,9 @@ # -*- Mode: Python -*- # -# QAPI crypto definitions + +## +# = QAPI crypto definitions +## ## # @QCryptoTLSCredsEndpoint:
qapi/event.json +6 -0
@@ -1,3 +1,9 @@ +# -*- Mode: Python -*- + +## +# = Other events +## + ## # @SHUTDOWN: #
qapi/rocker.json +4 -0
@@ -1,3 +1,7 @@ +## +# = Rocker switch device +## + ## # @RockerSwitch: #
qapi/trace.json +3 -0
@@ -5,6 +5,9 @@ # This work is licensed under the terms of the GNU GPL, version 2 or later. # See the COPYING file in the top-level directory. +## +# = Tracing commands +## ## # @TraceEventState:
Signature · 1 line
2.11.0
PATCH v7 10/21 docs: add master qapi texi files
In reply to Marc-André LureauThe qapi2texi script generates a file to be included in a texi file. Add "QEMU QMP Reference Manual" and "QEMU Guest Agent Protocol Reference" master texi files.
--- docs/qemu-ga-ref.texi | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++ docs/qemu-qmp-ref.texi | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+) create mode 100644 docs/qemu-ga-ref.texi create mode 100644 docs/qemu-qmp-ref.texi
docs/qemu-ga-ref.texi new file +74 -0
@@ -0,0 +1,74 @@ +\input texinfo +@setfilename qemu-ga-ref.info + +@exampleindent 0 +@paragraphindent 0 + +@settitle QEMU Guest Agent Protocol Reference + +@copying +This is the QEMU Guest Agent Protocol reference manual. + +Copyright @copyright{} 2016 The QEMU Project developers + +@quotation +This manual is free documentation: you can redistribute it and/or +modify it under the terms of the GNU General Public License as +published by the Free Software Foundation, either version 2 of the +License, or (at your option) any later version. + +This manual is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this manual. If not, see http://www.gnu.org/licenses/. +@end quotation +@end copying + +@dircategory QEMU +@direntry +* QEMU-GA-Ref: (qemu-ga-ref). QEMU Guest Agent Protocol Reference +@end direntry + +@titlepage +@title Guest Agent Protocol Reference Manual +@subtitle QEMU version @value{VERSION} +@page +@vskip 0pt plus 1filll +@insertcopying +@end titlepage + +@contents + +@ifnottex +@node Top +@top QEMU Guest Agent protocol reference +@end ifnottex + +@menu +* API Reference:: +* Commands and Events Index:: +* Data Types Index:: +@end menu + +@node API Reference +@chapter API Reference + +@c for texi2pod: +@c man begin DESCRIPTION + +@include qemu-ga-qapi.texi + +@c man end + +@node Commands and Events Index +@unnumbered Commands and Events Index +@printindex fn + +@node Data Types Index +@unnumbered Data Types Index +@printindex tp + +@bye
docs/qemu-qmp-ref.texi new file +74 -0
74 lines not on this page · raw message
Signature · 1 line
2.11.0
PATCH v7 11/21 qapi: rework qapi Exception
In reply to Marc-André LureauUse a base class QAPIError, and QAPIParseError for parser errors and QAPISemError for semantic errors, suggested by Markus Armbruster.
--- scripts/qapi.py | 334 ++++++++++++++++++++++++++------------------------------ 1 file changed, 156 insertions(+), 178 deletions(-)
scripts/qapi.py +156 -178
@@ -91,35 +91,38 @@ def error_path(parent): return res -class QAPISchemaError(Exception): - def __init__(self, schema, msg): +class QAPIError(Exception): + def __init__(self, fname, line, col, incl_info, msg): Exception.__init__(self) - self.fname = schema.fname + self.fname = fname + self.line = line + self.col = col + self.info = incl_info self.msg = msg - self.col = 1 - self.line = schema.line - for ch in schema.src[schema.line_pos:schema.pos]: - if ch == '\t': - self.col = (self.col + 7) % 8 + 1 - else: - self.col += 1 - self.info = schema.incl_info def __str__(self): - return error_path(self.info) + \ - "%s:%d:%d: %s" % (self.fname, self.line, self.col, self.msg) + loc = "%s:%d" % (self.fname, self.line) + if self.col is not None: + loc += ":%s" % self.col + return error_path(self.info) + "%s: %s" % (loc, self.msg) -class QAPIExprError(Exception): - def __init__(self, expr_info, msg): - Exception.__init__(self) - assert expr_info - self.info = expr_info - self.msg = msg +class QAPIParseError(QAPIError): + def __init__(self, parser, msg): + col = 1 + for ch in parser.src[parser.line_pos:parser.pos]: + if ch == '\t': + col = (col + 7) % 8 + 1 + else: + col += 1 + QAPIError.__init__(self, parser.fname, parser.line, col, + parser.incl_info, msg) - def __str__(self): - return error_path(self.info['parent']) + \ - "%s:%d: %s" % (self.info['file'], self.info['line'], self.msg) + +class QAPISemError(QAPIError): + def __init__(self, info, msg): + QAPIError.__init__(self, info['file'], info['line'], None, + info['parent'], msg) class QAPISchemaParser(object):
@@ -140,25 +143,24 @@ class QAPISchemaParser(object): self.accept() while self.tok is not None: - expr_info = {'file': fname, 'line': self.line, - 'parent': self.incl_info} + info = {'file': fname, 'line': self.line, + 'parent': self.incl_info} expr = self.get_expr(False) if isinstance(expr, dict) and "include" in expr: if len(expr) != 1: - raise QAPIExprError(expr_info, - "Invalid 'include' directive") + raise QAPISemError(info, "Invalid 'include' directive") include = expr["include"] if not isinstance(include, str): - raise QAPIExprError(expr_info, - "Value of 'include' must be a string") + raise QAPISemError(info, + "Value of 'include' must be a string") incl_abs_fname = os.path.join(os.path.dirname(abs_fname), include) # catch inclusion cycle - inf = expr_info + inf = info while inf: if incl_abs_fname == os.path.abspath(inf['file']): - raise QAPIExprError(expr_info, "Inclusion loop for %s" - % include) + raise QAPISemError(info, "Inclusion loop for %s" + % include) inf = inf['parent'] # skip multiple include of the same file if incl_abs_fname in previously_included:
@@ -166,14 +168,13 @@ class QAPISchemaParser(object): try: fobj = open(incl_abs_fname, 'r') except IOError as e: - raise QAPIExprError(expr_info, - '%s: %s' % (e.strerror, include)) + raise QAPISemError(info, '%s: %s' % (e.strerror, include)) exprs_include = QAPISchemaParser(fobj, previously_included, - expr_info) + info) self.exprs.extend(exprs_include.exprs) else: expr_elem = {'expr': expr, - 'info': expr_info} + 'info': info} self.exprs.append(expr_elem) def accept(self):
@@ -194,8 +195,7 @@ class QAPISchemaParser(object): ch = self.src[self.cursor] self.cursor += 1 if ch == '\n': - raise QAPISchemaError(self, - 'Missing terminating "\'"') + raise QAPIParseError(self, 'Missing terminating "\'"') if esc: if ch == 'b': string += '\b'
@@ -213,25 +213,25 @@ class QAPISchemaParser(object): ch = self.src[self.cursor] self.cursor += 1 if ch not in "0123456789abcdefABCDEF": - raise QAPISchemaError(self, - '\\u escape needs 4 ' - 'hex digits') + raise QAPIParseError(self, + '\\u escape needs 4 ' + 'hex digits') value = (value << 4) + int(ch, 16) # If Python 2 and 3 didn't disagree so much on # how to handle Unicode, then we could allow # Unicode string defaults. But most of QAPI is # ASCII-only, so we aren't losing much for now. if not value or value > 0x7f: - raise QAPISchemaError(self, - 'For now, \\u escape ' - 'only supports non-zero ' - 'values up to \\u007f') + raise QAPIParseError(self, + 'For now, \\u escape ' + 'only supports non-zero ' + 'values up to \\u007f') string += chr(value) elif ch in "\\/'\"": string += ch else: - raise QAPISchemaError(self, - "Unknown escape \\%s" % ch) + raise QAPIParseError(self, + "Unknown escape \\%s" % ch) esc = False elif ch == "\\": esc = True
@@ -259,7 +259,7 @@ class QAPISchemaParser(object): self.line += 1 self.line_pos = self.cursor elif not self.tok.isspace(): - raise QAPISchemaError(self, 'Stray "%s"' % self.tok) + raise QAPIParseError(self, 'Stray "%s"' % self.tok) def get_members(self): expr = OrderedDict()
@@ -267,24 +267,24 @@ class QAPISchemaParser(object): self.accept() return expr if self.tok != "'": - raise QAPISchemaError(self, 'Expected string or "}"') + raise QAPIParseError(self, 'Expected string or "}"') while True: key = self.val self.accept() if self.tok != ':': - raise QAPISchemaError(self, 'Expected ":"') + raise QAPIParseError(self, 'Expected ":"') self.accept() if key in expr: - raise QAPISchemaError(self, 'Duplicate key "%s"' % key) + raise QAPIParseError(self, 'Duplicate key "%s"' % key) expr[key] = self.get_expr(True) if self.tok == '}': self.accept() return expr if self.tok != ',': - raise QAPISchemaError(self, 'Expected "," or "}"') + raise QAPIParseError(self, 'Expected "," or "}"') self.accept() if self.tok != "'": - raise QAPISchemaError(self, 'Expected string') + raise QAPIParseError(self, 'Expected string') def get_values(self): expr = []
@@ -292,20 +292,20 @@ class QAPISchemaParser(object): self.accept() return expr if self.tok not in "{['tfn": - raise QAPISchemaError(self, 'Expected "{", "[", "]", string, ' - 'boolean or "null"') + raise QAPIParseError(self, 'Expected "{", "[", "]", string, ' + 'boolean or "null"') while True: expr.append(self.get_expr(True)) if self.tok == ']': self.accept() return expr if self.tok != ',': - raise QAPISchemaError(self, 'Expected "," or "]"') + raise QAPIParseError(self, 'Expected "," or "]"') self.accept() def get_expr(self, nested): if self.tok != '{' and not nested: - raise QAPISchemaError(self, 'Expected "{"') + raise QAPIParseError(self, 'Expected "{"') if self.tok == '{': self.accept() expr = self.get_members()
@@ -316,7 +316,7 @@ class QAPISchemaParser(object): expr = self.val self.accept() else: - raise QAPISchemaError(self, 'Expected "{", "[" or string') + raise QAPIParseError(self, 'Expected "{", "[" or string') return expr #
@@ -375,20 +375,18 @@ valid_name = re.compile('^(__[a-zA-Z0-9.-]+_)?' '[a-zA-Z][a-zA-Z0-9_-]*$') -def check_name(expr_info, source, name, allow_optional=False, +def check_name(info, source, name, allow_optional=False, enum_member=False): global valid_name membername = name if not isinstance(name, str): - raise QAPIExprError(expr_info, - "%s requires a string name" % source) + raise QAPISemError(info, "%s requires a string name" % source) if name.startswith('*'): membername = name[1:] if not allow_optional: - raise QAPIExprError(expr_info, - "%s does not allow optional name '%s'" - % (source, name)) + 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():
@@ -397,8 +395,7 @@ def check_name(expr_info, source, name, allow_optional=False, # and 'q_obj_*' implicit type names. if not valid_name.match(membername) or \ c_name(membername, False).startswith('q_'): - raise QAPIExprError(expr_info, - "%s uses invalid name '%s'" % (source, name)) + raise QAPISemError(info, "%s uses invalid name '%s'" % (source, name)) def add_name(name, info, meta, implicit=False):
@@ -407,13 +404,11 @@ def add_name(name, info, meta, implicit=False): # FIXME should reject names that differ only in '_' vs. '.' # vs. '-', because they're liable to clash in generated C. if name in all_names: - raise QAPIExprError(info, - "%s '%s' is already defined" - % (all_names[name], name)) + raise QAPISemError(info, "%s '%s' is already defined" + % (all_names[name], name)) if not implicit and (name.endswith('Kind') or name.endswith('List')): - raise QAPIExprError(info, - "%s '%s' should not end in '%s'" - % (meta, name, name[-4:])) + raise QAPISemError(info, "%s '%s' should not end in '%s'" + % (meta, name, name[-4:])) all_names[name] = meta
@@ -465,7 +460,7 @@ def is_enum(name): return find_enum(name) is not None -def check_type(expr_info, source, value, allow_array=False, +def check_type(info, source, value, allow_array=False, allow_dict=False, allow_optional=False, allow_metas=[]): global all_names
@@ -476,69 +471,64 @@ def check_type(expr_info, source, value, allow_array=False, # Check if array type for value is okay if isinstance(value, list): if not allow_array: - raise QAPIExprError(expr_info, - "%s cannot be an array" % source) + raise QAPISemError(info, "%s cannot be an array" % source) if len(value) != 1 or not isinstance(value[0], str): - raise QAPIExprError(expr_info, - "%s: array type must contain single type name" - % source) + raise QAPISemError(info, + "%s: array type must contain single type name" % + source) value = value[0] # Check if type name for value is okay if isinstance(value, str): if value not in all_names: - raise QAPIExprError(expr_info, - "%s uses unknown type '%s'" - % (source, value)) + raise QAPISemError(info, "%s uses unknown type '%s'" + % (source, value)) if not all_names[value] in allow_metas: - raise QAPIExprError(expr_info, - "%s cannot use %s type '%s'" - % (source, all_names[value], value)) + raise QAPISemError(info, "%s cannot use %s type '%s'" % + (source, all_names[value], value)) return if not allow_dict: - raise QAPIExprError(expr_info, - "%s should be a type name" % source) + raise QAPISemError(info, "%s should be a type name" % source) if not isinstance(value, OrderedDict): - raise QAPIExprError(expr_info, - "%s should be a dictionary or type name" % source) + raise QAPISemError(info, + "%s should be a dictionary or type name" % source) # value is a dictionary, check that each member is okay for (key, arg) in value.items(): - check_name(expr_info, "Member of %s" % source, key, + check_name(info, "Member of %s" % source, key, allow_optional=allow_optional) if c_name(key, False) == 'u' or c_name(key, False).startswith('has_'): - raise QAPIExprError(expr_info, - "Member of %s uses reserved name '%s'" - % (source, key)) + raise QAPISemError(info, "Member of %s uses reserved name '%s'" + % (source, key)) # Todo: allow dictionaries to represent default values of # an optional argument. - check_type(expr_info, "Member '%s' of %s" % (key, source), arg, + check_type(info, "Member '%s' of %s" % (key, source), arg, allow_array=True, allow_metas=['built-in', 'union', 'alternate', 'struct', 'enum']) -def check_command(expr, expr_info): +def check_command(expr, info): name = expr['command'] boxed = expr.get('boxed', False) args_meta = ['struct'] if boxed: args_meta += ['union', 'alternate'] - check_type(expr_info, "'data' for command '%s'" % name, + check_type(info, "'data' for command '%s'" % name, expr.get('data'), allow_dict=not boxed, allow_optional=True, allow_metas=args_meta) returns_meta = ['union', 'struct'] if name in returns_whitelist: returns_meta += ['built-in', 'alternate', 'enum'] - check_type(expr_info, "'returns' for command '%s'" % name, + check_type(info, "'returns' for command '%s'" % name, expr.get('returns'), allow_array=True, allow_optional=True, allow_metas=returns_meta) -def check_event(expr, expr_info): +def check_event(expr, info): global events name = expr['event'] boxed = expr.get('boxed', False)
@@ -547,12 +537,12 @@ def check_event(expr, expr_info): if boxed: meta += ['union', 'alternate'] events.append(name) - check_type(expr_info, "'data' for event '%s'" % name, + check_type(info, "'data' for event '%s'" % name, expr.get('data'), allow_dict=not boxed, allow_optional=True, allow_metas=meta) -def check_union(expr, expr_info): +def check_union(expr, info): name = expr['union'] base = expr.get('base') discriminator = expr.get('discriminator')
@@ -565,123 +555,117 @@ def check_union(expr, expr_info): enum_define = None allow_metas = ['built-in', 'union', 'alternate', 'struct', 'enum'] if base is not None: - raise QAPIExprError(expr_info, - "Simple union '%s' must not have a base" - % name) + raise QAPISemError(info, "Simple union '%s' must not have a base" % + name) # Else, it's a flat union. else: # The object must have a string or dictionary 'base'. - check_type(expr_info, "'base' for union '%s'" % name, + check_type(info, "'base' for union '%s'" % name, base, allow_dict=True, allow_optional=True, allow_metas=['struct']) if not base: - raise QAPIExprError(expr_info, - "Flat union '%s' must have a base" - % name) + raise QAPISemError(info, "Flat union '%s' must have a base" + % name) base_members = find_base_members(base) assert base_members # The value of member 'discriminator' must name a non-optional # member of the base struct. - check_name(expr_info, "Discriminator of flat union '%s'" % name, + check_name(info, "Discriminator of flat union '%s'" % name, discriminator) discriminator_type = base_members.get(discriminator) if not discriminator_type: - raise QAPIExprError(expr_info, - "Discriminator '%s' is not a member of base " - "struct '%s'" - % (discriminator, base)) + raise QAPISemError(info, + "Discriminator '%s' is not a member of base " + "struct '%s'" + % (discriminator, base)) enum_define = find_enum(discriminator_type) allow_metas = ['struct'] # Do not allow string discriminator if not enum_define: - raise QAPIExprError(expr_info, - "Discriminator '%s' must be of enumeration " - "type" % discriminator) + raise QAPISemError(info, + "Discriminator '%s' must be of enumeration " + "type" % discriminator) # Check every branch; don't allow an empty union if len(members) == 0: - raise QAPIExprError(expr_info, - "Union '%s' cannot have empty 'data'" % name) + raise QAPISemError(info, "Union '%s' cannot have empty 'data'" % name) for (key, value) in members.items(): - check_name(expr_info, "Member of union '%s'" % name, key) + check_name(info, "Member of union '%s'" % name, key) # Each value must name a known type - check_type(expr_info, "Member '%s' of union '%s'" % (key, name), + check_type(info, "Member '%s' of union '%s'" % (key, name), value, allow_array=not base, allow_metas=allow_metas) # If the discriminator names an enum type, then all members # of 'data' must also be members of the enum type. if enum_define: if key not in enum_define['enum_values']: - raise QAPIExprError(expr_info, - "Discriminator value '%s' is not found in " - "enum '%s'" % - (key, enum_define["enum_name"])) + raise QAPISemError(info, + "Discriminator value '%s' is not found in " + "enum '%s'" + % (key, enum_define["enum_name"])) # If discriminator is user-defined, ensure all values are covered if enum_define: for value in enum_define['enum_values']: if value not in members.keys(): - raise QAPIExprError(expr_info, - "Union '%s' data missing '%s' branch" - % (name, value)) + raise QAPISemError(info, "Union '%s' data missing '%s' branch" + % (name, value)) -def check_alternate(expr, expr_info): +def check_alternate(expr, info): name = expr['alternate'] members = expr['data'] types_seen = {} # Check every branch; require at least two branches if len(members) < 2: - raise QAPIExprError(expr_info, - "Alternate '%s' should have at least two branches " - "in 'data'" % name) + raise QAPISemError(info, + "Alternate '%s' should have at least two branches " + "in 'data'" % name) for (key, value) in members.items(): - check_name(expr_info, "Member of alternate '%s'" % name, key) + check_name(info, "Member of alternate '%s'" % name, key) # Ensure alternates have no type conflicts. - check_type(expr_info, "Member '%s' of alternate '%s'" % (key, name), + check_type(info, "Member '%s' of alternate '%s'" % (key, name), value, allow_metas=['built-in', 'union', 'struct', 'enum']) qtype = find_alternate_member_qtype(value) if not qtype: - raise QAPIExprError(expr_info, - "Alternate '%s' member '%s' cannot use " - "type '%s'" % (name, key, value)) + raise QAPISemError(info, "Alternate '%s' member '%s' cannot use " + "type '%s'" % (name, key, value)) if qtype in types_seen: - raise QAPIExprError(expr_info, - "Alternate '%s' member '%s' can't " - "be distinguished from member '%s'" - % (name, key, types_seen[qtype])) + raise QAPISemError(info, "Alternate '%s' member '%s' can't " + "be distinguished from member '%s'" + % (name, key, types_seen[qtype])) types_seen[qtype] = key -def check_enum(expr, expr_info): +def check_enum(expr, info): name = expr['enum'] members = expr.get('data') prefix = expr.get('prefix') if not isinstance(members, list): - raise QAPIExprError(expr_info, - "Enum '%s' requires an array for 'data'" % name) + raise QAPISemError(info, + "Enum '%s' requires an array for 'data'" % name) if prefix is not None and not isinstance(prefix, str): - raise QAPIExprError(expr_info, - "Enum '%s' requires a string for 'prefix'" % name) + raise QAPISemError(info, + "Enum '%s' requires a string for 'prefix'" % name) for member in members: - check_name(expr_info, "Member of enum '%s'" % name, member, + check_name(info, "Member of enum '%s'" % name, member, enum_member=True) -def check_struct(expr, expr_info): +def check_struct(expr, info): name = expr['struct'] members = expr['data'] - check_type(expr_info, "'data' for struct '%s'" % name, members, + check_type(info, "'data' for struct '%s'" % name, members, allow_dict=True, allow_optional=True) - check_type(expr_info, "'base' for struct '%s'" % name, expr.get('base'), + check_type(info, "'base' for struct '%s'" % name, expr.get('base'), allow_metas=['struct'])
@@ -690,27 +674,24 @@ def check_keys(expr_elem, meta, required, optional=[]): info = expr_elem['info'] name = expr[meta] if not isinstance(name, str): - raise QAPIExprError(info, - "'%s' key must have a string value" % meta) + raise QAPISemError(info, "'%s' key must have a string value" % meta) required = required + [meta] for (key, value) in expr.items(): if key not in required and key not in optional: - raise QAPIExprError(info, - "Unknown key '%s' in %s '%s'" - % (key, meta, name)) + raise QAPISemError(info, "Unknown key '%s' in %s '%s'" + % (key, meta, name)) if (key == 'gen' or key == 'success-response') and value is not False: - raise QAPIExprError(info, - "'%s' of %s '%s' should only use false value" - % (key, meta, name)) + raise QAPISemError(info, + "'%s' of %s '%s' should only use false value" + % (key, meta, name)) if key == 'boxed' and value is not True: - raise QAPIExprError(info, - "'%s' of %s '%s' should only use true value" - % (key, meta, name)) + raise QAPISemError(info, + "'%s' of %s '%s' should only use true value" + % (key, meta, name)) for key in required: if key not in expr: - raise QAPIExprError(info, - "Key '%s' is missing from %s '%s'" - % (key, meta, name)) + raise QAPISemError(info, "Key '%s' is missing from %s '%s'" + % (key, meta, name)) def check_exprs(exprs):
@@ -743,8 +724,8 @@ def check_exprs(exprs): check_keys(expr_elem, 'event', [], ['data', 'boxed']) add_name(expr['event'], info, 'event') else: - raise QAPIExprError(expr_elem['info'], - "Expression is missing metatype") + raise QAPISemError(expr_elem['info'], + "Expression is missing metatype") # Try again for hidden UnionKind enum for expr_elem in exprs:
@@ -978,8 +959,8 @@ class QAPISchemaObjectType(QAPISchemaType): def check(self, schema): if self.members is False: # check for cycles - raise QAPIExprError(self.info, - "Object %s contains itself" % self.name) + raise QAPISemError(self.info, + "Object %s contains itself" % self.name) if self.members: return self.members = False # mark as being checked
@@ -1051,12 +1032,11 @@ class QAPISchemaMember(object): def check_clash(self, info, seen): cname = c_name(self.name) if cname.lower() != cname and self.owner not in case_whitelist: - raise QAPIExprError(info, - "%s should not use uppercase" % self.describe()) + raise QAPISemError(info, + "%s should not use uppercase" % self.describe()) if cname in seen: - raise QAPIExprError(info, - "%s collides with %s" - % (self.describe(), seen[cname].describe())) + raise QAPISemError(info, "%s collides with %s" % + (self.describe(), seen[cname].describe())) seen[cname] = self def _pretty_owner(self):
@@ -1201,14 +1181,13 @@ class QAPISchemaCommand(QAPISchemaEntity): self.arg_type.check(schema) if self.boxed: if self.arg_type.is_empty(): - raise QAPIExprError(self.info, - "Cannot use 'boxed' with empty type") + raise QAPISemError(self.info, + "Cannot use 'boxed' with empty type") else: assert not isinstance(self.arg_type, QAPISchemaAlternateType) assert not self.arg_type.variants elif self.boxed: - raise QAPIExprError(self.info, - "Use of 'boxed' requires 'data'") + raise QAPISemError(self.info, "Use of 'boxed' requires 'data'") if self._ret_type_name: self.ret_type = schema.lookup_type(self._ret_type_name) assert isinstance(self.ret_type, QAPISchemaType)
@@ -1235,14 +1214,13 @@ class QAPISchemaEvent(QAPISchemaEntity): self.arg_type.check(schema) if self.boxed: if self.arg_type.is_empty(): - raise QAPIExprError(self.info, - "Cannot use 'boxed' with empty type") + raise QAPISemError(self.info, + "Cannot use 'boxed' with empty type") else: assert not isinstance(self.arg_type, QAPISchemaAlternateType) assert not self.arg_type.variants elif self.boxed: - raise QAPIExprError(self.info, - "Use of 'boxed' requires 'data'") + raise QAPISemError(self.info, "Use of 'boxed' requires 'data'") def visit(self, visitor): visitor.visit_event(self.name, self.info, self.arg_type, self.boxed)
@@ -1258,7 +1236,7 @@ class QAPISchema(object): self._predefining = False self._def_exprs() self.check() - except (QAPISchemaError, QAPIExprError) as err: + except QAPIError as err: print >>sys.stderr, err exit(1)
Signature · 1 line
2.11.0
PATCH v7 12/21 qapi.py: fix line break before binary operator pep8
In reply to Marc-André LureauPython code style accepts both form, but pep8 complains. Better to clean up the single warning for now, so new errors stand out more easily.
Fix scripts/qapi.py:1539:21: W503 line break before binary operator
--- scripts/qapi.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/qapi.py +2 -2
@@ -1535,8 +1535,8 @@ def c_name(name, protect=True): # namespace pollution: polluted_words = set(['unix', 'errno', 'mips', 'sparc']) name = name.translate(c_name_trans) - if protect and (name in c89_words | c99_words | c11_words | gcc_words - | cpp_words | polluted_words): + if protect and (name in c89_words | c99_words | c11_words | gcc_words | + cpp_words | polluted_words): return "q_" + name return name
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH v7 12/21] qapi.py: fix line break before binary operator pep8
Quoted 4 lines · Marc-André Lureau
Python code style accepts both form, but pep8 complains. Better to clean up the single warning for now, so new errors stand out more easily.
Fix
scripts/qapi.py:1539:21: W503 line break before binary operator
PEP 8 permits both, but prefers line break before binary operator. Thus, this warning is clearly bogus. What version of pep8 do you use? Mine doesn't warn.
Re: [Qemu-devel] [PATCH v7 12/21] qapi.py: fix line break before binary operator pep8
Hi
----- Original Message -----
Quoted 10 lines
Quoted 4 lines · Marc-André Lureau
Python code style accepts both form, but pep8 complains. Better to clean up the single warning for now, so new errors stand out more easily.
Fix
scripts/qapi.py:1539:21: W503 line break before binary operatorPEP 8 permits both, but prefers line break before binary operator. Thus, this warning is clearly bogus. What version of pep8 do you use? Mine doesn't warn.
I tried both 1.6.2 and 1.7.0
Re: [Qemu-devel] [PATCH v7 12/21] qapi.py: fix line break before binary operator pep8
Quoted 8 lines · Marc-André Lureau
Hi
----- Original Message -----
Quoted 5 lines
Quoted 3 lines · Marc-André Lureau
Python code style accepts both form, but pep8 complains. Better to clean up the single warning for now, so new errors stand out more easily.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Fix
scripts/qapi.py:1539:21: W503 line break before binary operatorPEP 8 permits both, but prefers line break before binary operator. Thus, this warning is clearly bogus. What version of pep8 do you use? Mine doesn't warn.
I tried both 1.6.2 and 1.7.0
I tried again, and I can now see the warning. No idea what I did wrong the first time.
Turns out PEP8 used to demand line break after the operator, but no more[1]. The pep8 program hasn't caught up, but it will[2]: its current git HEAD already suppresses W503. There's work in progress[3] on a new W504 to warn on line break after binary operator.
We will have to live with a mix of old and new pep8 / pycodestyle versions. Changing code to make new versions instead of old versions complain instead is not a good idea. We should simply ignore the obsolete warning from old versions.
pep8 lets you do that with --ignore=W503. Sadly, --ignore overwrites the default, so you have to --ignore=E121,E123,E126,E226,E24,E704,W503. Or have a file tox.ini with
[pep8]
ignore=E121,E123,E126,E226,E24,E704,W503[1] https://hg.python.org/peps/rev/3857909d7956
[2] https://github.com/PyCQA/pycodestyle/issues/498
[3] https://github.com/PyCQA/pycodestyle/pull/502
Re: [Qemu-devel] [PATCH v7 12/21] qapi.py: fix line break before binary operator pep8
Hi
Quoted 27 lines · Markus Armbruster
Quoted 6 lines · Marc-André Lureau
Hi
----- Original Message -----
Quoted 3 lines
Quoted 1 line · Marc-André Lureau
Python code style accepts both form, but pep8 complains. Better to
clean
Quoted 9 lines
Quoted 7 lines
Quoted 3 lines
up the single warning for now, so new errors stand out more easily.
Fix
scripts/qapi.py:1539:21: W503 line break before binary operatorPEP 8 permits both, but prefers line break before binary operator. Thus, this warning is clearly bogus. What version of pep8 do you use? Mine doesn't warn.
I tried both 1.6.2 and 1.7.0
I tried again, and I can now see the warning. No idea what I did wrong the first time.
Turns out PEP8 used to demand line break after the operator, but no more[1]. The pep8 program hasn't caught up, but it will[2]: its current git HEAD already suppresses W503. There's work in progress[3] on a new W504 to warn on line break after binary operator.
Quoted 6 lines
We will have to live with a mix of old and new pep8 / pycodestyle versions. Changing code to make new versions instead of old versions complain instead is not a good idea. We should simply ignore the obsolete warning from old versions.
ok, feel free to drop this patch then
thanks
Quoted 8 lines
pep8 lets you do that with --ignore=W503. Sadly, --ignore overwrites the default, so you have to --ignore=E121,E123,E126,E226,E24,E704,W503. Or have a file tox.ini with
[pep8] ignore=E121,E123,E126,E226,E24,E704,W503
Quoted 5 lines
[1] https://hg.python.org/peps/rev/3857909d7956
[2] https://github.com/PyCQA/pycodestyle/issues/498
[3] https://github.com/PyCQA/pycodestyle/pull/502--
Marc-André Lureau
PATCH v7 13/21 texi2pod: learn quotation, deftp and deftypefn
In reply to Marc-André LureauLearn a few more markups used for API documentation.
--- scripts/texi2pod.pl | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-)
scripts/texi2pod.pl +51 -3
@@ -37,6 +37,7 @@ $inf = ""; $ibase = ""; @ipath = (); $encoding = undef; +@args = (); while ($_ = shift) { if (/^-D(.*)$/) {
@@ -162,7 +163,8 @@ while(<$inf>) { if ($ended =~ /^(?:ifset|ifclear|ignore|menu|iftex)$/) { $skipping = pop @skstack; next; - } elsif ($ended =~ /^(?:example|smallexample|display)$/) { + } elsif ($ended =~ /^(?:example|smallexample|display + |quotation|deftp|deftypefn)$/x) { $shift = ""; $_ = ""; # need a paragraph break } elsif ($ended =~ /^(?:itemize|enumerate|[fv]?table)$/) {
@@ -303,6 +305,7 @@ while(<$inf>) { $ic =~ s/\@(?:code|kbd)/C/; $ic =~ s/\@(?:dfn|var|emph|cite|i)/I/; $ic =~ s/\@(?:file)/F/; + $ic =~ s/\@(?:asis)//; $_ = "\n=over 4\n"; };
@@ -323,10 +326,54 @@ while(<$inf>) { $_ = "\n=item ".join (" : ", @columns)."\n"; }; + /^\@(quotation)\s*(.+)?$/ and do { + push @endwstack, $endw; + $endw = $1; + $_ = "\n$2:" + }; + + /^{(.*)}$|^(.*)$/ and $#args > 0 and do { + $kind = $args[0]; + $arguments = $1 // ""; + if ($endw eq "deftypefn") { + $ret = $args[1]; + $fname = "B<$args[2]>"; + $_ = $ret ? "$ret " : ""; + $_ .= "$fname $arguments ($kind)"; + } else { + $_ = "B<$args[1]> ($kind)\n\n$arguments"; + } + @args = (); + }; + + /^\@(deftp)\s*(.+)?$/ and do { + push @endwstack, $endw; + $endw = $1; + $arg = $2; + $arg =~ s/{([^}]*)}/$1/g; + $arg =~ s/\@$//; + @args = split (/ /, $arg); + $_ = ""; + }; + + /^\@(deftypefn)\s*(.+)?$/ and do { + push @endwstack, $endw; + $endw = $1; + $arg = $2; + $arg =~ s/{([^}]*)}/$1/g; + $arg =~ s/\@$//; + @args = split (/ /, $arg); + $_ = ""; + }; + /^\@itemx?\s*(.+)?$/ and do { if (defined $1) { - # Entity escapes prevent munging by the <> processing below. - $_ = "\n=item $ic\<$1\>\n"; + if ($ic eq "") { + $_ = "\n=item $1\n"; + } else { + # Entity escapes prevent munging by the <> processing below. + $_ = "\n=item $ic\<$1\>\n"; + } } else { $_ = "\n=item $ic\n"; $ic =~ y/A-Ya-y/B-Zb-z/;
@@ -388,6 +435,7 @@ sub postprocess s/\@sc\{([^\}]*)\}/\U$1/g; s/\@file\{([^\}]*)\}/F<$1>/g; s/\@w\{([^\}]*)\}/S<$1>/g; + s/\@t\{([^\}]*)\}/$1/g; s/\@(?:dmn|math)\{([^\}]*)\}/$1/g; # keep references of the form @ref{...}, print them bold
Signature · 1 line
2.11.0
PATCH v7 14/21 (SQUASHED) move doc to schema
In reply to Marc-André Lureauqmp-commands: move 'add_client' doc to schema
qmp-commands: move 'query-name' doc to schema
qmp-commands: move 'query-kvm' doc to schema
qmp-commands: move 'query-status' doc to schema
qmp-commands: move 'query-uuid' doc to schema
qmp-commands: move 'query-chardev' doc to schema
qmp-commands: move 'query-chardev-backends' doc to schema
qmp-commands: move 'ringbuf-write' doc to schema
qmp-commands: move 'ringbuf-read' doc to schema
qmp-commands: move 'query-events' doc to schema
qmp-commands: move 'query-migrate' doc to schema
qmp-commands: move 'migrate-set-capabilities' doc to schema
qmp-commands: move 'query-migrate-capabilities' doc to schema
qmp-commands: move 'migrate-set-parameters' doc to schema
qmp-commands: move 'query-migrate-parameters' doc to schema
qmp-commands: move 'client_migrate_info' doc to schema
qmp-commands: move 'migrate-start-postcopy' doc to schema
qmp-commands: move 'query-mice' doc to schema
qmp-commands: move 'query-cpus' doc to schema
qmp-commands: move 'query-iothreads' doc to schema
qmp-commands: move 'query-vnc' doc to schema
qmp-commands: move 'query-spice' doc to schema
qmp-commands: move 'query-balloon' doc to schema
qmp-commands: move 'query-pci' doc to schema
qmp-commands: move 'quit' doc to schema
qmp-commands: move 'stop' doc to schema
qmp-commands: move 'system_reset' doc to schema
qmp-commands: move 'system_powerdown' doc to schema
qmp-commands: move 'cpu-add' doc to schema
qmp-commands: move 'memsave' doc to schema
Notice that "cpu" argument is actually "cpu-index" in the json.
qmp-commands: move 'pmemsave' doc to schema
qmp-commands: move 'cont' doc to schema
qmp-commands: move 'system_wakeup' doc to schema
qmp-commands: move 'inject-nmi' doc to schema
qmp-commands: move 'set_link' doc to schema
qmp-commands: move 'balloon' doc to schema
qmp-commands: move 'transaction' doc to schema
qmp-commands: move 'human-monitor-command' doc to schema
qmp-commands: move 'migrate_cancel' doc to schema
qmp-commands: move 'migrate_set_downtime' doc to schema
qmp-commands: move 'migrate_set_speed' doc to schema
qmp-commands: move 'query-migrate-cache-size' doc to schema
qmp-commands: move 'set_password' doc to schema
qmp-commands: move 'expire_password' doc to schema
qmp-commands: move 'change' doc to schema
qmp-commands: move 'migrate' doc to schema
qmp-commands: move 'migrate-incoming' doc to schema
qmp-commands: move 'xen-save-devices-state' doc to schema
qmp-commands: move 'xen-set-global-dirty-log' doc to schema
qmp-commands: move 'device_del' doc to schema
qmp-commands: move 'dump-guest-memory' doc to schema
qmp-commands: move 'query-dump-guest-memory-capability' doc to schema
qmp-commands: move 'dump-skeys' doc to schema
qmp-commands: move 'netdev_add' doc to schema
qmp-commands: move 'netdev_del' doc to schema
qmp-commands: move 'object-add' doc to schema
qmp-commands: move 'object-del' doc to schema
qmp-commands: move 'getfd' doc to schema
qmp-commands: move 'closefd' doc to schema
qmp-commands: move 'add-fd' doc to schema
qmp-commands: move 'remove-fd' doc to schema
qmp-commands: move 'query-fdsets' doc to schema
qmp-commands: move 'send-key' doc to schema
qmp-commands: move 'screendump' doc to schema
qmp-commands: move 'chardev-add' doc to schema
qmp-commands: move 'chardev-remove' doc to schema
qmp-commands: move 'query-tpm-models' doc to schema
qmp-commands: move 'query-tpm-types' doc to schema
qmp-commands: move 'query-tpm' doc to schema
qmp-commands: move 'query-command-line-options' doc to schema
qmp-commands: move 'query-rx-filter' doc to schema
qmp-commands: move 'input-send-event' doc to schema
qmp-commands: move 'query-memdev' doc to schema
qmp-commands: move 'query-memory-devices' doc to schema
qmp-commands: move 'query-acpi-ospm-status' doc to schema
qmp-commands: move 'rtc-reset-reinjection' doc to schema
qmp-commands: move 'query-block' doc to schema
qmp-commands: move 'query-blockstats' doc to schema
qmp-commands: move 'block_passwd' doc to schema
qmp-commands: move 'block_resize' doc to schema
qmp-commands: move 'blockdev-snapshot-sync' doc to schema
qmp-commands: move 'blockdev-snapshot' doc to schema
qmp-commands: move 'change-backing-file' doc to schema
qmp-commands: move 'block-commit' doc to schema
qmp-commands: move 'drive-backup' doc to schema
qmp-commands: move 'blockdev-backup' doc to schema
qmp-commands: move 'query-named-block-nodes' doc to schema
qmp-commands: move 'drive-mirror' doc to schema
qmp-commands: move 'block-dirty-bitmap-add' doc to schema
qmp-commands: move 'block-dirty-bitmap-remove' doc to schema
qmp-commands: move 'block-dirty-bitmap-clear' doc to schema
qmp-commands: move 'block_set_io_throttle' doc to schema
qmp-commands: move 'block-stream' doc to schema
qmp-commands: move 'blockdev-add' doc to schema
qmp-commands: move 'x-blockdev-del' doc to schema
qmp-commands: move 'blockdev-open-tray' doc to schema
qmp-commands: move 'blockdev-close-tray' doc to schema
qmp-commands: move 'x-blockdev-remove-medium' doc to schema
qmp-commands: move 'x-blockdev-insert-medium' doc to schema
qmp-commands: move 'blockdev-change-medium' doc to schema
qmp-commands: move 'block-set-write-threshold' doc to schema
qmp-commands: move 'blockdev-snapshot-internal-sync' doc to schema
qmp-commands: move 'blockdev-snapshot-delete-internal-sync' doc to schema
qmp-commands: move 'eject' doc to schema
qmp-commands: move 'query-version' doc to schema
qmp-commands: move 'query-commands' doc to schema
qmp-commands: move 'query-rocker' doc to schema
qmp-commands: move 'query-rocker-ports' doc to schema
qmp-commands: move 'query-rocker-of-dpa-flows' doc to schema
qmp-commands: move 'query-rocker-of-dpa-groups' doc to schema
qmp-commands: move 'trace-event-get-state' doc to schema
qmp-commands: move 'trace-event-set-state' doc to schema
qmp-commands: move 'query-hotpluggable-cpus' doc to schema
qmp-commands: move 'query-gic-capabilities' doc to schema
qmp-commands: move 'x-blockdev-change' doc to schema
qmp-commands: move 'blockdev-mirror' doc to schema
qmp-commands: move 'query-dump' doc to schema
qmp-commands: move 'migrate-set-cache-size' doc to schema
qmp-commands: move 'xen-load-devices-state' doc to schema
qmp-commands: move 'x-colo-lost-heartbeat' doc to schema
qmp-commands: remove query-qmp-schema from txt
It's better described in the schema already.
qmp-commands: remove qmp_capabilities from txt
It's better described in the schema already.
qmp-commands: remove cpu from txt
The cpu command is deprecated since commit 755f196898.
qmp-commands: remove device_add from txt
It's already fully described in the schema. Fix the schema to document the command and not the argument (place doc before first arg).
qmp-commands: move documentation bits to schema
Moving the remaining bits of documentation to the json file (text improvements is not the objective of this patch)
qmp-events: move 'BLOCK_IMAGE_CORRUPTED' doc to schema
qmp-events: move 'BLOCK_IO_ERROR' doc to schema
qmp-events: move 'BLOCK_JOB_COMPLETED' doc to schema
qmp-events: move 'BLOCK_JOB_CANCELLED' doc to schema
qmp-events: move 'BLOCK_JOB_ERROR' doc to schema
qmp-events: move 'BLOCK_JOB_READY' doc to schema
qmp-events: move 'DEVICE_TRAY_MOVED' doc to schema
qmp-events: move 'SHUTDOWN' doc to schema
qmp-events: move 'POWERDOWN' doc to schema
qmp-events: move 'RESET' doc to schema
qmp-events: move 'STOP' doc to schema
qmp-events: move 'RESUME' doc to schema
qmp-events: move 'SUSPEND' doc to schema
qmp-events: move 'SUSPEND_DISK' doc to schema
qmp-events: move 'WAKEUP' doc to schema
qmp-events: move 'RTC_CHANGE' doc to schema
qmp-events: move 'WATCHDOG' doc to schema
qmp-events: move 'DEVICE_DELETED' doc to schema
qmp-events: move 'NIC_RX_FILTER_CHANGED' doc to schema
qmp-events: move 'VNC_CONNECTED' doc to schema
qmp-events: move 'VNC_INITIALIZED' doc to schema
qmp-events: move 'VNC_DISCONNECTED' doc to schema
qmp-events: move 'SPICE_CONNECTED' doc to schema
qmp-events: move 'SPICE_INITIALIZED' doc to schema
qmp-events: move 'SPICE_DISCONNECTED' doc to schema
qmp-events: move 'SPICE_MIGRATE_COMPLETED' doc to schema
qmp-events: move 'MIGRATION' doc to schema
qmp-events: move 'ACPI_DEVICE_OST' doc to schema
qmp-events: move 'BALLOON_CHANGE' doc to schema
qmp-events: move 'GUEST_PANICKED' doc to schema
qmp-events: move 'QUORUM_FAILURE' doc to schema
qmp-events: move 'QUORUM_REPORT_BAD' doc to schema
qmp-events: move 'VSERPORT_CHANGE' doc to schema
qmp-events: move 'MEM_UNPLUG_ERROR' doc to schema
qmp-events: move 'DUMP_COMPLETED' doc to schema
qmp-events: move 'MIGRATION_PASS' doc to schema
--- qapi-schema.json | 1271 +++++++++++++++- qapi/block-core.json | 670 ++++++++- qapi/block.json | 56 +- qapi/common.json | 32 + qapi/event.json | 240 ++++ qapi/rocker.json | 57 +- qapi/trace.json | 14 + Makefile | 1 - docs/qmp-commands.txt | 3824 ------------------------------------------------- docs/qmp-events.txt | 731 ---------- 10 files changed, 2300 insertions(+), 4596 deletions(-) delete mode 100644 docs/qmp-commands.txt delete mode 100644 docs/qmp-events.txt
qapi-schema.json +1250 -21
@@ -1,6 +1,53 @@ # -*- Mode: Python -*- +## +# = Introduction +# +# This document describes all commands currently supported by QMP. +# +# Most of the time their usage is exactly the same as in the user Monitor, this +# means that any other document which also describe commands (the manpage, +# QEMU's manual, etc) can and should be consulted. +# +# QMP has two types of commands: regular and query commands. Regular commands +# usually change the Virtual Machine's state someway, while query commands just +# return information. The sections below are divided accordingly. +# +# It's important to observe that all communication examples are formatted in +# a reader-friendly way, so that they're easier to understand. However, in real +# protocol usage, they're emitted as a single line. +# +# Also, the following notation is used to denote data flow: +# +# Example: +# +# | -> data issued by the Client +# | <- Server data response +# +# Please, refer to the QMP specification (docs/qmp-spec.txt) for +# detailed information on the Server command and response formats. +# +# = Stability Considerations +# +# The current QMP command set (described in this file) may be useful for a +# number of use cases, however it's limited and several commands have bad +# defined semantics, specially with regard to command completion. +# +# These problems are going to be solved incrementally in the next QEMU releases +# and we're going to establish a deprecation policy for badly defined commands. +# +# If you're planning to adopt QMP, please observe the following: # -# QAPI Schema +# 1. The deprecation policy will take effect and be documented soon, please +# check the documentation of each used command as soon as a new release of +# QEMU is available +# +# 2. DO NOT rely on anything which is not explicit documented +# +# 3. Errors, in special, are not documented. Applications should NOT check +# for specific errors classes or data (it's strongly recommended to only +# check for the "error" key) +# +## # QAPI common definitions { 'include': 'qapi/common.json' }
@@ -89,6 +136,13 @@ # Returns: nothing on success. # # Since: 0.14.0 +# +# Example: +# +# -> { "execute": "add_client", "arguments": { "protocol": "vnc", +# "fdname": "myclient" } } +# <- { "return": {} } +# ## { 'command': 'add_client', 'data': { 'protocol': 'str', 'fdname': 'str', '*skipauth': 'bool',
@@ -113,6 +167,12 @@ # Returns: @NameInfo of the guest # # Since: 0.14.0 +# +# Example: +# +# -> { "execute": "query-name" } +# <- { "return": { "name": "qemu-name" } } +# ## { 'command': 'query-name', 'returns': 'NameInfo' }
@@ -137,6 +197,12 @@ # Returns: @KvmInfo # # Since: 0.14.0 +# +# Example: +# +# -> { "execute": "query-kvm" } +# <- { "return": { "enabled": true, "present": true } } +# ## { 'command': 'query-kvm', 'returns': 'KvmInfo' }
@@ -217,13 +283,21 @@ # Returns: @StatusInfo reflecting all VCPUs # # Since: 0.14.0 +# +# Example: +# +# -> { "execute": "query-status" } +# <- { "return": { "running": true, +# "singlestep": false, +# "status": "running" } } +# ## { 'command': 'query-status', 'returns': 'StatusInfo' } ## # @UuidInfo: # -# Guest UUID information. +# Guest UUID information (Universally Unique Identifier). # # @UUID: the UUID of the guest #
@@ -241,6 +315,12 @@ # Returns: The @UuidInfo for the guest # # Since: 0.14.0 +# +# Example: +# +# -> { "execute": "query-uuid" } +# <- { "return": { "UUID": "550e8400-e29b-41d4-a716-446655440000" } } +# ## { 'command': 'query-uuid', 'returns': 'UuidInfo' }
@@ -274,6 +354,30 @@ # Returns: a list of @ChardevInfo # # Since: 0.14.0 +# +# Example: +# +# -> { "execute": "query-chardev" } +# <- { +# "return": [ +# { +# "label": "charchannel0", +# "filename": "unix:/var/lib/libvirt/qemu/seabios.rhel6.agent,server", +# "frontend-open": false +# }, +# { +# "label": "charmonitor", +# "filename": "unix:/var/lib/libvirt/qemu/seabios.rhel6.monitor,server", +# "frontend-open": true +# }, +# { +# "label": "charserial0", +# "filename": "pty:/dev/pts/2", +# "frontend-open": true +# } +# ] +# } +# ## { 'command': 'query-chardev', 'returns': ['ChardevInfo'] }
@@ -296,6 +400,27 @@ # Returns: a list of @ChardevBackendInfo # # Since: 2.0 +# +# Example: +# +# -> { "execute": "query-chardev-backends" } +# <- { +# "return":[ +# { +# "name":"udp" +# }, +# { +# "name":"tcp" +# }, +# { +# "name":"unix" +# }, +# { +# "name":"spiceport" +# } +# ] +# } +# ## { 'command': 'query-chardev-backends', 'returns': ['ChardevBackendInfo'] }
@@ -332,6 +457,15 @@ # Returns: Nothing on success # # Since: 1.4 +# +# Example: +# +# -> { "execute": "ringbuf-write", +# "arguments": { "device": "foo", +# "data": "abcdefgh", +# "format": "utf8" } } +# <- { "return": {} } +# ## { 'command': 'ringbuf-write', 'data': {'device': 'str', 'data': 'str',
@@ -359,6 +493,15 @@ # Returns: data read from the device # # Since: 1.4 +# +# Example: +# +# -> { "execute": "ringbuf-read", +# "arguments": { "device": "foo", +# "size": 1000, +# "format": "utf8" } } +# <- { "return": "abcdefgh" } +# ## { 'command': 'ringbuf-read', 'data': {'device': 'str', 'size': 'int', '*format': 'DataFormat'},
@@ -383,6 +526,23 @@ # Returns: A list of @EventInfo for all supported events # # Since: 1.2.0 +# +# Example: +# +# -> { "execute": "query-events" } +# <- { +# "return": [ +# { +# "name":"SHUTDOWN" +# }, +# { +# "name":"RESET" +# } +# ] +# } +# +# Note: This example has been shortened as the real response is too long. +# ## { 'command': 'query-events', 'returns': ['EventInfo'] }
@@ -542,11 +702,124 @@ ## # @query-migrate: # -# Returns information about current migration process. +# Returns information about current migration process. If migration +# is active there will be another json-object with RAM migration +# status and if block migration is active another one with block +# migration status. # # Returns: @MigrationInfo # # Since: 0.14.0 +# +# Example: +# +# 1. Before the first migration +# +# -> { "execute": "query-migrate" } +# <- { "return": {} } +# +# 2. Migration is done and has succeeded +# +# -> { "execute": "query-migrate" } +# <- { "return": { +# "status": "completed", +# "ram":{ +# "transferred":123, +# "remaining":123, +# "total":246, +# "total-time":12345, +# "setup-time":12345, +# "downtime":12345, +# "duplicate":123, +# "normal":123, +# "normal-bytes":123456, +# "dirty-sync-count":15 +# } +# } +# } +# +# 3. Migration is done and has failed +# +# -> { "execute": "query-migrate" } +# <- { "return": { "status": "failed" } } +# +# 4. Migration is being performed and is not a block migration: +# +# -> { "execute": "query-migrate" } +# <- { +# "return":{ +# "status":"active", +# "ram":{ +# "transferred":123, +# "remaining":123, +# "total":246, +# "total-time":12345, +# "setup-time":12345, +# "expected-downtime":12345, +# "duplicate":123, +# "normal":123, +# "normal-bytes":123456, +# "dirty-sync-count":15 +# } +# } +# } +# +# 5. Migration is being performed and is a block migration: +# +# -> { "execute": "query-migrate" } +# <- { +# "return":{ +# "status":"active", +# "ram":{ +# "total":1057024, +# "remaining":1053304, +# "transferred":3720, +# "total-time":12345, +# "setup-time":12345, +# "expected-downtime":12345, +# "duplicate":123, +# "normal":123, +# "normal-bytes":123456, +# "dirty-sync-count":15 +# }, +# "disk":{ +# "total":20971520, +# "remaining":20880384, +# "transferred":91136 +# } +# } +# } +# +# 6. Migration is being performed and XBZRLE is active: +# +# -> { "execute": "query-migrate" } +# <- { +# "return":{ +# "status":"active", +# "capabilities" : [ { "capability": "xbzrle", "state" : true } ], +# "ram":{ +# "total":1057024, +# "remaining":1053304, +# "transferred":3720, +# "total-time":12345, +# "setup-time":12345, +# "expected-downtime":12345, +# "duplicate":10, +# "normal":3333, +# "normal-bytes":3412992, +# "dirty-sync-count":15 +# }, +# "xbzrle-cache":{ +# "cache-size":67108864, +# "bytes":20971520, +# "pages":2444343, +# "cache-miss":2244, +# "cache-miss-rate":0.123, +# "overflow":34434 +# } +# } +# } +# ## { 'command': 'query-migrate', 'returns': 'MigrationInfo' }
@@ -620,6 +893,12 @@ # @capabilities: json array of capability modifications to make # # Since: 1.2 +# +# Example: +# +# -> { "execute": "migrate-set-capabilities" , "arguments": +# { "capabilities": [ { "capability": "xbzrle", "state": true } ] } } +# ## { 'command': 'migrate-set-capabilities', 'data': { 'capabilities': ['MigrationCapabilityStatus'] } }
@@ -632,6 +911,21 @@ # Returns: @MigrationCapabilitiesStatus # # Since: 1.2 +# +# Example: +# +# -> { "execute": "query-migrate-capabilities" } +# <- { "return": [ +# {"state": false, "capability": "xbzrle"}, +# {"state": false, "capability": "rdma-pin-all"}, +# {"state": false, "capability": "auto-converge"}, +# {"state": false, "capability": "zero-blocks"}, +# {"state": false, "capability": "compress"}, +# {"state": true, "capability": "events"}, +# {"state": false, "capability": "postcopy-ram"}, +# {"state": false, "capability": "x-colo"} +# ]} +# ## { 'command': 'query-migrate-capabilities', 'returns': ['MigrationCapabilityStatus']}
@@ -700,6 +994,12 @@ # Set various migration parameters. See MigrationParameters for details. # # Since: 2.4 +# +# Example: +# +# -> { "execute": "migrate-set-parameters" , +# "arguments": { "compress-level": 1 } } +# ## { 'command': 'migrate-set-parameters', 'boxed': true, 'data': 'MigrationParameters' }
@@ -771,6 +1071,21 @@ # Returns: @MigrationParameters # # Since: 2.4 +# +# Example: +# +# -> { "execute": "query-migrate-parameters" } +# <- { "return": { +# "decompress-threads": 2, +# "cpu-throttle-increment": 10, +# "compress-threads": 8, +# "compress-level": 1, +# "cpu-throttle-initial": 20, +# "max-bandwidth": 33554432, +# "downtime-limit": 300 +# } +# } +# ## { 'command': 'query-migrate-parameters', 'returns': 'MigrationParameters' }
@@ -789,6 +1104,15 @@ # @cert-subject: #optional server certificate subject # # Since: 0.14.0 +# +# Example: +# +# -> { "execute": "client_migrate_info", +# "arguments": { "protocol": "spice", +# "hostname": "virt42.lab.kraxel.org", +# "port": 1234 } } +# <- { "return": {} } +# ## { 'command': 'client_migrate_info', 'data': { 'protocol': 'str', 'hostname': 'str', '*port': 'int',
@@ -802,6 +1126,12 @@ # command. # # Since: 2.5 +# +# Example: +# +# -> { "execute": "migrate-start-postcopy" } +# <- { "return": {} } +# ## { 'command': 'migrate-start-postcopy' }
@@ -874,6 +1204,12 @@ # then takes over server operation to become the service VM. # # Since: 2.8 +# +# Example: +# +# -> { "execute": "x-colo-lost-heartbeat" } +# <- { "return": {} } +# ## { 'command': 'x-colo-lost-heartbeat' }
@@ -904,6 +1240,26 @@ # Returns: a list of @MouseInfo for each device # # Since: 0.14.0 +# +# Example: +# +# -> { "execute": "query-mice" } +# <- { "return": [ +# { +# "name":"QEMU Microsoft Mouse", +# "index":0, +# "current":false, +# "absolute":false +# }, +# { +# "name":"QEMU PS/2 Mouse", +# "index":1, +# "current":true, +# "absolute":true +# } +# ] +# } +# ## { 'command': 'query-mice', 'returns': ['MouseInfo'] }
@@ -1028,6 +1384,32 @@ # Returns: a list of @CpuInfo for each virtual CPU # # Since: 0.14.0 +# +# Example: +# +# -> { "execute": "query-cpus" } +# <- { "return": [ +# { +# "CPU":0, +# "current":true, +# "halted":false, +# "qom_path":"/machine/unattached/device[0]", +# "arch":"x86", +# "pc":3227107138, +# "thread_id":3134 +# }, +# { +# "CPU":1, +# "current":false, +# "halted":true, +# "qom_path":"/machine/unattached/device[2]", +# "arch":"x86", +# "pc":7108165, +# "thread_id":3135 +# } +# ] +# } +# ## { 'command': 'query-cpus', 'returns': ['CpuInfo'] }
@@ -1057,6 +1439,22 @@ # Returns: a list of @IOThreadInfo for each iothread # # Since: 2.0 +# +# Example: +# +# -> { "execute": "query-iothreads" } +# <- { "return": [ +# { +# "id":"iothread0", +# "thread-id":3134 +# }, +# { +# "id":"iothread1", +# "thread-id":3135 +# } +# ] +# } +# ## { 'command': 'query-iothreads', 'returns': ['IOThreadInfo'] }
@@ -1239,6 +1637,26 @@ # Returns: @VncInfo # # Since: 0.14.0 +# +# Example: +# +# -> { "execute": "query-vnc" } +# <- { "return": { +# "enabled":true, +# "host":"0.0.0.0", +# "service":"50402", +# "auth":"vnc", +# "family":"ipv4", +# "clients":[ +# { +# "host":"127.0.0.1", +# "service":"50401", +# "family":"ipv4" +# } +# ] +# } +# } +# ## { 'command': 'query-vnc', 'returns': 'VncInfo' }
@@ -1336,7 +1754,7 @@ # @enabled: true if the SPICE server is enabled, false otherwise # # @migrated: true if the last guest migration completed and spice -# migration had completed as well. false otherwise. +# migration had completed as well. false otherwise. (since 1.4) # # @host: #optional The hostname the SPICE server is bound to. This depends on # the name resolution on the host and may be an IP address.
@@ -1354,9 +1772,7 @@ # # @mouse-mode: The mode in which the mouse cursor is displayed currently. Can # be determined by the client or the server, or unknown if spice -# server doesn't provide this information. -# -# Since: 1.1 +# server doesn't provide this information. (since: 1.1) # # @channels: a list of @SpiceChannel for each active spice channel #
@@ -1375,6 +1791,40 @@ # Returns: @SpiceInfo # # Since: 0.14.0 +# +# Example: +# +# -> { "execute": "query-spice" } +# <- { "return": { +# "enabled": true, +# "auth": "spice", +# "port": 5920, +# "tls-port": 5921, +# "host": "0.0.0.0", +# "channels": [ +# { +# "port": "54924", +# "family": "ipv4", +# "channel-type": 1, +# "connection-id": 1804289383, +# "host": "127.0.0.1", +# "channel-id": 0, +# "tls": true +# }, +# { +# "port": "36710", +# "family": "ipv4", +# "channel-type": 4, +# "connection-id": 1804289383, +# "host": "127.0.0.1", +# "channel-id": 0, +# "tls": false +# }, +# [ ... more channels follow ... ] +# ] +# } +# } +# ## { 'command': 'query-spice', 'returns': 'SpiceInfo' }
@@ -1396,11 +1846,22 @@ # Return information about the balloon device. # # Returns: @BalloonInfo on success +# # If the balloon driver is enabled but not functional because the KVM # kernel module cannot support it, KvmMissingCap +# # If no balloon device is present, DeviceNotActive # # Since: 0.14.0 +# +# Example: +# +# -> { "execute": "query-balloon" } +# <- { "return": { +# "actual": 1073741824, +# } +# } +# ## { 'command': 'query-balloon', 'returns': 'BalloonInfo' }
@@ -1427,6 +1888,8 @@ # @type: 'io' if the region is a PIO region # 'memory' if the region is a MMIO region # +# @size: memory size +# # @prefetch: #optional if @type is 'memory', true if the memory is prefetchable # # @mem_type_64: #optional if @type is 'memory', true if the BAR is 64-bit
@@ -1560,9 +2023,144 @@ # # Return information about the PCI bus topology of the guest. # -# Returns: a list of @PciInfo for each PCI bus +# Returns: a list of @PciInfo for each PCI bus. Each bus is +# represented by a json-object, which has a key with a json-array of +# all PCI devices attached to it. Each device is represented by a +# json-object. # # Since: 0.14.0 +# +# Example: +# +# -> { "execute": "query-pci" } +# <- { "return": [ +# { +# "bus": 0, +# "devices": [ +# { +# "bus": 0, +# "qdev_id": "", +# "slot": 0, +# "class_info": { +# "class": 1536, +# "desc": "Host bridge" +# }, +# "id": { +# "device": 32902, +# "vendor": 4663 +# }, +# "function": 0, +# "regions": [ +# ] +# }, +# { +# "bus": 0, +# "qdev_id": "", +# "slot": 1, +# "class_info": { +# "class": 1537, +# "desc": "ISA bridge" +# }, +# "id": { +# "device": 32902, +# "vendor": 28672 +# }, +# "function": 0, +# "regions": [ +# ] +# }, +# { +# "bus": 0, +# "qdev_id": "", +# "slot": 1, +# "class_info": { +# "class": 257, +# "desc": "IDE controller" +# }, +# "id": { +# "device": 32902, +# "vendor": 28688 +# }, +# "function": 1, +# "regions": [ +# { +# "bar": 4, +# "size": 16, +# "address": 49152, +# "type": "io" +# } +# ] +# }, +# { +# "bus": 0, +# "qdev_id": "", +# "slot": 2, +# "class_info": { +# "class": 768, +# "desc": "VGA controller" +# }, +# "id": { +# "device": 4115, +# "vendor": 184 +# }, +# "function": 0, +# "regions": [ +# { +# "prefetch": true, +# "mem_type_64": false, +# "bar": 0, +# "size": 33554432, +# "address": 4026531840, +# "type": "memory" +# }, +# { +# "prefetch": false, +# "mem_type_64": false, +# "bar": 1, +# "size": 4096, +# "address": 4060086272, +# "type": "memory" +# }, +# { +# "prefetch": false, +# "mem_type_64": false, +# "bar": 6, +# "size": 65536, +# "address": -1, +# "type": "memory" +# } +# ] +# }, +# { +# "bus": 0, +# "qdev_id": "", +# "irq": 11, +# "slot": 4, +# "class_info": { +# "class": 1280, +# "desc": "RAM controller" +# }, +# "id": { +# "device": 6900, +# "vendor": 4098 +# }, +# "function": 0, +# "regions": [ +# { +# "bar": 0, +# "size": 32, +# "address": 49280, +# "type": "io" +# } +# ] +# } +# ] +# } +# ] +# } +# +# Note: This example has been shortened as the real response is too long. +# ## { 'command': 'query-pci', 'returns': ['PciInfo'] }
@@ -1575,6 +2173,11 @@ # unexpected. # # Since: 0.14.0 +# +# Example: +# +# -> { "execute": "quit" } +# <- { "return": {} } ## { 'command': 'quit' }
@@ -1589,6 +2192,12 @@ # state. In "inmigrate" state, it will ensure that the guest # remains paused once migration finishes, as if the -S option was # passed on the command line. +# +# Example: +# +# -> { "execute": "stop" } +# <- { "return": {} } +# ## { 'command': 'stop' }
@@ -1598,6 +2207,12 @@ # Performs a hard reset of a guest. # # Since: 0.14.0 +# +# Example: +# +# -> { "execute": "system_reset" } +# <- { "return": {} } +# ## { 'command': 'system_reset' }
@@ -1612,6 +2227,11 @@ # returning does not indicate that a guest has accepted the request or # that it has shut down. Many guests will respond to this command by # prompting the user in some way. +# Example: +# +# -> { "execute": "system_powerdown" } +# <- { "return": {} } +# ## { 'command': 'system_powerdown' }
@@ -1636,6 +2256,12 @@ # Returns: Nothing on success # # Since: 1.5 +# +# Example: +# +# -> { "execute": "cpu-add", "arguments": { "id": 2 } } +# <- { "return": {} } +# ## { 'command': 'cpu-add', 'data': {'id': 'int'} }
@@ -1658,6 +2284,15 @@ # Since: 0.14.0 # # Notes: Errors were not reliably returned until 1.1 +# +# Example: +# +# -> { "execute": "memsave", +# "arguments": { "val": 10, +# "size": 100, +# "filename": "/tmp/virtual-mem-dump" } } +# <- { "return": {} } +# ## { 'command': 'memsave', 'data': {'val': 'int', 'size': 'int', 'filename': 'str', '*cpu-index': 'int'} }
@@ -1678,6 +2313,15 @@ # Since: 0.14.0 # # Notes: Errors were not reliably returned until 1.1 +# +# Example: +# +# -> { "execute": "pmemsave", +# "arguments": { "val": 10, +# "size": 100, +# "filename": "/tmp/physical-mem-dump" } } +# <- { "return": {} } +# ## { 'command': 'pmemsave', 'data': {'val': 'int', 'size': 'int', 'filename': 'str'} }
@@ -1698,6 +2342,12 @@ # this case, the effect of the command is to make sure the guest # starts once migration finishes, removing the effect of the -S # command line option if it was passed. +# +# Example: +# +# -> { "execute": "cont" } +# <- { "return": {} } +# ## { 'command': 'cont' }
@@ -1709,6 +2359,12 @@ # Since: 1.1 # # Returns: nothing. +# +# Example: +# +# -> { "execute": "system_wakeup" } +# <- { "return": {} } +# ## { 'command': 'system_wakeup' }
@@ -1716,12 +2372,19 @@ # @inject-nmi: # # Injects a Non-Maskable Interrupt into the default CPU (x86/s390) or all CPUs (ppc64). +# The command fails when the guest doesn't support injecting. # # Returns: If successful, nothing # # Since: 0.14.0 # # Note: prior to 2.1, this command was only supported for x86 and s390 VMs +# +# Example: +# +# -> { "execute": "inject-nmi" } +# <- { "return": {} } +# ## { 'command': 'inject-nmi' }
@@ -1742,6 +2405,13 @@ # Notes: Not all network adapters support setting link status. This command # will succeed even if the network adapter does not support link status # notification. +# +# Example: +# +# -> { "execute": "set_link", +# "arguments": { "name": "e1000.0", "up": false } } +# <- { "return": {} } +# ## { 'command': 'set_link', 'data': {'name': 'str', 'up': 'bool'} }
@@ -1762,6 +2432,12 @@ # size independent of this command. # # Since: 0.14.0 +# +# Example: +# +# -> { "execute": "balloon", "arguments": { "value": 536870912 } } +# <- { "return": {} } +# ## { 'command': 'balloon', 'data': {'value': 'int'} }
@@ -1848,6 +2524,28 @@ # operation fails, then the entire set of actions will be abandoned and the # appropriate error returned. # +# For external snapshots, the dictionary contains the device, the file to use for +# the new snapshot, and the format. The default format, if not specified, is +# qcow2. +# +# Each new snapshot defaults to being created by QEMU (wiping any +# contents if the file already exists), but it is also possible to reuse +# an externally-created file. In the latter case, you should ensure that +# the new image file has the same contents as the current one; QEMU cannot +# perform any meaningful check. Typically this is achieved by using the +# current image file as the backing file for the new image. +# +# On failure, the original disks pre-snapshot attempt will be used. +# +# For internal snapshots, the dictionary contains the device and the snapshot's +# name. If an internal snapshot matching name already exists, the request will +# be rejected. Only some image formats support it, for example, qcow2, rbd, +# and sheepdog. +# +# On failure, qemu will try delete the newly created internal snapshot in the +# transaction. When an I/O error occurs during deletion, the user needs to fix +# it later with qemu-img or other command. +# # @actions: List of @TransactionAction; # information needed for the respective operations. #
@@ -1856,6 +2554,7 @@ # for additional detail. # # Returns: nothing on success +# # Errors depend on the operations of the transaction # # Note: The transaction aborts on the first failure. Therefore, there will be
@@ -1863,6 +2562,28 @@ # subsequent actions will not have been attempted. # # Since: 1.1 +# +# Example: +# +# -> { "execute": "transaction", +# "arguments": { "actions": [ +# { "type": "blockdev-snapshot-sync", "data" : { "device": "ide-hd0", +# "snapshot-file": "/some/place/my-image", +# "format": "qcow2" } }, +# { "type": "blockdev-snapshot-sync", "data" : { "node-name": "myfile", +# "snapshot-file": "/some/place/my-image2", +# "snapshot-node-name": "node3432", +# "mode": "existing", +# "format": "qcow2" } }, +# { "type": "blockdev-snapshot-sync", "data" : { "device": "ide-hd1", +# "snapshot-file": "/some/place/my-image2", +# "mode": "existing", +# "format": "qcow2" } }, +# { "type": "blockdev-snapshot-internal-sync", "data" : { +# "device": "ide-hd2", +# "name": "snapshot0" } } ] } } +# <- { "return": {} } +# ## { 'command': 'transaction', 'data': { 'actions': [ 'TransactionAction' ],
@@ -1884,7 +2605,11 @@ # Since: 0.14.0 # # Notes: This command only exists as a stop-gap. Its use is highly -# discouraged. The semantics of this command are not guaranteed. +# discouraged. The semantics of this command are not +# guaranteed: this means that command names, arguments and +# responses can change or be removed at ANY time. Applications +# that rely on long term stability guarantees should NOT +# use this command. # # Known limitations: #
@@ -1893,6 +2618,13 @@ # # * Commands that prompt the user for data (eg. 'cont' when the block # device is encrypted) don't currently work +# +# Example: +# +# -> { "execute": "human-monitor-command", +# "arguments": { "command-line": "info kvm" } } +# <- { "return": "kvm support: enabled\r\n" } +# ## { 'command': 'human-monitor-command', 'data': {'command-line': 'str', '*cpu-index': 'int'},
@@ -1908,6 +2640,12 @@ # Notes: This command succeeds even if there is no migration process running. # # Since: 0.14.0 +# +# Example: +# +# -> { "execute": "migrate_cancel" } +# <- { "return": {} } +# ## { 'command': 'migrate_cancel' }
@@ -1923,6 +2661,12 @@ # Notes: This command is deprecated in favor of 'migrate-set-parameters' # # Since: 0.14.0 +# +# Example: +# +# -> { "execute": "migrate_set_downtime", "arguments": { "value": 0.1 } } +# <- { "return": {} } +# ## { 'command': 'migrate_set_downtime', 'data': {'value': 'number'} }
@@ -1931,20 +2675,26 @@ # # Set maximum speed for migration. # -# @value: maximum speed in bytes. +# @value: maximum speed in bytes per second. # # Returns: nothing on success # # Notes: This command is deprecated in favor of 'migrate-set-parameters' # # Since: 0.14.0 +# +# Example: +# +# -> { "execute": "migrate_set_speed", "arguments": { "value": 1024 } } +# <- { "return": {} } +# ## { 'command': 'migrate_set_speed', 'data': {'value': 'int'} } ## # @migrate-set-cache-size: # -# Set XBZRLE cache size +# Set cache size to be used by XBZRLE migration # # @value: cache size in bytes #
@@ -1954,17 +2704,30 @@ # Returns: nothing on success # # Since: 1.2 +# +# Example: +# +# -> { "execute": "migrate-set-cache-size", +# "arguments": { "value": 536870912 } } +# <- { "return": {} } +# ## { 'command': 'migrate-set-cache-size', 'data': {'value': 'int'} } ## # @query-migrate-cache-size: # -# query XBZRLE cache size +# Query migration XBZRLE cache size # # Returns: XBZRLE cache size in bytes # # Since: 1.2 +# +# Example: +# +# -> { "execute": "query-migrate-cache-size" } +# <- { "return": 67108864 } +# ## { 'command': 'query-migrate-cache-size', 'returns': 'int' }
@@ -2081,6 +2844,13 @@ # If Spice is not enabled, DeviceNotFound # # Since: 0.14.0 +# +# Example: +# +# -> { "execute": "set_password", "arguments": { "protocol": "vnc", +# "password": "secret" } } +# <- { "return": {} } +# ## { 'command': 'set_password', 'data': {'protocol': 'str', 'password': 'str', '*connected': 'str'} }
@@ -2107,6 +2877,13 @@ # coordinate server time with client time. It is not recommended to # use the absolute time version of the @time parameter unless you're # sure you are on the same machine as the QEMU instance. +# +# Example: +# +# -> { "execute": "expire_password", "arguments": { "protocol": "vnc", +# "time": "+60" } } +# <- { "return": {} } +# ## { 'command': 'expire_password', 'data': {'protocol': 'str', 'time': 'str'} }
@@ -2157,6 +2934,23 @@ # change-vnc-password. # # Since: 0.14.0 +# +# Example: +# +# 1. Change a removable medium +# +# -> { "execute": "change", +# "arguments": { "device": "ide1-cd0", +# "target": "/srv/images/Fedora-12-x86_64-DVD.iso" } } +# <- { "return": {} } +# +# 2. Change VNC password +# +# -> { "execute": "change", +# "arguments": { "device": "vnc", "target": "password", +# "arg": "foobar1" } } +# <- { "return": {} } +# ## { 'command': 'change', 'data': {'device': 'str', 'target': 'str', '*arg': 'str'} }
@@ -2239,6 +3033,22 @@ # Returns: nothing on success # # Since: 0.14.0 +# +# Notes: +# +# 1. The 'query-migrate' command should be used to check migration's progress +# and final result (this information is provided by the 'status' member) +# +# 2. All boolean arguments default to false +# +# 3. The user Monitor's "detach" argument is invalid in QMP and should not +# be used +# +# Example: +# +# -> { "execute": "migrate", "arguments": { "uri": "tcp:0:4446" } } +# <- { "return": {} } +# ## { 'command': 'migrate', 'data': {'uri': 'str', '*blk': 'bool', '*inc': 'bool', '*detach': 'bool' } }
@@ -2255,9 +3065,24 @@ # Returns: nothing on success # # Since: 2.3 -# Note: It's a bad idea to use a string for the uri, but it needs to stay -# compatible with -incoming and the format of the uri is already exposed -# above libvirt +# +# Notes: +# +# 1. It's a bad idea to use a string for the uri, but it needs to stay +# compatible with -incoming and the format of the uri is already exposed +# above libvirt. +# +# 2. QEMU must be started with -incoming defer to allow migrate-incoming to +# be used. +# +# 3. The uri format is the same as for -incoming +# +# Example: +# +# -> { "execute": "migrate-incoming", +# "arguments": { "uri": "tcp::4446" } } +# <- { "return": {} } +# ## { 'command': 'migrate-incoming', 'data': {'uri': 'str' } }
@@ -2274,6 +3099,13 @@ # Returns: Nothing on success # # Since: 1.1 +# +# Example: +# +# -> { "execute": "xen-save-devices-state", +# "arguments": { "filename": "/tmp/save" } } +# <- { "return": {} } +# ## { 'command': 'xen-save-devices-state', 'data': {'filename': 'str'} }
@@ -2287,6 +3119,13 @@ # Returns: nothing # # Since: 1.3 +# +# Example: +# +# -> { "execute": "xen-set-global-dirty-log", +# "arguments": { "enable": true } } +# <- { "return": {} } +# ## { 'command': 'xen-set-global-dirty-log', 'data': { 'enable': 'bool' } }
@@ -2335,7 +3174,7 @@ # # Remove a device from a guest # -# @id: the name or QOM path of the device +# @id: the device's ID or QOM path # # Returns: Nothing on success # If @id is not a valid device, DeviceNotFound
@@ -2348,6 +3187,17 @@ # for all devices. # # Since: 0.14.0 +# +# Example: +# +# -> { "execute": "device_del", +# "arguments": { "id": "net1" } } +# <- { "return": {} } +# +# -> { "execute": "device_del", +# "arguments": { "id": "/machine/peripheral-anon/device[0]" } } +# <- { "return": {} } +# ## { 'command': 'device_del', 'data': {'id': 'str'} }
@@ -2414,9 +3264,18 @@ # @length is not allowed to be specified with non-elf @format at the # same time (since 2.0) # +# Note: All boolean arguments default to false +# # Returns: nothing on success # # Since: 1.2 +# +# Example: +# +# -> { "execute": "dump-guest-memory", +# "arguments": { "protocol": "fd:dump" } } +# <- { "return": {} } +# ## { 'command': 'dump-guest-memory', 'data': { 'paging': 'bool', 'protocol': 'str', '*detach': 'bool',
@@ -2467,6 +3326,13 @@ # Returns: A @DumpStatus object showing the dump status. # # Since: 2.6 +# +# Example: +# +# -> { "execute": "query-dump" } +# <- { "return": { "status": "active", "completed": 1024000, +# "total": 2048000 } } +# ## { 'command': 'query-dump', 'returns': 'DumpQueryResult' }
@@ -2490,6 +3356,13 @@ # dump-guest-memory # # Since: 2.0 +# +# Example: +# +# -> { "execute": "query-dump-guest-memory-capability" } +# <- { "return": { "formats": +# ["elf", "kdump-zlib", "kdump-lzo", "kdump-snappy"] } +# ## { 'command': 'query-dump-guest-memory-capability', 'returns': 'DumpGuestMemoryCapability' }
@@ -2504,6 +3377,13 @@ # This command is only supported on s390 architecture. # # Since: 2.5 +# +# Example: +# +# -> { "execute": "dump-skeys", +# "arguments": { "filename": "/tmp/skeys" } } +# <- { "return": {} } +# ## { 'command': 'dump-skeys', 'data': { 'filename': 'str' } }
@@ -2529,6 +3409,14 @@ # # Returns: Nothing on success # If @type is not a valid network backend, DeviceNotFound +# +# Example: +# +# -> { "execute": "netdev_add", +# "arguments": { "type": "user", "id": "netdev1", +# "dnssearch": "example.org" } } +# <- { "return": {} } +# ## { 'command': 'netdev_add', 'data': {'type': 'str', 'id': 'str'},
@@ -2545,6 +3433,12 @@ # If @id is not a valid network backend, DeviceNotFound # # Since: 0.14.0 +# +# Example: +# +# -> { "execute": "netdev_del", "arguments": { "id": "netdev1" } } +# <- { "return": {} } +# ## { 'command': 'netdev_del', 'data': {'id': 'str'} }
@@ -2563,6 +3457,14 @@ # Error if @qom-type is not a valid class name # # Since: 2.0 +# +# Example: +# +# -> { "execute": "object-add", +# "arguments": { "qom-type": "rng-random", "id": "rng1", +# "props": { "filename": "/dev/hwrng" } } } +# <- { "return": {} } +# ## { 'command': 'object-add', 'data': {'qom-type': 'str', 'id': 'str', '*props': 'any'} }
@@ -2578,6 +3480,12 @@ # Error if @id is not a valid id for a QOM object # # Since: 2.0 +# +# Example: +# +# -> { "execute": "object-del", "arguments": { "id": "rng1" } } +# <- { "return": {} } +# ## { 'command': 'object-del', 'data': {'id': 'str'} }
@@ -3152,8 +4060,15 @@ # Notes: If @fdname already exists, the file descriptor assigned to # it will be closed and replaced by the received file # descriptor. +# # The 'closefd' command can be used to explicitly close the # file descriptor when it is no longer needed. +# +# Example: +# +# -> { "execute": "getfd", "arguments": { "fdname": "fd1" } } +# <- { "return": {} } +# ## { 'command': 'getfd', 'data': {'fdname': 'str'} }
@@ -3167,6 +4082,12 @@ # Returns: Nothing on success # # Since: 0.14.0 +# +# Example: +# +# -> { "execute": "closefd", "arguments": { "fdname": "fd1" } } +# <- { "return": {} } +# ## { 'command': 'closefd', 'data': {'fdname': 'str'} }
@@ -3516,7 +4437,9 @@ # @opaque: #optional A free-form string that can be used to describe the fd. # # Returns: @AddfdInfo on success +# # If file descriptor was not received, FdNotSupplied +# # If @fdset-id is a negative value, InvalidParameterValue # # Notes: The list of fd sets is shared by all monitor connections.
@@ -3524,6 +4447,12 @@ # If @fdset-id is not specified, a new fd set will be created. # # Since: 1.2.0 +# +# Example: +# +# -> { "execute": "add-fd", "arguments": { "fdset-id": 1 } } +# <- { "return": { "fdset-id": 1, "fd": 3 } } +# ## { 'command': 'add-fd', 'data': {'*fdset-id': 'int', '*opaque': 'str'}, 'returns': 'AddfdInfo' }
@@ -3546,6 +4475,12 @@ # # If @fd is not specified, all file descriptors in @fdset-id # will be removed. +# +# Example: +# +# -> { "execute": "remove-fd", "arguments": { "fdset-id": 1, "fd": 3 } } +# <- { "return": {} } +# ## { 'command': 'remove-fd', 'data': {'fdset-id': 'int', '*fd': 'int'} }
@@ -3588,6 +4523,37 @@ # # Note: The list of fd sets is shared by all monitor connections. # +# Example: +# +# -> { "execute": "query-fdsets" } +# <- { "return": [ +# { +# "fds": [ +# { +# "fd": 30, +# "opaque": "rdonly:/path/to/file" +# }, +# { +# "fd": 24, +# "opaque": "rdwr:/path/to/file" +# } +# ], +# "fdset-id": 1 +# }, +# { +# "fds": [ +# { +# "fd": 28 +# }, +# { +# "fd": 29 +# } +# ], +# "fdset-id": 0 +# } +# ] +# } +# ## { 'command': 'query-fdsets', 'returns': ['FdsetInfo'] }
@@ -3680,6 +4646,14 @@ # # Since: 1.3.0 # +# Example: +# +# -> { "execute": "send-key", +# "arguments": { "keys": [ { "type": "qcode", "data": "ctrl" }, +# { "type": "qcode", "data": "alt" }, +# { "type": "qcode", "data": "delete" } ] } } +# <- { "return": {} } +# ## { 'command': 'send-key', 'data': { 'keys': ['KeyValue'], '*hold-time': 'int' } }
@@ -3694,6 +4668,13 @@ # Returns: Nothing on success # # Since: 0.14.0 +# +# Example: +# +# -> { "execute": "screendump", +# "arguments": { "filename": "/tmp/image" } } +# <- { "return": {} } +# ## { 'command': 'screendump', 'data': {'filename': 'str'} }
@@ -3918,6 +4899,25 @@ # Returns: ChardevReturn. # # Since: 1.4 +# +# Example: +# +# -> { "execute" : "chardev-add", +# "arguments" : { "id" : "foo", +# "backend" : { "type" : "null", "data" : {} } } } +# <- { "return": {} } +# +# -> { "execute" : "chardev-add", +# "arguments" : { "id" : "bar", +# "backend" : { "type" : "file", +# "data" : { "out" : "/tmp/bar.log" } } } } +# <- { "return": {} } +# +# -> { "execute" : "chardev-add", +# "arguments" : { "id" : "baz", +# "backend" : { "type" : "pty", "data" : {} } } } +# <- { "return": { "pty" : "/dev/pty/42" } } +# ## { 'command': 'chardev-add', 'data': {'id' : 'str', 'backend' : 'ChardevBackend' },
@@ -3933,6 +4933,12 @@ # Returns: Nothing on success # # Since: 1.4 +# +# Example: +# +# -> { "execute": "chardev-remove", "arguments": { "id" : "foo" } } +# <- { "return": {} } +# ## { 'command': 'chardev-remove', 'data': {'id': 'str'} }
@@ -3955,6 +4961,12 @@ # Returns: a list of TpmModel # # Since: 1.5 +# +# Example: +# +# -> { "execute": "query-tpm-models" } +# <- { "return": [ "tpm-tis" ] } +# ## { 'command': 'query-tpm-models', 'returns': ['TpmModel'] }
@@ -3977,6 +4989,12 @@ # Returns: a list of TpmType # # Since: 1.5 +# +# Example: +# +# -> { "execute": "query-tpm-types" } +# <- { "return": [ "passthrough" ] } +# ## { 'command': 'query-tpm-types', 'returns': ['TpmType'] }
@@ -4033,6 +5051,25 @@ # Returns: @TPMInfo on success # # Since: 1.5 +# +# Example: +# +# -> { "execute": "query-tpm" } +# <- { "return": +# [ +# { "model": "tpm-tis", +# "options": +# { "type": "passthrough", +# "data": +# { "cancel-path": "/sys/class/misc/tpm0/device/cancel", +# "path": "/dev/tpm0" +# } +# }, +# "id": "tpm0" +# } +# ] +# } +# ## { 'command': 'query-tpm', 'returns': ['TPMInfo'] }
@@ -4159,6 +5196,28 @@ # @option). Returns an error if the given @option doesn't exist. # # Since: 1.5 +# +# Example: +# +# -> { "execute": "query-command-line-options", +# "arguments": { "option": "option-rom" } } +# <- { "return": [ +# { +# "parameters": [ +# { +# "name": "romfile", +# "type": "string" +# }, +# { +# "name": "bootindex", +# "type": "number" +# } +# ], +# "option": "option-rom" +# } +# ] +# } +# ## {'command': 'query-command-line-options', 'data': { '*option': 'str' }, 'returns': ['CommandLineOptionInfo'] }
@@ -4280,6 +5339,36 @@ # isn't a NIC. # # Since: 1.6 +# +# Example: +# +# -> { "execute": "query-rx-filter", "arguments": { "name": "vnet0" } } +# <- { "return": [ +# { +# "promiscuous": true, +# "name": "vnet0", +# "main-mac": "52:54:00:12:34:56", +# "unicast": "normal", +# "vlan": "normal", +# "vlan-table": [ +# 4, +# 0 +# ], +# "unicast-table": [ +# ], +# "multicast": "normal", +# "multicast-overflow": false, +# "unicast-overflow": false, +# "multicast-table": [ +# "01:00:5e:00:00:01", +# "33:33:00:00:00:01", +# "33:33:ff:12:34:56" +# ], +# "broadcast-allowed": false +# } +# ] +# } +# ## { 'command': 'query-rx-filter', 'data': { '*name': 'str' }, 'returns': ['RxFilterInfo'] }
@@ -4378,9 +5467,9 @@ # # Returns: Nothing on success. # -# The @display and @head parameters can be used to send the input -# event to specific input devices in case (a) multiple input devices -# of the same kind are added to the virtual machine and (b) you have +# The @device and @head parameters can be used to send the input event +# to specific input devices in case (a) multiple input devices of the +# same kind are added to the virtual machine and (b) you have # configured input routing (see docs/multiseat.txt) for those input # devices. The parameters work exactly like the device and head # properties of input devices. If @device is missing, only devices
@@ -4390,6 +5479,48 @@ # precedence. # # Since: 2.6 +# +# Note: The consoles are visible in the qom tree, under +# /backend/console[$index]. They have a device link and head property, +# so it is possible to map which console belongs to which device and +# display. +# +# Example: +# +# 1. Press left mouse button. +# +# -> { "execute": "input-send-event", +# "arguments": { "device": "video0", +# "events": [ { "type": "btn", +# "data" : { "down": true, "button": "left" } } ] } } +# <- { "return": {} } +# +# -> { "execute": "input-send-event", +# "arguments": { "device": "video0", +# "events": [ { "type": "btn", +# "data" : { "down": false, "button": "left" } } ] } } +# <- { "return": {} } +# +# 2. Press ctrl-alt-del. +# +# -> { "execute": "input-send-event", +# "arguments": { "events": [ +# { "type": "key", "data" : { "down": true, +# "key": {"type": "qcode", "data": "ctrl" } } }, +# { "type": "key", "data" : { "down": true, +# "key": {"type": "qcode", "data": "alt" } } }, +# { "type": "key", "data" : { "down": true, +# "key": {"type": "qcode", "data": "delete" } } } ] } } +# <- { "return": {} } +# +# 3. Move mouse pointer to absolute coordinates (20000, 400). +# +# -> { "execute": "input-send-event" , +# "arguments": { "events": [ +# { "type": "abs", "data" : { "axis": "x", "value" : 20000 } }, +# { "type": "abs", "data" : { "axis": "y", "value" : 400 } } ] } } +# <- { "return": {} } +# ## { 'command': 'input-send-event', 'data': { '*device': 'str',
@@ -4489,6 +5620,30 @@ # Returns: a list of @Memdev. # # Since: 2.1 +# +# Example: +# +# -> { "execute": "query-memdev" } +# <- { "return": [ +# { +# "size": 536870912, +# "merge": false, +# "dump": true, +# "prealloc": false, +# "host-nodes": [0, 1], +# "policy": "bind" +# }, +# { +# "size": 536870912, +# "merge": false, +# "dump": true, +# "prealloc": true, +# "host-nodes": [2, 3], +# "policy": "preferred" +# } +# ] +# } +# ## { 'command': 'query-memdev', 'returns': ['Memdev'] }
@@ -4542,6 +5697,22 @@ # Lists available memory devices and their state # # Since: 2.1 +# +# Example: +# +# -> { "execute": "query-memory-devices" } +# <- { "return": [ { "data": +# { "addr": 5368709120, +# "hotpluggable": true, +# "hotplugged": true, +# "id": "d1", +# "memdev": "/objects/memX", +# "node": 0, +# "size": 1073741824, +# "slot": 0}, +# "type": "dimm" +# } ] } +# ## { 'command': 'query-memory-devices', 'returns': ['MemoryDeviceInfo'] }
@@ -4582,10 +5753,20 @@ ## # @query-acpi-ospm-status: # -# Lists ACPI OSPM status of ACPI device objects, -# which might be reported via _OST method +# Return a list of ACPIOSTInfo for devices that support status +# reporting via ACPI _OST method. # # Since: 2.1 +# +# Example: +# +# -> { "execute": "query-acpi-ospm-status" } +# <- { "return": [ { "device": "d1", "slot": "0", "slot-type": "DIMM", "source": 1, "status": 0}, +# { "slot": "1", "slot-type": "DIMM", "source": 0, "status": 0}, +# { "slot": "2", "slot-type": "DIMM", "source": 0, "status": 0}, +# { "slot": "3", "slot-type": "DIMM", "source": 0, "status": 0} +# ]} +# ## { 'command': 'query-acpi-ospm-status', 'returns': ['ACPIOSTInfo'] }
@@ -4652,6 +5833,12 @@ # command. # # Since: 2.1 +# +# Example: +# +# -> { "execute": "rtc-reset-reinjection" } +# <- { "return": {} } +# ## { 'command': 'rtc-reset-reinjection' }
@@ -4687,6 +5874,13 @@ # format. # # Since: 2.7 +# +# Example: +# +# -> { "execute": "xen-load-devices-state", +# "arguments": { "filename": "/tmp/resume" } } +# <- { "return": {} } +# ## { 'command': 'xen-load-devices-state', 'data': {'filename': 'str'} }
@@ -4723,6 +5917,13 @@ # Returns: a list of GICCapability objects. # # Since: 2.6 +# +# Example: +# +# -> { "execute": "query-gic-capabilities" } +# <- { "return": [{ "version": 2, "emulated": true, "kernel": false }, +# { "version": 3, "emulated": false, "kernel": true } ] } +# ## { 'command': 'query-gic-capabilities', 'returns': ['GICCapability'] }
@@ -4779,5 +5980,33 @@ # Returns: a list of HotpluggableCPU objects. # # Since: 2.7 +# +# Example: +# +# For pseries machine type started with -smp 2,cores=2,maxcpus=4 -cpu POWER8: +# +# -> { "execute": "query-hotpluggable-cpus" } +# <- {"return": [ +# { "props": { "core": 8 }, "type": "POWER8-spapr-cpu-core", +# "vcpus-count": 1 }, +# { "props": { "core": 0 }, "type": "POWER8-spapr-cpu-core", +# "vcpus-count": 1, "qom-path": "/machine/unattached/device[0]"} +# ]}' +# +# For pc machine type started with -smp 1,maxcpus=2: +# +# -> { "execute": "query-hotpluggable-cpus" } +# <- {"return": [ +# { +# "type": "qemu64-x86_64-cpu", "vcpus-count": 1, +# "props": {"core-id": 0, "socket-id": 1, "thread-id": 0} +# }, +# { +# "qom-path": "/machine/unattached/device[0]", +# "type": "qemu64-x86_64-cpu", "vcpus-count": 1, +# "props": {"core-id": 0, "socket-id": 0, "thread-id": 0} +# } +# ]} +# ## { 'command': 'query-hotpluggable-cpus', 'returns': ['HotpluggableCPU'] }
qapi/block-core.json +659 -11
941 lines not on this page · raw message
qapi/block.json +52 -4
98 lines not on this page · raw message
qapi/common.json +32 -0
@@ -77,6 +77,21 @@ # Returns: A @VersionInfo object describing the current version of QEMU. # # Since: 0.14.0 +# +# Example: +# +# -> { "execute": "query-version" } +# <- { +# "return":{ +# "qemu":{ +# "major":0, +# "minor":11, +# "micro":5 +# }, +# "package":"" +# } +# } +# ## { 'command': 'query-version', 'returns': 'VersionInfo' }
@@ -99,6 +114,23 @@ # Returns: A list of @CommandInfo for all supported commands # # Since: 0.14.0 +# +# Example: +# +# -> { "execute": "query-commands" } +# <- { +# "return":[ +# { +# "name":"query-balloon" +# }, +# { +# "name":"system_powerdown" +# } +# ] +# } +# +# Note: This example has been shortened as the real response is too long. +# ## { 'command': 'query-commands', 'returns': ['CommandInfo'] }
qapi/event.json +240 -0
49 lines not on this page · raw message
qapi/rocker.json +53 -4
57 lines not on this page · raw message
docs/qmp-commands.txt deleted +0 -3824
3,824 lines not on this page · raw message
docs/qmp-events.txt deleted +0 -731
731 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.11.0
Part of the diff is not shown here. View the raw message.
PATCH v7 15/21 qapi: add qapi2texi script
In reply to Marc-André LureauAs the name suggests, the qapi2texi script converts JSON QAPI description into a texi file suitable for different target formats (info/man/txt/pdf/html...).
It parses the following kind of blocks:
Free-form:
##
# = Section
# == Subsection
#
# Some text foo with *emphasis*
# 1. with a list
# 2. like that
#
# And some code:
# | $ echo foo # | -> do this # | <- get that
#
##
Symbol description:
##
# @symbol:
#
# Symbol body ditto ergo sum. Foo bar
# baz ding.
#
# @param1: the frob to frobnicate
# @param2: #optional how hard to frobnicate
#
# Returns: the frobnicated frob.
# If frob isn't frobnicatable, GenericError.
#
# Since: version
# Notes: notes, comments can have
# - itemized list
# - like this
#
# Example:
#
# -> { "execute": "quit" }
# <- { "return": {} }
#
##That's roughly following the following EBNF grammar:
api_comment = "##\n" comment "##\n"
comment = freeform_comment | symbol_commentfreeform_comment = { "# " text "\n" | "#\n" }symbol_comment = "# @" name ":\n" { member | tag_section | freeform_comment }
member = "# @" name ':' [ text ] "\n" freeform_commenttag_section = "# " ( "Returns:", "Since:", "Note:", "Notes:", "Example:", "Examples:" ) [ text ] "\n" freeform_comment text = free text with markup
Note that the grammar is ambiguous: a line "# @foo:\n" can be parsed both as freeform_comment and as symbol_comment. The actual parser recognizes symbol_comment.
See docs/qapi-code-gen.txt for more details.
Deficiencies:
- the generated QMP documentation includes internal types
- union-type support is lacking
- type information is lacking in generated documentation
- doc comment error message positions are imprecise, they point to the beginning of the comment.
- see other TODO/FIXME in this commit
--- scripts/qapi.py | 247 ++++++++++++++++++- scripts/qapi2texi.py | 266 +++++++++++++++++++++ docs/qapi-code-gen.txt | 174 +++++++++++--- tests/Makefile.include | 20 ++ tests/qapi-schema/alternate-any.err | 2 +- tests/qapi-schema/alternate-any.json | 4 + tests/qapi-schema/alternate-array.err | 2 +- tests/qapi-schema/alternate-array.json | 7 + tests/qapi-schema/alternate-base.err | 2 +- tests/qapi-schema/alternate-base.json | 7 + tests/qapi-schema/alternate-clash.err | 2 +- tests/qapi-schema/alternate-clash.json | 4 + tests/qapi-schema/alternate-conflict-dict.err | 2 +- tests/qapi-schema/alternate-conflict-dict.json | 10 + tests/qapi-schema/alternate-conflict-string.err | 2 +- tests/qapi-schema/alternate-conflict-string.json | 7 + tests/qapi-schema/alternate-empty.err | 2 +- tests/qapi-schema/alternate-empty.json | 4 + tests/qapi-schema/alternate-nested.err | 2 +- tests/qapi-schema/alternate-nested.json | 7 + tests/qapi-schema/alternate-unknown.err | 2 +- tests/qapi-schema/alternate-unknown.json | 4 + tests/qapi-schema/args-alternate.err | 2 +- tests/qapi-schema/args-alternate.json | 8 + tests/qapi-schema/args-any.err | 2 +- tests/qapi-schema/args-any.json | 4 + tests/qapi-schema/args-array-empty.err | 2 +- tests/qapi-schema/args-array-empty.json | 4 + tests/qapi-schema/args-array-unknown.err | 2 +- tests/qapi-schema/args-array-unknown.json | 4 + tests/qapi-schema/args-bad-boxed.err | 2 +- tests/qapi-schema/args-bad-boxed.json | 4 + tests/qapi-schema/args-boxed-anon.err | 2 +- tests/qapi-schema/args-boxed-anon.json | 4 + tests/qapi-schema/args-boxed-empty.err | 2 +- tests/qapi-schema/args-boxed-empty.json | 8 + tests/qapi-schema/args-boxed-string.err | 2 +- tests/qapi-schema/args-boxed-string.json | 4 + tests/qapi-schema/args-int.err | 2 +- tests/qapi-schema/args-int.json | 4 + tests/qapi-schema/args-invalid.err | 2 +- tests/qapi-schema/args-invalid.json | 3 + tests/qapi-schema/args-member-array-bad.err | 2 +- tests/qapi-schema/args-member-array-bad.json | 4 + tests/qapi-schema/args-member-case.err | 2 +- tests/qapi-schema/args-member-case.json | 4 + tests/qapi-schema/args-member-unknown.err | 2 +- tests/qapi-schema/args-member-unknown.json | 4 + tests/qapi-schema/args-name-clash.err | 2 +- tests/qapi-schema/args-name-clash.json | 4 + tests/qapi-schema/args-union.err | 2 +- tests/qapi-schema/args-union.json | 7 + tests/qapi-schema/args-unknown.err | 2 +- tests/qapi-schema/args-unknown.json | 4 + tests/qapi-schema/bad-base.err | 2 +- tests/qapi-schema/bad-base.json | 7 + tests/qapi-schema/bad-data.err | 2 +- tests/qapi-schema/bad-data.json | 4 + tests/qapi-schema/bad-ident.err | 2 +- tests/qapi-schema/bad-ident.json | 4 + tests/qapi-schema/bad-type-bool.err | 2 +- tests/qapi-schema/bad-type-bool.json | 4 + tests/qapi-schema/bad-type-dict.err | 2 +- tests/qapi-schema/bad-type-dict.json | 4 + tests/qapi-schema/base-cycle-direct.err | 2 +- tests/qapi-schema/base-cycle-direct.json | 4 + tests/qapi-schema/base-cycle-indirect.err | 2 +- tests/qapi-schema/base-cycle-indirect.json | 7 + tests/qapi-schema/command-int.err | 2 +- tests/qapi-schema/command-int.json | 4 + tests/qapi-schema/comments.json | 4 + tests/qapi-schema/comments.out | 3 + tests/qapi-schema/doc-bad-args.err | 1 + tests/qapi-schema/doc-bad-args.exit | 1 + tests/qapi-schema/doc-bad-args.json | 8 + tests/qapi-schema/doc-bad-args.out | 0 tests/qapi-schema/doc-bad-symbol.err | 1 + tests/qapi-schema/doc-bad-symbol.exit | 1 + tests/qapi-schema/doc-bad-symbol.json | 6 + tests/qapi-schema/doc-bad-symbol.out | 0 tests/qapi-schema/doc-duplicated-arg.err | 1 + tests/qapi-schema/doc-duplicated-arg.exit | 1 + tests/qapi-schema/doc-duplicated-arg.json | 7 + tests/qapi-schema/doc-duplicated-arg.out | 0 tests/qapi-schema/doc-duplicated-return.err | 1 + tests/qapi-schema/doc-duplicated-return.exit | 1 + tests/qapi-schema/doc-duplicated-return.json | 8 + tests/qapi-schema/doc-duplicated-return.out | 0 tests/qapi-schema/doc-duplicated-since.err | 1 + tests/qapi-schema/doc-duplicated-since.exit | 1 + tests/qapi-schema/doc-duplicated-since.json | 8 + tests/qapi-schema/doc-duplicated-since.out | 0 tests/qapi-schema/doc-empty-arg.err | 1 + tests/qapi-schema/doc-empty-arg.exit | 1 + tests/qapi-schema/doc-empty-arg.json | 6 + tests/qapi-schema/doc-empty-arg.out | 0 tests/qapi-schema/doc-empty-section.err | 1 + tests/qapi-schema/doc-empty-section.exit | 1 + tests/qapi-schema/doc-empty-section.json | 8 + tests/qapi-schema/doc-empty-section.out | 0 tests/qapi-schema/doc-empty-symbol.err | 1 + tests/qapi-schema/doc-empty-symbol.exit | 1 + tests/qapi-schema/doc-empty-symbol.json | 5 + tests/qapi-schema/doc-empty-symbol.out | 0 tests/qapi-schema/doc-interleaved-section.err | 1 + tests/qapi-schema/doc-interleaved-section.exit | 1 + tests/qapi-schema/doc-interleaved-section.json | 21 ++ tests/qapi-schema/doc-interleaved-section.out | 0 tests/qapi-schema/doc-invalid-end.err | 1 + tests/qapi-schema/doc-invalid-end.exit | 1 + tests/qapi-schema/doc-invalid-end.json | 5 + tests/qapi-schema/doc-invalid-end.out | 0 tests/qapi-schema/doc-invalid-end2.err | 1 + tests/qapi-schema/doc-invalid-end2.exit | 1 + tests/qapi-schema/doc-invalid-end2.json | 5 + tests/qapi-schema/doc-invalid-end2.out | 0 tests/qapi-schema/doc-invalid-return.err | 1 + tests/qapi-schema/doc-invalid-return.exit | 1 + tests/qapi-schema/doc-invalid-return.json | 7 + tests/qapi-schema/doc-invalid-return.out | 0 tests/qapi-schema/doc-invalid-section.err | 1 + tests/qapi-schema/doc-invalid-section.exit | 1 + tests/qapi-schema/doc-invalid-section.json | 6 + tests/qapi-schema/doc-invalid-section.out | 0 tests/qapi-schema/doc-invalid-start.err | 1 + tests/qapi-schema/doc-invalid-start.exit | 1 + tests/qapi-schema/doc-invalid-start.json | 5 + tests/qapi-schema/doc-invalid-start.out | 0 tests/qapi-schema/doc-missing-colon.err | 1 + tests/qapi-schema/doc-missing-colon.exit | 1 + tests/qapi-schema/doc-missing-colon.json | 5 + tests/qapi-schema/doc-missing-colon.out | 0 tests/qapi-schema/doc-missing-expr.err | 1 + tests/qapi-schema/doc-missing-expr.exit | 1 + tests/qapi-schema/doc-missing-expr.json | 5 + tests/qapi-schema/doc-missing-expr.out | 0 tests/qapi-schema/doc-missing-space.err | 1 + tests/qapi-schema/doc-missing-space.exit | 1 + tests/qapi-schema/doc-missing-space.json | 6 + tests/qapi-schema/doc-missing-space.out | 0 tests/qapi-schema/doc-optional.err | 1 + tests/qapi-schema/doc-optional.exit | 1 + tests/qapi-schema/doc-optional.json | 7 + tests/qapi-schema/doc-optional.out | 0 tests/qapi-schema/double-type.err | 2 +- tests/qapi-schema/double-type.json | 4 + tests/qapi-schema/enum-bad-name.err | 2 +- tests/qapi-schema/enum-bad-name.json | 4 + tests/qapi-schema/enum-bad-prefix.err | 2 +- tests/qapi-schema/enum-bad-prefix.json | 4 + tests/qapi-schema/enum-clash-member.err | 2 +- tests/qapi-schema/enum-clash-member.json | 4 + tests/qapi-schema/enum-dict-member.err | 2 +- tests/qapi-schema/enum-dict-member.json | 4 + tests/qapi-schema/enum-member-case.err | 2 +- tests/qapi-schema/enum-member-case.json | 7 + tests/qapi-schema/enum-missing-data.err | 2 +- tests/qapi-schema/enum-missing-data.json | 4 + tests/qapi-schema/enum-wrong-data.err | 2 +- tests/qapi-schema/enum-wrong-data.json | 4 + tests/qapi-schema/event-boxed-empty.err | 2 +- tests/qapi-schema/event-boxed-empty.json | 4 + tests/qapi-schema/event-case.json | 4 + tests/qapi-schema/event-case.out | 3 + tests/qapi-schema/event-nest-struct.err | 2 +- tests/qapi-schema/event-nest-struct.json | 4 + tests/qapi-schema/flat-union-array-branch.err | 2 +- tests/qapi-schema/flat-union-array-branch.json | 12 + tests/qapi-schema/flat-union-bad-base.err | 2 +- tests/qapi-schema/flat-union-bad-base.json | 13 + tests/qapi-schema/flat-union-bad-discriminator.err | 2 +- .../qapi-schema/flat-union-bad-discriminator.json | 16 ++ tests/qapi-schema/flat-union-base-any.err | 2 +- tests/qapi-schema/flat-union-base-any.json | 13 + tests/qapi-schema/flat-union-base-union.err | 2 +- tests/qapi-schema/flat-union-base-union.json | 16 ++ tests/qapi-schema/flat-union-clash-member.err | 2 +- tests/qapi-schema/flat-union-clash-member.json | 16 ++ tests/qapi-schema/flat-union-empty.err | 2 +- tests/qapi-schema/flat-union-empty.json | 10 + tests/qapi-schema/flat-union-incomplete-branch.err | 2 +- .../qapi-schema/flat-union-incomplete-branch.json | 10 + tests/qapi-schema/flat-union-inline.err | 2 +- tests/qapi-schema/flat-union-inline.json | 10 + tests/qapi-schema/flat-union-int-branch.err | 2 +- tests/qapi-schema/flat-union-int-branch.json | 13 + .../qapi-schema/flat-union-invalid-branch-key.err | 2 +- .../qapi-schema/flat-union-invalid-branch-key.json | 15 ++ .../flat-union-invalid-discriminator.err | 2 +- .../flat-union-invalid-discriminator.json | 15 ++ tests/qapi-schema/flat-union-no-base.err | 2 +- tests/qapi-schema/flat-union-no-base.json | 13 + .../flat-union-optional-discriminator.err | 2 +- .../flat-union-optional-discriminator.json | 13 + .../flat-union-string-discriminator.err | 2 +- .../flat-union-string-discriminator.json | 15 ++ tests/qapi-schema/ident-with-escape.json | 4 + tests/qapi-schema/ident-with-escape.out | 3 + tests/qapi-schema/include-relpath-sub.json | 3 + tests/qapi-schema/include-relpath.out | 3 + tests/qapi-schema/include-repetition.out | 3 + tests/qapi-schema/include-simple-sub.json | 3 + tests/qapi-schema/include-simple.out | 3 + tests/qapi-schema/indented-expr.json | 6 + tests/qapi-schema/indented-expr.out | 6 + tests/qapi-schema/missing-type.err | 2 +- tests/qapi-schema/missing-type.json | 4 + tests/qapi-schema/nested-struct-data.err | 2 +- tests/qapi-schema/nested-struct-data.json | 4 + tests/qapi-schema/qapi-schema-test.json | 213 +++++++++++++++++ tests/qapi-schema/qapi-schema-test.out | 212 ++++++++++++++++ tests/qapi-schema/redefined-builtin.err | 2 +- tests/qapi-schema/redefined-builtin.json | 4 + tests/qapi-schema/redefined-command.err | 2 +- tests/qapi-schema/redefined-command.json | 7 + tests/qapi-schema/redefined-event.err | 2 +- tests/qapi-schema/redefined-event.json | 7 + tests/qapi-schema/redefined-type.err | 2 +- tests/qapi-schema/redefined-type.json | 7 + tests/qapi-schema/reserved-command-q.err | 2 +- tests/qapi-schema/reserved-command-q.json | 7 + tests/qapi-schema/reserved-enum-q.err | 2 +- tests/qapi-schema/reserved-enum-q.json | 4 + tests/qapi-schema/reserved-member-has.err | 2 +- tests/qapi-schema/reserved-member-has.json | 4 + tests/qapi-schema/reserved-member-q.err | 2 +- tests/qapi-schema/reserved-member-q.json | 4 + tests/qapi-schema/reserved-member-u.err | 2 +- tests/qapi-schema/reserved-member-u.json | 4 + tests/qapi-schema/reserved-member-underscore.err | 2 +- tests/qapi-schema/reserved-member-underscore.json | 4 + tests/qapi-schema/reserved-type-kind.err | 2 +- tests/qapi-schema/reserved-type-kind.json | 4 + tests/qapi-schema/reserved-type-list.err | 2 +- tests/qapi-schema/reserved-type-list.json | 4 + tests/qapi-schema/returns-alternate.err | 2 +- tests/qapi-schema/returns-alternate.json | 7 + tests/qapi-schema/returns-array-bad.err | 2 +- tests/qapi-schema/returns-array-bad.json | 4 + tests/qapi-schema/returns-dict.err | 2 +- tests/qapi-schema/returns-dict.json | 4 + tests/qapi-schema/returns-unknown.err | 2 +- tests/qapi-schema/returns-unknown.json | 4 + tests/qapi-schema/returns-whitelist.err | 2 +- tests/qapi-schema/returns-whitelist.json | 16 ++ tests/qapi-schema/struct-base-clash-deep.err | 2 +- tests/qapi-schema/struct-base-clash-deep.json | 10 + tests/qapi-schema/struct-base-clash.err | 2 +- tests/qapi-schema/struct-base-clash.json | 7 + tests/qapi-schema/struct-data-invalid.err | 2 +- tests/qapi-schema/struct-data-invalid.json | 3 + tests/qapi-schema/struct-member-invalid.err | 2 +- tests/qapi-schema/struct-member-invalid.json | 3 + tests/qapi-schema/test-qapi.py | 12 + tests/qapi-schema/type-bypass-bad-gen.err | 2 +- tests/qapi-schema/type-bypass-bad-gen.json | 4 + tests/qapi-schema/unicode-str.err | 2 +- tests/qapi-schema/unicode-str.json | 4 + tests/qapi-schema/union-base-no-discriminator.err | 2 +- tests/qapi-schema/union-base-no-discriminator.json | 12 + tests/qapi-schema/union-branch-case.err | 2 +- tests/qapi-schema/union-branch-case.json | 4 + tests/qapi-schema/union-clash-branches.err | 2 +- tests/qapi-schema/union-clash-branches.json | 4 + tests/qapi-schema/union-empty.err | 2 +- tests/qapi-schema/union-empty.json | 4 + tests/qapi-schema/union-invalid-base.err | 2 +- tests/qapi-schema/union-invalid-base.json | 10 + tests/qapi-schema/union-optional-branch.err | 2 +- tests/qapi-schema/union-optional-branch.json | 4 + tests/qapi-schema/union-unknown.err | 2 +- tests/qapi-schema/union-unknown.json | 4 + tests/qapi-schema/unknown-escape.err | 2 +- tests/qapi-schema/unknown-escape.json | 4 + tests/qapi-schema/unknown-expr-key.err | 2 +- tests/qapi-schema/unknown-expr-key.json | 4 + 276 files changed, 2006 insertions(+), 127 deletions(-) create mode 100755 scripts/qapi2texi.py create mode 100644 tests/qapi-schema/doc-bad-args.err create mode 100644 tests/qapi-schema/doc-bad-args.exit create mode 100644 tests/qapi-schema/doc-bad-args.json create mode 100644 tests/qapi-schema/doc-bad-args.out create mode 100644 tests/qapi-schema/doc-bad-symbol.err create mode 100644 tests/qapi-schema/doc-bad-symbol.exit create mode 100644 tests/qapi-schema/doc-bad-symbol.json create mode 100644 tests/qapi-schema/doc-bad-symbol.out create mode 100644 tests/qapi-schema/doc-duplicated-arg.err create mode 100644 tests/qapi-schema/doc-duplicated-arg.exit create mode 100644 tests/qapi-schema/doc-duplicated-arg.json create mode 100644 tests/qapi-schema/doc-duplicated-arg.out create mode 100644 tests/qapi-schema/doc-duplicated-return.err create mode 100644 tests/qapi-schema/doc-duplicated-return.exit create mode 100644 tests/qapi-schema/doc-duplicated-return.json create mode 100644 tests/qapi-schema/doc-duplicated-return.out create mode 100644 tests/qapi-schema/doc-duplicated-since.err create mode 100644 tests/qapi-schema/doc-duplicated-since.exit create mode 100644 tests/qapi-schema/doc-duplicated-since.json create mode 100644 tests/qapi-schema/doc-duplicated-since.out create mode 100644 tests/qapi-schema/doc-empty-arg.err create mode 100644 tests/qapi-schema/doc-empty-arg.exit create mode 100644 tests/qapi-schema/doc-empty-arg.json create mode 100644 tests/qapi-schema/doc-empty-arg.out create mode 100644 tests/qapi-schema/doc-empty-section.err create mode 100644 tests/qapi-schema/doc-empty-section.exit create mode 100644 tests/qapi-schema/doc-empty-section.json create mode 100644 tests/qapi-schema/doc-empty-section.out create mode 100644 tests/qapi-schema/doc-empty-symbol.err create mode 100644 tests/qapi-schema/doc-empty-symbol.exit create mode 100644 tests/qapi-schema/doc-empty-symbol.json create mode 100644 tests/qapi-schema/doc-empty-symbol.out create mode 100644 tests/qapi-schema/doc-interleaved-section.err create mode 100644 tests/qapi-schema/doc-interleaved-section.exit create mode 100644 tests/qapi-schema/doc-interleaved-section.json create mode 100644 tests/qapi-schema/doc-interleaved-section.out create mode 100644 tests/qapi-schema/doc-invalid-end.err create mode 100644 tests/qapi-schema/doc-invalid-end.exit create mode 100644 tests/qapi-schema/doc-invalid-end.json create mode 100644 tests/qapi-schema/doc-invalid-end.out create mode 100644 tests/qapi-schema/doc-invalid-end2.err create mode 100644 tests/qapi-schema/doc-invalid-end2.exit create mode 100644 tests/qapi-schema/doc-invalid-end2.json create mode 100644 tests/qapi-schema/doc-invalid-end2.out create mode 100644 tests/qapi-schema/doc-invalid-return.err create mode 100644 tests/qapi-schema/doc-invalid-return.exit create mode 100644 tests/qapi-schema/doc-invalid-return.json create mode 100644 tests/qapi-schema/doc-invalid-return.out create mode 100644 tests/qapi-schema/doc-invalid-section.err create mode 100644 tests/qapi-schema/doc-invalid-section.exit create mode 100644 tests/qapi-schema/doc-invalid-section.json create mode 100644 tests/qapi-schema/doc-invalid-section.out create mode 100644 tests/qapi-schema/doc-invalid-start.err create mode 100644 tests/qapi-schema/doc-invalid-start.exit create mode 100644 tests/qapi-schema/doc-invalid-start.json create mode 100644 tests/qapi-schema/doc-invalid-start.out create mode 100644 tests/qapi-schema/doc-missing-colon.err create mode 100644 tests/qapi-schema/doc-missing-colon.exit create mode 100644 tests/qapi-schema/doc-missing-colon.json create mode 100644 tests/qapi-schema/doc-missing-colon.out create mode 100644 tests/qapi-schema/doc-missing-expr.err create mode 100644 tests/qapi-schema/doc-missing-expr.exit create mode 100644 tests/qapi-schema/doc-missing-expr.json create mode 100644 tests/qapi-schema/doc-missing-expr.out create mode 100644 tests/qapi-schema/doc-missing-space.err create mode 100644 tests/qapi-schema/doc-missing-space.exit create mode 100644 tests/qapi-schema/doc-missing-space.json create mode 100644 tests/qapi-schema/doc-missing-space.out create mode 100644 tests/qapi-schema/doc-optional.err create mode 100644 tests/qapi-schema/doc-optional.exit create mode 100644 tests/qapi-schema/doc-optional.json create mode 100644 tests/qapi-schema/doc-optional.out
scripts/qapi.py +245 -2
@@ -125,6 +125,122 @@ class QAPISemError(QAPIError): info['parent'], msg) +class QAPIDoc(object): + class Section(object): + def __init__(self, name=None): + # optional section name (argument/member or section name) + self.name = name + # the list of lines for this section + self.content = [] + + def append(self, line): + self.content.append(line) + + def __repr__(self): + return "\n".join(self.content).strip() + + class ArgSection(Section): + pass + + def __init__(self, parser, info): + # self.parser is used to report errors with QAPIParseError. The + # resulting error position depends on the state of the parser. + # It happens to be the beginning of the comment. More or less + # servicable, but action at a distance. + self.parser = parser + self.info = info + self.symbol = None + self.body = QAPIDoc.Section() + # dict mapping parameter name to ArgSection + self.args = OrderedDict() + # a list of Section + self.sections = [] + # the current section + self.section = self.body + # associated expression (to be set by expression parser) + self.expr = None + + def has_section(self, name): + """Return True if we have a section with this name.""" + for i in self.sections: + if i.name == name: + return True + return False + + def append(self, line): + """Parse a comment line and add it to the documentation.""" + line = line[1:] + if not line: + self._append_freeform(line) + return + + if line[0] != ' ': + raise QAPIParseError(self.parser, "Missing space after #") + line = line[1:] + + # FIXME not nice: things like '# @foo:' and '# @foo: ' aren't + # recognized, and get silently treated as ordinary text + if self.symbol: + self._append_symbol_line(line) + elif not self.body.content and line.startswith("@"): + if not line.endswith(":"): + raise QAPIParseError(self.parser, "Line should end with :") + self.symbol = line[1:-1] + # FIXME invalid names other than the empty string aren't flagged + if not self.symbol: + raise QAPIParseError(self.parser, "Invalid name") + else: + self._append_freeform(line) + + def _append_symbol_line(self, line): + name = line.split(' ', 1)[0] + + if name.startswith("@") and name.endswith(":"): + line = line[len(name)+1:] + self._start_args_section(name[1:-1]) + elif name in ("Returns:", "Since:", + # those are often singular or plural + "Note:", "Notes:", + "Example:", "Examples:", + "TODO:"): + line = line[len(name)+1:] + self._start_section(name[:-1]) + + self._append_freeform(line) + + def _start_args_section(self, name): + # FIXME invalid names other than the empty string aren't flagged + if not name: + raise QAPIParseError(self.parser, "Invalid parameter name") + if name in self.args: + raise QAPIParseError(self.parser, + "'%s' parameter name duplicated" % name) + if self.sections: + raise QAPIParseError(self.parser, + "'%s' parameter documentation is interleaved " + "with other sections" % name) + self.section = QAPIDoc.ArgSection(name) + self.args[name] = self.section + + def _start_section(self, name=""): + if name in ("Returns", "Since") and self.has_section(name): + raise QAPIParseError(self.parser, + "Duplicated '%s' section" % name) + self.section = QAPIDoc.Section(name) + self.sections.append(self.section) + + def _append_freeform(self, line): + in_arg = isinstance(self.section, QAPIDoc.ArgSection) + if (in_arg and self.section.content and + not self.section.content[-1] and + line and not line[0].isspace()): + self._start_section() + if (in_arg or not self.section.name or + not self.section.name.startswith("Example")): + line = line.strip() + self.section.append(line) + + class QAPISchemaParser(object): def __init__(self, fp, previously_included=[], incl_info=None):
@@ -140,11 +256,17 @@ class QAPISchemaParser(object): self.line = 1 self.line_pos = 0 self.exprs = [] + self.docs = [] self.accept() while self.tok is not None: info = {'file': fname, 'line': self.line, 'parent': self.incl_info} + if self.tok == '#': + doc = self.get_doc(info) + self.docs.append(doc) + continue + expr = self.get_expr(False) if isinstance(expr, dict) and "include" in expr: if len(expr) != 1:
@@ -162,6 +284,7 @@ class QAPISchemaParser(object): raise QAPISemError(info, "Inclusion loop for %s" % include) inf = inf['parent'] + # skip multiple include of the same file if incl_abs_fname in previously_included: continue
@@ -172,12 +295,19 @@ class QAPISchemaParser(object): exprs_include = QAPISchemaParser(fobj, previously_included, info) self.exprs.extend(exprs_include.exprs) + self.docs.extend(exprs_include.docs) else: expr_elem = {'expr': expr, 'info': info} + if (self.docs and + self.docs[-1].info['file'] == fname and + not self.docs[-1].expr): + self.docs[-1].expr = expr + expr_elem['doc'] = self.docs[-1] + self.exprs.append(expr_elem) - def accept(self): + def accept(self, skip_comment=True): while True: self.tok = self.src[self.cursor] self.pos = self.cursor
@@ -185,7 +315,13 @@ class QAPISchemaParser(object): self.val = None if self.tok == '#': + if self.src[self.cursor] == '#': + # Start of doc comment + skip_comment = False self.cursor = self.src.find('\n', self.cursor) + if not skip_comment: + self.val = self.src[self.pos:self.cursor] + return elif self.tok in "{}:,[]": return elif self.tok == "'":
@@ -319,6 +455,28 @@ class QAPISchemaParser(object): raise QAPIParseError(self, 'Expected "{", "[" or string') return expr + def get_doc(self, info): + if self.val != '##': + raise QAPIParseError(self, "Junk after '##' at start of " + "documentation comment") + + doc = QAPIDoc(self, info) + self.accept(False) + while self.tok == '#': + if self.val.startswith('##'): + # End of doc comment + if self.val != '##': + raise QAPIParseError(self, "Junk after '##' at end of " + "documentation comment") + self.accept() + return doc + else: + doc.append(self.val) + self.accept(False) + + raise QAPIParseError(self, "Documentation comment must end with '##'") + + # # Semantic analysis of schema expressions # TODO fold into QAPISchema
@@ -703,6 +861,11 @@ def check_exprs(exprs): for expr_elem in exprs: expr = expr_elem['expr'] info = expr_elem['info'] + + if 'doc' not in expr_elem: + raise QAPISemError(info, + "Expression missing documentation comment") + if 'enum' in expr: check_keys(expr_elem, 'enum', ['data'], ['prefix']) add_enum(expr['enum'], info, expr['data'])
@@ -761,6 +924,84 @@ def check_exprs(exprs): return exprs +def check_freeform_doc(doc): + if doc.symbol: + raise QAPISemError(doc.info, + "Documention for '%s' is not followed" + " by the definition" % doc.symbol) + + body = str(doc.body) + if re.search(r'@\S+:', body, re.MULTILINE): + raise QAPISemError(doc.info, + "Free-form documentation block must not contain" + " @NAME: sections") + + +def check_definition_doc(doc, expr, info): + for i in ('enum', 'union', 'alternate', 'struct', 'command', 'event'): + if i in expr: + meta = i + break + + name = expr[meta] + if doc.symbol != name: + raise QAPISemError(info, "Definition of '%s' follows documentation" + " for '%s'" % (name, doc.symbol)) + if doc.has_section('Returns') and 'command' not in expr: + raise QAPISemError(info, "'Returns:' is only valid for commands") + + if meta == 'union': + args = expr.get('base', []) + else: + args = expr.get('data', []) + if isinstance(args, dict): + args = args.keys() + + if meta == 'alternate' or \ + (meta == 'union' and not expr.get('discriminator')): + args.append('type') + + if isinstance(args, list): + for arg in args: + if arg[0] == '*': + opt = True + desc = doc.args.get(arg[1:]) + else: + opt = False + desc = doc.args.get(arg) + if not desc: + continue + desc_opt = "#optional" in str(desc) + if desc_opt and not opt: + raise QAPISemError(info, "Description has #optional, " + "but the declaration doesn't") + if not desc_opt and opt: + # silently fix the doc + desc.append("#optional") + + doc_args = set(doc.args.keys()) + args = set([name.strip('*') for name in args]) + if not doc_args.issubset(args): + raise QAPISemError(info, "The following documented members are not in " + "the declaration: %s" % ", ".join(doc_args - args)) + + +def check_docs(docs): + for doc in docs: + for section in doc.args.values() + doc.sections: + content = str(section) + if not content or content.isspace(): + raise QAPISemError(doc.info, + "Empty doc section '%s'" % section.name) + + if not doc.expr: + check_freeform_doc(doc) + else: + check_definition_doc(doc, doc.expr, doc.info) + + return docs + + # # Schema compiler frontend #
@@ -1229,7 +1470,9 @@ class QAPISchemaEvent(QAPISchemaEntity): class QAPISchema(object): def __init__(self, fname): try: - self.exprs = check_exprs(QAPISchemaParser(open(fname, "r")).exprs) + parser = QAPISchemaParser(open(fname, "r")) + self.exprs = check_exprs(parser.exprs) + self.docs = check_docs(parser.docs) self._entity_dict = {} self._predefining = True self._def_predefineds()
scripts/qapi2texi.py new file +266 -0
266 lines not on this page · raw message
docs/qapi-code-gen.txt +141 -33
181 lines not on this page · raw message
tests/Makefile.include +20 -0
@@ -350,6 +350,24 @@ qapi-schema += base-cycle-direct.json qapi-schema += base-cycle-indirect.json qapi-schema += command-int.json qapi-schema += comments.json +qapi-schema += doc-bad-args.json +qapi-schema += doc-bad-symbol.json +qapi-schema += doc-duplicated-arg.json +qapi-schema += doc-duplicated-return.json +qapi-schema += doc-duplicated-since.json +qapi-schema += doc-empty-arg.json +qapi-schema += doc-empty-section.json +qapi-schema += doc-empty-symbol.json +qapi-schema += doc-interleaved-section.json +qapi-schema += doc-invalid-end.json +qapi-schema += doc-invalid-end2.json +qapi-schema += doc-invalid-return.json +qapi-schema += doc-invalid-section.json +qapi-schema += doc-invalid-start.json +qapi-schema += doc-missing-colon.json +qapi-schema += doc-missing-expr.json +qapi-schema += doc-missing-space.json +qapi-schema += doc-optional.json qapi-schema += double-data.json qapi-schema += double-type.json qapi-schema += duplicate-key.json
@@ -443,6 +461,8 @@ qapi-schema += union-optional-branch.json qapi-schema += union-unknown.json qapi-schema += unknown-escape.json qapi-schema += unknown-expr-key.json + + check-qapi-schema-y := $(addprefix tests/qapi-schema/, $(qapi-schema)) GENERATED_HEADERS += tests/test-qapi-types.h tests/test-qapi-visit.h \
tests/qapi-schema/alternate-any.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/alternate-any.json:2: Alternate 'Alt' member 'one' cannot use type 'any' +tests/qapi-schema/alternate-any.json:6: Alternate 'Alt' member 'one' cannot use type 'any'
tests/qapi-schema/alternate-any.json +4 -0
@@ -1,4 +1,8 @@ # we do not allow the 'any' type as an alternate branch + +## +# @Alt: +## { 'alternate': 'Alt', 'data': { 'one': 'any', 'two': 'int' } }
tests/qapi-schema/alternate-array.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/alternate-array.json:5: Member 'two' of alternate 'Alt' cannot be an array +tests/qapi-schema/alternate-array.json:12: Member 'two' of alternate 'Alt' cannot be an array
tests/qapi-schema/alternate-array.json +7 -0
@@ -1,7 +1,14 @@ # we do not allow array branches in alternates + +## +# @One: +## # TODO: should we support this? { 'struct': 'One', 'data': { 'name': 'str' } } +## +# @Alt: +## { 'alternate': 'Alt', 'data': { 'one': 'One', 'two': [ 'int' ] } }
tests/qapi-schema/alternate-base.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/alternate-base.json:4: Unknown key 'base' in alternate 'Alt' +tests/qapi-schema/alternate-base.json:11: Unknown key 'base' in alternate 'Alt'
tests/qapi-schema/alternate-base.json +7 -0
@@ -1,6 +1,13 @@ # we reject alternate with base type + +## +# @Base: +## { 'struct': 'Base', 'data': { 'string': 'str' } } +## +# @Alt: +## { 'alternate': 'Alt', 'base': 'Base', 'data': { 'number': 'int' } }
tests/qapi-schema/alternate-clash.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/alternate-clash.json:7: 'a_b' (branch of Alt1) collides with 'a-b' (branch of Alt1) +tests/qapi-schema/alternate-clash.json:11: 'a_b' (branch of Alt1) collides with 'a-b' (branch of Alt1)
tests/qapi-schema/alternate-clash.json +4 -0
@@ -4,5 +4,9 @@ # TODO: In the future, if alternates are simplified to not generate # the implicit Alt1Kind enum, we would still have a collision with the # resulting C union trying to have two members named 'a_b'. + +## +# @Alt1: +## { 'alternate': 'Alt1', 'data': { 'a-b': 'str', 'a_b': 'int' } }
tests/qapi-schema/alternate-conflict-dict.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/alternate-conflict-dict.json:6: Alternate 'Alt' member 'two' can't be distinguished from member 'one' +tests/qapi-schema/alternate-conflict-dict.json:16: Alternate 'Alt' member 'two' can't be distinguished from member 'one'
tests/qapi-schema/alternate-conflict-dict.json +10 -0
@@ -1,8 +1,18 @@ # we reject alternates with multiple object branches + +## +# @One: +## { 'struct': 'One', 'data': { 'name': 'str' } } +## +# @Two: +## { 'struct': 'Two', 'data': { 'value': 'int' } } +## +# @Alt: +## { 'alternate': 'Alt', 'data': { 'one': 'One', 'two': 'Two' } }
tests/qapi-schema/alternate-conflict-string.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/alternate-conflict-string.json:4: Alternate 'Alt' member 'two' can't be distinguished from member 'one' +tests/qapi-schema/alternate-conflict-string.json:11: Alternate 'Alt' member 'two' can't be distinguished from member 'one'
tests/qapi-schema/alternate-conflict-string.json +7 -0
@@ -1,6 +1,13 @@ # we reject alternates with multiple string-like branches + +## +# @Enum: +## { 'enum': 'Enum', 'data': [ 'hello', 'world' ] } +## +# @Alt: +## { 'alternate': 'Alt', 'data': { 'one': 'str', 'two': 'Enum' } }
tests/qapi-schema/alternate-empty.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/alternate-empty.json:2: Alternate 'Alt' should have at least two branches in 'data' +tests/qapi-schema/alternate-empty.json:6: Alternate 'Alt' should have at least two branches in 'data'
tests/qapi-schema/alternate-empty.json +4 -0
@@ -1,2 +1,6 @@ # alternates must list at least two types to be useful + +## +# @Alt: +## { 'alternate': 'Alt', 'data': { 'i': 'int' } }
tests/qapi-schema/alternate-nested.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/alternate-nested.json:4: Member 'nested' of alternate 'Alt2' cannot use alternate type 'Alt1' +tests/qapi-schema/alternate-nested.json:11: Member 'nested' of alternate 'Alt2' cannot use alternate type 'Alt1'
tests/qapi-schema/alternate-nested.json +7 -0
@@ -1,5 +1,12 @@ # we reject a nested alternate branch + +## +# @Alt1: +## { 'alternate': 'Alt1', 'data': { 'name': 'str', 'value': 'int' } } +## +# @Alt2: +## { 'alternate': 'Alt2', 'data': { 'nested': 'Alt1', 'b': 'bool' } }
tests/qapi-schema/alternate-unknown.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/alternate-unknown.json:2: Member 'unknown' of alternate 'Alt' uses unknown type 'MissingType' +tests/qapi-schema/alternate-unknown.json:6: Member 'unknown' of alternate 'Alt' uses unknown type 'MissingType'
tests/qapi-schema/alternate-unknown.json +4 -0
@@ -1,3 +1,7 @@ # we reject an alternate with unknown type in branch + +## +# @Alt: +## { 'alternate': 'Alt', 'data': { 'unknown': 'MissingType', 'i': 'int' } }
tests/qapi-schema/args-alternate.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/args-alternate.json:3: 'data' for command 'oops' cannot use alternate type 'Alt' +tests/qapi-schema/args-alternate.json:11: 'data' for command 'oops' cannot use alternate type 'Alt'
tests/qapi-schema/args-alternate.json +8 -0
@@ -1,3 +1,11 @@ # we do not allow alternate arguments + +## +# @Alt: +## { 'alternate': 'Alt', 'data': { 'case1': 'int', 'case2': 'str' } } + +## +# @oops: +## { 'command': 'oops', 'data': 'Alt' }
tests/qapi-schema/args-any.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/args-any.json:2: 'data' for command 'oops' cannot use built-in type 'any' +tests/qapi-schema/args-any.json:6: 'data' for command 'oops' cannot use built-in type 'any'
tests/qapi-schema/args-any.json +4 -0
@@ -1,2 +1,6 @@ # we do not allow an 'any' argument + +## +# @oops: +## { 'command': 'oops', 'data': 'any' }
tests/qapi-schema/args-array-empty.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/args-array-empty.json:2: Member 'empty' of 'data' for command 'oops': array type must contain single type name +tests/qapi-schema/args-array-empty.json:6: Member 'empty' of 'data' for command 'oops': array type must contain single type name
tests/qapi-schema/args-array-empty.json +4 -0
@@ -1,2 +1,6 @@ # we reject an array for data if it does not contain a known type + +## +# @oops: +## { 'command': 'oops', 'data': { 'empty': [ ] } }
tests/qapi-schema/args-array-unknown.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/args-array-unknown.json:2: Member 'array' of 'data' for command 'oops' uses unknown type 'NoSuchType' +tests/qapi-schema/args-array-unknown.json:6: Member 'array' of 'data' for command 'oops' uses unknown type 'NoSuchType'
tests/qapi-schema/args-array-unknown.json +4 -0
@@ -1,2 +1,6 @@ # we reject an array for data if it does not contain a known type + +## +# @oops: +## { 'command': 'oops', 'data': { 'array': [ 'NoSuchType' ] } }
tests/qapi-schema/args-bad-boxed.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/args-bad-boxed.json:2: 'boxed' of command 'foo' should only use true value +tests/qapi-schema/args-bad-boxed.json:6: 'boxed' of command 'foo' should only use true value
tests/qapi-schema/args-bad-boxed.json +4 -0
@@ -1,2 +1,6 @@ # 'boxed' should only appear with value true + +## +# @foo: +## { 'command': 'foo', 'boxed': false }
tests/qapi-schema/args-boxed-anon.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/args-boxed-anon.json:2: 'data' for command 'foo' should be a type name +tests/qapi-schema/args-boxed-anon.json:6: 'data' for command 'foo' should be a type name
tests/qapi-schema/args-boxed-anon.json +4 -0
@@ -1,2 +1,6 @@ # 'boxed' can only be used with named types + +## +# @foo: +## { 'command': 'foo', 'boxed': true, 'data': { 'string': 'str' } }
tests/qapi-schema/args-boxed-empty.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/args-boxed-empty.json:3: Cannot use 'boxed' with empty type +tests/qapi-schema/args-boxed-empty.json:11: Cannot use 'boxed' with empty type
tests/qapi-schema/args-boxed-empty.json +8 -0
@@ -1,3 +1,11 @@ # 'boxed' requires a non-empty type + +## +# @Empty: +## { 'struct': 'Empty', 'data': {} } + +## +# @foo: +## { 'command': 'foo', 'boxed': true, 'data': 'Empty' }
tests/qapi-schema/args-boxed-string.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/args-boxed-string.json:2: 'data' for command 'foo' cannot use built-in type 'str' +tests/qapi-schema/args-boxed-string.json:6: 'data' for command 'foo' cannot use built-in type 'str'
tests/qapi-schema/args-boxed-string.json +4 -0
@@ -1,2 +1,6 @@ # 'boxed' requires a complex (not built-in) type + +## +# @foo: +## { 'command': 'foo', 'boxed': true, 'data': 'str' }
tests/qapi-schema/args-int.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/args-int.json:2: 'data' for command 'oops' cannot use built-in type 'int' +tests/qapi-schema/args-int.json:6: 'data' for command 'oops' cannot use built-in type 'int'
tests/qapi-schema/args-int.json +4 -0
@@ -1,2 +1,6 @@ # we reject commands where data is not an array or complex type + +## +# @oops: +## { 'command': 'oops', 'data': 'int' }
tests/qapi-schema/args-invalid.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/args-invalid.json:1: 'data' for command 'foo' should be a dictionary or type name +tests/qapi-schema/args-invalid.json:4: 'data' for command 'foo' should be a dictionary or type name
tests/qapi-schema/args-invalid.json +3 -0
@@ -1,2 +1,5 @@ +## +# @foo: +## { 'command': 'foo', 'data': false }
tests/qapi-schema/args-member-array-bad.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/args-member-array-bad.json:2: Member 'member' of 'data' for command 'oops': array type must contain single type name +tests/qapi-schema/args-member-array-bad.json:6: Member 'member' of 'data' for command 'oops': array type must contain single type name
tests/qapi-schema/args-member-array-bad.json +4 -0
@@ -1,2 +1,6 @@ # we reject data if it does not contain a valid array type + +## +# @oops: +## { 'command': 'oops', 'data': { 'member': [ { 'nested': 'str' } ] } }
tests/qapi-schema/args-member-case.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/args-member-case.json:2: 'Arg' (parameter of no-way-this-will-get-whitelisted) should not use uppercase +tests/qapi-schema/args-member-case.json:6: 'Arg' (parameter of no-way-this-will-get-whitelisted) should not use uppercase
tests/qapi-schema/args-member-case.json +4 -0
@@ -1,2 +1,6 @@ # Member names should be 'lower-case' unless the struct/command is whitelisted + +## +# @no-way-this-will-get-whitelisted: +## { 'command': 'no-way-this-will-get-whitelisted', 'data': { 'Arg': 'int' } }
tests/qapi-schema/args-member-unknown.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/args-member-unknown.json:2: Member 'member' of 'data' for command 'oops' uses unknown type 'NoSuchType' +tests/qapi-schema/args-member-unknown.json:6: Member 'member' of 'data' for command 'oops' uses unknown type 'NoSuchType'
tests/qapi-schema/args-member-unknown.json +4 -0
@@ -1,2 +1,6 @@ # we reject data if it does not contain a known type + +## +# @oops: +## { 'command': 'oops', 'data': { 'member': 'NoSuchType' } }
tests/qapi-schema/args-name-clash.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/args-name-clash.json:4: 'a_b' (parameter of oops) collides with 'a-b' (parameter of oops) +tests/qapi-schema/args-name-clash.json:8: 'a_b' (parameter of oops) collides with 'a-b' (parameter of oops)
tests/qapi-schema/args-name-clash.json +4 -0
@@ -1,4 +1,8 @@ # C member name collision # Reject members that clash when mapped to C names (we would have two 'a_b' # members). + +## +# @oops: +## { 'command': 'oops', 'data': { 'a-b': 'str', 'a_b': 'str' } }
tests/qapi-schema/args-union.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/args-union.json:3: 'data' for command 'oops' cannot use union type 'Uni' +tests/qapi-schema/args-union.json:10: 'data' for command 'oops' cannot use union type 'Uni'
tests/qapi-schema/args-union.json +7 -0
@@ -1,3 +1,10 @@ # use of union arguments requires 'boxed':true + +## +# @Uni: +## { 'union': 'Uni', 'data': { 'case1': 'int', 'case2': 'str' } } +## +# oops: +## { 'command': 'oops', 'data': 'Uni' }
tests/qapi-schema/args-unknown.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/args-unknown.json:2: 'data' for command 'oops' uses unknown type 'NoSuchType' +tests/qapi-schema/args-unknown.json:6: 'data' for command 'oops' uses unknown type 'NoSuchType'
tests/qapi-schema/args-unknown.json +4 -0
@@ -1,2 +1,6 @@ # we reject data if it does not contain a known type + +## +# @oops: +## { 'command': 'oops', 'data': 'NoSuchType' }
tests/qapi-schema/bad-base.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/bad-base.json:3: 'base' for struct 'MyType' cannot use union type 'Union' +tests/qapi-schema/bad-base.json:10: 'base' for struct 'MyType' cannot use union type 'Union'
tests/qapi-schema/bad-base.json +7 -0
@@ -1,3 +1,10 @@ # we reject a base that is not a struct + +## +# @Union: +## { 'union': 'Union', 'data': { 'a': 'int', 'b': 'str' } } +## +# @MyType: +## { 'struct': 'MyType', 'base': 'Union', 'data': { 'c': 'int' } }
tests/qapi-schema/bad-data.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/bad-data.json:2: 'data' for command 'oops' cannot be an array +tests/qapi-schema/bad-data.json:6: 'data' for command 'oops' cannot be an array
tests/qapi-schema/bad-data.json +4 -0
@@ -1,2 +1,6 @@ # we ensure 'data' is a dictionary for all but enums + +## +# @oops: +## { 'command': 'oops', 'data': [ ] }
tests/qapi-schema/bad-ident.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/bad-ident.json:2: 'struct' does not allow optional name '*oops' +tests/qapi-schema/bad-ident.json:6: 'struct' does not allow optional name '*oops'
tests/qapi-schema/bad-ident.json +4 -0
@@ -1,2 +1,6 @@ # we reject creating a type name with bad name + +## +# @*oops: +## { 'struct': '*oops', 'data': { 'i': 'int' } }
tests/qapi-schema/bad-type-bool.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/bad-type-bool.json:2: 'struct' key must have a string value +tests/qapi-schema/bad-type-bool.json:6: 'struct' key must have a string value
tests/qapi-schema/bad-type-bool.json +4 -0
@@ -1,2 +1,6 @@ # we reject an expression with a metatype that is not a string + +## +# @true: +## { 'struct': true, 'data': { } }
tests/qapi-schema/bad-type-dict.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/bad-type-dict.json:2: 'command' key must have a string value +tests/qapi-schema/bad-type-dict.json:6: 'command' key must have a string value
tests/qapi-schema/bad-type-dict.json +4 -0
@@ -1,2 +1,6 @@ # we reject an expression with a metatype that is not a string + +## +# @foo: +## { 'command': { } }
tests/qapi-schema/base-cycle-direct.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/base-cycle-direct.json:2: Object Loopy contains itself +tests/qapi-schema/base-cycle-direct.json:6: Object Loopy contains itself
tests/qapi-schema/base-cycle-direct.json +4 -0
@@ -1,2 +1,6 @@ # we reject a loop in base classes + +## +# @Loopy: +## { 'struct': 'Loopy', 'base': 'Loopy', 'data': {} }
tests/qapi-schema/base-cycle-indirect.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/base-cycle-indirect.json:2: Object Base1 contains itself +tests/qapi-schema/base-cycle-indirect.json:6: Object Base1 contains itself
tests/qapi-schema/base-cycle-indirect.json +7 -0
@@ -1,3 +1,10 @@ # we reject a loop in base classes + +## +# @Base1: +## { 'struct': 'Base1', 'base': 'Base2', 'data': {} } +## +# @Base2: +## { 'struct': 'Base2', 'base': 'Base1', 'data': {} }
tests/qapi-schema/command-int.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/command-int.json:2: built-in 'int' is already defined +tests/qapi-schema/command-int.json:6: built-in 'int' is already defined
tests/qapi-schema/command-int.json +4 -0
@@ -1,2 +1,6 @@ # we reject collisions between commands and types + +## +# @int: +## { 'command': 'int', 'data': { 'character': 'str' } }
tests/qapi-schema/comments.json +4 -0
@@ -1,4 +1,8 @@ # Unindented comment + +## +# @Status: +## { 'enum': 'Status', # Comment to the right of code # Indented comment 'data': [ 'good', 'bad', 'ugly' ] }
tests/qapi-schema/comments.out +3 -0
@@ -2,3 +2,6 @@ enum QType ['none', 'qnull', 'qint', 'qstring', 'qdict', 'qlist', 'qfloat', 'qbo prefix QTYPE enum Status ['good', 'bad', 'ugly'] object q_empty +doc symbol=Status expr=('enum', 'Status') + body= +
tests/qapi-schema/doc-bad-args.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/doc-bad-args.json:3: The following documented members are not in the declaration: b
tests/qapi-schema/doc-bad-args.exit new file +1 -0
@@ -0,0 +1 @@ +1
tests/qapi-schema/doc-bad-args.json new file +8 -0
@@ -0,0 +1,8 @@ +# Arguments listed in the doc comment must exist in the actual schema + +## +# @foo: +# @a: a +# @b: b +## +{ 'command': 'foo', 'data': {'a': 'int'} }
tests/qapi-schema/doc-bad-args.out new file +0 -0
tests/qapi-schema/doc-bad-symbol.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/doc-bad-symbol.json:3: Definition of 'foo' follows documentation for 'food'
tests/qapi-schema/doc-bad-symbol.exit new file +1 -0
@@ -0,0 +1 @@ +1
tests/qapi-schema/doc-bad-symbol.json new file +6 -0
@@ -0,0 +1,6 @@ +# Documentation symbol mismatch with expression + +## +# @food: +## +{ 'command': 'foo', 'data': {'a': 'int'} }
tests/qapi-schema/doc-bad-symbol.out new file +0 -0
tests/qapi-schema/doc-duplicated-arg.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/doc-duplicated-arg.json:6:1: 'a' parameter name duplicated
tests/qapi-schema/doc-duplicated-arg.exit new file +1 -0
@@ -0,0 +1 @@ +1
tests/qapi-schema/doc-duplicated-arg.json new file +7 -0
@@ -0,0 +1,7 @@ +# Do not allow duplicated argument + +## +# @foo: +# @a: +# @a: +##
tests/qapi-schema/doc-duplicated-arg.out new file +0 -0
tests/qapi-schema/doc-duplicated-return.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/doc-duplicated-return.json:7:1: Duplicated 'Returns' section
tests/qapi-schema/doc-duplicated-return.exit new file +1 -0
@@ -0,0 +1 @@ +1
tests/qapi-schema/doc-duplicated-return.json new file +8 -0
@@ -0,0 +1,8 @@ +# Do not allow duplicated Returns section + +## +# @foo: +# +# Returns: 0 +# Returns: 1 +##
tests/qapi-schema/doc-duplicated-return.out new file +0 -0
tests/qapi-schema/doc-duplicated-since.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/doc-duplicated-since.json:7:1: Duplicated 'Since' section
tests/qapi-schema/doc-duplicated-since.exit new file +1 -0
@@ -0,0 +1 @@ +1
tests/qapi-schema/doc-duplicated-since.json new file +8 -0
@@ -0,0 +1,8 @@ +# Do not allow duplicated Since section + +## +# @foo: +# +# Since: 0 +# Since: 1 +##
tests/qapi-schema/doc-duplicated-since.out new file +0 -0
tests/qapi-schema/doc-empty-arg.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/doc-empty-arg.json:5:1: Invalid parameter name
tests/qapi-schema/doc-empty-arg.exit new file +1 -0
@@ -0,0 +1 @@ +1
tests/qapi-schema/doc-empty-arg.json new file +6 -0
@@ -0,0 +1,6 @@ +# An invalid empty argument name + +## +# @foo: +# @: +##
tests/qapi-schema/doc-empty-arg.out new file +0 -0
tests/qapi-schema/doc-empty-section.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/doc-empty-section.json:3: Empty doc section 'Note'
tests/qapi-schema/doc-empty-section.exit new file +1 -0
@@ -0,0 +1 @@ +1
tests/qapi-schema/doc-empty-section.json new file +8 -0
@@ -0,0 +1,8 @@ +# Tagged-section must not be empty + +## +# @foo: +# +# Note: +## +{ 'command': 'foo', 'data': {'a': 'int'} }
tests/qapi-schema/doc-empty-section.out new file +0 -0
tests/qapi-schema/doc-empty-symbol.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/doc-empty-symbol.json:4:1: Invalid name
tests/qapi-schema/doc-empty-symbol.exit new file +1 -0
@@ -0,0 +1 @@ +1
tests/qapi-schema/doc-empty-symbol.json new file +5 -0
@@ -0,0 +1,5 @@ +# Invalid documentation symbol + +## +# @: +##
tests/qapi-schema/doc-empty-symbol.out new file +0 -0
tests/qapi-schema/doc-interleaved-section.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/doc-interleaved-section.json:15:1: 'foobar' parameter documentation is interleaved with other sections
tests/qapi-schema/doc-interleaved-section.exit new file +1 -0
@@ -0,0 +1 @@ +1
tests/qapi-schema/doc-interleaved-section.json new file +21 -0
@@ -0,0 +1,21 @@ +# Arguments and sections must not be interleaved + +## +# @TestStruct: +# +# body +# +# @integer: foo +# blah +# +# bao +# +# Note: a section. +# +# @foobar: catch this +# +# Since: 2.3 +# +## +{ 'struct': 'TestStruct', + 'data': { 'integer': 'int', 'foobar': 'int' } }
tests/qapi-schema/doc-interleaved-section.out new file +0 -0
tests/qapi-schema/doc-invalid-end.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/doc-invalid-end.json:5:2: Documentation comment must end with '##'
tests/qapi-schema/doc-invalid-end.exit new file +1 -0
@@ -0,0 +1 @@ +1
tests/qapi-schema/doc-invalid-end.json new file +5 -0
@@ -0,0 +1,5 @@ +# Documentation must end with '##' + +## +# An invalid comment +#
tests/qapi-schema/doc-invalid-end.out new file +0 -0
tests/qapi-schema/doc-invalid-end2.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/doc-invalid-end2.json:5:1: Junk after '##' at end of documentation comment
tests/qapi-schema/doc-invalid-end2.exit new file +1 -0
@@ -0,0 +1 @@ +1
tests/qapi-schema/doc-invalid-end2.json new file +5 -0
@@ -0,0 +1,5 @@ +# Documentation must end with '##' + +## +# +## invalid
tests/qapi-schema/doc-invalid-end2.out new file +0 -0
tests/qapi-schema/doc-invalid-return.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/doc-invalid-return.json:3: 'Returns:' is only valid for commands
tests/qapi-schema/doc-invalid-return.exit new file +1 -0
@@ -0,0 +1 @@ +1
tests/qapi-schema/doc-invalid-return.json new file +7 -0
@@ -0,0 +1,7 @@ +# Events can't have 'Returns' section + +## +# @foo: +# Returns: blah +## +{ 'event': 'foo' }
tests/qapi-schema/doc-invalid-return.out new file +0 -0
tests/qapi-schema/doc-invalid-section.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/doc-invalid-section.json:3: Free-form documentation block must not contain @NAME: sections
tests/qapi-schema/doc-invalid-section.exit new file +1 -0
@@ -0,0 +1 @@ +1
tests/qapi-schema/doc-invalid-section.json new file +6 -0
@@ -0,0 +1,6 @@ +# Free-form documentation doesn't have tagged-sections + +## +# freeform +# @note: foo +##
tests/qapi-schema/doc-invalid-section.out new file +0 -0
tests/qapi-schema/doc-invalid-start.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/doc-invalid-start.json:3:1: Junk after '##' at start of documentation comment
tests/qapi-schema/doc-invalid-start.exit new file +1 -0
@@ -0,0 +1 @@ +1
tests/qapi-schema/doc-invalid-start.json new file +5 -0
@@ -0,0 +1,5 @@ +# Documentation must start with '##' + +## invalid +# +##
tests/qapi-schema/doc-invalid-start.out new file +0 -0
tests/qapi-schema/doc-missing-colon.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/doc-missing-colon.json:4:1: Line should end with :
tests/qapi-schema/doc-missing-colon.exit new file +1 -0
@@ -0,0 +1 @@ +1
tests/qapi-schema/doc-missing-colon.json new file +5 -0
@@ -0,0 +1,5 @@ +# The symbol section must end with ':' + +## +# @missing-colon +##
tests/qapi-schema/doc-missing-colon.out new file +0 -0
tests/qapi-schema/doc-missing-expr.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/doc-missing-expr.json:3: Documention for 'bar' is not followed by the definition
tests/qapi-schema/doc-missing-expr.exit new file +1 -0
@@ -0,0 +1 @@ +1
tests/qapi-schema/doc-missing-expr.json new file +5 -0
@@ -0,0 +1,5 @@ +# Expression documentation must be followed by the actual expression + +## +# @bar: +##
tests/qapi-schema/doc-missing-expr.out new file +0 -0
tests/qapi-schema/doc-missing-space.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/doc-missing-space.json:5:1: Missing space after #
tests/qapi-schema/doc-missing-space.exit new file +1 -0
@@ -0,0 +1 @@ +1
tests/qapi-schema/doc-missing-space.json new file +6 -0
@@ -0,0 +1,6 @@ +# Documentation line must have a leading space + +## +# missing space: +#wef +##
tests/qapi-schema/doc-missing-space.out new file +0 -0
tests/qapi-schema/doc-optional.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/doc-optional.json:3: Description has #optional, but the declaration doesn't
tests/qapi-schema/doc-optional.exit new file +1 -0
@@ -0,0 +1 @@ +1
tests/qapi-schema/doc-optional.json new file +7 -0
@@ -0,0 +1,7 @@ +# Description #optional should match declaration + +## +# @foo: +# @a: a #optional +## +{ 'command': 'foo', 'data': {'a': 'int'} }
tests/qapi-schema/doc-optional.out new file +0 -0
tests/qapi-schema/double-type.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/double-type.json:2: Unknown key 'command' in struct 'bar' +tests/qapi-schema/double-type.json:6: Unknown key 'command' in struct 'bar'
tests/qapi-schema/double-type.json +4 -0
@@ -1,2 +1,6 @@ # we reject an expression with ambiguous metatype + +## +# @foo: +## { 'command': 'foo', 'struct': 'bar', 'data': { } }
tests/qapi-schema/enum-bad-name.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/enum-bad-name.json:2: Member of enum 'MyEnum' uses invalid name 'not^possible' +tests/qapi-schema/enum-bad-name.json:6: Member of enum 'MyEnum' uses invalid name 'not^possible'
tests/qapi-schema/enum-bad-name.json +4 -0
@@ -1,2 +1,6 @@ # we ensure all enum names can map to C + +## +# @MyEnum: +## { 'enum': 'MyEnum', 'data': [ 'not^possible' ] }
tests/qapi-schema/enum-bad-prefix.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/enum-bad-prefix.json:2: Enum 'MyEnum' requires a string for 'prefix' +tests/qapi-schema/enum-bad-prefix.json:6: Enum 'MyEnum' requires a string for 'prefix'
tests/qapi-schema/enum-bad-prefix.json +4 -0
@@ -1,2 +1,6 @@ # The prefix must be a string type + +## +# @MyEnum: +## { 'enum': 'MyEnum', 'data': [ 'one' ], 'prefix': [ 'fish' ] }
tests/qapi-schema/enum-clash-member.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/enum-clash-member.json:2: 'one_two' (member of MyEnum) collides with 'one-two' (member of MyEnum) +tests/qapi-schema/enum-clash-member.json:6: 'one_two' (member of MyEnum) collides with 'one-two' (member of MyEnum)
tests/qapi-schema/enum-clash-member.json +4 -0
@@ -1,2 +1,6 @@ # we reject enums where members will clash when mapped to C enum + +## +# @MyEnum: +## { 'enum': 'MyEnum', 'data': [ 'one-two', 'one_two' ] }
tests/qapi-schema/enum-dict-member.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/enum-dict-member.json:2: Member of enum 'MyEnum' requires a string name +tests/qapi-schema/enum-dict-member.json:6: Member of enum 'MyEnum' requires a string name
tests/qapi-schema/enum-dict-member.json +4 -0
@@ -1,2 +1,6 @@ # we reject any enum member that is not a string + +## +# @MyEnum: +## { 'enum': 'MyEnum', 'data': [ { 'value': 'str' } ] }
tests/qapi-schema/enum-member-case.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/enum-member-case.json:3: 'Value' (member of NoWayThisWillGetWhitelisted) should not use uppercase +tests/qapi-schema/enum-member-case.json:10: 'Value' (member of NoWayThisWillGetWhitelisted) should not use uppercase
tests/qapi-schema/enum-member-case.json +7 -0
@@ -1,3 +1,10 @@ # Member names should be 'lower-case' unless the enum is whitelisted + +## +# @UuidInfo: +## { 'enum': 'UuidInfo', 'data': [ 'Value' ] } # UuidInfo is whitelisted +## +# @NoWayThisWillGetWhitelisted: +## { 'enum': 'NoWayThisWillGetWhitelisted', 'data': [ 'Value' ] }
tests/qapi-schema/enum-missing-data.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/enum-missing-data.json:2: Key 'data' is missing from enum 'MyEnum' +tests/qapi-schema/enum-missing-data.json:6: Key 'data' is missing from enum 'MyEnum'
tests/qapi-schema/enum-missing-data.json +4 -0
@@ -1,2 +1,6 @@ # we require that all QAPI enums have a data array + +## +# @MyEnum: +## { 'enum': 'MyEnum' }
tests/qapi-schema/enum-wrong-data.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/enum-wrong-data.json:2: Enum 'MyEnum' requires an array for 'data' +tests/qapi-schema/enum-wrong-data.json:6: Enum 'MyEnum' requires an array for 'data'
tests/qapi-schema/enum-wrong-data.json +4 -0
@@ -1,2 +1,6 @@ # we require that all qapi enums have an array for data + +## +# @MyEnum: +## { 'enum': 'MyEnum', 'data': { 'value': 'str' } }
tests/qapi-schema/event-boxed-empty.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/event-boxed-empty.json:2: Use of 'boxed' requires 'data' +tests/qapi-schema/event-boxed-empty.json:6: Use of 'boxed' requires 'data'
tests/qapi-schema/event-boxed-empty.json +4 -0
@@ -1,2 +1,6 @@ # 'boxed' requires a non-empty type + +## +# @FOO: +## { 'event': 'FOO', 'boxed': true }
tests/qapi-schema/event-case.json +4 -0
@@ -1,3 +1,7 @@ # TODO: might be nice to enforce naming conventions; but until then this works # even though events should usually be ALL_CAPS + +## +# @oops: +## { 'event': 'oops' }
tests/qapi-schema/event-case.out +3 -0
@@ -3,3 +3,6 @@ enum QType ['none', 'qnull', 'qint', 'qstring', 'qdict', 'qlist', 'qfloat', 'qbo event oops None boxed=False object q_empty +doc symbol=oops expr=('event', 'oops') + body= +
tests/qapi-schema/event-nest-struct.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/event-nest-struct.json:1: Member 'a' of 'data' for event 'EVENT_A' should be a type name +tests/qapi-schema/event-nest-struct.json:5: Member 'a' of 'data' for event 'EVENT_A' should be a type name
tests/qapi-schema/event-nest-struct.json +4 -0
@@ -1,2 +1,6 @@ +## +# @EVENT_A: +# event-nest-struct +## { 'event': 'EVENT_A', 'data': { 'a' : { 'string' : 'str', 'integer': 'int' }, 'b' : 'str' } }
tests/qapi-schema/flat-union-array-branch.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/flat-union-array-branch.json:8: Member 'value1' of union 'TestUnion' cannot be an array +tests/qapi-schema/flat-union-array-branch.json:20: Member 'value1' of union 'TestUnion' cannot be an array
tests/qapi-schema/flat-union-array-branch.json +12 -0
@@ -1,10 +1,22 @@ +## +# @TestEnum: +## # we require flat union branches to be a struct { 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } +## +# @Base: +## { 'struct': 'Base', 'data': { 'enum1': 'TestEnum' } } +## +# @TestTypeB: +## { 'struct': 'TestTypeB', 'data': { 'integer': 'int' } } +## +# @TestUnion: +## { 'union': 'TestUnion', 'base': 'Base', 'discriminator': 'enum1',
tests/qapi-schema/flat-union-bad-base.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/flat-union-bad-base.json:8: 'string' (member of TestTypeA) collides with 'string' (base of TestUnion) +tests/qapi-schema/flat-union-bad-base.json:21: 'string' (member of TestTypeA) collides with 'string' (base of TestUnion)
tests/qapi-schema/flat-union-bad-base.json +13 -0
@@ -1,10 +1,23 @@ # we allow anonymous base, but enforce no duplicate keys + +## +# @TestEnum: +## { 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } +## +# @TestTypeA: +## { 'struct': 'TestTypeA', 'data': { 'string': 'str' } } +## +# @TestTypeB: +## { 'struct': 'TestTypeB', 'data': { 'integer': 'int' } } +## +# @TestUnion: +## { 'union': 'TestUnion', 'base': { 'enum1': 'TestEnum', 'string': 'str' }, 'discriminator': 'enum1',
tests/qapi-schema/flat-union-bad-discriminator.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/flat-union-bad-discriminator.json:11: Discriminator of flat union 'TestUnion' requires a string name +tests/qapi-schema/flat-union-bad-discriminator.json:27: Discriminator of flat union 'TestUnion' requires a string name
tests/qapi-schema/flat-union-bad-discriminator.json +16 -0
@@ -1,13 +1,29 @@ # we require the discriminator to be a string naming a base-type member # this tests the old syntax for anonymous unions before we added alternates + +## +# @TestEnum: +## { 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } +## +# @TestBase: +## { 'struct': 'TestBase', 'data': { 'enum1': 'TestEnum', 'kind': 'str' } } +## +# @TestTypeA: +## { 'struct': 'TestTypeA', 'data': { 'string': 'str' } } +## +# @TestTypeB: +## { 'struct': 'TestTypeB', 'data': { 'integer': 'int' } } +## +# @TestUnion: +## { 'union': 'TestUnion', 'base': 'TestBase', 'discriminator': {},
tests/qapi-schema/flat-union-base-any.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/flat-union-base-any.json:8: 'base' for union 'TestUnion' cannot use built-in type 'any' +tests/qapi-schema/flat-union-base-any.json:21: 'base' for union 'TestUnion' cannot use built-in type 'any'
tests/qapi-schema/flat-union-base-any.json +13 -0
@@ -1,10 +1,23 @@ # we require the base to be an existing struct + +## +# @TestEnum: +## { 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } +## +# @TestTypeA: +## { 'struct': 'TestTypeA', 'data': { 'string': 'str' } } +## +# @TestTypeB: +## { 'struct': 'TestTypeB', 'data': { 'integer': 'int' } } +## +# @TestUnion: +## { 'union': 'TestUnion', 'base': 'any', 'discriminator': 'enum1',
tests/qapi-schema/flat-union-base-union.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/flat-union-base-union.json:14: 'base' for union 'TestUnion' cannot use union type 'UnionBase' +tests/qapi-schema/flat-union-base-union.json:30: 'base' for union 'TestUnion' cannot use union type 'UnionBase'
tests/qapi-schema/flat-union-base-union.json +16 -0
@@ -2,15 +2,31 @@ # TODO: It would be possible to allow a union as a base, as long as all # permutations of QMP names exposed by base do not clash with any QMP # member names added by local variants. + +## +# @TestEnum: +## { 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } +## +# @TestTypeA: +## { 'struct': 'TestTypeA', 'data': { 'string': 'str' } } +## +# @TestTypeB: +## { 'struct': 'TestTypeB', 'data': { 'integer': 'int' } } +## +# @UnionBase: +## { 'union': 'UnionBase', 'data': { 'kind1': 'TestTypeA', 'kind2': 'TestTypeB' } } +## +# @TestUnion: +## { 'union': 'TestUnion', 'base': 'UnionBase', 'discriminator': 'type',
tests/qapi-schema/flat-union-clash-member.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/flat-union-clash-member.json:11: 'name' (member of Branch1) collides with 'name' (member of Base) +tests/qapi-schema/flat-union-clash-member.json:27: 'name' (member of Branch1) collides with 'name' (member of Base)
tests/qapi-schema/flat-union-clash-member.json +16 -0
@@ -1,13 +1,29 @@ # We check for no duplicate keys between branch members and base # base's member 'name' clashes with Branch1's + +## +# @TestEnum: +## { 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } +## +# @Base: +## { 'struct': 'Base', 'data': { 'enum1': 'TestEnum', '*name': 'str' } } +## +# @Branch1: +## { 'struct': 'Branch1', 'data': { 'name': 'str' } } +## +# @Branch2: +## { 'struct': 'Branch2', 'data': { 'value': 'int' } } +## +# @TestUnion: +## { 'union': 'TestUnion', 'base': 'Base', 'discriminator': 'enum1',
tests/qapi-schema/flat-union-empty.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/flat-union-empty.json:4: Union 'Union' cannot have empty 'data' +tests/qapi-schema/flat-union-empty.json:14: Union 'Union' cannot have empty 'data'
tests/qapi-schema/flat-union-empty.json +10 -0
@@ -1,4 +1,14 @@ # flat unions cannot be empty + +## +# @Empty: +## { 'enum': 'Empty', 'data': [ ] } +## +# @Base: +## { 'struct': 'Base', 'data': { 'type': 'Empty' } } +## +# @Union: +## { 'union': 'Union', 'base': 'Base', 'discriminator': 'type', 'data': { } }
tests/qapi-schema/flat-union-incomplete-branch.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/flat-union-incomplete-branch.json:6: Union 'TestUnion' data missing 'value2' branch +tests/qapi-schema/flat-union-incomplete-branch.json:16: Union 'TestUnion' data missing 'value2' branch
tests/qapi-schema/flat-union-incomplete-branch.json +10 -0
@@ -1,8 +1,18 @@ # we require all branches of the union to be covered + +## +# @TestEnum: +## { 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } +## +# @TestTypeA: +## { 'struct': 'TestTypeA', 'data': { 'string': 'str' } } +## +# @TestUnion: +## { 'union': 'TestUnion', 'base': { 'type': 'TestEnum' }, 'discriminator': 'type',
tests/qapi-schema/flat-union-inline.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/flat-union-inline.json:7: Member 'value1' of union 'TestUnion' should be a type name +tests/qapi-schema/flat-union-inline.json:17: Member 'value1' of union 'TestUnion' should be a type name
tests/qapi-schema/flat-union-inline.json +10 -0
@@ -1,9 +1,19 @@ # we require branches to be a struct name # TODO: should we allow anonymous inline branch types? + +## +# @TestEnum: +## { 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } +## +# @Base: +## { 'struct': 'Base', 'data': { 'enum1': 'TestEnum', 'kind': 'str' } } +## +# @TestUnion: +## { 'union': 'TestUnion', 'base': 'Base', 'discriminator': 'enum1',
tests/qapi-schema/flat-union-int-branch.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/flat-union-int-branch.json:8: Member 'value1' of union 'TestUnion' cannot use built-in type 'int' +tests/qapi-schema/flat-union-int-branch.json:21: Member 'value1' of union 'TestUnion' cannot use built-in type 'int'
tests/qapi-schema/flat-union-int-branch.json +13 -0
@@ -1,10 +1,23 @@ # we require flat union branches to be a struct + +## +# @TestEnum: +## { 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } +## +# @Base: +## { 'struct': 'Base', 'data': { 'enum1': 'TestEnum' } } +## +# @TestTypeB: +## { 'struct': 'TestTypeB', 'data': { 'integer': 'int' } } +## +# @TestUnion: +## { 'union': 'TestUnion', 'base': 'Base', 'discriminator': 'enum1',
tests/qapi-schema/flat-union-invalid-branch-key.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/flat-union-invalid-branch-key.json:13: Discriminator value 'value_wrong' is not found in enum 'TestEnum' +tests/qapi-schema/flat-union-invalid-branch-key.json:28: Discriminator value 'value_wrong' is not found in enum 'TestEnum'
tests/qapi-schema/flat-union-invalid-branch-key.json +15 -0
@@ -1,15 +1,30 @@ +## +# @TestEnum: +## { 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } +## +# @TestBase: +## { 'struct': 'TestBase', 'data': { 'enum1': 'TestEnum' } } +## +# @TestTypeA: +## { 'struct': 'TestTypeA', 'data': { 'string': 'str' } } +## +# @TestTypeB: +## { 'struct': 'TestTypeB', 'data': { 'integer': 'int' } } +## +# @TestUnion: +## { 'union': 'TestUnion', 'base': 'TestBase', 'discriminator': 'enum1',
tests/qapi-schema/flat-union-invalid-discriminator.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/flat-union-invalid-discriminator.json:13: Discriminator 'enum_wrong' is not a member of base struct 'TestBase' +tests/qapi-schema/flat-union-invalid-discriminator.json:28: Discriminator 'enum_wrong' is not a member of base struct 'TestBase'
tests/qapi-schema/flat-union-invalid-discriminator.json +15 -0
@@ -1,15 +1,30 @@ +## +# @TestEnum: +## { 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } +## +# @TestBase: +## { 'struct': 'TestBase', 'data': { 'enum1': 'TestEnum' } } +## +# @TestTypeA: +## { 'struct': 'TestTypeA', 'data': { 'string': 'str' } } +## +# @TestTypeB: +## { 'struct': 'TestTypeB', 'data': { 'integer': 'int' } } +## +# @TestUnion: +## { 'union': 'TestUnion', 'base': 'TestBase', 'discriminator': 'enum_wrong',
tests/qapi-schema/flat-union-no-base.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/flat-union-no-base.json:9: Flat union 'TestUnion' must have a base +tests/qapi-schema/flat-union-no-base.json:22: Flat union 'TestUnion' must have a base
tests/qapi-schema/flat-union-no-base.json +13 -0
@@ -1,11 +1,24 @@ # flat unions require a base # TODO: simple unions should be able to use an enum discriminator + +## +# @TestTypeA: +## { 'struct': 'TestTypeA', 'data': { 'string': 'str' } } +## +# @TestTypeB: +## { 'struct': 'TestTypeB', 'data': { 'integer': 'int' } } +## +# @Enum: +## { 'enum': 'Enum', 'data': [ 'value1', 'value2' ] } +## +# @TestUnion: +## { 'union': 'TestUnion', 'discriminator': 'Enum', 'data': { 'value1': 'TestTypeA',
tests/qapi-schema/flat-union-optional-discriminator.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/flat-union-optional-discriminator.json:6: Discriminator of flat union 'MyUnion' does not allow optional name '*switch' +tests/qapi-schema/flat-union-optional-discriminator.json:19: Discriminator of flat union 'MyUnion' does not allow optional name '*switch'
tests/qapi-schema/flat-union-optional-discriminator.json +13 -0
@@ -1,8 +1,21 @@ # we require the discriminator to be non-optional + +## +# @Enum: +## { 'enum': 'Enum', 'data': [ 'one', 'two' ] } +## +# @Base: +## { 'struct': 'Base', 'data': { '*switch': 'Enum' } } +## +# @Branch: +## { 'struct': 'Branch', 'data': { 'name': 'str' } } +## +# @MyUnion: +## { 'union': 'MyUnion', 'base': 'Base', 'discriminator': '*switch',
tests/qapi-schema/flat-union-string-discriminator.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/flat-union-string-discriminator.json:13: Discriminator 'kind' must be of enumeration type +tests/qapi-schema/flat-union-string-discriminator.json:28: Discriminator 'kind' must be of enumeration type
tests/qapi-schema/flat-union-string-discriminator.json +15 -0
@@ -1,15 +1,30 @@ +## +# @TestEnum: +## { 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } +## +# @TestBase: +## { 'struct': 'TestBase', 'data': { 'enum1': 'TestEnum', 'kind': 'str' } } +## +# @TestTypeA: +## { 'struct': 'TestTypeA', 'data': { 'string': 'str' } } +## +# @TestTypeB: +## { 'struct': 'TestTypeB', 'data': { 'integer': 'int' } } +## +# @TestUnion: +## { 'union': 'TestUnion', 'base': 'TestBase', 'discriminator': 'kind',
tests/qapi-schema/ident-with-escape.json +4 -0
@@ -1,4 +1,8 @@ # we allow escape sequences in strings, if they map back to ASCII # { 'command': 'fooA', 'data': { 'bar1': 'str' } } + +## +# @fooA: +## { 'c\u006fmmand': '\u0066\u006f\u006FA', 'd\u0061ta': { '\u0062\u0061\u00721': '\u0073\u0074\u0072' } }
tests/qapi-schema/ident-with-escape.out +3 -0
@@ -5,3 +5,6 @@ command fooA q_obj_fooA-arg -> None object q_empty object q_obj_fooA-arg member bar1: str optional=False +doc symbol=fooA expr=('command', 'fooA') + body= +
tests/qapi-schema/include-relpath-sub.json +3 -0
@@ -1,2 +1,5 @@ +## +# @Status: +## { 'enum': 'Status', 'data': [ 'good', 'bad', 'ugly' ] }
tests/qapi-schema/include-relpath.out +3 -0
@@ -2,3 +2,6 @@ enum QType ['none', 'qnull', 'qint', 'qstring', 'qdict', 'qlist', 'qfloat', 'qbo prefix QTYPE enum Status ['good', 'bad', 'ugly'] object q_empty +doc symbol=Status expr=('enum', 'Status') + body= +
tests/qapi-schema/include-repetition.out +3 -0
@@ -2,3 +2,6 @@ enum QType ['none', 'qnull', 'qint', 'qstring', 'qdict', 'qlist', 'qfloat', 'qbo prefix QTYPE enum Status ['good', 'bad', 'ugly'] object q_empty +doc symbol=Status expr=('enum', 'Status') + body= +
tests/qapi-schema/include-simple-sub.json +3 -0
@@ -1,2 +1,5 @@ +## +# @Status: +## { 'enum': 'Status', 'data': [ 'good', 'bad', 'ugly' ] }
tests/qapi-schema/include-simple.out +3 -0
@@ -2,3 +2,6 @@ enum QType ['none', 'qnull', 'qint', 'qstring', 'qdict', 'qlist', 'qfloat', 'qbo prefix QTYPE enum Status ['good', 'bad', 'ugly'] object q_empty +doc symbol=Status expr=('enum', 'Status') + body= +
tests/qapi-schema/indented-expr.json +6 -0
@@ -1,2 +1,8 @@ +## +# @eins: +## { 'command' : 'eins' } +## +# @zwei: +## { 'command' : 'zwei' }
tests/qapi-schema/indented-expr.out +6 -0
@@ -5,3 +5,9 @@ command eins None -> None object q_empty command zwei None -> None gen=True success_response=True boxed=False +doc symbol=eins expr=('command', 'eins') + body= + +doc symbol=zwei expr=('command', 'zwei') + body= +
tests/qapi-schema/missing-type.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/missing-type.json:2: Expression is missing metatype +tests/qapi-schema/missing-type.json:6: Expression is missing metatype
tests/qapi-schema/missing-type.json +4 -0
@@ -1,2 +1,6 @@ # we reject an expression with missing metatype + +## +# @foo: +## { 'data': { } }
tests/qapi-schema/nested-struct-data.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/nested-struct-data.json:2: Member 'a' of 'data' for command 'foo' should be a type name +tests/qapi-schema/nested-struct-data.json:6: Member 'a' of 'data' for command 'foo' should be a type name
tests/qapi-schema/nested-struct-data.json +4 -0
@@ -1,3 +1,7 @@ # inline subtypes collide with our desired future use of defaults + +## +# @foo: +## { 'command': 'foo', 'data': { 'a' : { 'string' : 'str', 'integer': 'int' }, 'b' : 'str' } }
tests/qapi-schema/qapi-schema-test.json +213 -0
375 lines not on this page · raw message
tests/qapi-schema/qapi-schema-test.out +212 -0
215 lines not on this page · raw message
tests/qapi-schema/redefined-builtin.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/redefined-builtin.json:2: built-in 'size' is already defined +tests/qapi-schema/redefined-builtin.json:6: built-in 'size' is already defined
tests/qapi-schema/redefined-builtin.json +4 -0
@@ -1,2 +1,6 @@ # we reject types that duplicate builtin names + +## +# @size: +## { 'struct': 'size', 'data': { 'myint': 'size' } }
tests/qapi-schema/redefined-command.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/redefined-command.json:3: command 'foo' is already defined +tests/qapi-schema/redefined-command.json:10: command 'foo' is already defined
tests/qapi-schema/redefined-command.json +7 -0
@@ -1,3 +1,10 @@ # we reject commands defined more than once + +## +# @foo: +## { 'command': 'foo', 'data': { 'one': 'str' } } +## +# @foo: +## { 'command': 'foo', 'data': { '*two': 'str' } }
tests/qapi-schema/redefined-event.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/redefined-event.json:3: event 'EVENT_A' is already defined +tests/qapi-schema/redefined-event.json:10: event 'EVENT_A' is already defined
tests/qapi-schema/redefined-event.json +7 -0
@@ -1,3 +1,10 @@ # we reject duplicate events + +## +# @EVENT_A: +## { 'event': 'EVENT_A', 'data': { 'myint': 'int' } } +## +# @EVENT_A: +## { 'event': 'EVENT_A', 'data': { 'myint': 'int' } }
tests/qapi-schema/redefined-type.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/redefined-type.json:3: struct 'foo' is already defined +tests/qapi-schema/redefined-type.json:10: struct 'foo' is already defined
tests/qapi-schema/redefined-type.json +7 -0
@@ -1,3 +1,10 @@ # we reject types defined more than once + +## +# @foo: +## { 'struct': 'foo', 'data': { 'one': 'str' } } +## +# @foo: +## { 'enum': 'foo', 'data': [ 'two' ] }
tests/qapi-schema/reserved-command-q.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/reserved-command-q.json:5: 'command' uses invalid name 'q-unix' +tests/qapi-schema/reserved-command-q.json:12: 'command' uses invalid name 'q-unix'
tests/qapi-schema/reserved-command-q.json +7 -0
@@ -1,5 +1,12 @@ # C entity name collision # We reject names like 'q-unix', because they can collide with the mangled # name for 'unix' in generated C. + +## +# @unix: +## { 'command': 'unix' } +## +# @q-unix: +## { 'command': 'q-unix' }
tests/qapi-schema/reserved-enum-q.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/reserved-enum-q.json:4: Member of enum 'Foo' uses invalid name 'q-Unix' +tests/qapi-schema/reserved-enum-q.json:8: Member of enum 'Foo' uses invalid name 'q-Unix'
tests/qapi-schema/reserved-enum-q.json +4 -0
@@ -1,4 +1,8 @@ # C entity name collision # We reject names like 'q-unix', because they can collide with the mangled # name for 'unix' in generated C. + +## +# @Foo: +## { 'enum': 'Foo', 'data': [ 'unix', 'q-Unix' ] }
tests/qapi-schema/reserved-member-has.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/reserved-member-has.json:5: Member of 'data' for command 'oops' uses reserved name 'has-a' +tests/qapi-schema/reserved-member-has.json:9: Member of 'data' for command 'oops' uses reserved name 'has-a'
tests/qapi-schema/reserved-member-has.json +4 -0
@@ -2,4 +2,8 @@ # We reject names like 'has-a', because they can collide with the flag # for an optional 'a' in generated C. # TODO we could munge the optional flag name to avoid the collision. + +## +# @oops: +## { 'command': 'oops', 'data': { '*a': 'str', 'has-a': 'str' } }
tests/qapi-schema/reserved-member-q.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/reserved-member-q.json:4: Member of 'data' for struct 'Foo' uses invalid name 'q-unix' +tests/qapi-schema/reserved-member-q.json:8: Member of 'data' for struct 'Foo' uses invalid name 'q-unix'
tests/qapi-schema/reserved-member-q.json +4 -0
@@ -1,4 +1,8 @@ # C member name collision # We reject names like 'q-unix', because they can collide with the mangled # name for 'unix' in generated C. + +## +# @Foo: +## { 'struct': 'Foo', 'data': { 'unix':'int', 'q-unix':'bool' } }
tests/qapi-schema/reserved-member-u.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/reserved-member-u.json:7: Member of 'data' for struct 'Oops' uses reserved name 'u' +tests/qapi-schema/reserved-member-u.json:11: Member of 'data' for struct 'Oops' uses reserved name 'u'
tests/qapi-schema/reserved-member-u.json +4 -0
@@ -4,4 +4,8 @@ # This is true even for non-unions, because it is possible to convert a # struct to flat union while remaining backwards compatible in QMP. # TODO - we could munge the member name to 'q_u' to avoid the collision + +## +# @Oops: +## { 'struct': 'Oops', 'data': { 'u': 'str' } }
tests/qapi-schema/reserved-member-underscore.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/reserved-member-underscore.json:4: Member of 'data' for struct 'Oops' uses invalid name '_oops' +tests/qapi-schema/reserved-member-underscore.json:8: Member of 'data' for struct 'Oops' uses invalid name '_oops'
tests/qapi-schema/reserved-member-underscore.json +4 -0
@@ -1,4 +1,8 @@ # C member name collision # We reject use of a single leading underscore in all names (names must # begin with a letter or a downstream extension double-underscore prefix). + +## +# @Oops: +## { 'struct': 'Oops', 'data': { '_oops': 'str' } }
tests/qapi-schema/reserved-type-kind.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/reserved-type-kind.json:2: enum 'UnionKind' should not end in 'Kind' +tests/qapi-schema/reserved-type-kind.json:6: enum 'UnionKind' should not end in 'Kind'
tests/qapi-schema/reserved-type-kind.json +4 -0
@@ -1,2 +1,6 @@ # we reject types that would conflict with implicit union enum + +## +# @UnionKind: +## { 'enum': 'UnionKind', 'data': [ 'oops' ] }
tests/qapi-schema/reserved-type-list.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/reserved-type-list.json:5: struct 'FooList' should not end in 'List' +tests/qapi-schema/reserved-type-list.json:9: struct 'FooList' should not end in 'List'
tests/qapi-schema/reserved-type-list.json +4 -0
@@ -2,4 +2,8 @@ # We reserve names ending in 'List' for use by array types. # TODO - we could choose array names to avoid collision with user types, # in order to let this compile + +## +# @FooList: +## { 'struct': 'FooList', 'data': { 's': 'str' } }
tests/qapi-schema/returns-alternate.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/returns-alternate.json:3: 'returns' for command 'oops' cannot use alternate type 'Alt' +tests/qapi-schema/returns-alternate.json:10: 'returns' for command 'oops' cannot use alternate type 'Alt'
tests/qapi-schema/returns-alternate.json +7 -0
@@ -1,3 +1,10 @@ # we reject returns if it is an alternate type + +## +# @Alt: +## { 'alternate': 'Alt', 'data': { 'a': 'int', 'b': 'str' } } +## +# @oops: +## { 'command': 'oops', 'returns': 'Alt' }
tests/qapi-schema/returns-array-bad.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/returns-array-bad.json:2: 'returns' for command 'oops': array type must contain single type name +tests/qapi-schema/returns-array-bad.json:6: 'returns' for command 'oops': array type must contain single type name
tests/qapi-schema/returns-array-bad.json +4 -0
@@ -1,2 +1,6 @@ # we reject an array return that is not a single type + +## +# @oops: +## { 'command': 'oops', 'returns': [ 'str', 'str' ] }
tests/qapi-schema/returns-dict.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/returns-dict.json:2: 'returns' for command 'oops' should be a type name +tests/qapi-schema/returns-dict.json:6: 'returns' for command 'oops' should be a type name
tests/qapi-schema/returns-dict.json +4 -0
@@ -1,2 +1,6 @@ # we reject inline struct return type + +## +# @oops: +## { 'command': 'oops', 'returns': { 'a': 'str' } }
tests/qapi-schema/returns-unknown.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/returns-unknown.json:2: 'returns' for command 'oops' uses unknown type 'NoSuchType' +tests/qapi-schema/returns-unknown.json:6: 'returns' for command 'oops' uses unknown type 'NoSuchType'
tests/qapi-schema/returns-unknown.json +4 -0
@@ -1,2 +1,6 @@ # we reject returns if it does not contain a known type + +## +# @oops: +## { 'command': 'oops', 'returns': 'NoSuchType' }
tests/qapi-schema/returns-whitelist.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/returns-whitelist.json:10: 'returns' for command 'no-way-this-will-get-whitelisted' cannot use built-in type 'int' +tests/qapi-schema/returns-whitelist.json:26: 'returns' for command 'no-way-this-will-get-whitelisted' cannot use built-in type 'int'
tests/qapi-schema/returns-whitelist.json +16 -0
@@ -1,11 +1,27 @@ # we enforce that 'returns' be a dict or array of dict unless whitelisted + +## +# @human-monitor-command: +## { 'command': 'human-monitor-command', 'data': {'command-line': 'str', '*cpu-index': 'int'}, 'returns': 'str' } +## +# @TpmModel: +## { 'enum': 'TpmModel', 'data': [ 'tpm-tis' ] } +## +# @query-tpm-models: +## { 'command': 'query-tpm-models', 'returns': ['TpmModel'] } +## +# @guest-get-time: +## { 'command': 'guest-get-time', 'returns': 'int' } +## +# @no-way-this-will-get-whitelisted: +## { 'command': 'no-way-this-will-get-whitelisted', 'returns': [ 'int' ] }
tests/qapi-schema/struct-base-clash-deep.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/struct-base-clash-deep.json:10: 'name' (member of Sub) collides with 'name' (member of Base) +tests/qapi-schema/struct-base-clash-deep.json:20: 'name' (member of Sub) collides with 'name' (member of Base)
tests/qapi-schema/struct-base-clash-deep.json +10 -0
@@ -2,11 +2,21 @@ # Here, 'name' would have to appear twice on the wire, locally and # indirectly for the grandparent base; the collision doesn't care that # one instance is optional. + +## +# @Base: +## { 'struct': 'Base', 'data': { 'name': 'str' } } +## +# @Mid: +## { 'struct': 'Mid', 'base': 'Base', 'data': { 'value': 'int' } } +## +# @Sub: +## { 'struct': 'Sub', 'base': 'Mid', 'data': { '*name': 'str' } }
tests/qapi-schema/struct-base-clash.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/struct-base-clash.json:5: 'name' (member of Sub) collides with 'name' (member of Base) +tests/qapi-schema/struct-base-clash.json:12: 'name' (member of Sub) collides with 'name' (member of Base)
tests/qapi-schema/struct-base-clash.json +7 -0
@@ -1,7 +1,14 @@ # Reject attempts to duplicate QMP members # Here, 'name' would have to appear twice on the wire, locally and for base. + +## +# @Base: +## { 'struct': 'Base', 'data': { 'name': 'str' } } +## +# @Sub: +## { 'struct': 'Sub', 'base': 'Base', 'data': { 'name': 'str' } }
tests/qapi-schema/struct-data-invalid.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/struct-data-invalid.json:1: 'data' for struct 'foo' should be a dictionary or type name +tests/qapi-schema/struct-data-invalid.json:4: 'data' for struct 'foo' should be a dictionary or type name
tests/qapi-schema/struct-data-invalid.json +3 -0
@@ -1,2 +1,5 @@ +## +# @foo: +## { 'struct': 'foo', 'data': false }
tests/qapi-schema/struct-member-invalid.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/struct-member-invalid.json:1: Member 'a' of 'data' for struct 'foo' should be a type name +tests/qapi-schema/struct-member-invalid.json:4: Member 'a' of 'data' for struct 'foo' should be a type name
tests/qapi-schema/struct-member-invalid.json +3 -0
@@ -1,2 +1,5 @@ +## +# @foo: +## { 'struct': 'foo', 'data': { 'a': false } }
tests/qapi-schema/test-qapi.py +12 -0
@@ -55,3 +55,15 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): schema = QAPISchema(sys.argv[1]) schema.visit(QAPISchemaTestVisitor()) + +for doc in schema.docs: + if doc.symbol: + print 'doc symbol=%s expr=%s' % \ + (doc.symbol, doc.expr.items()[0]) + else: + print 'doc freeform' + for arg, section in doc.args.iteritems(): + print ' arg=%s\n%s' % (arg, section) + for section in doc.sections: + print ' section=%s\n%s' % (section.name, section) + print ' body=\n%s' % doc.body
tests/qapi-schema/type-bypass-bad-gen.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/type-bypass-bad-gen.json:2: 'gen' of command 'foo' should only use false value +tests/qapi-schema/type-bypass-bad-gen.json:6: 'gen' of command 'foo' should only use false value
tests/qapi-schema/type-bypass-bad-gen.json +4 -0
@@ -1,2 +1,6 @@ # 'gen' should only appear with value false + +## +# @foo: +## { 'command': 'foo', 'gen': 'whatever' }
tests/qapi-schema/unicode-str.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/unicode-str.json:2: 'command' uses invalid name 'é' +tests/qapi-schema/unicode-str.json:6: 'command' uses invalid name 'é'
tests/qapi-schema/unicode-str.json +4 -0
@@ -1,2 +1,6 @@ # we don't support full Unicode strings, yet + +## +# @e: +## { 'command': 'é' }
tests/qapi-schema/union-base-no-discriminator.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/union-base-no-discriminator.json:11: Simple union 'TestUnion' must not have a base +tests/qapi-schema/union-base-no-discriminator.json:23: Simple union 'TestUnion' must not have a base
tests/qapi-schema/union-base-no-discriminator.json +12 -0
@@ -1,13 +1,25 @@ +## +# @TestTypeA: +## # we reject simple unions with a base (or flat unions without discriminator) { 'struct': 'TestTypeA', 'data': { 'string': 'str' } } +## +# @TestTypeB: +## { 'struct': 'TestTypeB', 'data': { 'integer': 'int' } } +## +# @Base: +## { 'struct': 'Base', 'data': { 'string': 'str' } } +## +# @TestUnion: +## { 'union': 'TestUnion', 'base': 'Base', 'data': { 'value1': 'TestTypeA',
tests/qapi-schema/union-branch-case.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/union-branch-case.json:2: 'Branch' (branch of NoWayThisWillGetWhitelisted) should not use uppercase +tests/qapi-schema/union-branch-case.json:6: 'Branch' (branch of NoWayThisWillGetWhitelisted) should not use uppercase
tests/qapi-schema/union-branch-case.json +4 -0
@@ -1,2 +1,6 @@ # Branch names should be 'lower-case' unless the union is whitelisted + +## +# @NoWayThisWillGetWhitelisted: +## { 'union': 'NoWayThisWillGetWhitelisted', 'data': { 'Branch': 'int' } }
tests/qapi-schema/union-clash-branches.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/union-clash-branches.json:4: 'a_b' (branch of TestUnion) collides with 'a-b' (branch of TestUnion) +tests/qapi-schema/union-clash-branches.json:8: 'a_b' (branch of TestUnion) collides with 'a-b' (branch of TestUnion)
tests/qapi-schema/union-clash-branches.json +4 -0
@@ -1,5 +1,9 @@ # Union branch name collision # Reject a union that would result in a collision in generated C names (this # would try to generate two members 'a_b'). + +## +# @TestUnion: +## { 'union': 'TestUnion', 'data': { 'a-b': 'int', 'a_b': 'str' } }
tests/qapi-schema/union-empty.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/union-empty.json:2: Union 'Union' cannot have empty 'data' +tests/qapi-schema/union-empty.json:6: Union 'Union' cannot have empty 'data'
tests/qapi-schema/union-empty.json +4 -0
@@ -1,2 +1,6 @@ # unions cannot be empty + +## +# @Union: +## { 'union': 'Union', 'data': { } }
tests/qapi-schema/union-invalid-base.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/union-invalid-base.json:8: 'base' for union 'TestUnion' cannot use built-in type 'int' +tests/qapi-schema/union-invalid-base.json:18: 'base' for union 'TestUnion' cannot use built-in type 'int'
tests/qapi-schema/union-invalid-base.json +10 -0
@@ -1,10 +1,20 @@ # a union base type must be a struct + +## +# @TestTypeA: +## { 'struct': 'TestTypeA', 'data': { 'string': 'str' } } +## +# @TestTypeB: +## { 'struct': 'TestTypeB', 'data': { 'integer': 'int' } } +## +# @TestUnion: +## { 'union': 'TestUnion', 'base': 'int', 'discriminator': 'int',
tests/qapi-schema/union-optional-branch.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/union-optional-branch.json:2: Member of union 'Union' does not allow optional name '*a' +tests/qapi-schema/union-optional-branch.json:6: Member of union 'Union' does not allow optional name '*a'
tests/qapi-schema/union-optional-branch.json +4 -0
@@ -1,2 +1,6 @@ # union branches cannot be optional + +## +# @Union: +## { 'union': 'Union', 'data': { '*a': 'int', 'b': 'str' } }
tests/qapi-schema/union-unknown.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/union-unknown.json:2: Member 'unknown' of union 'Union' uses unknown type 'MissingType' +tests/qapi-schema/union-unknown.json:6: Member 'unknown' of union 'Union' uses unknown type 'MissingType'
tests/qapi-schema/union-unknown.json +4 -0
@@ -1,3 +1,7 @@ # we reject a union with unknown type in branch + +## +# @Union: +## { 'union': 'Union', 'data': { 'unknown': 'MissingType' } }
tests/qapi-schema/unknown-escape.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/unknown-escape.json:3:21: Unknown escape \x +tests/qapi-schema/unknown-escape.json:7:21: Unknown escape \x
tests/qapi-schema/unknown-escape.json +4 -0
@@ -1,3 +1,7 @@ # we only recognize JSON escape sequences, plus our \' extension (no \x) + +## +# @foo: +## # { 'command': 'foo', 'data': {} } { 'command': 'foo', 'dat\x61':{} }
tests/qapi-schema/unknown-expr-key.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/unknown-expr-key.json:2: Unknown key 'bogus' in struct 'bar' +tests/qapi-schema/unknown-expr-key.json:6: Unknown key 'bogus' in struct 'bar'
tests/qapi-schema/unknown-expr-key.json +4 -0
@@ -1,2 +1,6 @@ # we reject an expression with unknown top-level keys + +## +# @bar: +## { 'struct': 'bar', 'data': { 'string': 'str'}, 'bogus': { } }
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH v7 15/21] qapi: add qapi2texi script
Quoted 59 lines · Marc-André Lureau
As the name suggests, the qapi2texi script converts JSON QAPI description into a texi file suitable for different target formats (info/man/txt/pdf/html...).
It parses the following kind of blocks:
Free-form:
##
# = Section
# == Subsection
#
# Some text foo with *emphasis*
# 1. with a list
# 2. like that
#
# And some code:# | $ echo foo # | -> do this # | <- get that#
##Symbol description:
##
# @symbol:
#
# Symbol body ditto ergo sum. Foo bar# baz ding. # # @param1: the frob to frobnicate # @param2: #optional how hard to frobnicate # # Returns: the frobnicated frob. # If frob isn't frobnicatable, GenericError. # # Since: version # Notes: notes, comments can have # - itemized list # - like this # # Example: # # -> { "execute": "quit" } # <- { "return": {} } # ##That's roughly following the following EBNF grammar:
api_comment= "##\n" comment "##\n"
comment =freeform_comment|symbol_commentfreeform_comment= { "# " text "\n" | "#\n" }symbol_comment= "# @" name ":\n" { member |tag_section|freeform_comment}
member = "# @" name ':' [ text ] "\n"freeform_commenttag_section= "# " ( "Returns:", "Since:", "Note:", "Notes:", "Example:", "Examples:" ) [ text ] "\n"freeform_commenttext = free text with markup
Quoted 7 lines
Note that the grammar is ambiguous: a line "# @foo:\n" can be parsed both as
freeform_commentand assymbol_comment. The actual parser recognizessymbol_comment.See
docs/qapi-code-gen.txtfor more details.Deficiencies:
Perhaps "Deficiencies and limitations".
Quoted 2 lines
- the generated QMP documentation includes internal types
- union-type support is lacking
"union type" (no dash).
Quoted 4 lines
- type information is lacking in generated documentation
- doc comment error message positions are imprecise, they point to the beginning of the comment.
- see other TODO/FIXME in this commit
Suggest: - a few minor issues, all marked TODO/FIXME in the code
Quoted 3 lines
Signed-off-by Marc-André Lureau <[email protected]>---
[diffstat snipped...]
Quoted 92 lines
scripts/qapi.py +84
-0@@ -125,6 +125,122 @@ class QAPISemError(QAPIError): info['parent'], msg) +class QAPIDoc(object): + class Section(object): + def __init__(self, name=None): + # optional section name (argument/member or section name) + self.name = name + # the list of lines for this section + self.content = [] + + def append(self, line): + self.content.append(line) + + def __repr__(self): + return "\n".join(self.content).strip() + + class ArgSection(Section): + pass + + def __init__(self, parser, info): + # self.parser is used to report errors with QAPIParseError. The + # resulting error position depends on the state of the parser. + # It happens to be the beginning of the comment. More or less + # servicable, but action at a distance. + self.parser = parser + self.info = info + self.symbol = None + self.body = QAPIDoc.Section() + # dict mapping parameter name to ArgSection + self.args = OrderedDict() + # a list of Section + self.sections = [] + # the current section + self.section = self.body + # associated expression (to be set by expression parser) + self.expr = None + + def has_section(self, name): + """Return True if we have a section with this name.""" + for i in self.sections: + if i.name == name: + return True + return False + + def append(self, line): + """Parse a comment line and add it to the documentation.""" + line = line[1:] + if not line: + self._append_freeform(line) + return + + if line[0] != ' ': + raise QAPIParseError(self.parser, "Missing space after #") + line = line[1:] + + # FIXME not nice: things like '# @foo:' and '# @foo: ' aren't + # recognized, and get silently treated as ordinary text + if self.symbol: + self._append_symbol_line(line) + elif not self.body.content and line.startswith("@"): + if not line.endswith(":"): + raise QAPIParseError(self.parser, "Line should end with :") + self.symbol = line[1:-1] + # FIXME invalid names other than the empty string aren't flagged + if not self.symbol: + raise QAPIParseError(self.parser, "Invalid name") + else: + self._append_freeform(line) + + def _append_symbol_line(self, line): + name = line.split(' ', 1)[0] + + if name.startswith("@") and name.endswith(":"): + line = line[len(name)+1:] + self._start_args_section(name[1:-1]) + elif name in ("Returns:", "Since:", + # those are often singular or plural + "Note:", "Notes:", + "Example:", "Examples:", + "TODO:"): + line = line[len(name)+1:] + self._start_section(name[:-1]) + + self._append_freeform(line) + + def _start_args_section(self, name):
scripts/qapi.py class QAPISemError(QAPIError): · line 221
Quoted 10 lines
scripts/qapi.py +10
-0+ # FIXME invalid names other than the empty string aren't flagged + if not name: + raise QAPIParseError(self.parser, "Invalid parameter name") + if name in self.args: + raise QAPIParseError(self.parser, + "'%s' parameter name duplicated" % name) + if self.sections: + raise QAPIParseError(self.parser, + "'%s' parameter documentation is interleaved " + "with other sections" % name)
This error message is rather confusing. Ideally, we'd point to the the source code that made us add to self.sections, but that's not in the cards right now. Here's my best try:
raise QAPIParseError(self.parser,
"'@%s:' can't follow '%s' section"
% (name, self.sections[0].name))scripts/qapi.py class QAPISemError(QAPIError): · line 225
Quoted 4 lines
scripts/qapi.py +4
-0+ self.section = QAPIDoc.ArgSection(name) + self.args[name] = self.section + + def _start_section(self, name=""):
Note: @name changed to default to "" since v6 for the benefit of _append_freeform() below.
scripts/qapi.py class QAPISemError(QAPIError): · line 236
Quoted 11 lines
scripts/qapi.py +11
-0+ if name in ("Returns", "Since") and self.has_section(name): + raise QAPIParseError(self.parser, + "Duplicated '%s' section" % name) + self.section = QAPIDoc.Section(name) + self.sections.append(self.section) + + def _append_freeform(self, line): + in_arg = isinstance(self.section, QAPIDoc.ArgSection) + if (in_arg and self.section.content and + not self.section.content[-1] and + line and not line[0].isspace()):
PEP8 recommends breaking lines before operators in new code.
scripts/qapi.py class QAPISemError(QAPIError): · line 237
Quoted 1 line
scripts/qapi.py +1
-0+ self._start_section()
Changed from v6's
raise QAPIParseError(self.parser, "Invalid section indentation")
May well be an improvement (I'm certainly no fan of this error myself), but it throws my review off the fast track: now I have to figure out how the new code works. Can you give me a hint on what this change does?
Or should we take a shortcut and revert to v6 here? We can always improve on top.
scripts/qapi.py class QAPISemError(QAPIError): · line 239
Quoted 2 lines
scripts/qapi.py +2
-0+ if (in_arg or not self.section.name or + not self.section.name.startswith("Example")):
Again, break before the operator.
Quoted 34 lines
scripts/qapi.py +11
-0+ line = line.strip() + self.section.append(line) + + class QAPISchemaParser(object): def __init__(self, fp, previously_included=[], incl_info=None):@@ -140,11 +256,17 @@ class QAPISchemaParser(object): self.line = 1 self.line_pos = 0 self.exprs = [] + self.docs = [] self.accept() while self.tok is not None: info = {'file': fname, 'line': self.line, 'parent': self.incl_info} + if self.tok == '#': + doc = self.get_doc(info) + self.docs.append(doc) + continue + expr = self.get_expr(False) if isinstance(expr, dict) and "include" in expr: if len(expr) != 1:@@ -162,6 +284,7 @@ class QAPISchemaParser(object): raise QAPISemError(info, "Inclusion loop for %s" % include) inf = inf['parent'] + # skip multiple include of the same file if incl_abs_fname in previously_included: continue
scripts/qapi.py class QAPISchemaParser(object): · line 304
Quoted 10 lines
scripts/qapi.py +4
-0@@ -172,12 +295,19 @@ class QAPISchemaParser(object): exprs_include = QAPISchemaParser(fobj, previously_included, info) self.exprs.extend(exprs_include.exprs) + self.docs.extend(exprs_include.docs) else: expr_elem = {'expr': expr, 'info': info} + if (self.docs and + self.docs[-1].info['file'] == fname and + not self.docs[-1].expr):
Again, break before the operator.
Quoted 14 lines
scripts/qapi.py +4
-1+ self.docs[-1].expr = expr + expr_elem['doc'] = self.docs[-1] + self.exprs.append(expr_elem) - def accept(self): + def accept(self, skip_comment=True): while True: self.tok = self.src[self.cursor] self.pos = self.cursor@@ -185,7 +315,13 @@ class QAPISchemaParser(object): self.val = None if self.tok == '#':
scripts/qapi.py class QAPISchemaParser(object): · line 327
Quoted 10 lines
scripts/qapi.py +6
-0+ if self.src[self.cursor] == '#': + # Start of doc comment + skip_comment = False self.cursor = self.src.find('\n', self.cursor) + if not skip_comment: + self.val = self.src[self.pos:self.cursor] + return elif self.tok in "{}:,[]": return elif self.tok == "'":
Copied from review of v3, so I don't forget:
Comment tokens are thrown away as before, except when the parser asks for them by passing skip_comment=False, or when the comment token starts with ##. The parser asks while parsing a doc comment, in get_doc().
This is a backchannel from the parser to the lexer. I'd rather avoid such lexer hacks, but I guess we can address that on top.
A comment starting with ## inside an expression is now a syntax error. For instance, input
{
##yields
/dev/stdin:2:1: Expected string or "}"
Rather unfriendly error message, but we can fix that on top.
Quoted 49 lines
scripts/qapi.py +31
-0@@ -319,6 +455,28 @@ class QAPISchemaParser(object): raise QAPIParseError(self, 'Expected "{", "[" or string') return expr + def get_doc(self, info): + if self.val != '##': + raise QAPIParseError(self, "Junk after '##' at start of " + "documentation comment") + + doc = QAPIDoc(self, info) + self.accept(False) + while self.tok == '#': + if self.val.startswith('##'): + # End of doc comment + if self.val != '##': + raise QAPIParseError(self, "Junk after '##' at end of " + "documentation comment") + self.accept() + return doc + else: + doc.append(self.val) + self.accept(False) + + raise QAPIParseError(self, "Documentation comment must end with '##'") + + # # Semantic analysis of schema expressions # TODO fold into QAPISchema@@ -703,6 +861,11 @@ def check_exprs(exprs): for expr_elem in exprs: expr = expr_elem['expr'] info = expr_elem['info'] + + if 'doc' not in expr_elem: + raise QAPISemError(info, + "Expression missing documentation comment") + if 'enum' in expr: check_keys(expr_elem, 'enum', ['data'], ['prefix']) add_enum(expr['enum'], info, expr['data'])@@ -761,6 +924,84 @@ def check_exprs(exprs): return exprs +def check_freeform_doc(doc): + if doc.symbol: + raise QAPISemError(doc.info, + "Documention for '%s' is not followed"
scripts/qapi.py def check_exprs(exprs): · line 940
Quoted 10 lines
scripts/qapi.py +10
-0+ " by the definition" % doc.symbol) + + body = str(doc.body) + if re.search(r'@\S+:', body, re.MULTILINE): + raise QAPISemError(doc.info, + "Free-form documentation block must not contain" + " @NAME: sections") + + +def check_definition_doc(doc, expr, info):
Lots of churn in this function. It can certainly use improvement, as pointed out in prior reviews, but it triggers still more review. Based on the tests, I guess it's for finding documented parameters that don't actually exist, and to diagnose optional mismatch. Anything else?
Or should we take a shortcut and revert to v6 here? We can always improve on top. I think v6 would need a # TODO Should ensure #optional matches the schema.
scripts/qapi.py def check_exprs(exprs): · line 951
Quoted 11 lines
scripts/qapi.py +11
-0+ for i in ('enum', 'union', 'alternate', 'struct', 'command', 'event'): + if i in expr: + meta = i + break + + name = expr[meta] + if doc.symbol != name: + raise QAPISemError(info, "Definition of '%s' follows documentation" + " for '%s'" % (name, doc.symbol)) + if doc.has_section('Returns') and 'command' not in expr: + raise QAPISemError(info, "'Returns:' is only valid for commands")
Copied from review of v5, so I don't forget:
We accept 'Returns:' even when the command doesn't return anything, because we currently use it to document errors, too. Can't say I like that, but it's out of scope here.
Quoted 25 lines
scripts/qapi.py +25
-0+ + if meta == 'union': + args = expr.get('base', []) + else: + args = expr.get('data', []) + if isinstance(args, dict): + args = args.keys() + + if meta == 'alternate' or \ + (meta == 'union' and not expr.get('discriminator')): + args.append('type') + + if isinstance(args, list): + for arg in args: + if arg[0] == '*': + opt = True + desc = doc.args.get(arg[1:]) + else: + opt = False + desc = doc.args.get(arg) + if not desc: + continue + desc_opt = "#optional" in str(desc) + if desc_opt and not opt: + raise QAPISemError(info, "Description has #optional, "
scripts/qapi.py def check_exprs(exprs): · line 986
Quoted 10 lines
scripts/qapi.py +10
-0+ "but the declaration doesn't") + if not desc_opt and opt: + # silently fix the doc + desc.append("#optional") + + doc_args = set(doc.args.keys()) + args = set([name.strip('*') for name in args]) + if not doc_args.issubset(args): + raise QAPISemError(info, "The following documented members are not in " + "the declaration: %s" % ", ".join(doc_args - args))
Copied from review of v5, so I don't forget:
As explained in review of v3, this is only a subset of the real set of members. Computing the exact set is impractical when working with the abstract syntax tree. I believe we'll eventually have to rewrite this code to work with the QAPISchemaEntity instead.
Quoted 135 lines
scripts/qapi.py +21
-1+ + +def check_docs(docs): + for doc in docs: + for section in doc.args.values() + doc.sections: + content = str(section) + if not content or content.isspace(): + raise QAPISemError(doc.info, + "Empty doc section '%s'" % section.name) + + if not doc.expr: + check_freeform_doc(doc) + else: + check_definition_doc(doc, doc.expr, doc.info) + + return docs + + # # Schema compiler frontend #@@ -1229,7 +1470,9 @@ class QAPISchemaEvent(QAPISchemaEntity): class QAPISchema(object): def __init__(self, fname): try: - self.exprs = check_exprs(QAPISchemaParser(open(fname, "r")).exprs) + parser = QAPISchemaParser(open(fname, "r")) + self.exprs = check_exprs(parser.exprs) + self.docs = check_docs(parser.docs) self._entity_dict = {} self._predefining = True self._def_predefineds()scripts/qapi2texi.py new file +97
-0@@ -0,0 +1,266 @@ +#!/usr/bin/env python +# QAPI texi generator +# +# 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 re +import sys + +import qapi + +COMMAND_FMT = """ +@deftypefn {type} {{}} {name} + +{body} + +@end deftypefn + +""".format + +ENUM_FMT = """ +@deftp Enum {name} + +{body} + +@end deftp + +""".format + +STRUCT_FMT = """ +@deftp {{{type}}} {name} + +{body} + +@end deftp + +""".format + +EXAMPLE_FMT = """@example +{code} +@end example +""".format + + +def subst_strong(doc): + """Replaces *foo* by @strong{foo}""" + return re.sub(r'\*([^*\n]+)\*', r'@emph{\1}', doc) + + +def subst_emph(doc): + """Replaces _foo_ by @emph{foo}""" + 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 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) + + +def texi_format(doc): + """ + Format documentation + + Lines starting with: + - |: generates an @example + - =: generates @section + - ==: generates @subsection + - 1. or 1): generates an @enumerate @item + - */-: generates an @itemize list + """ + lines = [] + doc = subst_braces(doc) + doc = subst_vars(doc) + doc = subst_emph(doc) + doc = subst_strong(doc) + inlist = "" + lastempty = False + for line in doc.split('\n'): + empty = line == "" + + # FIXME: Doing this in a single if / elif chain is + # problematic. For instance, a line without markup terminates
scripts/qapi2texi.py line 107
Quoted 10 lines
scripts/qapi2texi.py new file +10
-0+ # a list if it follows a blank line (reaches the final elif), + # but a line with some *other* markup, such as a = title + # doesn't. + if line.startswith("| "): + line = EXAMPLE_FMT(code=line[2:]) + elif line.startswith("= "): + line = "@section " + line[2:] + elif line.startswith("== "): + line = "@subsection " + line[3:] + elif re.match("^([0-9]*[.]) ", line):
[.] is an unusual way to say \.
Perhaps we should consistently use r"..." for strings used as regular expressions.
Quoted 41 lines
scripts/qapi2texi.py new file +41
-0+ if not inlist: + lines.append("@enumerate") + inlist = "enumerate" + line = line[line.find(" ")+1:] + lines.append("@item") + elif re.match("^[*-] ", line): + if not inlist: + lines.append("@itemize %s" % {'*': "@bullet", + '-': "@minus"}[line[0]]) + inlist = "itemize" + lines.append("@item") + line = line[2:] + elif lastempty and inlist: + lines.append("@end %s\n" % inlist) + inlist = "" + + lastempty = empty + lines.append(line) + + if inlist: + lines.append("@end %s\n" % inlist) + return "\n".join(lines) + + +def texi_body(doc): + """ + Format the body of a symbol documentation: + - main body + - table of arguments + - followed by "Returns/Notes/Since/Example" sections + """ + body = texi_format(str(doc.body)) + "\n" + if doc.args: + body += "@table @asis\n" + for arg, section in doc.args.iteritems(): + desc = str(section) + opt = '' + if "#optional" in desc: + desc = desc.replace("#optional", "") + opt = ' (optional)' + body += "@item @code{'%s'}%s\n%s\n" % (arg, opt,
scripts/qapi2texi.py line 158
Quoted 10 lines
scripts/qapi2texi.py new file +10
-0+ texi_format(desc)) + body += "@end table\n" + + for section in doc.sections: + name, doc = (section.name, str(section)) + func = texi_format + if name.startswith("Example"): + func = texi_example + + if name:
@quotation produces confusing .txt and .html output, as discussed in review of v6. Either drop it, or record the problem in a comment, e.g.
# FIXME the indentation produced by @quotation in .txt and # .html output is confusing
Quoted 13 lines
scripts/qapi2texi.py new file +13
-0+ body += "\n@quotation %s\n%s\n@end quotation" % \ + (name, func(doc)) + else: + body += func(doc) + + return body + + +def texi_alternate(expr, doc): + """Format an alternate to texi""" + body = texi_body(doc) + return STRUCT_FMT(type="Alternate", + name=doc.symbol,
scripts/qapi2texi.py line 181
Quoted 10 lines
scripts/qapi2texi.py new file +10
-0+ body=body) + + +def texi_union(expr, doc): + """Format a union to texi""" + discriminator = expr.get("discriminator") + if discriminator: + union = "Flat Union" + else: + union = "Simple Union"
Not sure flat vs. simple matters for users of generated documentation, but let's not worry about that now.
Quoted 160 lines
scripts/qapi2texi.py new file +85
-0+ + body = texi_body(doc) + return STRUCT_FMT(type=union, + name=doc.symbol, + body=body) + + +def texi_enum(expr, doc): + """Format an enum to texi""" + for i in expr['data']: + if i not in doc.args: + doc.args[i] = '' + body = texi_body(doc) + return ENUM_FMT(name=doc.symbol, + body=body) + + +def texi_struct(expr, doc): + """Format a struct to texi""" + body = texi_body(doc) + return STRUCT_FMT(type="Struct", + name=doc.symbol, + body=body) + + +def texi_command(expr, doc): + """Format a command to texi""" + body = texi_body(doc) + return COMMAND_FMT(type="Command", + name=doc.symbol, + body=body) + + +def texi_event(expr, doc): + """Format an event to texi""" + body = texi_body(doc) + return COMMAND_FMT(type="Event", + name=doc.symbol, + body=body) + + +def texi_expr(expr, doc): + """Format an expr to texi""" + (kind, _) = expr.items()[0] + + fmt = {"command": texi_command, + "struct": texi_struct, + "enum": texi_enum, + "union": texi_union, + "alternate": texi_alternate, + "event": texi_event}[kind] + + return fmt(expr, doc) + + +def texi(docs): + """Convert QAPI schema expressions to texi documentation""" + res = [] + for doc in docs: + expr = doc.expr + if not expr: + res.append(texi_body(doc)) + continue + try: + doc = texi_expr(expr, doc) + res.append(doc) + except: + print >>sys.stderr, "error at @%s" % doc.info + raise + + return '\n'.join(res) + + +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) + + schema = qapi.QAPISchema(argv[1]) + print texi(schema.docs) + + +if __name__ == "__main__": + main(sys.argv)docs/qapi-code-gen.txt +33
-33@@ -44,40 +44,148 @@ 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. + +=== Comments === + Comments are allowed; anything between an unquoted # and the following -newline is ignored. Although there is not yet a documentation -generator, a form of stylized comments has developed for consistently -documenting details about an expression and when it was added to the -schema. The documentation is delimited between two lines of ##, then -the first line names the expression, an optional overview is provided, -then individual documentation about each member of 'data' is provided, -and finally, a 'Since: x.y.z' tag lists the release that introduced -the expression. Optional members are tagged with the phrase -'#optional', often with their default value; and extensions added -after the expression was first released are also given a '(since -x.y.z)' comment. For example: - - ## - # @BlockStats: - # - # Statistics of a virtual block device or a block backing device. - # - # @device: #optional If the stats are for a virtual block device, the name - # corresponding to the virtual block device. - # - # @stats: A @BlockDeviceStats for the device. - # - # @parent: #optional This describes the file block device if it has one. - # - # @backing: #optional This describes the backing block device if it has one. - # (Since 2.0) - # - # Since: 0.14.0 - ## - { 'struct': 'BlockStats', - 'data': {'*device': 'str', 'stats': 'BlockDeviceStats', - '*parent': 'BlockStats', - '*backing': 'BlockStats'} } +newline is ignored. + +A multi-line comment that starts and ends with a '##' line is a +documentation comment. These are parsed by the documentation +generator, which recognizes certain markup detailed below. + + +==== Documentation markup ==== + +Comment text starting with '=' is a section title: + + # = Section title + +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 + # multiple lines + # * Second item + +You can also use '-' instead of '*'. +
docs/qapi-code-gen.txt Input must be ASCII (although QMP supports full Unicode strings, the · line 90
Quoted 10 lines
docs/qapi-code-gen.txt +10
-0+A decimal number followed by '.' starts a numbered list: + + # 1. First item, may span + # multiple lines + # 2. Second item + +The actual number doesn't matter. You could even use '*' instead of +'2.' for the second item. + +FIXME what exactly ends a list
Can you say offhand what ends a list? If yes, can we resolve this FIXME now rather than later?
Quoted 26 lines
docs/qapi-code-gen.txt +26
-0+ +Additional whitespace between the initial '#' and the comment text is +permitted. + +*foo* and _foo_ are for strong and emphasis styles respectively (they +do not work over multiple lines). @foo is used to reference a name in +the schema. + +Example: + +## +# = Section +# == Subsection +# +# Some text foo with *strong* and _emphasis_ +# 1. with a list +# 2. like that +# +# And some code: +# | $ echo foo +# | -> do this +# | <- get that +# +## + +
docs/qapi-code-gen.txt Input must be ASCII (although QMP supports full Unicode strings, the · line 126
Quoted 10 lines
docs/qapi-code-gen.txt +10
-0+==== Expression documentation ==== + +Each expression that isn't an include directive must be preceded by a +documentation block. Such blocks are called expression documentation +blocks. + +The first line of the documentation names the expression, then the +documentation body is provided, then individual documentation about +each member of 'data' is provided. Finally, several tagged sections +can be added.
In my review of v6, I wrote:
I'm afraid this is more aspiration than specification: the parser accepts these things in almost any order.
Could be filed under "deficiencies" for now.
To file under "deficiencies", we need to add a FIXME or TODO either here, or in the parser. Assuming you haven't tightened the parser meanwhile (hope you haven't; we need to control the churn).
Member of 'data' won't remain accurate. Consider:
{ 'union': 'GlusterServer',
'base': { 'type': 'GlusterTransport' }, 'discriminator': 'type',
'data': { 'unix': 'UnixSocketAddress',
'tcp': 'InetSocketAddress' } }
Its doc comment currently doesn't contain argument sections. It should eventually contain @type:, @unix: and @tcp:. Only the latter two are members of 'data'.
I should propose something better, but I'm getting perilously close to the christmas break already. Later.
Also: passive voice is meh (not your idea; you adapted the existing text).
What about:
The documentation block consists of a first line naming the expression, an optional overview, a description of each argument (for commands and events) or member (for structs, unions and alternates), and optional tagged sections.
I still don't like the use of "section" for both the = things and the tagged sections, but it's not important enough to spend time on it now.
docs/qapi-code-gen.txt Input must be ASCII (although QMP supports full Unicode strings, the · line 128
Quoted 2 lines
docs/qapi-code-gen.txt +2
-0+ +Optional members are tagged with the phrase '#optional', often with
If we adopt my text, we should say "arguments / members" here.
docs/qapi-code-gen.txt Input must be ASCII (although QMP supports full Unicode strings, the · line 133
Quoted 5 lines
docs/qapi-code-gen.txt +5
-0+their default value; and extensions added after the expression was +first released are also given a '(since x.y.z)' comment. + +A tagged section starts with one of the following words: +"Note:"/"Notes:", "Since:", "Example"/"Examples", "Returns:", "TODO:".
What ends such a section? The start of the next one / end of the comment block?
I suspect we could avoid PATCH 03 by recognizing "TODO" in addition to "TODO:". Might also be more robust. But let's ignore this now.
docs/qapi-code-gen.txt Input must be ASCII (although QMP supports full Unicode strings, the · line 135
Quoted 2 lines
docs/qapi-code-gen.txt +2
-0+ +A 'Since: x.y.z' tag lists the release that introduced the expression.
Nitpick: 'Since: x.y.z' is a tagged section, not a tag.
Quoted 46 lines
docs/qapi-code-gen.txt +46
-0+ +For example: + +## +# @BlockStats: +# +# Statistics of a virtual block device or a block backing device. +# +# @device: #optional If the stats are for a virtual block device, the name +# corresponding to the virtual block device. +# +# @node-name: #optional The node name of the device. (since 2.3) +# +# ... more members ... +# +# Since: 0.14.0 +## +{ 'struct': 'BlockStats', + 'data': {'*device': 'str', '*node-name': 'str', + ... more members ... } } + +## +# @query-blockstats: +# +# Query the @BlockStats for all virtual block devices. +# +# @query-nodes: #optional If true, the command will query all the +# block nodes ... explain, explain ... (since 2.3) +# +# Returns: A list of @BlockStats for each virtual block devices. +# +# Since: 0.14.0 +# +# Example: +# +# -> { "execute": "query-blockstats" } +# <- { +# ... lots of output ... +# } +# +## +{ 'command': 'query-blockstats', + 'data': { '*query-nodes': 'bool' }, + 'returns': ['BlockStats'] } + +==== Free-form documentation ====
docs/qapi-code-gen.txt Input must be ASCII (although QMP supports full Unicode strings, the · line 191
Quoted 10 lines
docs/qapi-code-gen.txt +7
-0+ +A documentation block that isn't an expression documentation block is +a free-form documentation block. These may be used to provide +additional text and structuring content. + + +=== Schema overview === The schema sets up a series of types, as well as commands and events that will use those types. Forward references are allowed: the parser
[Tests look okay, snipped...]
Re: [Qemu-devel] [PATCH v7 15/21] qapi: add qapi2texi script
Hi
----- Original Message -----
Quoted 67 lines
Quoted 65 lines · Marc-André Lureau
As the name suggests, the qapi2texi script converts JSON QAPI description into a texi file suitable for different target formats (info/man/txt/pdf/html...).
It parses the following kind of blocks:
Free-form:
##
# = Section
# == Subsection
#
# Some text foo with *emphasis*
# 1. with a list
# 2. like that
#
# And some code:# | $ echo foo # | -> do this # | <- get that#
##Symbol description:
##
# @symbol:
#
# Symbol body ditto ergo sum. Foo bar# baz ding. # # @param1: the frob to frobnicate # @param2: #optional how hard to frobnicate # # Returns: the frobnicated frob. # If frob isn't frobnicatable, GenericError. # # Since: version # Notes: notes, comments can have # - itemized list # - like this # # Example: # # -> { "execute": "quit" } # <- { "return": {} } # ##That's roughly following the following EBNF grammar:
api_comment= "##\n" comment "##\n"
comment =freeform_comment|symbol_commentfreeform_comment= { "# " text "\n" | "#\n" }symbol_comment= "# @" name ":\n" { member |tag_section|freeform_comment}
member = "# @" name ':' [ text ] "\n"freeform_commenttag_section= "# " ( "Returns:", "Since:", "Note:", "Notes:", "Example:", "Examples:" ) [ text ] "\n"freeform_comment
text = free text with markupNote that the grammar is ambiguous: a line "# @foo:\n" can be parsed both as
freeform_commentand assymbol_comment. The actual parser recognizessymbol_comment.
Quoted 5 lines
Quoted 3 lines
See
docs/qapi-code-gen.txtfor more details.Deficiencies:
Perhaps "Deficiencies and limitations".
ok
Quoted 4 lines
Quoted 3 lines
- the generated QMP documentation includes internal types
- union-type support is lacking
Quoted 9 lines
"union type" (no dash).
Quoted 4 lines
- type information is lacking in generated documentation
- doc comment error message positions are imprecise, they point to the beginning of the comment.
- see other TODO/FIXME in this commitSuggest: - a few minor issues, all marked TODO/FIXME in the code
ok
Quoted 114 lines
Quoted 3 lines
Signed-off-by Marc-André Lureau <[email protected]>---
[diffstat snipped...]
Quoted 103 lines
scripts/qapi.py +62
-0@@ -125,6 +125,122 @@ class QAPISemError(QAPIError): info['parent'], msg) +class QAPIDoc(object): + class Section(object): + def __init__(self, name=None): + # optional section name (argument/member or section name) + self.name = name + # the list of lines for this section + self.content = [] + + def append(self, line): + self.content.append(line) + + def __repr__(self): + return "\n".join(self.content).strip() + + class ArgSection(Section): + pass + + def __init__(self, parser, info): + # self.parser is used to report errors with QAPIParseError. The + # resulting error position depends on the state of the parser. + # It happens to be the beginning of the comment. More or less + # servicable, but action at a distance. + self.parser = parser + self.info = info + self.symbol = None + self.body = QAPIDoc.Section() + # dict mapping parameter name to ArgSection + self.args = OrderedDict() + # a list of Section + self.sections = [] + # the current section + self.section = self.body + # associated expression (to be set by expression parser) + self.expr = None + + def has_section(self, name): + """Return True if we have a section with this name.""" + for i in self.sections: + if i.name == name: + return True + return False + + def append(self, line): + """Parse a comment line and add it to the documentation.""" + line = line[1:] + if not line: + self._append_freeform(line) + return + + if line[0] != ' ': + raise QAPIParseError(self.parser, "Missing space after #") + line = line[1:] + + # FIXME not nice: things like '# @foo:' and '# @foo: ' aren't + # recognized, and get silently treated as ordinary text + if self.symbol: + self._append_symbol_line(line) + elif not self.body.content and line.startswith("@"): + if not line.endswith(":"): + raise QAPIParseError(self.parser, "Line should end with :") + self.symbol = line[1:-1] + # FIXME invalid names other than the empty string aren'tflagged
scripts/qapi.py +31
-0+ if not self.symbol: + raise QAPIParseError(self.parser, "Invalid name") + else: + self._append_freeform(line) + + def _append_symbol_line(self, line): + name = line.split(' ', 1)[0] + + if name.startswith("@") and name.endswith(":"): + line = line[len(name)+1:] + self._start_args_section(name[1:-1]) + elif name in ("Returns:", "Since:", + # those are often singular or plural + "Note:", "Notes:", + "Example:", "Examples:", + "TODO:"): + line = line[len(name)+1:] + self._start_section(name[:-1]) + + self._append_freeform(line) + + def _start_args_section(self, name): + # FIXME invalid names other than the empty string aren't flagged + if not name: + raise QAPIParseError(self.parser, "Invalid parameter name") + if name in self.args: + raise QAPIParseError(self.parser, + "'%s' parameter name duplicated" % name) + if self.sections: + raise QAPIParseError(self.parser, + "'%s' parameter documentation isQuoted 2 lines
interleaved "
+ "with other sections" % name)This error message is rather confusing. Ideally, we'd point to the the source code that made us add to self.sections, but that's not in the cards right now. Here's my best try:
Quoted 4 lines
raise QAPIParseError(self.parser,
"'@%s:' can't follow '%s' section"
% (name, self.sections[0].name))works for me too
Quoted 20 lines
scripts/qapi.py class QAPISemError(QAPIError): · line 225
Quoted 4 lines
scripts/qapi.py +4
-0+ self.section = QAPIDoc.ArgSection(name) + self.args[name] = self.section + + def _start_section(self, name=""):Note: @name changed to default to "" since v6 for the benefit of
_append_freeform()below.scripts/qapi.py class QAPISemError(QAPIError): · line 236
Quoted 11 lines
scripts/qapi.py +11
-0+ if name in ("Returns", "Since") and self.has_section(name): + raise QAPIParseError(self.parser, + "Duplicated '%s' section" % name) + self.section = QAPIDoc.Section(name) + self.sections.append(self.section) + + def _append_freeform(self, line): + in_arg = isinstance(self.section, QAPIDoc.ArgSection) + if (in_arg and self.section.content and + not self.section.content[-1] and + line and not line[0].isspace()):
Quoted 1 line
PEP8 recommends breaking lines before operators in new code.
ok
Quoted 11 lines
Quoted 2 lines
+
self._start_section()Changed from v6's
raise
QAPIParseError(self.parser, "Invalid section indentation")May well be an improvement (I'm certainly no fan of this error myself), but it throws my review off the fast track: now I have to figure out how the new code works. Can you give me a hint on what this change does?
In v6, we rejected unindented sections after arguments (see tests/qapi-schema/doc-bad-section.json):
# @arg: blah bla
# zing bar
#
# This should be rejected
And a patch in v6 reordered the json comments. But you asked for the doc to not be reordered without careful review (both source and output). So those additional paragraphs are added as untitled sections, and the doc generator keep section order. The output will be in the same order as the source.
Quoted 2 lines
Or should we take a shortcut and revert to v6 here? We can always improve on top.
Probably not needed to revert.
Quoted 5 lines
scripts/qapi.py class QAPISemError(QAPIError): · line 239
Quoted 3 lines
scripts/qapi.py +2
-0+ if (in_arg or not self.section.name or + not self.section.name.startswith("Example")):Again, break before the operator.
ok
Quoted 40 lines
Quoted 40 lines
scripts/qapi.py +12
-0+ line = line.strip() + self.section.append(line) + + class QAPISchemaParser(object): def __init__(self, fp, previously_included=[], incl_info=None):@@ -140,11 +256,17 @@ class QAPISchemaParser(object): self.line = 1 self.line_pos = 0 self.exprs = [] + self.docs = [] self.accept() while self.tok is not None: info = {'file': fname, 'line': self.line, 'parent': self.incl_info} + if self.tok == '#': + doc = self.get_doc(info) + self.docs.append(doc) + continue + expr = self.get_expr(False) if isinstance(expr, dict) and "include" in expr: if len(expr) != 1:@@ -162,6 +284,7 @@ class QAPISchemaParser(object): raise QAPISemError(info, "Inclusion loop for %s" % include) inf = inf['parent'] + # skip multiple include of the same file if incl_abs_fname in previously_included: continue@@ -172,12 +295,19 @@ class QAPISchemaParser(object): exprs_include = QAPISchemaParser(fobj, previously_included, info) self.exprs.extend(exprs_include.exprs) + self.docs.extend(exprs_include.docs)
Quoted 8 lines
scripts/qapi.py class QAPISchemaParser(object): · line 304
Quoted 6 lines
scripts/qapi.py +3
-0else: expr_elem = {'expr': expr, 'info': info} + if (self.docs and + self.docs[-1].info['file'] == fname and + not self.docs[-1].expr):Again, break before the operator.
ok
Quoted 106 lines
Quoted 15 lines
scripts/qapi.py +4
-1+ self.docs[-1].expr = expr + expr_elem['doc'] = self.docs[-1] + self.exprs.append(expr_elem) - def accept(self): + def accept(self, skip_comment=True): while True: self.tok = self.src[self.cursor]self.pos = self.cursor
scripts/qapi.py +0
-0@@ -185,7 +315,13 @@ class QAPISchemaParser(object): self.val = None if self.tok == '#':scripts/qapi.py class QAPISchemaParser(object): · line 327
Quoted 10 lines
scripts/qapi.py +6
-0+ if self.src[self.cursor] == '#': + # Start of doc comment + skip_comment = False self.cursor = self.src.find('\n', self.cursor) + if not skip_comment: + self.val = self.src[self.pos:self.cursor] + return elif self.tok in "{}:,[]": return elif self.tok == "'":Copied from review of v3, so I don't forget:
Comment tokens are thrown away as before, except when the parser asks for them by passing skip_comment=False, or when the comment token starts with ##. The parser asks while parsing a doc comment, in
get_doc().This is a backchannel from the parser to the lexer. I'd rather avoid such lexer hacks, but I guess we can address that on top.
A comment starting with ## inside an expression is now a syntax error. For instance, input
{ ##yields
/dev/stdin:2:1: Expected string or "}"Rather unfriendly error message, but we can fix that on top.
Quoted 59 lines
scripts/qapi.py +12
-0@@ -319,6 +455,28 @@ class QAPISchemaParser(object): raise QAPIParseError(self, 'Expected "{", "[" or string') return expr + def get_doc(self, info): + if self.val != '##': + raise QAPIParseError(self, "Junk after '##' at start of " + "documentation comment") + + doc = QAPIDoc(self, info) + self.accept(False) + while self.tok == '#': + if self.val.startswith('##'): + # End of doc comment + if self.val != '##': + raise QAPIParseError(self, "Junk after '##' at end of"
scripts/qapi.py +8
-0+ "documentation comment") + self.accept() + return doc + else: + doc.append(self.val) + self.accept(False) + + raise QAPIParseError(self, "Documentation comment must end with'##'")
scripts/qapi.py +17
-0+ + # # Semantic analysis of schema expressions # TODO fold into QAPISchema@@ -703,6 +861,11 @@ def check_exprs(exprs): for expr_elem in exprs: expr = expr_elem['expr'] info = expr_elem['info'] + + if 'doc' not in expr_elem: + raise QAPISemError(info, + "Expression missing documentation comment") + if 'enum' in expr: check_keys(expr_elem, 'enum', ['data'], ['prefix']) add_enum(expr['enum'], info, expr['data'])@@ -761,6 +924,84 @@ def check_exprs(exprs): return exprs +def check_freeform_doc(doc): + if doc.symbol: + raise QAPISemError(doc.info, + "Documention for '%s' is not followed" + " by the definition" % doc.symbol) + + body = str(doc.body) + if re.search(r'@\S+:', body, re.MULTILINE): + raise QAPISemError(doc.info, + "Free-form documentation block must notcontain"
+ " @NAME: sections")
Quoted 9 lines
scripts/qapi.py def check_exprs(exprs): · line 940
Quoted 3 lines
scripts/qapi.py +3
-0+ + +def check_definition_doc(doc, expr, info):Lots of churn in this function. It can certainly use improvement, as pointed out in prior reviews, but it triggers still more review. Based on the tests, I guess it's for finding documented parameters that don't actually exist, and to diagnose optional mismatch. Anything else?
implicitely adds #optional (since it's no longer in type info, it better be in the description), code simplification, message improvement too.
I'd rather keep this too, and improve on top.
Quoted 211 lines
Or should we take a shortcut and revert to v6 here? We can always improve on top. I think v6 would need a # TODO Should ensure #optional matches the schema.
scripts/qapi.py def check_exprs(exprs): · line 951
Quoted 12 lines
scripts/qapi.py +8
-0+ for i in ('enum', 'union', 'alternate', 'struct', 'command', 'event'): + if i in expr: + meta = i + break + + name = expr[meta] + if doc.symbol != name: + raise QAPISemError(info, "Definition of '%s' followsdocumentation"
scripts/qapi.py +3
-0+ " for '%s'" % (name, doc.symbol)) + if doc.has_section('Returns') and 'command' not in expr: + raise QAPISemError(info, "'Returns:' is only valid for commands")Copied from review of v5, so I don't forget:
We accept 'Returns:' even when the command doesn't return anything, because we currently use it to document errors, too. Can't say I like that, but it's out of scope here.
Quoted 34 lines
scripts/qapi.py +34
-0+ + if meta == 'union': + args = expr.get('base', []) + else: + args = expr.get('data', []) + if isinstance(args, dict): + args = args.keys() + + if meta == 'alternate' or \ + (meta == 'union' and not expr.get('discriminator')): + args.append('type') + + if isinstance(args, list): + for arg in args: + if arg[0] == '*': + opt = True + desc = doc.args.get(arg[1:]) + else: + opt = False + desc = doc.args.get(arg) + if not desc: + continue + desc_opt = "#optional" in str(desc) + if desc_opt and not opt: + raise QAPISemError(info, "Description has #optional, " + "but the declaration doesn't") + if not desc_opt and opt: + # silently fix the doc + desc.append("#optional") + + doc_args = set(doc.args.keys()) + args = set([name.strip('*') for name in args]) + if not doc_args.issubset(args): + raise QAPISemError(info, "The following documented members are notQuoted 3 lines
in "
+ "the declaration: %s" % ", ".join(doc_args -
args))Copied from review of v5, so I don't forget:
As explained in review of v3, this is only a subset of the real set of members. Computing the exact set is impractical when working with the abstract syntax tree. I believe we'll eventually have to rewrite this code to work with the QAPISchemaEntity instead.
Quoted 143 lines
scripts/qapi.py +9
-0+ + +def check_docs(docs): + for doc in docs: + for section in doc.args.values() + doc.sections: + content = str(section) + if not content or content.isspace(): + raise QAPISemError(doc.info, + "Empty doc section '%s'" %section.name)
scripts/qapi.py +12
-1+ + if not doc.expr: + check_freeform_doc(doc) + else: + check_definition_doc(doc, doc.expr, doc.info) + + return docs + + # # Schema compiler frontend #@@ -1229,7 +1470,9 @@ class QAPISchemaEvent(QAPISchemaEntity): class QAPISchema(object): def __init__(self, fname): try: - self.exprs = check_exprs(QAPISchemaParser(open(fname, "r")).exprs) + parser = QAPISchemaParser(open(fname, "r")) + self.exprs = check_exprs(parser.exprs) + self.docs = check_docs(parser.docs) self._entity_dict = {} self._predefining = True
self._def_predefineds()scripts/qapi2texi.py new file +6
-0@@ -0,0 +1,266 @@ +#!/usr/bin/env python +# QAPI texi generator +# +# 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 texinfoformat"""
scripts/qapi2texi.py new file +63
-0+import re +import sys + +import qapi + +COMMAND_FMT = """ +@deftypefn {type} {{}} {name} + +{body} + +@end deftypefn + +""".format + +ENUM_FMT = """ +@deftp Enum {name} + +{body} + +@end deftp + +""".format + +STRUCT_FMT = """ +@deftp {{{type}}} {name} + +{body} + +@end deftp + +""".format + +EXAMPLE_FMT = """@example +{code} +@end example +""".format + + +def subst_strong(doc): + """Replaces *foo* by @strong{foo}""" + return re.sub(r'\*([^*\n]+)\*', r'@emph{\1}', doc) + + +def subst_emph(doc): + """Replaces _foo_ by @emph{foo}""" + 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 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
scripts/qapi2texi.py new file +32
-0+ # need to delay it until after subst_vars() in texi_format(). + doc = subst_braces(doc).strip('\n') + return EXAMPLE_FMT(code=doc) + + +def texi_format(doc): + """ + Format documentation + + Lines starting with: + - |: generates an @example + - =: generates @section + - ==: generates @subsection + - 1. or 1): generates an @enumerate @item + - */-: generates an @itemize list + """ + lines = [] + doc = subst_braces(doc) + doc = subst_vars(doc) + doc = subst_emph(doc) + doc = subst_strong(doc) + inlist = "" + lastempty = False + for line in doc.split('\n'): + empty = 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), + # but a line with some *other* markup, such as a = title + # doesn't. + if line.startswith("| "):
Quoted 8 lines
scripts/qapi2texi.py line 107
Quoted 6 lines
scripts/qapi2texi.py new file +6
-0+ line = EXAMPLE_FMT(code=line[2:]) + elif line.startswith("= "): + line = "@section " + line[2:] + elif line.startswith("== "): + line = "@subsection " + line[3:] + elif re.match("^([0-9]*[.]) ", line):[.] is an unusual way to say \.
Right, forgot to change that when removing ) from v6.
Quoted 4 lines
Perhaps we should consistently use r"..." for strings used as regular expressions.
No idea, could be changed on top.
Quoted 55 lines
Quoted 41 lines
scripts/qapi2texi.py new file +41
-0+ if not inlist: + lines.append("@enumerate") + inlist = "enumerate" + line = line[line.find(" ")+1:] + lines.append("@item") + elif re.match("^[*-] ", line): + if not inlist: + lines.append("@itemize %s" % {'*': "@bullet", + '-': "@minus"}[line[0]]) + inlist = "itemize" + lines.append("@item") + line = line[2:] + elif lastempty and inlist: + lines.append("@end %s\n" % inlist) + inlist = "" + + lastempty = empty + lines.append(line) + + if inlist: + lines.append("@end %s\n" % inlist) + return "\n".join(lines) + + +def texi_body(doc): + """ + Format the body of a symbol documentation: + - main body + - table of arguments + - followed by "Returns/Notes/Since/Example" sections + """ + body = texi_format(str(doc.body)) + "\n" + if doc.args: + body += "@table @asis\n" + for arg, section in doc.args.iteritems(): + desc = str(section) + opt = '' + if "#optional" in desc: + desc = desc.replace("#optional", "") + opt = ' (optional)' + body += "@item @code{'%s'}%s\n%s\n" % (arg, opt,scripts/qapi2texi.py line 158
Quoted 10 lines
scripts/qapi2texi.py new file +10
-0+ texi_format(desc)) + body += "@end table\n" + + for section in doc.sections: + name, doc = (section.name, str(section)) + func = texi_format + if name.startswith("Example"): + func = texi_example + + if name:@quotation produces confusing .txt and .html output, as discussed in review of v6. Either drop it, or record the problem in a comment, e.g.
Quoted 3 lines
# FIXME the indentation produced by @quotation in .txt and # .html output is confusing
added
Quoted 197 lines
Quoted 13 lines
scripts/qapi2texi.py new file +13
-0+ body += "\n@quotation %s\n%s\n@end quotation" % \ + (name, func(doc)) + else: + body += func(doc) + + return body + + +def texi_alternate(expr, doc): + """Format an alternate to texi""" + body = texi_body(doc) + return STRUCT_FMT(type="Alternate", + name=doc.symbol,scripts/qapi2texi.py line 181
Quoted 10 lines
scripts/qapi2texi.py new file +10
-0+ body=body) + + +def texi_union(expr, doc): + """Format a union to texi""" + discriminator = expr.get("discriminator") + if discriminator: + union = "Flat Union" + else: + union = "Simple Union"Not sure flat vs. simple matters for users of generated documentation, but let's not worry about that now.
Quoted 170 lines
scripts/qapi2texi.py new file +77
-0+ + body = texi_body(doc) + return STRUCT_FMT(type=union, + name=doc.symbol, + body=body) + + +def texi_enum(expr, doc): + """Format an enum to texi""" + for i in expr['data']: + if i not in doc.args: + doc.args[i] = '' + body = texi_body(doc) + return ENUM_FMT(name=doc.symbol, + body=body) + + +def texi_struct(expr, doc): + """Format a struct to texi""" + body = texi_body(doc) + return STRUCT_FMT(type="Struct", + name=doc.symbol, + body=body) + + +def texi_command(expr, doc): + """Format a command to texi""" + body = texi_body(doc) + return COMMAND_FMT(type="Command", + name=doc.symbol, + body=body) + + +def texi_event(expr, doc): + """Format an event to texi""" + body = texi_body(doc) + return COMMAND_FMT(type="Event", + name=doc.symbol, + body=body) + + +def texi_expr(expr, doc): + """Format an expr to texi""" + (kind, _) = expr.items()[0] + + fmt = {"command": texi_command, + "struct": texi_struct, + "enum": texi_enum, + "union": texi_union, + "alternate": texi_alternate, + "event": texi_event}[kind] + + return fmt(expr, doc) + + +def texi(docs): + """Convert QAPI schema expressions to texi documentation""" + res = [] + for doc in docs: + expr = doc.expr + if not expr: + res.append(texi_body(doc)) + continue + try: + doc = texi_expr(expr, doc) + res.append(doc) + except: + print >>sys.stderr, "error at @%s" % doc.info + raise + + return '\n'.join(res) + + +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]
scripts/qapi2texi.py new file +8
-0+ sys.exit(1) + + schema = qapi.QAPISchema(argv[1]) + print texi(schema.docs) + + +if __name__ == "__main__": + main(sys.argv)docs/qapi-code-gen.txt +0
-0@@ -44,40 +44,148 @@ Input must be ASCII (although QMP supports fullUnicode strings, the
QAPI parser does not). At present, there is no place where a QAPI schema requires the use of JSON numbers or null.docs/qapi-code-gen.txt +3
-18+ +=== Comments === + Comments are allowed; anything between an unquoted # and the following -newline is ignored. Although there is not yet a documentation -generator, a form of stylized comments has developed for consistently -documenting details about an expression and when it was added to the -schema. The documentation is delimited between two lines of ##, then -the first line names the expression, an optional overview is provided, -then individual documentation about each member of 'data' is provided, -and finally, a 'Since: x.y.z' tag lists the release that introduced -the expression. Optional members are tagged with the phrase -'#optional', often with their default value; and extensions added -after the expression was first released are also given a '(since -x.y.z)' comment. For example: - - ## - # @BlockStats: - # - # Statistics of a virtual block device or a block backing device. - # - # @device: #optional If the stats are for a virtual block device, thename
docs/qapi-code-gen.txt +0
-5- # corresponding to the virtual block device. - # - # @stats: A @BlockDeviceStats for the device. - # - # @parent: #optional This describes the file block device if it hasone.
docs/qapi-code-gen.txt +0
-2- # - # @backing: #optional This describes the backing block device if ithas one.
docs/qapi-code-gen.txt +35
-8- # (Since 2.0) - # - # Since: 0.14.0 - ## - { 'struct': 'BlockStats', - 'data': {'*device': 'str', 'stats': 'BlockDeviceStats', - '*parent': 'BlockStats', - '*backing': 'BlockStats'} } +newline is ignored. + +A multi-line comment that starts and ends with a '##' line is a +documentation comment. These are parsed by the documentation +generator, which recognizes certain markup detailed below. + + +==== Documentation markup ==== + +Comment text starting with '=' is a section title: + + # = Section title + +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 + # multiple lines + # * Second item + +You can also use '-' instead of '*'. + +A decimal number followed by '.' starts a numbered list: + + # 1. First item, may span + # multiple lines + # 2. Second item
Quoted 8 lines
docs/qapi-code-gen.txt Input must be ASCII (although QMP supports full Unicode strings, the · line 90
Quoted 5 lines
docs/qapi-code-gen.txt +5
-0+ +The actual number doesn't matter. You could even use '*' instead of +'2.' for the second item. + +FIXME what exactly ends a listCan you say offhand what ends a list? If yes, can we resolve this FIXME now rather than later?
well, the code is too permissive, there is a FIXME there already.
In general, I think we want to end a list after a blank line and a "non-item" line. Is the wording ok?
Quoted 40 lines
Quoted 27 lines
docs/qapi-code-gen.txt +26
-0+ +Additional whitespace between the initial '#' and the comment text is +permitted. + +*foo* and _foo_ are for strong and emphasis styles respectively (they +do not work over multiple lines). @foo is used to reference a name in +the schema. + +Example: + +## +# = Section +# == Subsection +# +# Some text foo with *strong* and _emphasis_ +# 1. with a list +# 2. like that +# +# And some code: +# | $ echo foo +# | -> do this +# | <- get that +# +## + +docs/qapi-code-gen.txt Input must be ASCII (although QMP supports full Unicode strings, the · line 126
Quoted 10 lines
docs/qapi-code-gen.txt +10
-0+==== Expression documentation ==== + +Each expression that isn't an include directive must be preceded by a +documentation block. Such blocks are called expression documentation +blocks. + +The first line of the documentation names the expression, then the +documentation body is provided, then individual documentation about +each member of 'data' is provided. Finally, several tagged sections +can be added.In my review of v6, I wrote:
Quoted 8 lines
I'm afraid this is more aspiration than specification: the parser accepts these things in almost any order.
Could be filed under "deficiencies" for now.
To file under "deficiencies", we need to add a FIXME or TODO either here, or in the parser. Assuming you haven't tightened the parser meanwhile (hope you haven't; we need to control the churn).
ok
Quoted 21 lines
Member of 'data' won't remain accurate. Consider:
{ 'union': 'GlusterServer',
'base': { 'type': 'GlusterTransport' }, 'discriminator': 'type',
'data': { 'unix': 'UnixSocketAddress',
'tcp': 'InetSocketAddress' } }Its doc comment currently doesn't contain argument sections. It should eventually contain @type:, @unix: and @tcp:. Only the latter two are members of 'data'.
I should propose something better, but I'm getting perilously close to the christmas break already. Later.
Also: passive voice is meh (not your idea; you adapted the existing text).
What about:
Quoted 8 lines
The documentation block consists of a first line naming the expression, an optional overview, a description of each argument (for commands and events) or member (for structs, unions and alternates), and optional tagged sections.
I still don't like the use of "section" for both the = things and the tagged sections, but it's not important enough to spend time on it now.
ok
Quoted 5 lines
docs/qapi-code-gen.txt Input must be ASCII (although QMP supports full Unicode strings, the · line 128
Quoted 2 lines
docs/qapi-code-gen.txt +2
-0+ +Optional members are tagged with the phrase '#optional', often withIf we adopt my text, we should say "arguments / members" here.
ok
Quoted 9 lines
docs/qapi-code-gen.txt Input must be ASCII (although QMP supports full Unicode strings, the · line 133
Quoted 5 lines
docs/qapi-code-gen.txt +5
-0+their default value; and extensions added after the expression was +first released are also given a '(since x.y.z)' comment. + +A tagged section starts with one of the following words: +"Note:"/"Notes:", "Since:", "Example"/"Examples", "Returns:", "TODO:".What ends such a section? The start of the next one / end of the comment block?
yes
Quoted 8 lines
I suspect we could avoid PATCH 03 by recognizing "TODO" in addition to "TODO:". Might also be more robust. But let's ignore this now.
docs/qapi-code-gen.txt Input must be ASCII (although QMP supports full Unicode strings, the · line 135
Quoted 2 lines
docs/qapi-code-gen.txt +2
-0+ +A 'Since: x.y.z' tag lists the release that introduced the expression.Nitpick: 'Since: x.y.z' is a tagged section, not a tag.
ok
Quoted 58 lines
Quoted 46 lines
docs/qapi-code-gen.txt +46
-0+ +For example: + +## +# @BlockStats: +# +# Statistics of a virtual block device or a block backing device. +# +# @device: #optional If the stats are for a virtual block device, the name +# corresponding to the virtual block device. +# +# @node-name: #optional The node name of the device. (since 2.3) +# +# ... more members ... +# +# Since: 0.14.0 +## +{ 'struct': 'BlockStats', + 'data': {'*device': 'str', '*node-name': 'str', + ... more members ... } } + +## +# @query-blockstats: +# +# Query the @BlockStats for all virtual block devices. +# +# @query-nodes: #optional If true, the command will query all the +# block nodes ... explain, explain ... (since 2.3) +# +# Returns: A list of @BlockStats for each virtual block devices. +# +# Since: 0.14.0 +# +# Example: +# +# -> { "execute": "query-blockstats" } +# <- { +# ... lots of output ... +# } +# +## +{ 'command': 'query-blockstats', + 'data': { '*query-nodes': 'bool' }, + 'returns': ['BlockStats'] } + +==== Free-form documentation ====docs/qapi-code-gen.txt Input must be ASCII (although QMP supports full Unicode strings, the · line 191
Quoted 10 lines
docs/qapi-code-gen.txt +7
-0+ +A documentation block that isn't an expression documentation block is +a free-form documentation block. These may be used to provide +additional text and structuring content. + + +=== Schema overview === The schema sets up a series of types, as well as commands and events that will use those types. Forward references are allowed: the parser[Tests look okay, snipped...]
Re: [Qemu-devel] [PATCH v7 15/21] qapi: add qapi2texi script
Quoted 258 lines · Marc-André Lureau
Hi
----- Original Message -----
Quoted 67 lines
Quoted 65 lines · Marc-André Lureau
As the name suggests, the qapi2texi script converts JSON QAPI description into a texi file suitable for different target formats (info/man/txt/pdf/html...).
It parses the following kind of blocks:
Free-form:
##
# = Section
# == Subsection
#
# Some text foo with *emphasis*
# 1. with a list
# 2. like that
#
# And some code:# | $ echo foo # | -> do this # | <- get that#
##Symbol description:
##
# @symbol:
#
# Symbol body ditto ergo sum. Foo bar# baz ding. # # @param1: the frob to frobnicate # @param2: #optional how hard to frobnicate # # Returns: the frobnicated frob. # If frob isn't frobnicatable, GenericError. # # Since: version # Notes: notes, comments can have # - itemized list # - like this # # Example: # # -> { "execute": "quit" } # <- { "return": {} } # ##That's roughly following the following EBNF grammar:
api_comment= "##\n" comment "##\n"
comment =freeform_comment|symbol_commentfreeform_comment= { "# " text "\n" | "#\n" }symbol_comment= "# @" name ":\n" { member |tag_section|freeform_comment}
member = "# @" name ':' [ text ] "\n"freeform_commenttag_section= "# " ( "Returns:", "Since:", "Note:", "Notes:", "Example:", "Examples:" ) [ text ] "\n"freeform_comment
text = free text with markupNote that the grammar is ambiguous: a line "# @foo:\n" can be parsed both as
freeform_commentand assymbol_comment. The actual parser recognizessymbol_comment.Quoted 5 lines
Quoted 3 lines
See
docs/qapi-code-gen.txtfor more details.Deficiencies:
Perhaps "Deficiencies and limitations".
ok
Quoted 4 lines
Quoted 3 lines
- the generated QMP documentation includes internal types
- union-type support is lackingQuoted 9 lines
"union type" (no dash).
Quoted 4 lines
- type information is lacking in generated documentation
- doc comment error message positions are imprecise, they point to the beginning of the comment.
- see other TODO/FIXME in this commitSuggest: - a few minor issues, all marked TODO/FIXME in the code
ok
Quoted 114 lines
Quoted 3 lines
Signed-off-by Marc-André Lureau <[email protected]>---
[diffstat snipped...]
Quoted 103 lines
scripts/qapi.py +62
-0@@ -125,6 +125,122 @@ class QAPISemError(QAPIError): info['parent'], msg) +class QAPIDoc(object): + class Section(object): + def __init__(self, name=None): + # optional section name (argument/member or section name) + self.name = name + # the list of lines for this section + self.content = [] + + def append(self, line): + self.content.append(line) + + def __repr__(self): + return "\n".join(self.content).strip() + + class ArgSection(Section): + pass + + def __init__(self, parser, info): + # self.parser is used to report errors with QAPIParseError. The + # resulting error position depends on the state of the parser. + # It happens to be the beginning of the comment. More or less + # servicable, but action at a distance. + self.parser = parser + self.info = info + self.symbol = None + self.body = QAPIDoc.Section() + # dict mapping parameter name to ArgSection + self.args = OrderedDict() + # a list of Section + self.sections = [] + # the current section + self.section = self.body + # associated expression (to be set by expression parser) + self.expr = None + + def has_section(self, name): + """Return True if we have a section with this name.""" + for i in self.sections: + if i.name == name: + return True + return False + + def append(self, line): + """Parse a comment line and add it to the documentation.""" + line = line[1:] + if not line: + self._append_freeform(line) + return + + if line[0] != ' ': + raise QAPIParseError(self.parser, "Missing space after #") + line = line[1:] + + # FIXME not nice: things like '# @foo:' and '# @foo: ' aren't + # recognized, and get silently treated as ordinary text + if self.symbol: + self._append_symbol_line(line) + elif not self.body.content and line.startswith("@"): + if not line.endswith(":"): + raise QAPIParseError(self.parser, "Line should end with :") + self.symbol = line[1:-1] + # FIXME invalid names other than the empty string aren'tflagged
scripts/qapi.py +31
-0+ if not self.symbol: + raise QAPIParseError(self.parser, "Invalid name") + else: + self._append_freeform(line) + + def _append_symbol_line(self, line): + name = line.split(' ', 1)[0] + + if name.startswith("@") and name.endswith(":"): + line = line[len(name)+1:] + self._start_args_section(name[1:-1]) + elif name in ("Returns:", "Since:", + # those are often singular or plural + "Note:", "Notes:", + "Example:", "Examples:", + "TODO:"): + line = line[len(name)+1:] + self._start_section(name[:-1]) + + self._append_freeform(line) + + def _start_args_section(self, name): + # FIXME invalid names other than the empty string aren't flagged + if not name: + raise QAPIParseError(self.parser, "Invalid parameter name") + if name in self.args: + raise QAPIParseError(self.parser, + "'%s' parameter name duplicated" % name) + if self.sections: + raise QAPIParseError(self.parser, + "'%s' parameter documentation isQuoted 2 lines
interleaved "
+ "with other sections" % name)This error message is rather confusing. Ideally, we'd point to the the source code that made us add to self.sections, but that's not in the cards right now. Here's my best try:
Quoted 4 lines
raise QAPIParseError(self.parser, "'@%s:' can't follow '%s' section" % (name, self.sections[0].name))works for me too
Quoted 20 lines
scripts/qapi.py class QAPISemError(QAPIError): · line 225
Quoted 4 lines
scripts/qapi.py +4
-0+ self.section = QAPIDoc.ArgSection(name) + self.args[name] = self.section + + def _start_section(self, name=""):Note: @name changed to default to "" since v6 for the benefit of
_append_freeform()below.scripts/qapi.py class QAPISemError(QAPIError): · line 236
Quoted 11 lines
scripts/qapi.py +11
-0+ if name in ("Returns", "Since") and self.has_section(name): + raise QAPIParseError(self.parser, + "Duplicated '%s' section" % name) + self.section = QAPIDoc.Section(name) + self.sections.append(self.section) + + def _append_freeform(self, line): + in_arg = isinstance(self.section, QAPIDoc.ArgSection) + if (in_arg and self.section.content and + not self.section.content[-1] and + line and not line[0].isspace()):Quoted 1 line
PEP8 recommends breaking lines before operators in new code.
ok
Quoted 11 lines
Quoted 2 lines
+
self._start_section()Changed from v6's
raise
QAPIParseError(self.parser, "Invalid section indentation")May well be an improvement (I'm certainly no fan of this error myself), but it throws my review off the fast track: now I have to figure out how the new code works. Can you give me a hint on what this change does?
In v6, we rejected unindented sections after arguments (see
tests/qapi-schema/doc-bad-section.json):# @arg: blah bla
# zing bar
#
# This should be rejected
Quoted 5 lines
And a patch in v6 reordered the json comments. But you asked for the doc to not be reordered without careful review (both source and output). So those additional paragraphs are added as untitled sections, and the doc generator keep section order. The output will be in the same order as the source.
Thanks.
Quoted 4 lines
Quoted 2 lines
Or should we take a shortcut and revert to v6 here? We can always improve on top.
Probably not needed to revert.
I played with it a bit, and it looks like it's working fine.
Quoted 174 lines
Quoted 4 lines
scripts/qapi.py class QAPISemError(QAPIError): · line 239
Quoted 2 lines
scripts/qapi.py +2
-0+ if (in_arg or not self.section.name or + not self.section.name.startswith("Example")):Again, break before the operator.
ok
Quoted 40 lines
Quoted 40 lines
scripts/qapi.py +12
-0+ line = line.strip() + self.section.append(line) + + class QAPISchemaParser(object): def __init__(self, fp, previously_included=[], incl_info=None):@@ -140,11 +256,17 @@ class QAPISchemaParser(object): self.line = 1 self.line_pos = 0 self.exprs = [] + self.docs = [] self.accept() while self.tok is not None: info = {'file': fname, 'line': self.line, 'parent': self.incl_info} + if self.tok == '#': + doc = self.get_doc(info) + self.docs.append(doc) + continue + expr = self.get_expr(False) if isinstance(expr, dict) and "include" in expr: if len(expr) != 1:@@ -162,6 +284,7 @@ class QAPISchemaParser(object): raise QAPISemError(info, "Inclusion loop for %s" % include) inf = inf['parent'] + # skip multiple include of the same file if incl_abs_fname in previously_included: continue@@ -172,12 +295,19 @@ class QAPISchemaParser(object): exprs_include = QAPISchemaParser(fobj, previously_included, info) self.exprs.extend(exprs_include.exprs) + self.docs.extend(exprs_include.docs)Quoted 8 lines
scripts/qapi.py class QAPISchemaParser(object): · line 304
Quoted 6 lines
scripts/qapi.py +3
-0else: expr_elem = {'expr': expr, 'info': info} + if (self.docs and + self.docs[-1].info['file'] == fname and + not self.docs[-1].expr):Again, break before the operator.
ok
Quoted 106 lines
Quoted 15 lines
scripts/qapi.py +4
-1+ self.docs[-1].expr = expr + expr_elem['doc'] = self.docs[-1] + self.exprs.append(expr_elem) - def accept(self): + def accept(self, skip_comment=True): while True: self.tok = self.src[self.cursor]self.pos = self.cursor
scripts/qapi.py +0
-0@@ -185,7 +315,13 @@ class QAPISchemaParser(object): self.val = None if self.tok == '#':scripts/qapi.py class QAPISchemaParser(object): · line 327
Quoted 10 lines
scripts/qapi.py +6
-0+ if self.src[self.cursor] == '#': + # Start of doc comment + skip_comment = False self.cursor = self.src.find('\n', self.cursor) + if not skip_comment: + self.val = self.src[self.pos:self.cursor] + return elif self.tok in "{}:,[]": return elif self.tok == "'":Copied from review of v3, so I don't forget:
Comment tokens are thrown away as before, except when the parser asks for them by passing skip_comment=False, or when the comment token starts with ##. The parser asks while parsing a doc comment, in
get_doc().This is a backchannel from the parser to the lexer. I'd rather avoid such lexer hacks, but I guess we can address that on top.
A comment starting with ## inside an expression is now a syntax error. For instance, input
{ ##yields
/dev/stdin:2:1: Expected string or "}"Rather unfriendly error message, but we can fix that on top.
Quoted 59 lines
scripts/qapi.py +12
-0@@ -319,6 +455,28 @@ class QAPISchemaParser(object): raise QAPIParseError(self, 'Expected "{", "[" or string') return expr + def get_doc(self, info): + if self.val != '##': + raise QAPIParseError(self, "Junk after '##' at start of " + "documentation comment") + + doc = QAPIDoc(self, info) + self.accept(False) + while self.tok == '#': + if self.val.startswith('##'): + # End of doc comment + if self.val != '##': + raise QAPIParseError(self, "Junk after '##' at end of"
scripts/qapi.py +8
-0+ "documentation comment") + self.accept() + return doc + else: + doc.append(self.val) + self.accept(False) + + raise QAPIParseError(self, "Documentation comment must end with'##'")
scripts/qapi.py +17
-0+ + # # Semantic analysis of schema expressions # TODO fold into QAPISchema@@ -703,6 +861,11 @@ def check_exprs(exprs): for expr_elem in exprs: expr = expr_elem['expr'] info = expr_elem['info'] + + if 'doc' not in expr_elem: + raise QAPISemError(info, + "Expression missing documentation comment") + if 'enum' in expr: check_keys(expr_elem, 'enum', ['data'], ['prefix']) add_enum(expr['enum'], info, expr['data'])@@ -761,6 +924,84 @@ def check_exprs(exprs): return exprs +def check_freeform_doc(doc): + if doc.symbol: + raise QAPISemError(doc.info, + "Documention for '%s' is not followed" + " by the definition" % doc.symbol) + + body = str(doc.body) + if re.search(r'@\S+:', body, re.MULTILINE): + raise QAPISemError(doc.info, + "Free-form documentation block must notcontain"
+ " @NAME: sections")Quoted 9 lines
scripts/qapi.py def check_exprs(exprs): · line 940
Quoted 3 lines
scripts/qapi.py +3
-0+ + +def check_definition_doc(doc, expr, info):Lots of churn in this function. It can certainly use improvement, as pointed out in prior reviews, but it triggers still more review. Based on the tests, I guess it's for finding documented parameters that don't actually exist, and to diagnose optional mismatch. Anything else?
Quoted 3 lines
implicitely adds #optional (since it's no longer in type info, it better be in the description), code simplification, message improvement too.
I'd rather keep this too, and improve on top.
Okay. Review below.
Quoted 19 lines
Quoted 19 lines
Or should we take a shortcut and revert to v6 here? We can always improve on top. I think v6 would need a # TODO Should ensure #optional matches the schema.
scripts/qapi.py def check_exprs(exprs): · line 951
Quoted 12 lines
scripts/qapi.py +8
-0+ for i in ('enum', 'union', 'alternate', 'struct', 'command', 'event'): + if i in expr: + meta = i + break + + name = expr[meta] + if doc.symbol != name: + raise QAPISemError(info, "Definition of '%s' followsdocumentation"
scripts/qapi.py +3
-0+ " for '%s'" % (name, doc.symbol)) + if doc.has_section('Returns') and 'command' not in expr: + raise QAPISemError(info, "'Returns:' is only valid for commands")Copied from review of v5, so I don't forget:
Quoted 7 lines
Quoted 7 lines
We accept 'Returns:' even when the command doesn't return anything, because we currently use it to document errors, too. Can't say I like that, but it's out of scope here.
Quoted 3 lines
scripts/qapi.py +3
-0+ + if meta == 'union': + args = expr.get('base', [])
Note: args is either string or dictionary.
Quoted 2 lines
Quoted 2 lines
scripts/qapi.py def check_exprs(exprs): · line 956
Quoted 2 lines
scripts/qapi.py +2
-0+ else: + args = expr.get('data', [])
Note: args is either string (only if command or event), dictionary (only if struct, alternate, command, event) or list (only if enum)
Quoted 2 lines
Quoted 2 lines
scripts/qapi.py def check_exprs(exprs): · line 958
Quoted 2 lines
scripts/qapi.py +2
-0+ if isinstance(args, dict): + args = args.keys()
Now args is either string (only if command or event) or list.
Quoted 3 lines
Quoted 3 lines
scripts/qapi.py def check_exprs(exprs): · line 961
Quoted 3 lines
scripts/qapi.py +3
-0+ + if meta == 'alternate' or \ + (meta == 'union' and not expr.get('discriminator')):
PEP8 prefers parenthesis over backslash, and recommends breaking lines before instead of after binary operators:
if (meta == 'alternate'
or (meta == 'union' and not expr.get('discriminator'))):Note: args can only be list here.
Quoted 1 line
Quoted 1 line
Quoted 1 line
+
args.append('type')
Works because we know it's a list. It's less than obvious, though.
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
scripts/qapi.py +10
-0+ + if isinstance(args, list): + for arg in args: + if arg[0] == '*': + opt = True + desc = doc.args.get(arg[1:]) + else: + opt = False + desc = doc.args.get(arg) + if not desc:
Quoted 8 lines
Quoted 8 lines
scripts/qapi.py def check_exprs(exprs): · line 980
Quoted 8 lines
scripts/qapi.py +8
-0+ continue + desc_opt = "#optional" in str(desc) + if desc_opt and not opt: + raise QAPISemError(info, "Description has #optional, " + "but the declaration doesn't") + if not desc_opt and opt: + # silently fix the doc + desc.append("#optional")
#optional is redundant information. But as long as we use it, it better be correct, to avoid misleading readers of the schema. Two sides of
correctness: it's there when arg is optional, and it's not there when it's not. You enforce the latter, but you silently fix the former. I figure you do that because #optional is currently missing in quite a few places.
Let's add
# TODO either fix the schema and make this an error, # or drop #optional entirely
Quoted 3 lines
Quoted 3 lines
scripts/qapi.py def check_exprs(exprs): · line 983
Quoted 3 lines
scripts/qapi.py +3
-0+ + doc_args = set(doc.args.keys()) + args = set([name.strip('*') for name in args])
Now args morphs from string or dict to set. I'd use a new variable.
If args is a string, it becomes a set of characters, which is not what you want. For instance, qapi-schema.json's QCryptoBlockOpenOptions has 'base': 'QCryptoBlockOptionsBase', and args changes from 'QCryptoBlockOptionsBase' to set(['O', 'a', 'C', 'B', 'e', 'i', 'c', 'k', 'l', 'o', 'n', 'Q', 'p', 's', 'r', 't', 'y']) here.
Quoted 3 lines
Quoted 3 lines
scripts/qapi.py def check_exprs(exprs): · line 986
Quoted 3 lines
scripts/qapi.py +3
-0+ if not doc_args.issubset(args): + raise QAPISemError(info, "The following documented members are not in " + "the declaration: %s" % ", ".join(doc_args - args))
If args is originally a string, then we happily accept documentation for its characters. Quite unlikely to bite in practice, but it's wrong anyways.
I suspect you could save yourself some grief by returning early when args is string, say:
if meta == 'union':
args = expr.get('base', [])
else:
args = expr.get('data', [])
if isinstance(args, str):
return
if isinstance(args, dict):
args = args.keys()
assert isinstance(args, list)
if (meta == 'alternate'
or (meta == 'union' and not expr.get('discriminator'))):
args.append('type')
for arg in args:
...Quoted 159 lines
Quoted 150 lines
Copied from review of v5, so I don't forget:
As explained in review of v3, this is only a subset of the real set of members. Computing the exact set is impractical when working with the abstract syntax tree. I believe we'll eventually have to rewrite this code to work with the QAPISchemaEntity instead.
Quoted 143 lines
scripts/qapi.py +9
-0+ + +def check_docs(docs): + for doc in docs: + for section in doc.args.values() + doc.sections: + content = str(section) + if not content or content.isspace(): + raise QAPISemError(doc.info, + "Empty doc section '%s'" %section.name)
scripts/qapi.py +12
-1+ + if not doc.expr: + check_freeform_doc(doc) + else: + check_definition_doc(doc, doc.expr, doc.info) + + return docs + + # # Schema compiler frontend #@@ -1229,7 +1470,9 @@ class QAPISchemaEvent(QAPISchemaEntity): class QAPISchema(object): def __init__(self, fname): try: - self.exprs = check_exprs(QAPISchemaParser(open(fname, "r")).exprs) + parser = QAPISchemaParser(open(fname, "r")) + self.exprs = check_exprs(parser.exprs) + self.docs = check_docs(parser.docs) self._entity_dict = {} self._predefining = True
self._def_predefineds()scripts/qapi2texi.py new file +6
-0@@ -0,0 +1,266 @@ +#!/usr/bin/env python +# QAPI texi generator +# +# 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 texinfoformat"""
scripts/qapi2texi.py new file +63
-0+import re +import sys + +import qapi + +COMMAND_FMT = """ +@deftypefn {type} {{}} {name} + +{body} + +@end deftypefn + +""".format + +ENUM_FMT = """ +@deftp Enum {name} + +{body} + +@end deftp + +""".format + +STRUCT_FMT = """ +@deftp {{{type}}} {name} + +{body} + +@end deftp + +""".format + +EXAMPLE_FMT = """@example +{code} +@end example +""".format + + +def subst_strong(doc): + """Replaces *foo* by @strong{foo}""" + return re.sub(r'\*([^*\n]+)\*', r'@emph{\1}', doc) + + +def subst_emph(doc): + """Replaces _foo_ by @emph{foo}""" + 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 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
scripts/qapi2texi.py new file +32
-0+ # need to delay it until after subst_vars() in texi_format(). + doc = subst_braces(doc).strip('\n') + return EXAMPLE_FMT(code=doc) + + +def texi_format(doc): + """ + Format documentation + + Lines starting with: + - |: generates an @example + - =: generates @section + - ==: generates @subsection + - 1. or 1): generates an @enumerate @item + - */-: generates an @itemize list + """ + lines = [] + doc = subst_braces(doc) + doc = subst_vars(doc) + doc = subst_emph(doc) + doc = subst_strong(doc) + inlist = "" + lastempty = False + for line in doc.split('\n'): + empty = 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), + # but a line with some *other* markup, such as a = title + # doesn't. + if line.startswith("| "):Quoted 8 lines
scripts/qapi2texi.py line 107
Quoted 6 lines
scripts/qapi2texi.py new file +6
-0+ line = EXAMPLE_FMT(code=line[2:]) + elif line.startswith("= "): + line = "@section " + line[2:] + elif line.startswith("== "): + line = "@subsection " + line[3:] + elif re.match("^([0-9]*[.]) ", line):[.] is an unusual way to say \.
Quoted 8 lines
Right, forgot to change that when removing ) from v6.
Quoted 4 lines
Perhaps we should consistently use r"..." for strings used as regular expressions.
No idea, could be changed on top.
Yes. But if you respin anyway, adding some r wouldn't hurt.
Quoted 55 lines
Quoted 55 lines
Quoted 41 lines
scripts/qapi2texi.py new file +41
-0+ if not inlist: + lines.append("@enumerate") + inlist = "enumerate" + line = line[line.find(" ")+1:] + lines.append("@item") + elif re.match("^[*-] ", line): + if not inlist: + lines.append("@itemize %s" % {'*': "@bullet", + '-': "@minus"}[line[0]]) + inlist = "itemize" + lines.append("@item") + line = line[2:] + elif lastempty and inlist: + lines.append("@end %s\n" % inlist) + inlist = "" + + lastempty = empty + lines.append(line) + + if inlist: + lines.append("@end %s\n" % inlist) + return "\n".join(lines) + + +def texi_body(doc): + """ + Format the body of a symbol documentation: + - main body + - table of arguments + - followed by "Returns/Notes/Since/Example" sections + """ + body = texi_format(str(doc.body)) + "\n" + if doc.args: + body += "@table @asis\n" + for arg, section in doc.args.iteritems(): + desc = str(section) + opt = '' + if "#optional" in desc: + desc = desc.replace("#optional", "") + opt = ' (optional)' + body += "@item @code{'%s'}%s\n%s\n" % (arg, opt,scripts/qapi2texi.py line 158
Quoted 10 lines
scripts/qapi2texi.py new file +10
-0+ texi_format(desc)) + body += "@end table\n" + + for section in doc.sections: + name, doc = (section.name, str(section)) + func = texi_format + if name.startswith("Example"): + func = texi_example + + if name:@quotation produces confusing .txt and .html output, as discussed in review of v6. Either drop it, or record the problem in a comment, e.g.
Quoted 5 lines
Quoted 3 lines
# FIXME the indentation produced by @quotation in .txt and # .html output is confusing
added
Thanks.
Quoted 188 lines
Quoted 188 lines
Quoted 13 lines
scripts/qapi2texi.py new file +13
-0+ body += "\n@quotation %s\n%s\n@end quotation" % \ + (name, func(doc)) + else: + body += func(doc) + + return body + + +def texi_alternate(expr, doc): + """Format an alternate to texi""" + body = texi_body(doc) + return STRUCT_FMT(type="Alternate", + name=doc.symbol,scripts/qapi2texi.py line 181
Quoted 10 lines
scripts/qapi2texi.py new file +10
-0+ body=body) + + +def texi_union(expr, doc): + """Format a union to texi""" + discriminator = expr.get("discriminator") + if discriminator: + union = "Flat Union" + else: + union = "Simple Union"Not sure flat vs. simple matters for users of generated documentation, but let's not worry about that now.
Quoted 161 lines
scripts/qapi2texi.py new file +77
-0+ + body = texi_body(doc) + return STRUCT_FMT(type=union, + name=doc.symbol, + body=body) + + +def texi_enum(expr, doc): + """Format an enum to texi""" + for i in expr['data']: + if i not in doc.args: + doc.args[i] = '' + body = texi_body(doc) + return ENUM_FMT(name=doc.symbol, + body=body) + + +def texi_struct(expr, doc): + """Format a struct to texi""" + body = texi_body(doc) + return STRUCT_FMT(type="Struct", + name=doc.symbol, + body=body) + + +def texi_command(expr, doc): + """Format a command to texi""" + body = texi_body(doc) + return COMMAND_FMT(type="Command", + name=doc.symbol, + body=body) + + +def texi_event(expr, doc): + """Format an event to texi""" + body = texi_body(doc) + return COMMAND_FMT(type="Event", + name=doc.symbol, + body=body) + + +def texi_expr(expr, doc): + """Format an expr to texi""" + (kind, _) = expr.items()[0] + + fmt = {"command": texi_command, + "struct": texi_struct, + "enum": texi_enum, + "union": texi_union, + "alternate": texi_alternate, + "event": texi_event}[kind] + + return fmt(expr, doc) + + +def texi(docs): + """Convert QAPI schema expressions to texi documentation""" + res = [] + for doc in docs: + expr = doc.expr + if not expr: + res.append(texi_body(doc)) + continue + try: + doc = texi_expr(expr, doc) + res.append(doc) + except: + print >>sys.stderr, "error at @%s" % doc.info + raise + + return '\n'.join(res) + + +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]
scripts/qapi2texi.py new file +8
-0+ sys.exit(1) + + schema = qapi.QAPISchema(argv[1]) + print texi(schema.docs) + + +if __name__ == "__main__": + main(sys.argv)docs/qapi-code-gen.txt +0
-0@@ -44,40 +44,148 @@ Input must be ASCII (although QMP supports fullUnicode strings, the
QAPI parser does not). At present, there is no place where a QAPI schema requires the use of JSON numbers or null.docs/qapi-code-gen.txt +3
-18+ +=== Comments === + Comments are allowed; anything between an unquoted # and the following -newline is ignored. Although there is not yet a documentation -generator, a form of stylized comments has developed for consistently -documenting details about an expression and when it was added to the -schema. The documentation is delimited between two lines of ##, then -the first line names the expression, an optional overview is provided, -then individual documentation about each member of 'data' is provided, -and finally, a 'Since: x.y.z' tag lists the release that introduced -the expression. Optional members are tagged with the phrase -'#optional', often with their default value; and extensions added -after the expression was first released are also given a '(since -x.y.z)' comment. For example: - - ## - # @BlockStats: - # - # Statistics of a virtual block device or a block backing device. - # - # @device: #optional If the stats are for a virtual block device, thename
docs/qapi-code-gen.txt +0
-5- # corresponding to the virtual block device. - # - # @stats: A @BlockDeviceStats for the device. - # - # @parent: #optional This describes the file block device if it hasone.
docs/qapi-code-gen.txt +0
-2- # - # @backing: #optional This describes the backing block device if ithas one.
docs/qapi-code-gen.txt +26
-8- # (Since 2.0) - # - # Since: 0.14.0 - ## - { 'struct': 'BlockStats', - 'data': {'*device': 'str', 'stats': 'BlockDeviceStats', - '*parent': 'BlockStats', - '*backing': 'BlockStats'} } +newline is ignored. + +A multi-line comment that starts and ends with a '##' line is a +documentation comment. These are parsed by the documentation +generator, which recognizes certain markup detailed below. + + +==== Documentation markup ==== + +Comment text starting with '=' is a section title: + + # = Section title + +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 + # multiple lines
Quoted 8 lines
Quoted 8 lines
docs/qapi-code-gen.txt Input must be ASCII (although QMP supports full Unicode strings, the · line 84
Quoted 8 lines
docs/qapi-code-gen.txt +8
-0+ # * Second item + +You can also use '-' instead of '*'. + +A decimal number followed by '.' starts a numbered list: + + # 1. First item, may span + # multiple lines
Should the second line be indented?
Quoted 10 lines
Quoted 9 lines
docs/qapi-code-gen.txt Input must be ASCII (although QMP supports full Unicode strings, the · line 90
Quoted 6 lines
docs/qapi-code-gen.txt +6
-0+ # 2. Second item + +The actual number doesn't matter. You could even use '*' instead of +'2.' for the second item. + +FIXME what exactly ends a listCan you say offhand what ends a list? If yes, can we resolve this FIXME now rather than later?
Quoted 3 lines
well, the code is too permissive, there is a FIXME there already.
In general, I think we want to end a list after a blank line and a "non-item" line. Is the wording ok?
Blank line is pretty restrictive, because list items consisting of multiple paragraphs aren't possible then.
I think writing something like this is fairly natural:
* First item, may span
multiple lines.
Even multiple paragaphs are okay.
* Second item
- This is a sublist
- Second item of sublist
* Third item
This sentence is not part of the list.
We don't support sublists, and I'm not saying we should, I'm just showing how they would fit in.
My point is that indentation is a natural way to delimit list items.
I don't expect you to implement this now. All I want for this series is reasonable documentation. As far as I can tell, texi_format() ends the list at a blank line, except when it doesn't (see its FIXME).
What about this: replace "FIXME what exactly ends a list" by
Lists can't be nested. Blank lines are currently not supported within lists.
and add to texi_format()'s FIXME something like
Make sure to update section "Documentation markup" in docs/qapi-code-gen.txt when fixing this.
Okay?
Quoted 171 lines
Quoted 39 lines
Quoted 26 lines
docs/qapi-code-gen.txt +26
-0+ +Additional whitespace between the initial '#' and the comment text is +permitted. + +*foo* and _foo_ are for strong and emphasis styles respectively (they +do not work over multiple lines). @foo is used to reference a name in +the schema. + +Example: + +## +# = Section +# == Subsection +# +# Some text foo with *strong* and _emphasis_ +# 1. with a list +# 2. like that +# +# And some code: +# | $ echo foo +# | -> do this +# | <- get that +# +## + +docs/qapi-code-gen.txt Input must be ASCII (although QMP supports full Unicode strings, the · line 126
Quoted 10 lines
docs/qapi-code-gen.txt +10
-0+==== Expression documentation ==== + +Each expression that isn't an include directive must be preceded by a +documentation block. Such blocks are called expression documentation +blocks. + +The first line of the documentation names the expression, then the +documentation body is provided, then individual documentation about +each member of 'data' is provided. Finally, several tagged sections +can be added.In my review of v6, I wrote:
Quoted 8 lines
I'm afraid this is more aspiration than specification: the parser accepts these things in almost any order.
Could be filed under "deficiencies" for now.
To file under "deficiencies", we need to add a FIXME or TODO either here, or in the parser. Assuming you haven't tightened the parser meanwhile (hope you haven't; we need to control the churn).
ok
Quoted 21 lines
Member of 'data' won't remain accurate. Consider:
{ 'union': 'GlusterServer',
'base': { 'type': 'GlusterTransport' }, 'discriminator': 'type',
'data': { 'unix': 'UnixSocketAddress',
'tcp': 'InetSocketAddress' } }Its doc comment currently doesn't contain argument sections. It should eventually contain @type:, @unix: and @tcp:. Only the latter two are members of 'data'.
I should propose something better, but I'm getting perilously close to the christmas break already. Later.
Also: passive voice is meh (not your idea; you adapted the existing text).
What about:
Quoted 8 lines
The documentation block consists of a first line naming the expression, an optional overview, a description of each argument (for commands and events) or member (for structs, unions and alternates), and optional tagged sections.
I still don't like the use of "section" for both the = things and the tagged sections, but it's not important enough to spend time on it now.
ok
Quoted 5 lines
docs/qapi-code-gen.txt Input must be ASCII (although QMP supports full Unicode strings, the · line 128
Quoted 2 lines
docs/qapi-code-gen.txt +2
-0+ +Optional members are tagged with the phrase '#optional', often withIf we adopt my text, we should say "arguments / members" here.
ok
Quoted 9 lines
docs/qapi-code-gen.txt Input must be ASCII (although QMP supports full Unicode strings, the · line 133
Quoted 5 lines
docs/qapi-code-gen.txt +5
-0+their default value; and extensions added after the expression was +first released are also given a '(since x.y.z)' comment. + +A tagged section starts with one of the following words: +"Note:"/"Notes:", "Since:", "Example"/"Examples", "Returns:", "TODO:".What ends such a section? The start of the next one / end of the comment block?
yes
Quoted 8 lines
I suspect we could avoid PATCH 03 by recognizing "TODO" in addition to "TODO:". Might also be more robust. But let's ignore this now.
docs/qapi-code-gen.txt Input must be ASCII (although QMP supports full Unicode strings, the · line 135
Quoted 2 lines
docs/qapi-code-gen.txt +2
-0+ +A 'Since: x.y.z' tag lists the release that introduced the expression.Nitpick: 'Since: x.y.z' is a tagged section, not a tag.
ok
Quoted 58 lines
Quoted 46 lines
docs/qapi-code-gen.txt +46
-0+ +For example: + +## +# @BlockStats: +# +# Statistics of a virtual block device or a block backing device. +# +# @device: #optional If the stats are for a virtual block device, the name +# corresponding to the virtual block device. +# +# @node-name: #optional The node name of the device. (since 2.3) +# +# ... more members ... +# +# Since: 0.14.0 +## +{ 'struct': 'BlockStats', + 'data': {'*device': 'str', '*node-name': 'str', + ... more members ... } } + +## +# @query-blockstats: +# +# Query the @BlockStats for all virtual block devices. +# +# @query-nodes: #optional If true, the command will query all the +# block nodes ... explain, explain ... (since 2.3) +# +# Returns: A list of @BlockStats for each virtual block devices. +# +# Since: 0.14.0 +# +# Example: +# +# -> { "execute": "query-blockstats" } +# <- { +# ... lots of output ... +# } +# +## +{ 'command': 'query-blockstats', + 'data': { '*query-nodes': 'bool' }, + 'returns': ['BlockStats'] } + +==== Free-form documentation ====docs/qapi-code-gen.txt Input must be ASCII (although QMP supports full Unicode strings, the · line 191
Quoted 10 lines
docs/qapi-code-gen.txt +7
-0+ +A documentation block that isn't an expression documentation block is +a free-form documentation block. These may be used to provide +additional text and structuring content. + + +=== Schema overview === The schema sets up a series of types, as well as commands and events that will use those types. Forward references are allowed: the parser[Tests look okay, snipped...]
Re: [Qemu-devel] [PATCH v7 15/21] qapi: add qapi2texi script
Hi
----- Original Message -----
Quoted 505 lines
Quoted 264 lines · Marc-André Lureau
Hi
----- Original Message -----
Quoted 69 lines
Quoted 67 lines · Marc-André Lureau
As the name suggests, the qapi2texi script converts JSON QAPI description into a texi file suitable for different target formats (info/man/txt/pdf/html...).
It parses the following kind of blocks:
Free-form:
##
# = Section
# == Subsection
#
# Some text foo with *emphasis*
# 1. with a list
# 2. like that
#
# And some code:# | $ echo foo # | -> do this # | <- get that#
##Symbol description:
##
# @symbol:
#
# Symbol body ditto ergo sum. Foo bar# baz ding. # # @param1: the frob to frobnicate # @param2: #optional how hard to frobnicate # # Returns: the frobnicated frob. # If frob isn't frobnicatable, GenericError. # # Since: version # Notes: notes, comments can have # - itemized list # - like this # # Example: # # -> { "execute": "quit" } # <- { "return": {} } # ##That's roughly following the following EBNF grammar:
api_comment= "##\n" comment "##\n"
comment =freeform_comment|symbol_commentfreeform_comment= { "# " text "\n" | "#\n" }symbol_comment= "# @" name ":\n" { member |tag_section|freeform_comment
}
member = "# @" name ':' [ text ] "\n"freeform_commenttag_section= "# " ( "Returns:", "Since:", "Note:", "Notes:", "Example:",
"Examples:" ) [ text ] "\n"freeform_comment
text = free text with markupNote that the grammar is ambiguous: a line "# @foo:\n" can be parsed both as
freeform_commentand assymbol_comment. The actual parser recognizessymbol_comment.Quoted 5 lines
Quoted 3 lines
See
docs/qapi-code-gen.txtfor more details.Deficiencies:
Perhaps "Deficiencies and limitations".
ok
Quoted 4 lines
Quoted 3 lines
- the generated QMP documentation includes internal types
- union-type support is lackingQuoted 9 lines
"union type" (no dash).
Quoted 4 lines
- type information is lacking in generated documentation
- doc comment error message positions are imprecise, they point to the beginning of the comment.
- see other TODO/FIXME in this commitSuggest: - a few minor issues, all marked TODO/FIXME in the code
ok
Quoted 117 lines
Quoted 3 lines
Signed-off-by Marc-André Lureau <[email protected]>---
[diffstat snipped...]
Quoted 106 lines
scripts/qapi.py +19
-0@@ -125,6 +125,122 @@ class QAPISemError(QAPIError): info['parent'], msg) +class QAPIDoc(object): + class Section(object): + def __init__(self, name=None): + # optional section name (argument/member or section name) + self.name = name + # the list of lines for this section + self.content = [] + + def append(self, line): + self.content.append(line) + + def __repr__(self): + return "\n".join(self.content).strip() + + class ArgSection(Section): + pass + + def __init__(self, parser, info): + # self.parser is used to report errors with QAPIParseError.The
scripts/qapi.py +41
-0+ # resulting error position depends on the state of the parser. + # It happens to be the beginning of the comment. More or less + # servicable, but action at a distance. + self.parser = parser + self.info = info + self.symbol = None + self.body = QAPIDoc.Section() + # dict mapping parameter name to ArgSection + self.args = OrderedDict() + # a list of Section + self.sections = [] + # the current section + self.section = self.body + # associated expression (to be set by expression parser) + self.expr = None + + def has_section(self, name): + """Return True if we have a section with this name.""" + for i in self.sections: + if i.name == name: + return True + return False + + def append(self, line): + """Parse a comment line and add it to the documentation.""" + line = line[1:] + if not line: + self._append_freeform(line) + return + + if line[0] != ' ': + raise QAPIParseError(self.parser, "Missing space after #") + line = line[1:] + + # FIXME not nice: things like '# @foo:' and '# @foo: ' aren't + # recognized, and get silently treated as ordinary text + if self.symbol: + self._append_symbol_line(line) + elif not self.body.content and line.startswith("@"): + if not line.endswith(":"): + raise QAPIParseError(self.parser, "Line should end with:")
scripts/qapi.py +2
-0+ self.symbol = line[1:-1] + # FIXME invalid names other than the empty string aren'tflagged
scripts/qapi.py +23
-0+ if not self.symbol: + raise QAPIParseError(self.parser, "Invalid name") + else: + self._append_freeform(line) + + def _append_symbol_line(self, line): + name = line.split(' ', 1)[0] + + if name.startswith("@") and name.endswith(":"): + line = line[len(name)+1:] + self._start_args_section(name[1:-1]) + elif name in ("Returns:", "Since:", + # those are often singular or plural + "Note:", "Notes:", + "Example:", "Examples:", + "TODO:"): + line = line[len(name)+1:] + self._start_section(name[:-1]) + + self._append_freeform(line) + + def _start_args_section(self, name): + # FIXME invalid names other than the empty string aren'tflagged
scripts/qapi.py +5
-0+ if not name: + raise QAPIParseError(self.parser, "Invalid parameter name") + if name in self.args: + raise QAPIParseError(self.parser, + "'%s' parameter name duplicated" %name)
scripts/qapi.py +3
-0+ if self.sections: + raise QAPIParseError(self.parser, + "'%s' parameter documentation isQuoted 2 lines
interleaved "
+ "with other sections" % name)This error message is rather confusing. Ideally, we'd point to the the source code that made us add to self.sections, but that's not in the cards right now. Here's my best try:
Quoted 4 lines
raise QAPIParseError(self.parser, "'@%s:' can't follow '%s' section" % (name, self.sections[0].name))works for me too
Quoted 20 lines
scripts/qapi.py class QAPISemError(QAPIError): · line 225
Quoted 4 lines
scripts/qapi.py +4
-0+ self.section = QAPIDoc.ArgSection(name) + self.args[name] = self.section + + def _start_section(self, name=""):Note: @name changed to default to "" since v6 for the benefit of
_append_freeform()below.scripts/qapi.py class QAPISemError(QAPIError): · line 236
Quoted 11 lines
scripts/qapi.py +11
-0+ if name in ("Returns", "Since") and self.has_section(name): + raise QAPIParseError(self.parser, + "Duplicated '%s' section" % name) + self.section = QAPIDoc.Section(name) + self.sections.append(self.section) + + def _append_freeform(self, line): + in_arg = isinstance(self.section, QAPIDoc.ArgSection) + if (in_arg and self.section.content and + not self.section.content[-1] and + line and not line[0].isspace()):Quoted 1 line
PEP8 recommends breaking lines before operators in new code.
ok
Quoted 11 lines
Quoted 2 lines
+
self._start_section()Changed from v6's
raise
QAPIParseError(self.parser, "Invalid section indentation")May well be an improvement (I'm certainly no fan of this error myself), but it throws my review off the fast track: now I have to figure out how the new code works. Can you give me a hint on what this change does?
In v6, we rejected unindented sections after arguments (see
tests/qapi-schema/doc-bad-section.json):# @arg: blah bla
# zing bar
#
# This should be rejectedQuoted 5 lines
And a patch in v6 reordered the json comments. But you asked for the doc to not be reordered without careful review (both source and output). So those additional paragraphs are added as untitled sections, and the doc generator keep section order. The output will be in the same order as the source.
Thanks.
Quoted 4 lines
Quoted 2 lines
Or should we take a shortcut and revert to v6 here? We can always improve on top.
Probably not needed to revert.
I played with it a bit, and it looks like it's working fine.
Quoted 177 lines
Quoted 4 lines
scripts/qapi.py class QAPISemError(QAPIError): · line 239
Quoted 2 lines
scripts/qapi.py +2
-0+ if (in_arg or not self.section.name or + not self.section.name.startswith("Example")):Again, break before the operator.
ok
Quoted 41 lines
Quoted 41 lines
scripts/qapi.py +11
-0+ line = line.strip() + self.section.append(line) + + class QAPISchemaParser(object): def __init__(self, fp, previously_included=[], incl_info=None):@@ -140,11 +256,17 @@ class QAPISchemaParser(object): self.line = 1 self.line_pos = 0 self.exprs = [] + self.docs = [] self.accept() while self.tok is not None: info = {'file': fname, 'line': self.line, 'parent': self.incl_info} + if self.tok == '#': + doc = self.get_doc(info) + self.docs.append(doc) + continue + expr = self.get_expr(False) if isinstance(expr, dict) and "include" in expr: if len(expr) != 1:@@ -162,6 +284,7 @@ class QAPISchemaParser(object): raise QAPISemError(info, "Inclusion loop for %s" % include) inf = inf['parent'] + # skip multiple include of the same file if incl_abs_fname in previously_included:continue
scripts/qapi.py +1
-0@@ -172,12 +295,19 @@ class QAPISchemaParser(object): exprs_include = QAPISchemaParser(fobj, previously_included, info) self.exprs.extend(exprs_include.exprs) + self.docs.extend(exprs_include.docs)Quoted 8 lines
scripts/qapi.py class QAPISchemaParser(object): · line 304
Quoted 6 lines
scripts/qapi.py +3
-0else: expr_elem = {'expr': expr, 'info': info} + if (self.docs and + self.docs[-1].info['file'] == fname and + not self.docs[-1].expr):Again, break before the operator.
ok
Quoted 108 lines
Quoted 15 lines
scripts/qapi.py +4
-1+ self.docs[-1].expr = expr + expr_elem['doc'] = self.docs[-1] + self.exprs.append(expr_elem) - def accept(self): + def accept(self, skip_comment=True): while True: self.tok = self.src[self.cursor]self.pos = self.cursor
scripts/qapi.py +0
-0@@ -185,7 +315,13 @@ class QAPISchemaParser(object): self.val = None if self.tok == '#':scripts/qapi.py class QAPISchemaParser(object): · line 327
Quoted 10 lines
scripts/qapi.py +6
-0+ if self.src[self.cursor] == '#': + # Start of doc comment + skip_comment = False self.cursor = self.src.find('\n', self.cursor) + if not skip_comment: + self.val = self.src[self.pos:self.cursor] + return elif self.tok in "{}:,[]": return elif self.tok == "'":Copied from review of v3, so I don't forget:
Comment tokens are thrown away as before, except when the parser asks for them by passing skip_comment=False, or when the comment token starts with ##. The parser asks while parsing a doc comment, in
get_doc().This is a backchannel from the parser to the lexer. I'd rather avoid such lexer hacks, but I guess we can address that on top.
A comment starting with ## inside an expression is now a syntax error. For instance, input
{ ##yields
/dev/stdin:2:1: Expected string or "}"Rather unfriendly error message, but we can fix that on top.
Quoted 61 lines
scripts/qapi.py +12
-0@@ -319,6 +455,28 @@ class QAPISchemaParser(object): raise QAPIParseError(self, 'Expected "{", "[" or string') return expr + def get_doc(self, info): + if self.val != '##': + raise QAPIParseError(self, "Junk after '##' at start of " + "documentation comment") + + doc = QAPIDoc(self, info) + self.accept(False) + while self.tok == '#': + if self.val.startswith('##'): + # End of doc comment + if self.val != '##': + raise QAPIParseError(self, "Junk after '##' at endof
"scripts/qapi.py +8
-0+ "documentation comment") + self.accept() + return doc + else: + doc.append(self.val) + self.accept(False) + + raise QAPIParseError(self, "Documentation comment must end with'##'")
scripts/qapi.py +7
-0+ + # # Semantic analysis of schema expressions # TODO fold into QAPISchema@@ -703,6 +861,11 @@ def check_exprs(exprs): for expr_elem in exprs: expr = expr_elem['expr'] info = expr_elem['info'] + + if 'doc' not in expr_elem: + raise QAPISemError(info, + "Expression missing documentation comment") + if 'enum' in expr: check_keys(expr_elem, 'enum', ['data'], ['prefix'])add_enum(expr['enum'], info, expr['data'])scripts/qapi.py +10
-0@@ -761,6 +924,84 @@ def check_exprs(exprs): return exprs +def check_freeform_doc(doc): + if doc.symbol: + raise QAPISemError(doc.info, + "Documention for '%s' is not followed" + " by the definition" % doc.symbol) + + body = str(doc.body) + if re.search(r'@\S+:', body, re.MULTILINE): + raise QAPISemError(doc.info, + "Free-form documentation block must notcontain"
+ " @NAME: sections")Quoted 9 lines
scripts/qapi.py def check_exprs(exprs): · line 940
Quoted 3 lines
scripts/qapi.py +3
-0+ + +def check_definition_doc(doc, expr, info):Lots of churn in this function. It can certainly use improvement, as pointed out in prior reviews, but it triggers still more review. Based on the tests, I guess it's for finding documented parameters that don't actually exist, and to diagnose optional mismatch. Anything else?
Quoted 4 lines
implicitely adds #optional (since it's no longer in type info, it better be in the description), code simplification, message improvement too.
I'd rather keep this too, and improve on top.
Okay. Review below.
Quoted 21 lines
Quoted 21 lines
Or should we take a shortcut and revert to v6 here? We can always improve on top. I think v6 would need a # TODO Should ensure #optional matches the schema.
Quoted 13 lines
+ for i in ('enum', 'union', 'alternate', 'struct', 'command',
'event'):scripts/qapi.py +7
-0+ if i in expr: + meta = i + break + + name = expr[meta] + if doc.symbol != name: + raise QAPISemError(info, "Definition of '%s' followsdocumentation"
scripts/qapi.py +3
-0+ " for '%s'" % (name, doc.symbol)) + if doc.has_section('Returns') and 'command' not in expr: + raise QAPISemError(info, "'Returns:' is only valid forQuoted 1 line
commands")
Copied from review of v5, so I don't forget:
Quoted 7 lines
Quoted 7 lines
We accept 'Returns:' even when the command doesn't return anything, because we currently use it to document errors, too. Can't say I like that, but it's out of scope here.
Quoted 3 lines
scripts/qapi.py +3
-0+ + if meta == 'union': + args = expr.get('base', [])Note: args is either string or dictionary.
Quoted 2 lines
Quoted 2 lines
scripts/qapi.py def check_exprs(exprs): · line 956
Quoted 2 lines
scripts/qapi.py +2
-0+ else: + args = expr.get('data', [])Note: args is either string (only if command or event), dictionary (only if struct, alternate, command, event) or list (only if enum)
Quoted 2 lines
Quoted 2 lines
scripts/qapi.py def check_exprs(exprs): · line 958
Quoted 2 lines
scripts/qapi.py +2
-0+ if isinstance(args, dict): + args = args.keys()
Quoted 8 lines
Now args is either string (only if command or event) or list.
Quoted 3 lines
Quoted 3 lines
scripts/qapi.py def check_exprs(exprs): · line 961
Quoted 3 lines
scripts/qapi.py +3
-0+ + if meta == 'alternate' or \ + (meta == 'union' and not expr.get('discriminator')):PEP8 prefers parenthesis over backslash, and recommends breaking lines before instead of after binary operators:
ok
Quoted 36 lines
if (meta == 'alternate' or (meta == 'union' and not expr.get('discriminator'))):Note: args can only be list here.
Quoted 1 line
Quoted 1 line
Quoted 1 line
+
args.append('type')Works because we know it's a list. It's less than obvious, though.
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
scripts/qapi.py +10
-0+ + if isinstance(args, list): + for arg in args: + if arg[0] == '*': + opt = True + desc = doc.args.get(arg[1:]) + else: + opt = False + desc = doc.args.get(arg) + if not desc:Quoted 8 lines
Quoted 8 lines
scripts/qapi.py def check_exprs(exprs): · line 980
Quoted 8 lines
scripts/qapi.py +8
-0+ continue + desc_opt = "#optional" in str(desc) + if desc_opt and not opt: + raise QAPISemError(info, "Description has #optional, " + "but the declaration doesn't") + if not desc_opt and opt: + # silently fix the doc + desc.append("#optional")#optional is redundant information. But as long as we use it, it better be correct, to avoid misleading readers of the schema. Two sides of
correctness: it's there when arg is optional, and it's not there when it's not. You enforce the latter, but you silently fix the former. I figure you do that because #optional is currently missing in quite a few places.
Quoted 4 lines
Let's add
# TODO either fix the schema and make this an error, # or drop #optional entirely
ok
Quoted 25 lines
Quoted 3 lines
Quoted 3 lines
scripts/qapi.py def check_exprs(exprs): · line 983
Quoted 3 lines
scripts/qapi.py +3
-0+ + doc_args = set(doc.args.keys()) + args = set([name.strip('*') for name in args])Now args morphs from string or dict to set. I'd use a new variable.
If args is a string, it becomes a set of characters, which is not what you want. For instance, qapi-schema.json's QCryptoBlockOpenOptions has 'base': 'QCryptoBlockOptionsBase', and args changes from 'QCryptoBlockOptionsBase' to
set(['O', 'a', 'C', 'B', 'e', 'i', 'c', 'k', 'l', 'o', 'n', 'Q', 'p', 's', 'r', 't', 'y'])here.Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
scripts/qapi.py +2
-0+ if not doc_args.issubset(args): + raise QAPISemError(info, "The following documented members arenot in "
+ "the declaration: %s" % ", ".join(doc_args -
args))If args is originally a string, then we happily accept documentation for its characters. Quite unlikely to bite in practice, but it's wrong anyways.
I suspect you could save yourself some grief by returning early when args is string, say:
Quoted 16 lines
if meta == 'union':
args = expr.get('base', [])
else:
args = expr.get('data', [])
if isinstance(args, str):
return
if isinstance(args, dict):
args = args.keys()
assert isinstance(args, list)
if (meta == 'alternate'
or (meta == 'union' and not expr.get('discriminator'))):
args.append('type')
for arg in args:
...ok
Quoted 164 lines
Quoted 164 lines
Quoted 152 lines
Copied from review of v5, so I don't forget:
As explained in review of v3, this is only a subset of the real set of members. Computing the exact set is impractical when working with the abstract syntax tree. I believe we'll eventually have to rewrite this code to work with the QAPISchemaEntity instead.
Quoted 144 lines
scripts/qapi.py +9
-0+ + +def check_docs(docs): + for doc in docs: + for section in doc.args.values() + doc.sections: + content = str(section) + if not content or content.isspace(): + raise QAPISemError(doc.info, + "Empty doc section '%s'" %section.name)
scripts/qapi.py +12
-1+ + if not doc.expr: + check_freeform_doc(doc) + else: + check_definition_doc(doc, doc.expr, doc.info) + + return docs + + # # Schema compiler frontend #@@ -1229,7 +1470,9 @@ class QAPISchemaEvent(QAPISchemaEntity): class QAPISchema(object): def __init__(self, fname): try: - self.exprs = check_exprs(QAPISchemaParser(open(fname, "r")).exprs) + parser = QAPISchemaParser(open(fname, "r")) + self.exprs = check_exprs(parser.exprs) + self.docs = check_docs(parser.docs) self._entity_dict = {} self._predefining = True
self._def_predefineds()scripts/qapi2texi.py new file +6
-0@@ -0,0 +1,266 @@ +#!/usr/bin/env python +# QAPI texi generator +# +# 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 texinfoformat"""
scripts/qapi2texi.py new file +63
-0+import re +import sys + +import qapi + +COMMAND_FMT = """ +@deftypefn {type} {{}} {name} + +{body} + +@end deftypefn + +""".format + +ENUM_FMT = """ +@deftp Enum {name} + +{body} + +@end deftp + +""".format + +STRUCT_FMT = """ +@deftp {{{type}}} {name} + +{body} + +@end deftp + +""".format + +EXAMPLE_FMT = """@example +{code} +@end example +""".format + + +def subst_strong(doc): + """Replaces *foo* by @strong{foo}""" + return re.sub(r'\*([^*\n]+)\*', r'@emph{\1}', doc) + + +def subst_emph(doc): + """Replaces _foo_ by @emph{foo}""" + 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 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 dothat,
wescripts/qapi2texi.py new file +32
-0+ # need to delay it until after subst_vars() in texi_format(). + doc = subst_braces(doc).strip('\n') + return EXAMPLE_FMT(code=doc) + + +def texi_format(doc): + """ + Format documentation + + Lines starting with: + - |: generates an @example + - =: generates @section + - ==: generates @subsection + - 1. or 1): generates an @enumerate @item + - */-: generates an @itemize list + """ + lines = [] + doc = subst_braces(doc) + doc = subst_vars(doc) + doc = subst_emph(doc) + doc = subst_strong(doc) + inlist = "" + lastempty = False + for line in doc.split('\n'): + empty = 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), + # but a line with some *other* markup, such as a = title + # doesn't. + if line.startswith("| "):Quoted 8 lines
scripts/qapi2texi.py line 107
Quoted 6 lines
scripts/qapi2texi.py new file +6
-0+ line = EXAMPLE_FMT(code=line[2:]) + elif line.startswith("= "): + line = "@section " + line[2:] + elif line.startswith("== "): + line = "@subsection " + line[3:] + elif re.match("^([0-9]*[.]) ", line):[.] is an unusual way to say \.
Right, forgot to change that when removing ) from v6.
Quoted 1 line
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Perhaps we should consistently use r"..." for strings used as regular expressions.
No idea, could be changed on top.
Yes. But if you respin anyway, adding some r wouldn't hurt.
ok
Quoted 255 lines
Quoted 56 lines
Quoted 56 lines
Quoted 42 lines
scripts/qapi2texi.py new file +41
-0+ if not inlist: + lines.append("@enumerate") + inlist = "enumerate" + line = line[line.find(" ")+1:] + lines.append("@item") + elif re.match("^[*-] ", line): + if not inlist: + lines.append("@itemize %s" % {'*': "@bullet", + '-': "@minus"}[line[0]]) + inlist = "itemize" + lines.append("@item") + line = line[2:] + elif lastempty and inlist: + lines.append("@end %s\n" % inlist) + inlist = "" + + lastempty = empty + lines.append(line) + + if inlist: + lines.append("@end %s\n" % inlist) + return "\n".join(lines) + + +def texi_body(doc): + """ + Format the body of a symbol documentation: + - main body + - table of arguments + - followed by "Returns/Notes/Since/Example" sections + """ + body = texi_format(str(doc.body)) + "\n" + if doc.args: + body += "@table @asis\n" + for arg, section in doc.args.iteritems(): + desc = str(section) + opt = '' + if "#optional" in desc: + desc = desc.replace("#optional", "") + opt = ' (optional)' + body += "@item @code{'%s'}%s\n%s\n" % (arg, opt,scripts/qapi2texi.py line 158
Quoted 10 lines
scripts/qapi2texi.py new file +10
-0+ texi_format(desc)) + body += "@end table\n" + + for section in doc.sections: + name, doc = (section.name, str(section)) + func = texi_format + if name.startswith("Example"): + func = texi_example + + if name:@quotation produces confusing .txt and .html output, as discussed in review of v6. Either drop it, or record the problem in a comment, e.g.
Quoted 5 lines
Quoted 3 lines
# FIXME the indentation produced by @quotation in .txt and # .html output is confusing
added
Thanks.
Quoted 191 lines
Quoted 191 lines
Quoted 13 lines
scripts/qapi2texi.py new file +13
-0+ body += "\n@quotation %s\n%s\n@end quotation" % \ + (name, func(doc)) + else: + body += func(doc) + + return body + + +def texi_alternate(expr, doc): + """Format an alternate to texi""" + body = texi_body(doc) + return STRUCT_FMT(type="Alternate", + name=doc.symbol,scripts/qapi2texi.py line 181
Quoted 10 lines
scripts/qapi2texi.py new file +10
-0+ body=body) + + +def texi_union(expr, doc): + """Format a union to texi""" + discriminator = expr.get("discriminator") + if discriminator: + union = "Flat Union" + else: + union = "Simple Union"Not sure flat vs. simple matters for users of generated documentation, but let's not worry about that now.
Quoted 164 lines
scripts/qapi2texi.py new file +77
-0+ + body = texi_body(doc) + return STRUCT_FMT(type=union, + name=doc.symbol, + body=body) + + +def texi_enum(expr, doc): + """Format an enum to texi""" + for i in expr['data']: + if i not in doc.args: + doc.args[i] = '' + body = texi_body(doc) + return ENUM_FMT(name=doc.symbol, + body=body) + + +def texi_struct(expr, doc): + """Format a struct to texi""" + body = texi_body(doc) + return STRUCT_FMT(type="Struct", + name=doc.symbol, + body=body) + + +def texi_command(expr, doc): + """Format a command to texi""" + body = texi_body(doc) + return COMMAND_FMT(type="Command", + name=doc.symbol, + body=body) + + +def texi_event(expr, doc): + """Format an event to texi""" + body = texi_body(doc) + return COMMAND_FMT(type="Event", + name=doc.symbol, + body=body) + + +def texi_expr(expr, doc): + """Format an expr to texi""" + (kind, _) = expr.items()[0] + + fmt = {"command": texi_command, + "struct": texi_struct, + "enum": texi_enum, + "union": texi_union, + "alternate": texi_alternate, + "event": texi_event}[kind] + + return fmt(expr, doc) + + +def texi(docs): + """Convert QAPI schema expressions to texi documentation""" + res = [] + for doc in docs: + expr = doc.expr + if not expr: + res.append(texi_body(doc)) + continue + try: + doc = texi_expr(expr, doc) + res.append(doc) + except: + print >>sys.stderr, "error at @%s" % doc.info + raise + + return '\n'.join(res) + + +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]
scripts/qapi2texi.py new file +8
-0+ sys.exit(1) + + schema = qapi.QAPISchema(argv[1]) + print texi(schema.docs) + + +if __name__ == "__main__": + main(sys.argv)docs/qapi-code-gen.txt +0
-0@@ -44,40 +44,148 @@ Input must be ASCII (although QMP supports fullUnicode strings, the
QAPI parser does not). At present, there is no place where a QAPI schema requires the use of JSON numbers or null.docs/qapi-code-gen.txt +3
-18+ +=== Comments === + Comments are allowed; anything between an unquoted # and the following -newline is ignored. Although there is not yet a documentation -generator, a form of stylized comments has developed for consistently -documenting details about an expression and when it was added to the -schema. The documentation is delimited between two lines of ##, then -the first line names the expression, an optional overview is provided, -then individual documentation about each member of 'data' is provided, -and finally, a 'Since: x.y.z' tag lists the release that introduced -the expression. Optional members are tagged with the phrase -'#optional', often with their default value; and extensions added -after the expression was first released are also given a '(since -x.y.z)' comment. For example: - - ## - # @BlockStats: - # - # Statistics of a virtual block device or a block backing device. - # - # @device: #optional If the stats are for a virtual block device,the
namedocs/qapi-code-gen.txt +0
-5- # corresponding to the virtual block device. - # - # @stats: A @BlockDeviceStats for the device. - # - # @parent: #optional This describes the file block device if it hasone.
docs/qapi-code-gen.txt +0
-2- # - # @backing: #optional This describes the backing block device if ithas one.
docs/qapi-code-gen.txt +28
-8- # (Since 2.0) - # - # Since: 0.14.0 - ## - { 'struct': 'BlockStats', - 'data': {'*device': 'str', 'stats': 'BlockDeviceStats', - '*parent': 'BlockStats', - '*backing': 'BlockStats'} } +newline is ignored. + +A multi-line comment that starts and ends with a '##' line is a +documentation comment. These are parsed by the documentation +generator, which recognizes certain markup detailed below. + + +==== Documentation markup ==== + +Comment text starting with '=' is a section title: + + # = Section title + +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 + # multiple lines + # * Second item +
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
docs/qapi-code-gen.txt Input must be ASCII (although QMP supports full Unicode strings, the · line 84
Quoted 6 lines
docs/qapi-code-gen.txt +6
-0+You can also use '-' instead of '*'. + +A decimal number followed by '.' starts a numbered list: + + # 1. First item, may span + # multiple linesShould the second line be indented?
ok
Quoted 49 lines
Quoted 11 lines
Quoted 10 lines
docs/qapi-code-gen.txt Input must be ASCII (although QMP supports full Unicode strings, the · line 90
Quoted 7 lines
docs/qapi-code-gen.txt +6
-0+ # 2. Second item + +The actual number doesn't matter. You could even use '*' instead of +'2.' for the second item. + +FIXME what exactly ends a listCan you say offhand what ends a list? If yes, can we resolve this FIXME now rather than later?
Quoted 4 lines
well, the code is too permissive, there is a FIXME there already.
In general, I think we want to end a list after a blank line and a "non-item" line. Is the wording ok?
Blank line is pretty restrictive, because list items consisting of multiple paragraphs aren't possible then.
I think writing something like this is fairly natural:
* First item, may span
multiple lines.Even multiple paragaphs are okay.
* Second item
- This is a sublist
- Second item of sublist* Third item
This sentence is not part of the list.
We don't support sublists, and I'm not saying we should, I'm just showing how they would fit in.
My point is that indentation is a natural way to delimit list items.
I don't expect you to implement this now. All I want for this series is reasonable documentation. As far as I can tell,
texi_format()ends the list at a blank line, except when it doesn't (see its FIXME).What about this: replace "FIXME what exactly ends a list" by
Lists can't be nested. Blank lines are currently not supported within lists.
Quoted 6 lines
and add to texi_format()'s FIXME something like
Make sure to update section "Documentation markup" in
docs/qapi-code-gen.txtwhen fixing this.Okay?
ok
Quoted 175 lines
Quoted 174 lines
Quoted 40 lines
Quoted 27 lines
docs/qapi-code-gen.txt +26
-0+ +Additional whitespace between the initial '#' and the comment text is +permitted. + +*foo* and _foo_ are for strong and emphasis styles respectively (they +do not work over multiple lines). @foo is used to reference a name in +the schema. + +Example: + +## +# = Section +# == Subsection +# +# Some text foo with *strong* and _emphasis_ +# 1. with a list +# 2. like that +# +# And some code: +# | $ echo foo +# | -> do this +# | <- get that +# +## + +docs/qapi-code-gen.txt Input must be ASCII (although QMP supports full Unicode strings, the · line 126
Quoted 10 lines
docs/qapi-code-gen.txt +10
-0+==== Expression documentation ==== + +Each expression that isn't an include directive must be preceded by a +documentation block. Such blocks are called expression documentation +blocks. + +The first line of the documentation names the expression, then the +documentation body is provided, then individual documentation about +each member of 'data' is provided. Finally, several tagged sections +can be added.In my review of v6, I wrote:
Quoted 8 lines
I'm afraid this is more aspiration than specification: the parser accepts these things in almost any order.
Could be filed under "deficiencies" for now.
To file under "deficiencies", we need to add a FIXME or TODO either here, or in the parser. Assuming you haven't tightened the parser meanwhile (hope you haven't; we need to control the churn).
ok
Quoted 22 lines
Member of 'data' won't remain accurate. Consider:
{ 'union': 'GlusterServer',
'base': { 'type': 'GlusterTransport' }, 'discriminator': 'type',
'data': { 'unix': 'UnixSocketAddress',
'tcp': 'InetSocketAddress' } }Its doc comment currently doesn't contain argument sections. It should
eventually contain @type:, @unix: and @tcp:. Only the latter two are members of 'data'.I should propose something better, but I'm getting perilously close to the christmas break already. Later.
Also: passive voice is meh (not your idea; you adapted the existing text).
What about:
Quoted 8 lines
The documentation block consists of a first line naming the expression, an optional overview, a description of each argument (for commands and events) or member (for structs, unions and alternates), and optional tagged sections.
I still don't like the use of "section" for both the = things and the tagged sections, but it's not important enough to spend time on it now.
ok
Quoted 5 lines
docs/qapi-code-gen.txt Input must be ASCII (although QMP supports full Unicode strings, the · line 128
Quoted 2 lines
docs/qapi-code-gen.txt +2
-0+ +Optional members are tagged with the phrase '#optional', often withIf we adopt my text, we should say "arguments / members" here.
ok
Quoted 9 lines
docs/qapi-code-gen.txt Input must be ASCII (although QMP supports full Unicode strings, the · line 133
Quoted 5 lines
docs/qapi-code-gen.txt +5
-0+their default value; and extensions added after the expression was +first released are also given a '(since x.y.z)' comment. + +A tagged section starts with one of the following words: +"Note:"/"Notes:", "Since:", "Example"/"Examples", "Returns:", "TODO:".What ends such a section? The start of the next one / end of the comment block?
yes
Quoted 8 lines
I suspect we could avoid PATCH 03 by recognizing "TODO" in addition to "TODO:". Might also be more robust. But let's ignore this now.
docs/qapi-code-gen.txt Input must be ASCII (although QMP supports full Unicode strings, the · line 135
Quoted 2 lines
docs/qapi-code-gen.txt +2
-0+ +A 'Since: x.y.z' tag lists the release that introduced the expression.Nitpick: 'Since: x.y.z' is a tagged section, not a tag.
ok
Quoted 59 lines
Quoted 47 lines
docs/qapi-code-gen.txt +9
-0+ +For example: + +## +# @BlockStats: +# +# Statistics of a virtual block device or a block backing device. +# +# @device: #optional If the stats are for a virtual block device, thename
docs/qapi-code-gen.txt +37
-0+# corresponding to the virtual block device. +# +# @node-name: #optional The node name of the device. (since 2.3) +# +# ... more members ... +# +# Since: 0.14.0 +## +{ 'struct': 'BlockStats', + 'data': {'*device': 'str', '*node-name': 'str', + ... more members ... } } + +## +# @query-blockstats: +# +# Query the @BlockStats for all virtual block devices. +# +# @query-nodes: #optional If true, the command will query all the +# block nodes ... explain, explain ... (since 2.3) +# +# Returns: A list of @BlockStats for each virtual block devices. +# +# Since: 0.14.0 +# +# Example: +# +# -> { "execute": "query-blockstats" } +# <- { +# ... lots of output ... +# } +# +## +{ 'command': 'query-blockstats', + 'data': { '*query-nodes': 'bool' }, + 'returns': ['BlockStats'] } + +==== Free-form documentation ====docs/qapi-code-gen.txt Input must be ASCII (although QMP supports full Unicode strings, the · line 191
Quoted 10 lines
docs/qapi-code-gen.txt +7
-0+ +A documentation block that isn't an expression documentation block is +a free-form documentation block. These may be used to provide +additional text and structuring content. + + +=== Schema overview === The schema sets up a series of types, as well as commands and events that will use those types. Forward references are allowed: the parser[Tests look okay, snipped...]
PATCH v7 16/21 docs: add qemu logo to pdf
In reply to Marc-André LureauAdd a logo to texi2pdf output. Other formats (info/html) are left as future improvements.
The PDF (needed by texi2pdf for vectorized images) was generated from pc-bios/qemu_logo.svg like this:
inkscape --export-pdf=docs/qemu_logo.pdf pc-bios/qemu_logo.svg
--- docs/qemu-ga-ref.texi | 4 ++++ docs/qemu-qmp-ref.texi | 4 ++++ docs/qemu_logo.pdf | Bin 0 -> 9117 bytes 3 files changed, 8 insertions(+) create mode 100644 docs/qemu_logo.pdf
docs/qemu-ga-ref.texi +4 -0
@@ -6,6 +6,10 @@ @settitle QEMU Guest Agent Protocol Reference +@iftex +@center @image{docs/qemu_logo} +@end iftex + @copying This is the QEMU Guest Agent Protocol reference manual.
docs/qemu-qmp-ref.texi +4 -0
@@ -6,6 +6,10 @@ @settitle QEMU QMP Reference Manual +@iftex +@center @image{docs/qemu_logo} +@end iftex + @copying This is the QEMU QMP reference manual.
docs/qemu_logo.pdf new file binary +0 -0
Signature · 1 line
2.11.0
PATCH v7 17/21 build-sys: use --no-split for info
In reply to Marc-André LureauSplitting the info files doesn't bring much benefits these days. This fixes also untracked generated info files from git ignore.
Let's use MAKEINFOFLAGS for common flags, --number-sections is already the default anyway, so adding it doesn't change the info output.
--- Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Makefile +4 -4
@@ -529,17 +529,17 @@ ui/console-gl.o: $(SRC_PATH)/ui/console-gl.c \ # documentation MAKEINFO=makeinfo -MAKEINFOFLAGS=--no-headers --no-split --number-sections +MAKEINFOFLAGS=--no-split --number-sections TEXIFLAG=$(if $(V),,--quiet) %.dvi: %.texi $(call quiet-command,texi2dvi $(TEXIFLAG) -I . $<,"GEN","$@") %.html: %.texi - $(call quiet-command,LC_ALL=C $(MAKEINFO) $(MAKEINFOFLAGS) --html $< -o $@, \ - "GEN","$@") + $(call quiet-command,LC_ALL=C $(MAKEINFO) $(MAKEINFOFLAGS) --no-headers \ + --html $< -o $@,"GEN","$@") %.info: %.texi - $(call quiet-command,$(MAKEINFO) $< -o $@,"GEN","$@") + $(call quiet-command,$(MAKEINFO) $(MAKEINFOFLAGS) $< -o $@,"GEN","$@") %.pdf: %.texi $(call quiet-command,texi2pdf $(TEXIFLAG) -I . $<,"GEN","$@")
Signature · 1 line
2.11.0
PATCH v7 18/21 build-sys: remove dvi doc generation
In reply to Marc-André LureauThere is no clear reason to have rules to generate dvi format documentation, pdf is generally better supported nowadays.
--- .gitignore | 1 - Makefile | 12 ++++-------- 2 files changed, 4 insertions(+), 9 deletions(-)
.gitignore +0 -1
@@ -60,7 +60,6 @@ *.a *.aux *.cp -*.dvi *.exe *.msi *.dll
Makefile +4 -8
@@ -80,7 +80,7 @@ GENERATED_HEADERS += module_block.h Makefile: ; configure: ; -.PHONY: all clean cscope distclean dvi html info install install-doc \ +.PHONY: all clean cscope distclean html info install install-doc \ pdf recurse-all speed test dist msi FORCE $(call set-vpath, $(SRC_PATH))
@@ -389,7 +389,7 @@ distclean: clean 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 - rm -f qemu-doc.info qemu-doc.aux qemu-doc.cp qemu-doc.cps qemu-doc.dvi + rm -f qemu-doc.info qemu-doc.aux qemu-doc.cp qemu-doc.cps rm -f qemu-doc.fn qemu-doc.fns qemu-doc.info qemu-doc.ky qemu-doc.kys rm -f qemu-doc.log qemu-doc.pdf qemu-doc.pg qemu-doc.toc qemu-doc.tp rm -f qemu-doc.vr
@@ -531,9 +531,6 @@ ui/console-gl.o: $(SRC_PATH)/ui/console-gl.c \ MAKEINFO=makeinfo MAKEINFOFLAGS=--no-split --number-sections TEXIFLAG=$(if $(V),,--quiet) -%.dvi: %.texi - $(call quiet-command,texi2dvi $(TEXIFLAG) -I . $<,"GEN","$@") - %.html: %.texi $(call quiet-command,LC_ALL=C $(MAKEINFO) $(MAKEINFOFLAGS) --no-headers \ --html $< -o $@,"GEN","$@")
@@ -587,12 +584,11 @@ qemu-ga.8: qemu-ga.texi $(POD2MAN) --section=8 --center=" " --release=" " qemu-ga.pod > $@, \ "GEN","$@") -dvi: qemu-doc.dvi html: qemu-doc.html info: qemu-doc.info pdf: qemu-doc.pdf -qemu-doc.dvi qemu-doc.html qemu-doc.info qemu-doc.pdf: \ +qemu-doc.html qemu-doc.info qemu-doc.pdf: \ qemu-img.texi qemu-nbd.texi qemu-options.texi qemu-option-trace.texi \ qemu-monitor.texi qemu-img-cmds.texi qemu-ga.texi \ qemu-monitor-info.texi
@@ -689,7 +685,7 @@ help: @echo ' docker - Help about targets running tests inside Docker containers' @echo '' @echo 'Documentation targets:' - @echo ' dvi html info pdf' + @echo ' html info pdf' @echo ' - Build documentation in specified format' @echo '' ifdef CONFIG_WIN32
Signature · 1 line
2.11.0
PATCH v7 19/21 build-sys: use a generic TEXI2MAN rule
In reply to Marc-André LureauThe recipe for making a man page from .texi is duplicated several times over. Capture it in suitable pattern rules instead.
--- Makefile | 24 ------------------------ rules.mak | 10 ++++++++++ 2 files changed, 10 insertions(+), 24 deletions(-)
Makefile +0 -24
@@ -554,35 +554,11 @@ qemu-img-cmds.texi: $(SRC_PATH)/qemu-img-cmds.hx $(SRC_PATH)/scripts/hxtool $(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -t < $< > $@,"GEN","$@") qemu.1: qemu-doc.texi qemu-options.texi qemu-monitor.texi qemu-monitor-info.texi - $(call quiet-command, \ - perl -Ww -- $(SRC_PATH)/scripts/texi2pod.pl $< qemu.pod && \ - $(POD2MAN) --section=1 --center=" " --release=" " qemu.pod > $@, \ - "GEN","$@") qemu.1: qemu-option-trace.texi - qemu-img.1: qemu-img.texi qemu-option-trace.texi qemu-img-cmds.texi - $(call quiet-command, \ - perl -Ww -- $(SRC_PATH)/scripts/texi2pod.pl $< qemu-img.pod && \ - $(POD2MAN) --section=1 --center=" " --release=" " qemu-img.pod > $@, \ - "GEN","$@") - fsdev/virtfs-proxy-helper.1: fsdev/virtfs-proxy-helper.texi - $(call quiet-command, \ - perl -Ww -- $(SRC_PATH)/scripts/texi2pod.pl $< fsdev/virtfs-proxy-helper.pod && \ - $(POD2MAN) --section=1 --center=" " --release=" " fsdev/virtfs-proxy-helper.pod > $@, \ - "GEN","$@") - qemu-nbd.8: qemu-nbd.texi qemu-option-trace.texi - $(call quiet-command, \ - perl -Ww -- $(SRC_PATH)/scripts/texi2pod.pl $< qemu-nbd.pod && \ - $(POD2MAN) --section=8 --center=" " --release=" " qemu-nbd.pod > $@, \ - "GEN","$@") - qemu-ga.8: qemu-ga.texi - $(call quiet-command, \ - perl -Ww -- $(SRC_PATH)/scripts/texi2pod.pl $< qemu-ga.pod && \ - $(POD2MAN) --section=8 --center=" " --release=" " qemu-ga.pod > $@, \ - "GEN","$@") html: qemu-doc.html info: qemu-doc.info
rules.mak +10 -0
@@ -361,3 +361,13 @@ define unnest-vars $(eval -include $(patsubst %.o,%.d,$(patsubst %.mo,%.d,$($v)))) $(eval $v := $(filter-out %/,$($v)))) endef + +TEXI2MAN = $(call quiet-command, \ + perl -Ww -- $(SRC_PATH)/scripts/texi2pod.pl $< [email protected] && \ + $(POD2MAN) --section=$(subst .,,$(suffix $@)) --center=" " --release=" " [email protected] > $@, \ + "GEN","$@") + +%.1: + $(call TEXI2MAN) +%.8: + $(call TEXI2MAN)
Signature · 1 line
2.11.0
PATCH v7 20/21 build-sys: add txt documentation rules
In reply to Marc-André LureauBuild plain text documentation, and install it.
--- .gitignore | 1 + Makefile | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-)
.gitignore +1 -0
@@ -40,6 +40,7 @@ /qmp-marshal.c /qemu-doc.html /qemu-doc.info +/qemu-doc.txt /qemu-img /qemu-nbd /qemu-options.def
Makefile +9 -3
@@ -81,7 +81,7 @@ Makefile: ; configure: ; .PHONY: all clean cscope distclean html info install install-doc \ - pdf recurse-all speed test dist msi FORCE + pdf txt recurse-all speed test dist msi FORCE $(call set-vpath, $(SRC_PATH))
@@ -90,7 +90,7 @@ LIBS+=-lz $(LIBS_TOOLS) HELPERS-$(CONFIG_LINUX) = qemu-bridge-helper$(EXESUF) ifdef BUILD_DOCS -DOCS=qemu-doc.html qemu.1 qemu-img.1 qemu-nbd.8 qemu-ga.8 +DOCS=qemu-doc.html qemu-doc.txt qemu.1 qemu-img.1 qemu-nbd.8 qemu-ga.8 ifdef CONFIG_VIRTFS DOCS+=fsdev/virtfs-proxy-helper.1 endif
@@ -431,6 +431,7 @@ endif install-doc: $(DOCS) $(INSTALL_DIR) "$(DESTDIR)$(qemu_docdir)" $(INSTALL_DATA) qemu-doc.html "$(DESTDIR)$(qemu_docdir)" + $(INSTALL_DATA) qemu-doc.txt "$(DESTDIR)$(qemu_docdir)" ifdef CONFIG_POSIX $(INSTALL_DIR) "$(DESTDIR)$(mandir)/man1" $(INSTALL_DATA) qemu.1 "$(DESTDIR)$(mandir)/man1"
@@ -538,6 +539,10 @@ TEXIFLAG=$(if $(V),,--quiet) %.info: %.texi $(call quiet-command,$(MAKEINFO) $(MAKEINFOFLAGS) $< -o $@,"GEN","$@") +%.txt: %.texi + $(call quiet-command,LC_ALL=C $(MAKEINFO) $(MAKEINFOFLAGS) --no-headers \ + --plaintext $< -o $@,"GEN $@") + %.pdf: %.texi $(call quiet-command,texi2pdf $(TEXIFLAG) -I . $<,"GEN","$@")
@@ -563,6 +568,7 @@ qemu-ga.8: qemu-ga.texi html: qemu-doc.html info: qemu-doc.info pdf: qemu-doc.pdf +txt: qemu-doc.txt qemu-doc.html qemu-doc.info qemu-doc.pdf: \ qemu-img.texi qemu-nbd.texi qemu-options.texi qemu-option-trace.texi \
@@ -661,7 +667,7 @@ help: @echo ' docker - Help about targets running tests inside Docker containers' @echo '' @echo 'Documentation targets:' - @echo ' html info pdf' + @echo ' html info pdf txt' @echo ' - Build documentation in specified format' @echo '' ifdef CONFIG_WIN32
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH v7 20/21] build-sys: add txt documentation rules
Quoted 52 lines · Marc-André Lureau
Build plain text documentation, and install it.
Signed-off-by Marc-André Lureau <[email protected]>Reviewed-by Markus Armbruster <[email protected]>--- .gitignore | 1 + Makefile | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-).gitignore +1
-0@@ -40,6 +40,7 @@ /qmp-marshal.c /qemu-doc.html /qemu-doc.info +/qemu-doc.txt /qemu-img /qemu-nbd /qemu-options.defMakefile +3
-2@@ -81,7 +81,7 @@ Makefile: ; configure: ; .PHONY: all clean cscope distclean html info install install-doc \ - pdf recurse-all speed test dist msi FORCE + pdf txt recurse-all speed test dist msi FORCE $(call set-vpath, $(SRC_PATH))@@ -90,7 +90,7 @@ LIBS+=-lz $(LIBS_TOOLS) HELPERS-$(CONFIG_LINUX) = qemu-bridge-helper$(EXESUF) ifdef BUILD_DOCS -DOCS=qemu-doc.html qemu.1 qemu-img.1 qemu-nbd.8 qemu-ga.8 +DOCS=qemu-doc.html qemu-doc.txt qemu.1 qemu-img.1 qemu-nbd.8 qemu-ga.8 ifdef CONFIG_VIRTFS DOCS+=fsdev/virtfs-proxy-helper.1 endif@@ -431,6 +431,7 @@ endif install-doc: $(DOCS) $(INSTALL_DIR) "$(DESTDIR)$(qemu_docdir)" $(INSTALL_DATA) qemu-doc.html "$(DESTDIR)$(qemu_docdir)" + $(INSTALL_DATA) qemu-doc.txt "$(DESTDIR)$(qemu_docdir)" ifdef CONFIG_POSIX $(INSTALL_DIR) "$(DESTDIR)$(mandir)/man1" $(INSTALL_DATA) qemu.1 "$(DESTDIR)$(mandir)/man1"
Makefile TEXIFLAG=$(if $(V),,--quiet) · line 544
Quoted 6 lines
Makefile +3
-0@@ -538,6 +539,10 @@ TEXIFLAG=$(if $(V),,--quiet) %.info: %.texi $(call quiet-command,$(MAKEINFO) $(MAKEINFOFLAGS) $< -o $@,"GEN","$@") +%.txt: %.texi + $(call quiet-command,LC_ALL=C $(MAKEINFO) $(MAKEINFOFLAGS) --no-headers \ + --plaintext $< -o $@,"GEN $@")
I believe this needs to be "GEN", "$@" now. See commit 0bdb12c.
Quoted 21 lines
Makefile +3
-1+ %.pdf: %.texi $(call quiet-command,texi2pdf $(TEXIFLAG) -I . $<,"GEN","$@")@@ -563,6 +568,7 @@ qemu-ga.8: qemu-ga.texi html: qemu-doc.html info: qemu-doc.info pdf: qemu-doc.pdf +txt: qemu-doc.txt qemu-doc.html qemu-doc.info qemu-doc.pdf: \ qemu-img.texi qemu-nbd.texi qemu-options.texi qemu-option-trace.texi \@@ -661,7 +667,7 @@ help: @echo ' docker - Help about targets running tests inside Docker containers' @echo '' @echo 'Documentation targets:' - @echo ' html info pdf' + @echo ' html info pdf txt' @echo ' - Build documentation in specified format' @echo '' ifdef CONFIG_WIN32
PATCH v7 21/21 build-sys: add qapi doc generation targets
In reply to Marc-André LureauGenerate and install the man, txt and html versions of QAPI documentation (generate and install qemu-doc.txt too).
Add it also to optional pdf/info targets.
--- .gitignore | 9 +++++++++ Makefile | 43 ++++++++++++++++++++++++++++++++++++------- configure | 2 +- docs/qmp-intro.txt | 3 +-- rules.mak | 2 ++ 5 files changed, 49 insertions(+), 10 deletions(-)
.gitignore +9 -0
@@ -109,6 +109,15 @@ /pc-bios/optionrom/kvmvapic.img /pc-bios/s390-ccw/s390-ccw.elf /pc-bios/s390-ccw/s390-ccw.img +/docs/qemu-ga-ref.html +/docs/qemu-ga-ref.txt +/docs/qemu-qmp-ref.html +/docs/qemu-qmp-ref.txt +docs/qemu-ga-ref.info* +docs/qemu-qmp-ref.info* +/qemu-ga-qapi.texi +/qemu-qapi.texi +*.tps .stgit-* cscope.* tags
Makefile +36 -7
107 lines not on this page · raw message
configure +1 -1
@@ -6183,7 +6183,7 @@ fi # build tree in object directory in case the source is not in the current directory DIRS="tests tests/tcg tests/tcg/cris tests/tcg/lm32 tests/libqos tests/qapi-schema tests/tcg/xtensa tests/qemu-iotests" -DIRS="$DIRS fsdev" +DIRS="$DIRS docs fsdev" DIRS="$DIRS pc-bios/optionrom pc-bios/spapr-rtas pc-bios/s390-ccw" DIRS="$DIRS roms/seabios roms/vgabios" DIRS="$DIRS qapi-generated"
docs/qmp-intro.txt +1 -2
@@ -16,8 +16,7 @@ QMP is JSON[1] based and features the following: For detailed information on QMP's usage, please, refer to the following files: o qmp-spec.txt QEMU Machine Protocol current specification -o qmp-commands.txt QMP supported commands (auto-generated at build-time) -o qmp-events.txt List of available asynchronous events +o qemu-qmp-ref.html QEMU QMP commands and events (auto-generated at build-time) [1] http://www.json.org
rules.mak +2 -0
@@ -369,5 +369,7 @@ TEXI2MAN = $(call quiet-command, \ %.1: $(call TEXI2MAN) +%.7: + $(call TEXI2MAN) %.8: $(call TEXI2MAN)
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH v7 21/21] build-sys: add qapi doc generation targets
Quoted 6 lines · Marc-André Lureau
Generate and install the man, txt and html versions of QAPI documentation (generate and install qemu-doc.txt too).
Add it also to optional pdf/info targets.
Signed-off-by Marc-André Lureau <[email protected]>
Quoted 10 lines · Marc-André Lureau
Add a qapi2texi script to generate the documentation from the qapi schemas.
The SQUASHED patch in this series is a squashed version of the documentation move from qmp-commands.txt to the schemas. The whole version (not sent on the ML to avoid spamming) is in the following git
branch: https://github.com/elmarco/qemu/commits/qapi-docPDF preview:
https://fedorapeople.org/~elmarco/qemu-qmp-ref.pdf (v7 without type info)
PATCH 15 "qapi: add qapi2texi script" might need another respin, depending on discussion. The rest looks ready to me, with a few commit message tweaks.
I could take PATCH 01-08,11 right away if that helps.
Hi
Quoted 12 lines · Markus Armbruster
Quoted 10 lines · Marc-André Lureau
Add a qapi2texi script to generate the documentation from the qapi schemas.
The SQUASHED patch in this series is a squashed version of the documentation move from qmp-commands.txt to the schemas. The whole version (not sent on the ML to avoid spamming) is in the following git
branch: https://github.com/elmarco/qemu/commits/qapi-docPDF preview:
https://fedorapeople.org/~elmarco/qemu-qmp-ref.pdf (v7 without type
Quoted 8 lines
info)
PATCH 15 "qapi: add qapi2texi script" might need another respin, depending on discussion. The rest looks ready to me, with a few commit message tweaks.
I could take PATCH 01-08,11 right away if that helps.
That will certainly help if you could take patches (including the one with minor nits if any), then I can rebase on top of your branch (qapi-next ?)
Signature · 1 line
Marc-André Lureau