diff --git a/docs/reference/gio/gdbus-codegen.xml b/docs/reference/gio/gdbus-codegen.xml index 9d5f3ce6d..67b139f49 100644 --- a/docs/reference/gio/gdbus-codegen.xml +++ b/docs/reference/gio/gdbus-codegen.xml @@ -37,6 +37,9 @@ OUTFILES FILE + + + OUTFILE @@ -262,6 +265,55 @@ + + + + + If this option is passed, it will generate the header code and write it to the disk by + using the path and file name provided by . + + + Using , or + are not allowed to be used along with + and options, because these options + are used to generate only one file. + + + + + + + + + If this option is passed, it will generate the source code and write it to the disk by + using the path and file name provided by . + + + Using , or + are not allowed to be used along with + and options, because these options + are used to generate only one file. + + + + + + OUTFILE + + + The full path where the header () or the source code + () will be written, using the path and filename provided by + . The full path could be something like + $($OUTFILE).{c,h}. + + + Using , or + is not allowed along with + , because the latter is used to generate only one file. + + + + ELEMENT KEY VALUE 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 # # 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 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,