From: "Marc-André Lureau" <marcandre.lureau@gmail.com>
To: QEMU <qemu-devel@nongnu.org>
Cc: "Eduardo Habkost" <ehabkost@redhat.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Michael Roth" <mdroth@linux.vnet.ibm.com>,
"Cleber Rosa" <crosa@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v4 42/51] qapi: add a 'unit' pragma
Date: Fri, 12 Jan 2018 12:54:48 +0100 [thread overview]
Message-ID: <CAJ+F1CLrSaCthi3HZhg1629oycPS=cPHkOBs1PcVBsvFy=9M1w@mail.gmail.com> (raw)
In-Reply-To: <20180111213250.16511-43-marcandre.lureau@redhat.com>
Hi
On Thu, Jan 11, 2018 at 10:32 PM, Marc-André Lureau
<marcandre.lureau@redhat.com> wrote:
> Add a pragma that allows to tag the following expressions in the
> schema with a unit name. By default, an expression has no unit name.
>
> See the docs/devel/qapi-code-gen.txt for more details.
>
I inadvertently merged the following patch "qapi: add a -u/--unit
option to specify which unit to visit" with this one.
Fixed in the github branch: https://github.com/elmarco/qemu/commits/qapi-if
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
> scripts/qapi.py | 22 +++++++++++++++++++---
> docs/devel/qapi-code-gen.txt | 4 ++++
> tests/Makefile.include | 7 ++++++-
> tests/qapi-schema/pragma-unit-invalid.err | 1 +
> tests/qapi-schema/pragma-unit-invalid.exit | 1 +
> tests/qapi-schema/pragma-unit-invalid.json | 3 +++
> tests/qapi-schema/pragma-unit-invalid.out | 0
> tests/qapi-schema/qapi-schema-test.json | 6 +++++-
> tests/qapi-schema/qapi-schema-test.out | 2 ++
> 9 files changed, 41 insertions(+), 5 deletions(-)
> create mode 100644 tests/qapi-schema/pragma-unit-invalid.err
> create mode 100644 tests/qapi-schema/pragma-unit-invalid.exit
> create mode 100644 tests/qapi-schema/pragma-unit-invalid.json
> create mode 100644 tests/qapi-schema/pragma-unit-invalid.out
>
> diff --git a/scripts/qapi.py b/scripts/qapi.py
> index f56460d028..07e738c3f1 100644
> --- a/scripts/qapi.py
> +++ b/scripts/qapi.py
> @@ -47,6 +47,9 @@ returns_whitelist = []
> # Whitelist of entities allowed to violate case conventions
> name_case_whitelist = []
>
> +# Unit names to include for the visit (default to all units)
> +visit_units = []
> +
> enum_types = {}
> struct_types = {}
> union_types = {}
> @@ -269,11 +272,12 @@ class QAPISchemaParser(object):
> self.exprs = []
> self.docs = []
> self.accept()
> + self.unit = None
> cur_doc = None
>
> while self.tok is not None:
> info = {'file': self.fname, 'line': self.line,
> - 'parent': self.incl_info}
> + 'parent': self.incl_info, 'unit': self.unit}
> if self.tok == '#':
> self.reject_expr_doc(cur_doc)
> cur_doc = self.get_doc(info)
> @@ -362,6 +366,11 @@ class QAPISchemaParser(object):
> "Pragma name-case-whitelist must be"
> " a list of strings")
> name_case_whitelist = value
> + elif name == 'unit':
> + if not isinstance(value, str):
> + raise QAPISemError(info,
> + "Pragma 'unit' must be string")
> + self.unit = value
> else:
> raise QAPISemError(info, "Unknown pragma '%s'" % name)
>
> @@ -1827,6 +1836,10 @@ class QAPISchema(object):
> def visit(self, visitor):
> visitor.visit_begin(self)
> for (name, entity) in sorted(self._entity_dict.items()):
> + # FIXME: implicit array types should use element type unit
> + unit = entity.info and entity.info.get('unit')
> + if visit_units and unit not in visit_units:
> + continue
> if visitor.visit_needed(entity):
> entity.visit(visitor)
> visitor.visit_end()
> @@ -2126,13 +2139,14 @@ def parse_command_line(extra_options='', extra_long_options=[]):
>
> try:
> opts, args = getopt.gnu_getopt(
> - sys.argv[1:], 'chp:o:i:' + extra_options,
> + sys.argv[1:], 'chp:o:u:i:' + extra_options,
> ['source', 'header', 'prefix=', 'output-dir=',
> - 'include='] + extra_long_options)
> + 'unit=', 'include='] + extra_long_options)
> except getopt.GetoptError as err:
> print >>sys.stderr, "%s: %s" % (sys.argv[0], str(err))
> sys.exit(1)
>
> + global visit_units
> output_dir = ''
> prefix = ''
> do_c = False
> @@ -2152,6 +2166,8 @@ def parse_command_line(extra_options='', extra_long_options=[]):
> prefix = a
> elif o in ('-o', '--output-dir'):
> output_dir = a + '/'
> + elif o in ('-u', '--unit'):
> + visit_units.append(a)
> elif o in ('-c', '--source'):
> do_c = True
> elif o in ('-h', '--header'):
> diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt
> index 479b755609..31bcbdac58 100644
> --- a/docs/devel/qapi-code-gen.txt
> +++ b/docs/devel/qapi-code-gen.txt
> @@ -326,6 +326,10 @@ violate the rules on permitted return types. Default is none.
> Pragma 'name-case-whitelist' takes a list of names that may violate
> rules on use of upper- vs. lower-case letters. Default is none.
>
> +Pragma 'unit' takes a string value. It will set the unit name for the
> +following expressions in the schema. Most code generators can filter
> +based on a unit name. This allows to select a subset of the
> +expressions. Default is none.
>
> === Struct types ===
>
> diff --git a/tests/Makefile.include b/tests/Makefile.include
> index 2b83f05954..2f39e2d5aa 100644
> --- a/tests/Makefile.include
> +++ b/tests/Makefile.include
> @@ -510,6 +510,7 @@ qapi-schema += pragma-extra-junk.json
> qapi-schema += pragma-name-case-whitelist-crap.json
> qapi-schema += pragma-non-dict.json
> qapi-schema += pragma-returns-whitelist-crap.json
> +qapi-schema += pragma-unit-invalid.json
> qapi-schema += qapi-schema-test.json
> qapi-schema += quoted-structural-chars.json
> qapi-schema += redefined-builtin.json
> @@ -665,13 +666,17 @@ $(SRC_PATH)/tests/qapi-schema/qapi-schema-test.json $(SRC_PATH)/scripts/qapi-com
> tests/test-qapi-event.c tests/test-qapi-event.h :\
> $(SRC_PATH)/tests/qapi-schema/qapi-schema-test.json $(SRC_PATH)/scripts/qapi-event.py $(qapi-py)
> $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-event.py \
> - $(gen-out-type) -o tests -p "test-" $<, \
> + $(gen-out-type) -o tests -p "test-" -u test-unit $<, \
> "GEN","$@")
> +# check that another-unit is not included
> + $(call quiet-command,[ $(gen-out-type) == -h ] || grep -v -q ANOTHER_EVENT $@,"TEST","$@")
> tests/test-qmp-introspect.c tests/test-qmp-introspect.h :\
> $(SRC_PATH)/tests/qapi-schema/qapi-schema-test.json $(SRC_PATH)/scripts/qapi-introspect.py $(qapi-py)
> $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-introspect.py \
> $(gen-out-type) -o tests -p "test-" $<, \
> "GEN","$@")
> +# check all units are included
> + $(call quiet-command,[ $(gen-out-type) == -h ] || grep -q ANOTHER_EVENT $@,"TEST","$@")
>
> tests/qapi-schema/doc-good.test.texi: $(SRC_PATH)/tests/qapi-schema/doc-good.json $(SRC_PATH)/scripts/qapi2texi.py $(qapi-py)
> $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi2texi.py $< > $@,"GEN","$@")
> diff --git a/tests/qapi-schema/pragma-unit-invalid.err b/tests/qapi-schema/pragma-unit-invalid.err
> new file mode 100644
> index 0000000000..e22176d42e
> --- /dev/null
> +++ b/tests/qapi-schema/pragma-unit-invalid.err
> @@ -0,0 +1 @@
> +tests/qapi-schema/pragma-unit-invalid.json:3: Pragma 'unit' must be string
> diff --git a/tests/qapi-schema/pragma-unit-invalid.exit b/tests/qapi-schema/pragma-unit-invalid.exit
> new file mode 100644
> index 0000000000..d00491fd7e
> --- /dev/null
> +++ b/tests/qapi-schema/pragma-unit-invalid.exit
> @@ -0,0 +1 @@
> +1
> diff --git a/tests/qapi-schema/pragma-unit-invalid.json b/tests/qapi-schema/pragma-unit-invalid.json
> new file mode 100644
> index 0000000000..636b53939a
> --- /dev/null
> +++ b/tests/qapi-schema/pragma-unit-invalid.json
> @@ -0,0 +1,3 @@
> +# Value of 'unit' pragma must be a string
> +
> +{ 'pragma': { 'unit': {} } }
> diff --git a/tests/qapi-schema/pragma-unit-invalid.out b/tests/qapi-schema/pragma-unit-invalid.out
> new file mode 100644
> index 0000000000..e69de29bb2
> diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qapi-schema-test.json
> index cd33c084cb..2fb1d3449c 100644
> --- a/tests/qapi-schema/qapi-schema-test.json
> +++ b/tests/qapi-schema/qapi-schema-test.json
> @@ -8,7 +8,8 @@
> # Commands allowed to return a non-dictionary:
> 'returns-whitelist': [
> 'guest-get-time',
> - 'guest-sync' ] } }
> + 'guest-sync' ],
> + 'unit': 'test-unit' } }
>
> { 'struct': 'TestStruct',
> 'data': { 'integer': {'type': 'int'}, 'boolean': 'bool', 'string': 'str' } }
> @@ -224,3 +225,6 @@
> { 'foo': 'TestIfStruct',
> 'bar': { 'type': 'TestIfEnum', 'if': 'defined(TEST_IF_EVT_BAR)' } },
> 'if': 'defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT)' }
> +
> +{ 'pragma': { 'unit': 'another-unit' } }
> +{ 'event': 'ANOTHER_EVENT' }
> diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qapi-schema-test.out
> index 7215aeb4a6..cbc61fc3a2 100644
> --- a/tests/qapi-schema/qapi-schema-test.out
> +++ b/tests/qapi-schema/qapi-schema-test.out
> @@ -1,3 +1,5 @@
> +event ANOTHER_EVENT None
> + boxed=False
> alternate AltEnumBool
> tag type
> case e: EnumOne
> --
> 2.16.0.rc1.1.gef27df75a1
>
>
--
Marc-André Lureau
next prev parent reply other threads:[~2018-01-12 11:54 UTC|newest]
Thread overview: 74+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-11 21:31 [Qemu-devel] [PATCH v4 00/51] Hi, Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 01/51] qlit: use QType instead of int Marc-André Lureau
2018-01-11 22:52 ` Eric Blake
2018-02-05 6:05 ` Markus Armbruster
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 02/51] qlit: add qobject_from_qlit() Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 03/51] qapi: generate a literal qobject for introspection Marc-André Lureau
2018-02-06 10:04 ` Markus Armbruster
2018-02-06 11:01 ` Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 04/51] qapi2texi: minor python code simplification Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 05/51] qapi: add 'if' to top-level expressions Marc-André Lureau
2018-02-05 6:12 ` Markus Armbruster
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 06/51] qapi: pass 'if' condition into QAPISchemaEntity objects Marc-André Lureau
2018-02-05 6:16 ` Markus Armbruster
2018-02-06 10:12 ` Markus Armbruster
2018-02-06 11:06 ` Marc-André Lureau
2018-02-06 12:14 ` Markus Armbruster
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 07/51] qapi: leave the ifcond attribute undefined until check() Marc-André Lureau
2018-02-05 6:22 ` Markus Armbruster
2018-02-06 11:20 ` Markus Armbruster
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 08/51] qapi: add 'ifcond' to visitor methods Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 09/51] qapi: mcgen() shouldn't indent # lines Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 10/51] qapi: add #if/#endif helpers Marc-André Lureau
2018-02-05 7:03 ` Markus Armbruster
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 11/51] qapi-introspect: modify to_qlit() to append ', ' on level > 0 Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 12/51] qapi-introspect: add preprocessor conditions to generated QLit Marc-André Lureau
2018-01-12 10:27 ` Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 13/51] qapi-commands: add #if conditions to commands Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 14/51] qapi-event: add #if conditions to events Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 15/51] qapi-types: refactor variants handling Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 16/51] qapi-types: add #if conditions to types & visitors Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 17/51] qapi: do not define enumeration value explicitely Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 18/51] qapi: rename QAPISchemaEnumType.values to .members Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 19/51] qapi: change enum visitor to take QAPISchemaMember Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 20/51] tests: modify visit_enum_type() in test-qapi to print members Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 21/51] qapi: factor out check_known_keys() Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 22/51] qapi: add a dictionnary form with 'name' key for enum members Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 23/51] qapi: add 'if' to " Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 24/51] qapi-event: add 'if' condition to implicit event enum Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 25/51] qapi: rename allow_dict to allow_implicit Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 26/51] qapi: add a dictionary form with 'type' key for members Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 27/51] qapi: add 'if' to implicit struct members Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 28/51] qapi: add an error in case a discriminator is conditionnal Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 29/51] qapi: add 'if' on union members Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 30/51] qapi: add 'if' to alternate members Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 31/51] qapi: add #if conditions to generated code Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 32/51] docs: document schema configuration Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 33/51] qapi2texi: add 'If:' section to generated documentation Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 34/51] qapi2texi: add 'If:' condition to enum values Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 35/51] qapi2texi: add 'If:' condition to struct members Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 36/51] qapi2texi: add condition to variants Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 37/51] qapi: add conditions to VNC type/commands/events on the schema Marc-André Lureau
2018-01-12 13:04 ` Gerd Hoffmann
2018-01-12 13:22 ` Marc-André Lureau
2018-01-12 13:55 ` Gerd Hoffmann
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 38/51] qapi: add conditions to SPICE " Marc-André Lureau
2018-01-12 13:09 ` Gerd Hoffmann
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 39/51] qapi: add conditions to REPLICATION type/commands " Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 40/51] qapi-commands: don't initialize command list in qmp_init_marshall() Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 41/51] qapi: add -i/--include filename.h Marc-André Lureau
2018-02-05 16:58 ` Markus Armbruster
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 42/51] qapi: add a 'unit' pragma Marc-André Lureau
2018-01-12 11:54 ` Marc-André Lureau [this message]
2018-02-05 18:13 ` Markus Armbruster
2018-02-06 11:01 ` Marc-André Lureau
2018-02-06 12:31 ` Markus Armbruster
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 43/51] build-sys: move qmp-introspect per target Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 44/51] build-sys: add a target schema Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 45/51] qapi: make rtc-reset-reinjection depend on TARGET_I386 Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 46/51] qapi: make s390 commands depend on TARGET_S390X Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 47/51] target.json: add a note about query-cpu* not being s390x-specific Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 48/51] qapi: make query-gic-capabilities depend on TARGET_ARM Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 49/51] qapi: make query-cpu-model-expansion depend on s390 or x86 Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 50/51] qapi: make query-cpu-definitions depend on specific targets Marc-André Lureau
2018-01-11 21:32 ` [Qemu-devel] [PATCH v4 51/51] qapi: remove qmp_unregister_command() Marc-André Lureau
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAJ+F1CLrSaCthi3HZhg1629oycPS=cPHkOBs1PcVBsvFy=9M1w@mail.gmail.com' \
--to=marcandre.lureau@gmail.com \
--cc=armbru@redhat.com \
--cc=crosa@redhat.com \
--cc=ehabkost@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).