iotests: Filter $SOCK_DIR
[qemu.git] / scripts / qapi-gen.py
blobf93f3c7c233e4edb9973fb9918b62f853f68ffad
1 #!/usr/bin/env python
2 # QAPI generator
4 # This work is licensed under the terms of the GNU GPL, version 2 or later.
5 # See the COPYING file in the top-level directory.
7 from __future__ import print_function
9 import argparse
10 import re
11 import sys
13 from qapi.commands import gen_commands
14 from qapi.doc import gen_doc
15 from qapi.events import gen_events
16 from qapi.introspect import gen_introspect
17 from qapi.schema import QAPIError, QAPISchema
18 from qapi.types import gen_types
19 from qapi.visit import gen_visit
22 def main(argv):
23 parser = argparse.ArgumentParser(
24 description='Generate code from a QAPI schema')
25 parser.add_argument('-b', '--builtins', action='store_true',
26 help="generate code for built-in types")
27 parser.add_argument('-o', '--output-dir', action='store', default='',
28 help="write output to directory OUTPUT_DIR")
29 parser.add_argument('-p', '--prefix', action='store', default='',
30 help="prefix for symbols")
31 parser.add_argument('-u', '--unmask-non-abi-names', action='store_true',
32 dest='unmask',
33 help="expose non-ABI names in introspection")
34 parser.add_argument('schema', action='store')
35 args = parser.parse_args()
37 match = re.match(r'([A-Za-z_.-][A-Za-z0-9_.-]*)?', args.prefix)
38 if match.end() != len(args.prefix):
39 print("%s: 'funny character '%s' in argument of --prefix"
40 % (sys.argv[0], args.prefix[match.end()]),
41 file=sys.stderr)
42 sys.exit(1)
44 try:
45 schema = QAPISchema(args.schema)
46 except QAPIError as err:
47 print(err, file=sys.stderr)
48 exit(1)
50 gen_types(schema, args.output_dir, args.prefix, args.builtins)
51 gen_visit(schema, args.output_dir, args.prefix, args.builtins)
52 gen_commands(schema, args.output_dir, args.prefix)
53 gen_events(schema, args.output_dir, args.prefix)
54 gen_introspect(schema, args.output_dir, args.prefix, args.unmask)
55 gen_doc(schema, args.output_dir, args.prefix)
58 if __name__ == '__main__':
59 main(sys.argv)