qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: "Benoît Canet" <benoit.canet@irqsave.net>, qemu-devel@nongnu.org
Cc: anthony@codemonkey.ws, Benoit Canet <benoit@irqsave.net>,
	armbru@redhat.com, wenchaoqemu@gmail.com, lcapitulino@redhat.com
Subject: Re: [Qemu-devel] [PATCH V2 3/3] qapi: Create an include directive for use in the JSON description files.
Date: Thu, 27 Mar 2014 11:39:21 -0600	[thread overview]
Message-ID: <53346249.7070705@redhat.com> (raw)
In-Reply-To: <1395934399-18769-4-git-send-email-benoit.canet@irqsave.net>

[-- Attachment #1: Type: text/plain, Size: 3608 bytes --]

On 03/27/2014 09:33 AM, Benoît Canet wrote:
> The new directive in the form { 'include': 'path/to/file.json' } will trigger the
> parsing of path/to/file.json.
> The directive will be replaced by the result of the parsing.
> 
> This will allow for easy modularisation of qapi JSON descriptions files.
> 
> Signed-off-by: Benoit Canet <benoit@irqsave.net>
> ---
>  docs/qapi-code-gen.txt                 |   14 ++++++++++++++
>  scripts/qapi.py                        |   17 ++++++++++++++++-
>  tests/Makefile                         |    2 +-
>  tests/qapi-schema/include.exit         |    1 +
>  tests/qapi-schema/include.json         |    4 ++++
>  tests/qapi-schema/include.out          |    8 ++++++++
>  tests/qapi-schema/include/include.json |    7 +++++++
>  tests/qapi-schema/include_loop.exit    |    1 +
>  tests/qapi-schema/include_loop.json    |    1 +
>  tests/qapi-schema/include_loop.out     |    1 +
>  10 files changed, 54 insertions(+), 2 deletions(-)
>  create mode 100644 tests/qapi-schema/include.err
>  create mode 100644 tests/qapi-schema/include.exit
>  create mode 100644 tests/qapi-schema/include.json
>  create mode 100644 tests/qapi-schema/include.out
>  create mode 100644 tests/qapi-schema/include/include.json
>  create mode 100644 tests/qapi-schema/include_loop.err
>  create mode 100644 tests/qapi-schema/include_loop.exit
>  create mode 100644 tests/qapi-schema/include_loop.json
>  create mode 100644 tests/qapi-schema/include_loop.out
>  

>      for expr_elem in schema.exprs:
>          expr = expr_elem['expr']
> -        if expr.has_key('enum'):
> +        if expr.has_key('include'):
> +            prefix = os.path.split(path)[0]
> +            sub_path = os.path.join(prefix, expr['include'])

Should you validate that expr['include'] is a string, so we know the
user didn't do something stupid like { 'include': true } or { 'include':
{ 'hello':'world' } }.  And if you add validation, you also need to add
tests.

> +        elif expr.has_key('enum'):
>              add_enum(expr['enum'], expr['data'])

For that matter (pre-existing, but you suffer from the same problem) -
there's no validation against unexpected keys, which means {
'enum':'foo', 'garbage':'blah' } and { 'include':'path',
'garbage':'blah' } both manage to silently ignore the 'garbage' key.  If
you fix it for 'enum', do that first as a separate commit.

> +++ b/tests/qapi-schema/include.json
> @@ -0,0 +1,4 @@
> +{ 'enum': 'Status',
> +  'data': [ 'good', 'bad', 'ugly' ] }
> +{ 'include': './include/include.json' }

This tests successful inclusion relative to directory names.

> +++ b/tests/qapi-schema/include_loop.json
> @@ -0,0 +1 @@
> +{ 'include': 'include_loop.json' }

And this tests that self-inclusion is rejected.

But still missing tests for:

error message when the error occurs in an included file (ideally, the
error message should be the location within the included file, not the
outer file)

error occurring after a successful include (ideally, the lines injected
by the included file do NOT upset the line number tracking of the
original file)

multi-file loops being rejected (a includes b includes a)

each include name is relative to the current file even across nested
inclusion that changes directory (such as 'a' includes 'include/b'
includes '../c', should work when 'a' and 'c' are in the same directory,
and NOT try to pick up 'c' in the parent directory of 'a').

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

  reply	other threads:[~2014-03-27 17:39 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-27 15:33 [Qemu-devel] [PATCH V2 0/3] Create an include directive for QAPI JSON files Benoît Canet
2014-03-27 15:33 ` [Qemu-devel] [PATCH V2 1/3] test-qapi: Make test-qapi.py spit useful error messages Benoît Canet
2014-03-27 15:33 ` [Qemu-devel] [PATCH V2 2/3] qapi: Change the qapi scripts to take their input as first argument Benoît Canet
2014-03-27 17:27   ` Eric Blake
2014-03-28  8:27     ` Markus Armbruster
2014-03-27 17:56   ` Markus Armbruster
2014-03-27 15:33 ` [Qemu-devel] [PATCH V2 3/3] qapi: Create an include directive for use in the JSON description files Benoît Canet
2014-03-27 17:39   ` Eric Blake [this message]
2014-03-27 18:07   ` Markus Armbruster
2014-03-27 19:46     ` Benoît Canet

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=53346249.7070705@redhat.com \
    --to=eblake@redhat.com \
    --cc=anthony@codemonkey.ws \
    --cc=armbru@redhat.com \
    --cc=benoit.canet@irqsave.net \
    --cc=benoit@irqsave.net \
    --cc=lcapitulino@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=wenchaoqemu@gmail.com \
    /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).