Received: from eggs.gnu.org ([208.118.235.92]:35004) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UTzgg-0008J1-5D for qemu-devel@nongnu.org; Sun, 21 Apr 2013 15:12:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UTzge-0001oR-Vh for qemu-devel@nongnu.org; Sun, 21 Apr 2013 15:12:34 -0400 Received: from roura.ac.upc.es ([147.83.33.10]:33196) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UTzge-0001oI-L2 for qemu-devel@nongnu.org; Sun, 21 Apr 2013 15:12:32 -0400 Received: from gw.ac.upc.edu (gw.ac.upc.es [147.83.30.3]) by roura.ac.upc.es (8.13.8/8.13.8) with ESMTP id r3LJCWGm001818 for ; Sun, 21 Apr 2013 21:12:32 +0200 Received: from localhost (unknown [84.88.51.85]) by gw.ac.upc.edu (Postfix) with ESMTP id E21CC6B01A4 for ; Sun, 21 Apr 2013 21:12:31 +0200 (CEST) From: =?utf-8?b?TGx1w61z?= Vilanova Date: Sun, 21 Apr 2013 21:12:31 +0200 Message-Id: <20130421191231.8947.63721.stgit@fimbulvetr.bsc.es> In-Reply-To: <20130421191129.8947.77964.stgit@fimbulvetr.bsc.es> References: <20130421191129.8947.77964.stgit@fimbulvetr.bsc.es> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v3 11/24] qapi: Add a primitive to include other files from a QAPI schema file List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Adds the "include(...)" primitive to the syntax of QAPI schema files. Signed-off-by: Llu=C3=ADs Vilanova --- scripts/qapi-commands.py | 10 +++++++--- scripts/qapi-types.py | 10 +++++++--- scripts/qapi-visit.py | 10 +++++++--- scripts/qapi.py | 12 +++++++++++- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py index e06332b..fa16651 100644 --- a/scripts/qapi-commands.py +++ b/scripts/qapi-commands.py @@ -386,13 +386,15 @@ def gen_command_def_prologue(prefix=3D"", proxy=3DF= alse): =20 =20 try: - opts, args =3D getopt.gnu_getopt(sys.argv[1:], "chp:o:m", + opts, args =3D getopt.gnu_getopt(sys.argv[1:], "chp:i:o:m", ["source", "header", "prefix=3D", - "output-dir=3D", "type=3D", "middle"= ]) + "input-dir=3D", "output-dir=3D", + "type=3D", "middle"]) except getopt.GetoptError, err: print str(err) sys.exit(1) =20 +input_dir =3D "" output_dir =3D "" prefix =3D "" dispatch_type =3D "sync" @@ -406,6 +408,8 @@ do_h =3D False for o, a in opts: if o in ("-p", "--prefix"): prefix =3D a + elif o in ("-i", "--input-dir"): + input_dir =3D a elif o in ("-o", "--output-dir"): output_dir =3D a + "/" elif o in ("-t", "--type"): @@ -437,7 +441,7 @@ except os.error, e: if e.errno !=3D errno.EEXIST: raise =20 -exprs =3D parse_schema(sys.stdin) +exprs =3D parse_schema(sys.stdin, input_dir) commands =3D filter(lambda expr: expr.has_key('command'), exprs) commands =3D filter(lambda expr: not expr.has_key('gen'), commands) =20 diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index 9e19920..ea33668 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -184,13 +184,15 @@ void qapi_free_%(type)s(%(c_type)s obj) =20 =20 try: - opts, args =3D getopt.gnu_getopt(sys.argv[1:], "chp:o:", - ["source", "header", "prefix=3D", "ou= tput-dir=3D"]) + opts, args =3D getopt.gnu_getopt(sys.argv[1:], "chp:i:o:", + ["source", "header", "prefix=3D", + "input-dir=3D", "output-dir=3D"]) except getopt.GetoptError, err: print str(err) sys.exit(1) =20 output_dir =3D "" +input_dir =3D "" prefix =3D "" c_file =3D 'qapi-types.c' h_file =3D 'qapi-types.h' @@ -201,6 +203,8 @@ do_h =3D False for o, a in opts: if o in ("-p", "--prefix"): prefix =3D a + elif o in ("-i", "--input-dir"): + input_dir =3D a elif o in ("-o", "--output-dir"): output_dir =3D a + "/" elif o in ("-c", "--source"): @@ -279,7 +283,7 @@ fdecl.write(mcgen(''' ''', guard=3Dguardname(h_file))) =20 -exprs =3D parse_schema(sys.stdin) +exprs =3D parse_schema(sys.stdin, input_dir) exprs =3D filter(lambda expr: not expr.has_key('gen'), exprs) =20 for expr in exprs: diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index a276540..c372e99 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -235,12 +235,14 @@ void visit_type_%(name)s(Visitor *m, %(name)s * obj= , const char *name, Error **e name=3Dname) =20 try: - opts, args =3D getopt.gnu_getopt(sys.argv[1:], "chp:o:", - ["source", "header", "prefix=3D", "ou= tput-dir=3D"]) + opts, args =3D getopt.gnu_getopt(sys.argv[1:], "chp:i:o:", + ["source", "header", "prefix=3D", + "input-dir=3D", "output-dir=3D"]) except getopt.GetoptError, err: print str(err) sys.exit(1) =20 +input_dir =3D "" output_dir =3D "" prefix =3D "" c_file =3D 'qapi-visit.c' @@ -252,6 +254,8 @@ do_h =3D False for o, a in opts: if o in ("-p", "--prefix"): prefix =3D a + elif o in ("-i", "--input-dir"): + input_dir =3D a elif o in ("-o", "--output-dir"): output_dir =3D a + "/" elif o in ("-c", "--source"): @@ -327,7 +331,7 @@ fdecl.write(mcgen(''' ''', prefix=3Dprefix, guard=3Dguardname(h_file))) =20 -exprs =3D parse_schema(sys.stdin) +exprs =3D parse_schema(sys.stdin, input_dir) =20 for expr in exprs: if expr.has_key('type'): diff --git a/scripts/qapi.py b/scripts/qapi.py index afc5f32..b4f98b5 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -9,8 +9,12 @@ # This work is licensed under the terms of the GNU GPLv2. # See the COPYING.LIB file in the top-level directory. =20 +import os +import re from ordereddict import OrderedDict =20 +include_cre =3D re.compile("\s*include\(\"([^\"]*)\"\)") + def tokenize(data): while len(data): ch =3D data[0] @@ -72,7 +76,7 @@ def parse(tokens): def evaluate(string): return parse(map(lambda x: x, tokenize(string)))[0] =20 -def parse_schema(fp): +def parse_schema(fp, input_dir): exprs =3D [] expr =3D '' expr_eval =3D None @@ -81,6 +85,12 @@ def parse_schema(fp): if line.startswith('#') or line =3D=3D '\n': continue =20 + line_file =3D include_cre.match(line) + if line_file is not None: + path =3D os.sep.join([input_dir, line_file.group(1)]) + exprs +=3D parse_schema(file(path), input_dir) + continue + if line.startswith(' '): expr +=3D line elif expr: