summaryrefslogtreecommitdiff
path: root/scripts/qapi-types.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-types.py
parent16d80f61814745bd3f5bb9f47ae3b00edf9e1e45 (diff)
downloadqemu-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-types.py')
-rw-r--r--scripts/qapi-types.py67
1 files changed, 18 insertions, 49 deletions
diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index 62044c11cb..6bd0b13759 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -11,8 +11,6 @@
from ordereddict import OrderedDict
from qapi import *
-import os
-import errno
def generate_fwd_struct(name, members, builtin_type=False):
if builtin_type:
@@ -273,8 +271,6 @@ void qapi_free_%(name)s(%(c_type)s obj)
c_type=c_type(name), name=c_name(name))
return ret
-c_file = 'qapi-types.c'
-h_file = 'qapi-types.h'
do_builtins = False
(input_file, output_dir, do_c, do_h, prefix, opts) = \
@@ -284,28 +280,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('''
-/* AUTOMATICALLY GENERATED, DO NOT MODIFY */
-
+c_comment = '''
/*
* deallocation functions for schema-defined QAPI types
*
@@ -319,16 +294,8 @@ fdef.write(mcgen('''
* See the COPYING.LIB file in the top-level directory.
*
*/
-
-#include "qapi/dealloc-visitor.h"
-#include "%(prefix)sqapi-types.h"
-#include "%(prefix)sqapi-visit.h"
-
-''', prefix=prefix))
-
-fdecl.write(mcgen('''
-/* AUTOMATICALLY GENERATED, DO NOT MODIFY */
-
+'''
+h_comment = '''
/*
* schema-defined QAPI types
*
@@ -341,15 +308,25 @@ fdecl.write(mcgen('''
* See the COPYING.LIB file in the top-level directory.
*
*/
+'''
-#ifndef %(guard)s
-#define %(guard)s
+(fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix,
+ 'qapi-types.c', 'qapi-types.h',
+ c_comment, h_comment)
+fdef.write(mcgen('''
+#include "qapi/dealloc-visitor.h"
+#include "%(prefix)sqapi-types.h"
+#include "%(prefix)sqapi-visit.h"
+
+''',
+ prefix=prefix))
+
+fdecl.write(mcgen('''
#include <stdbool.h>
#include <stdint.h>
-''',
- guard=guardname(h_file)))
+'''))
exprs = parse_schema(input_file)
exprs = filter(lambda expr: not expr.has_key('gen'), exprs)
@@ -427,12 +404,4 @@ for expr in exprs:
continue
fdecl.write(ret)
-fdecl.write('''
-#endif
-''')
-
-fdecl.flush()
-fdecl.close()
-
-fdef.flush()
-fdef.close()
+close_output(fdef, fdecl)