summaryrefslogtreecommitdiff
path: root/scripts/qapi-types.py
diff options
context:
space:
mode:
authorAvi Kivity <avi@redhat.com>2011-12-27 16:02:16 +0200
committerAnthony Liguori <aliguori@us.ibm.com>2011-12-27 09:28:58 -0600
commit8d3bc5178fbc06cdd89c064ae8f44e77c503e91e (patch)
tree5a636844be70c13422856569e90f9e487141a5c5 /scripts/qapi-types.py
parent4e1ea514f9b9f07358b84554dc3d35f533ec3971 (diff)
downloadqemu-8d3bc5178fbc06cdd89c064ae8f44e77c503e91e.tar.gz
Fix qapi code generation wrt parallel build
Make's multiple output syntax x.c x.h: x.template gen < x.template actually invokes the command once for x.c and once for x.h (with differing $@ in each invocation). During a parallel build, the two commands may be invoked in parallel; this opens up a race, where the second invocation trashes a file supposedly produced during the first, and now in use by a dependent command. The various qapi code generators are susceptible to this; fix by making them generate just one file per invocation. Signed-off-by: Avi Kivity <avi@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'scripts/qapi-types.py')
-rw-r--r--scripts/qapi-types.py27
1 files changed, 24 insertions, 3 deletions
diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index 267cb49b13..ae644bc06f 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -163,7 +163,8 @@ void qapi_free_%(type)s(%(c_type)s obj)
try:
- opts, args = getopt.gnu_getopt(sys.argv[1:], "p:o:", ["prefix=", "output-dir="])
+ opts, args = getopt.gnu_getopt(sys.argv[1:], "chp:o:",
+ ["source", "header", "prefix=", "output-dir="])
except getopt.GetoptError, err:
print str(err)
sys.exit(1)
@@ -173,11 +174,22 @@ prefix = ""
c_file = 'qapi-types.c'
h_file = 'qapi-types.h'
+do_c = False
+do_h = False
+
for o, a in opts:
if o in ("-p", "--prefix"):
prefix = a
elif o in ("-o", "--output-dir"):
output_dir = a + "/"
+ elif o in ("-c", "--source"):
+ do_h = True
+ elif o in ("-h", "--header"):
+ do_c = True
+
+if not do_c and not do_h:
+ do_c = True
+ do_h = True
c_file = output_dir + prefix + c_file
h_file = output_dir + prefix + h_file
@@ -188,8 +200,17 @@ except os.error, e:
if e.errno != errno.EEXIST:
raise
-fdef = open(c_file, 'w')
-fdecl = open(h_file, 'w')
+def maybe_open(really, name, opt):
+ class Null(object):
+ def write(self, str):
+ pass
+ def read(self):
+ return ''
+ if really:
+ return open(name, opt)
+
+fdef = maybe_open(do_c, c_file, 'w')
+fdecl = maybe_open(do_h, h_file, 'w')
fdef.write(mcgen('''
/* AUTOMATICALLY GENERATED, DO NOT MODIFY */