From patchwork Sun Apr 21 19:12:31 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Llu=C3=ADs_Vilanova?= X-Patchwork-Id: 238238 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 344BC2C010C for ; Mon, 22 Apr 2013 05:14:49 +1000 (EST) Received: from localhost ([::1]:48697 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UTzip-0002lC-8w for incoming@patchwork.ozlabs.org; Sun, 21 Apr 2013 15:14:47 -0400 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 To: qemu-devel@nongnu.org Date: Sun, 21 Apr 2013 21:12:31 +0200 Message-Id: <20130421191231.8947.63721.stgit@fimbulvetr.bsc.es> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <20130421191129.8947.77964.stgit@fimbulvetr.bsc.es> References: <20130421191129.8947.77964.stgit@fimbulvetr.bsc.es> User-Agent: StGit/0.16 MIME-Version: 1.0 X-MIME-Autoconverted: from 8bit to quoted-printable by roura.ac.upc.es id r3LJCWGm001818 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 147.83.33.10 Subject: [Qemu-devel] [PATCH v3 11/24] qapi: Add a primitive to include other files from a QAPI schema file X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Adds the "include(...)" primitive to the syntax of QAPI schema files. Signed-off-by: LluĂ­s 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="", proxy=False): try: - opts, args = getopt.gnu_getopt(sys.argv[1:], "chp:o:m", + opts, args = getopt.gnu_getopt(sys.argv[1:], "chp:i:o:m", ["source", "header", "prefix=", - "output-dir=", "type=", "middle"]) + "input-dir=", "output-dir=", + "type=", "middle"]) except getopt.GetoptError, err: print str(err) sys.exit(1) +input_dir = "" output_dir = "" prefix = "" dispatch_type = "sync" @@ -406,6 +408,8 @@ do_h = False for o, a in opts: if o in ("-p", "--prefix"): prefix = a + elif o in ("-i", "--input-dir"): + input_dir = a elif o in ("-o", "--output-dir"): output_dir = a + "/" elif o in ("-t", "--type"): @@ -437,7 +441,7 @@ except os.error, e: if e.errno != errno.EEXIST: raise -exprs = parse_schema(sys.stdin) +exprs = parse_schema(sys.stdin, input_dir) commands = filter(lambda expr: expr.has_key('command'), exprs) commands = filter(lambda expr: not expr.has_key('gen'), commands) 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) try: - opts, args = getopt.gnu_getopt(sys.argv[1:], "chp:o:", - ["source", "header", "prefix=", "output-dir="]) + opts, args = getopt.gnu_getopt(sys.argv[1:], "chp:i:o:", + ["source", "header", "prefix=", + "input-dir=", "output-dir="]) except getopt.GetoptError, err: print str(err) sys.exit(1) output_dir = "" +input_dir = "" prefix = "" c_file = 'qapi-types.c' h_file = 'qapi-types.h' @@ -201,6 +203,8 @@ do_h = False for o, a in opts: if o in ("-p", "--prefix"): prefix = a + elif o in ("-i", "--input-dir"): + input_dir = a elif o in ("-o", "--output-dir"): output_dir = a + "/" elif o in ("-c", "--source"): @@ -279,7 +283,7 @@ fdecl.write(mcgen(''' ''', guard=guardname(h_file))) -exprs = parse_schema(sys.stdin) +exprs = parse_schema(sys.stdin, input_dir) exprs = filter(lambda expr: not expr.has_key('gen'), exprs) 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=name) try: - opts, args = getopt.gnu_getopt(sys.argv[1:], "chp:o:", - ["source", "header", "prefix=", "output-dir="]) + opts, args = getopt.gnu_getopt(sys.argv[1:], "chp:i:o:", + ["source", "header", "prefix=", + "input-dir=", "output-dir="]) except getopt.GetoptError, err: print str(err) sys.exit(1) +input_dir = "" output_dir = "" prefix = "" c_file = 'qapi-visit.c' @@ -252,6 +254,8 @@ do_h = False for o, a in opts: if o in ("-p", "--prefix"): prefix = a + elif o in ("-i", "--input-dir"): + input_dir = a elif o in ("-o", "--output-dir"): output_dir = a + "/" elif o in ("-c", "--source"): @@ -327,7 +331,7 @@ fdecl.write(mcgen(''' ''', prefix=prefix, guard=guardname(h_file))) -exprs = parse_schema(sys.stdin) +exprs = parse_schema(sys.stdin, input_dir) 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. +import os +import re from ordereddict import OrderedDict +include_cre = re.compile("\s*include\(\"([^\"]*)\"\)") + def tokenize(data): while len(data): ch = data[0] @@ -72,7 +76,7 @@ def parse(tokens): def evaluate(string): return parse(map(lambda x: x, tokenize(string)))[0] -def parse_schema(fp): +def parse_schema(fp, input_dir): exprs = [] expr = '' expr_eval = None @@ -81,6 +85,12 @@ def parse_schema(fp): if line.startswith('#') or line == '\n': continue + line_file = include_cre.match(line) + if line_file is not None: + path = os.sep.join([input_dir, line_file.group(1)]) + exprs += parse_schema(file(path), input_dir) + continue + if line.startswith(' '): expr += line elif expr: