diff options
author | Markus Armbruster <armbru@redhat.com> | 2015-04-02 14:46:39 +0200 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2015-05-14 18:41:32 +0200 |
commit | 12f8e1b9ff57e99dafbb13f89cd5a99ad5c28527 (patch) | |
tree | 53c4f5a3e185e53f94475b8990dfaea0b8717c3a /scripts/qapi-commands.py | |
parent | 16d80f61814745bd3f5bb9f47ae3b00edf9e1e45 (diff) |
qapi: Factor open_output(), close_output() out of generators
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'scripts/qapi-commands.py')
-rw-r--r-- | scripts/qapi-commands.py | 101 |
1 files changed, 37 insertions, 64 deletions
diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py index 2889877680..c3e420e6c9 100644 --- a/scripts/qapi-commands.py +++ b/scripts/qapi-commands.py @@ -15,8 +15,6 @@ from ordereddict import OrderedDict from qapi import * import re -import os -import errno def generate_command_decl(name, args, ret_type): arglist="" @@ -311,51 +309,18 @@ qapi_init(qmp_init_marshal); registry=registry.rstrip()) return ret -def gen_command_decl_prologue(header, guard, prefix=""): +def gen_command_decl_prologue(prefix=""): ret = mcgen(''' -/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */ - -/* - * schema-defined QAPI function prototypes - * - * Copyright IBM, Corp. 2011 - * - * Authors: - * Anthony Liguori <aliguori@us.ibm.com> - * - * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. - * See the COPYING.LIB file in the top-level directory. - * - */ - -#ifndef %(guard)s -#define %(guard)s - #include "%(prefix)sqapi-types.h" #include "qapi/qmp/qdict.h" #include "qapi/error.h" ''', - header=basename(header), guard=guardname(header), prefix=prefix) + prefix=prefix) return ret def gen_command_def_prologue(prefix="", proxy=False): ret = mcgen(''' -/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */ - -/* - * schema-defined QMP->QAPI command dispatch - * - * Copyright IBM, Corp. 2011 - * - * Authors: - * Anthony Liguori <aliguori@us.ibm.com> - * - * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. - * See the COPYING.LIB file in the top-level directory. - * - */ - #include "qemu-common.h" #include "qemu/module.h" #include "qapi/qmp/qerror.h" @@ -374,8 +339,6 @@ def gen_command_def_prologue(prefix="", proxy=False): ret += '#include "%sqmp-commands.h"' % prefix return ret + "\n\n" -c_file = 'qmp-marshal.c' -h_file = 'qmp-commands.h' middle_mode = False (input_file, output_dir, do_c, do_h, prefix, opts) = \ @@ -385,29 +348,44 @@ for o, a in opts: if o in ("-m", "--middle"): middle_mode = True -c_file = output_dir + prefix + c_file -h_file = output_dir + prefix + h_file - -def maybe_open(really, name, opt): - if really: - return open(name, opt) - else: - import StringIO - return StringIO.StringIO() - -try: - os.makedirs(output_dir) -except os.error, e: - if e.errno != errno.EEXIST: - raise - exprs = parse_schema(input_file) commands = filter(lambda expr: expr.has_key('command'), exprs) commands = filter(lambda expr: not expr.has_key('gen'), commands) -fdecl = maybe_open(do_h, h_file, 'w') -fdef = maybe_open(do_c, c_file, 'w') -ret = gen_command_decl_prologue(header=basename(h_file), guard=guardname(h_file), prefix=prefix) +c_comment = ''' +/* + * schema-defined QMP->QAPI command dispatch + * + * Copyright IBM, Corp. 2011 + * + * Authors: + * Anthony Liguori <aliguori@us.ibm.com> + * + * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. + * See the COPYING.LIB file in the top-level directory. + * + */ +''' +h_comment = ''' +/* + * schema-defined QAPI function prototypes + * + * Copyright IBM, Corp. 2011 + * + * Authors: + * Anthony Liguori <aliguori@us.ibm.com> + * + * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. + * See the COPYING.LIB file in the top-level directory. + * + */ +''' + +(fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix, + 'qmp-marshal.c', 'qmp-commands.h', + c_comment, h_comment) + +ret = gen_command_decl_prologue(prefix=prefix) fdecl.write(ret) ret = gen_command_def_prologue(prefix=prefix) fdef.write(ret) @@ -431,13 +409,8 @@ for cmd in commands: ret = gen_marshal_input(cmd['command'], arglist, ret_type, middle_mode) + "\n" fdef.write(ret) -fdecl.write("\n#endif\n"); - if not middle_mode: ret = gen_registry(commands) fdef.write(ret) -fdef.flush() -fdef.close() -fdecl.flush() -fdecl.close() +close_output(fdef, fdecl) |