diff options
author | Iñigo Martínez <inigomartinez@gmail.com> | 2018-01-04 14:18:07 +0100 |
---|---|---|
committer | Iñigo Martínez <inigomartinez@gmail.com> | 2018-01-15 16:11:17 +0100 |
commit | e4d68c7b3e8b01ab1a4231bf6da21d045cb5a816 (patch) | |
tree | 288c9ca6363a5fccc23bbed4f7f36b9edf1538db /gio/gdbus-2.0/codegen/codegen_main.py | |
parent | 6c3af1cdda6d5f4967ce1dd1428fe8f0b512dd3f (diff) | |
download | glib-e4d68c7b3e8b01ab1a4231bf6da21d045cb5a816.tar.gz |
gdbus-codegen: Support for separate C header and code generation
gdbus-codegen's options only allow a simultaneous header and source
code generation.
A `--header` and `--body` options have been added along with the
`--output` option which allow separate C header and code
generation.
These options cannot be used in addition to the old options such
as `--generate-c-code`, `--generate-docbook` or
`--output-directory`.
These options have also been added to gdbus-codegen's documentation.
https://bugzilla.gnome.org/show_bug.cgi?id=791015
Diffstat (limited to 'gio/gdbus-2.0/codegen/codegen_main.py')
-rwxr-xr-x | gio/gdbus-2.0/codegen/codegen_main.py | 56 |
1 files changed, 44 insertions, 12 deletions
diff --git a/gio/gdbus-2.0/codegen/codegen_main.py b/gio/gdbus-2.0/codegen/codegen_main.py index a650e2e10..baf426634 100755 --- a/gio/gdbus-2.0/codegen/codegen_main.py +++ b/gio/gdbus-2.0/codegen/codegen_main.py @@ -3,6 +3,7 @@ # GDBus - GLib D-Bus Library # # Copyright (C) 2008-2011 Red Hat, Inc. +# Copyright (C) 2018 Iñigo Martínez <inigomartinez@gmail.com> # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -20,8 +21,8 @@ # Author: David Zeuthen <davidz@redhat.com> import argparse +import os import sys -from os import path from . import config from . import dbustypes @@ -157,8 +158,6 @@ def codegen_main(): help='The namespace to use for generated C code') arg_parser.add_argument('--c-generate-object-manager', action='store_true', help='Generate a GDBusObjectManagerClient subclass when generating C code') - arg_parser.add_argument('--generate-c-code', metavar='OUTFILES', - help='Generate C code in OUTFILES.[ch]') arg_parser.add_argument('--c-generate-autocleanup', choices=['none', 'objects', 'all'], default='objects', help='Generate autocleanup support') arg_parser.add_argument('--generate-docbook', metavar='OUTFILES', @@ -167,13 +166,49 @@ def codegen_main(): help='Use "pragma once" as the inclusion guard') arg_parser.add_argument('--annotate', nargs=3, action='append', metavar='WHAT KEY VALUE', help='Add annotation (may be used several times)') - arg_parser.add_argument('--output-directory', metavar='OUTDIR', default='', - help='Location to output generated files') + + group = arg_parser.add_mutually_exclusive_group() + group.add_argument('--generate-c-code', metavar='OUTFILES', + help='Generate C code in OUTFILES.[ch]') + group.add_argument('--header', action='store_true', + help='Generate C headers') + group.add_argument('--body', action='store_true', + help='Generate C code') + + group = arg_parser.add_mutually_exclusive_group() + group.add_argument('--output', metavar='FILE', + help='Write output into the specified file') + group.add_argument('--output-directory', metavar='OUTDIR', default='', + help='Location to output generated files') + args = arg_parser.parse_args(); if len(args.xml_files) > 0: print_warning('The "--xml-files" option is deprecated; use positional arguments instead') + if ((args.generate_c_code is not None or args.generate_docbook is not None) and + args.output is not None): + print_error('Using --generate-c-code or --generate-docbook and ' + '--output at the same time is not allowed') + + if args.generate_c_code: + outdir = args.output_directory + header_name = args.generate_c_code + '.h' + h_file = os.path.join(outdir, header_name) + args.header = True + c_file = os.path.join(outdir, args.generate_c_code + '.c') + args.body = True + else: + if args.output is None: + print_error('Using --header or --body requires --output') + + if args.header: + h_file = args.output + header_name = os.path.basename(h_file) + elif args.body: + c_file = args.output + header_name = os.path.splitext(c_file)[0] + '.h' + all_ifaces = [] for fname in args.files + args.xml_files: with open(fname, 'rb') as f: @@ -187,17 +222,13 @@ def codegen_main(): for i in all_ifaces: i.post_process(args.interface_prefix, args.c_namespace) - outdir = args.output_directory - docbook = args.generate_docbook docbook_gen = codegen_docbook.DocbookCodeGenerator(all_ifaces); if docbook: ret = docbook_gen.generate(docbook, outdir) - c_code = args.generate_c_code - if c_code: - header_name = c_code + '.h' - with open(path.join(outdir, header_name), 'w') as outfile: + if args.header: + with open(h_file, 'w') as outfile: gen = codegen.HeaderCodeGenerator(all_ifaces, args.c_namespace, args.c_generate_object_manager, @@ -207,7 +238,8 @@ def codegen_main(): outfile) gen.generate() - with open(path.join(outdir, c_code + '.c'), 'w') as outfile: + if args.body: + with open(c_file, 'w') as outfile: gen = codegen.CodeGenerator(all_ifaces, args.c_namespace, args.c_generate_object_manager, |