diff options
Diffstat (limited to 'scripts/qapi-visit.py')
-rw-r--r-- | scripts/qapi-visit.py | 63 |
1 files changed, 16 insertions, 47 deletions
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index 75f0cf3db5..5b99336488 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -15,8 +15,6 @@ from ordereddict import OrderedDict from qapi import * import re -import os -import errno implicit_structs = [] @@ -374,8 +372,6 @@ void visit_type_%(name)s(Visitor *m, %(name)s *obj, const char *name, Error **er ''', name=c_name(name)) -c_file = 'qapi-visit.c' -h_file = 'qapi-visit.h' do_builtins = False (input_file, output_dir, do_c, do_h, prefix, opts) = \ @@ -385,28 +381,7 @@ for o, a in opts: if o in ("-b", "--builtins"): do_builtins = True -c_file = output_dir + prefix + c_file -h_file = output_dir + prefix + h_file - -try: - os.makedirs(output_dir) -except os.error, e: - if e.errno != errno.EEXIST: - raise - -def maybe_open(really, name, opt): - if really: - return open(name, opt) - else: - import StringIO - return StringIO.StringIO() - -fdef = maybe_open(do_c, c_file, 'w') -fdecl = maybe_open(do_h, h_file, 'w') - -fdef.write(mcgen(''' -/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */ - +c_comment = ''' /* * schema-defined QAPI visitor functions * @@ -419,15 +394,8 @@ fdef.write(mcgen(''' * See the COPYING.LIB file in the top-level directory. * */ - -#include "qemu-common.h" -#include "%(header)s" -''', - header=basename(h_file))) - -fdecl.write(mcgen(''' -/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */ - +''' +h_comment = ''' /* * schema-defined QAPI visitor functions * @@ -440,15 +408,24 @@ fdecl.write(mcgen(''' * See the COPYING.LIB file in the top-level directory. * */ +''' + +(fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix, + 'qapi-visit.c', 'qapi-visit.h', + c_comment, h_comment) -#ifndef %(guard)s -#define %(guard)s +fdef.write(mcgen(''' +#include "qemu-common.h" +#include "%(prefix)sqapi-visit.h" +''', + prefix = prefix)) +fdecl.write(mcgen(''' #include "qapi/visitor.h" #include "%(prefix)sqapi-types.h" ''', - prefix=prefix, guard=guardname(h_file))) + prefix=prefix)) exprs = parse_schema(input_file) @@ -504,12 +481,4 @@ for expr in exprs: ret += generate_enum_declaration(expr['enum'], expr['data']) fdecl.write(ret) -fdecl.write(''' -#endif -''') - -fdecl.flush() -fdecl.close() - -fdef.flush() -fdef.close() +close_output(fdef, fdecl) |