summaryrefslogtreecommitdiffstats
path: root/scripts/qapi-visit.py
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2015-04-02 14:46:39 +0200
committerMarkus Armbruster <armbru@redhat.com>2015-05-14 18:41:32 +0200
commit12f8e1b9ff57e99dafbb13f89cd5a99ad5c28527 (patch)
tree53c4f5a3e185e53f94475b8990dfaea0b8717c3a /scripts/qapi-visit.py
parent16d80f61814745bd3f5bb9f47ae3b00edf9e1e45 (diff)
downloadhqemu-12f8e1b9ff57e99dafbb13f89cd5a99ad5c28527.zip
hqemu-12f8e1b9ff57e99dafbb13f89cd5a99ad5c28527.tar.gz
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-visit.py')
-rw-r--r--scripts/qapi-visit.py63
1 files changed, 16 insertions, 47 deletions
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index 75f0cf3..5b99336 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)
OpenPOWER on IntegriCloud