codegen: Add --interface-info-[body|header] modes

These generate basic .c and .h files containing the GDBusInterfaceInfo
for a D-Bus introspection XML file, but no other code (no skeletons,
proxies, GObjects, etc.).

This is useful for projects who want to describe their D-Bus interfaces
using introspection XML, but who wish to implement the interfaces
manually (for various reasons, typically because the skeletons generated
by gdbus-codegen are too simplistic and limiting). Previously, these
projects would have had to write the GDBusInterfaceInfo manually, which
is painstaking and error-prone.

The new --interface-info-[body|header] options are very similar to
--[body|header], but mutually exclusive with them.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

https://bugzilla.gnome.org/show_bug.cgi?id=795304
This commit is contained in:
Philip Withnall
2018-04-17 14:10:07 +01:00
parent 99b64d4014
commit 8916874ee6
3 changed files with 377 additions and 7 deletions

View File

@@ -175,6 +175,10 @@ def codegen_main():
help='Generate C headers')
group.add_argument('--body', action='store_true',
help='Generate C code')
group.add_argument('--interface-info-header', action='store_true',
help='Generate GDBusInterfaceInfo C header')
group.add_argument('--interface-info-body', action='store_true',
help='Generate GDBusInterfaceInfo C code')
group = arg_parser.add_mutually_exclusive_group()
group.add_argument('--output', metavar='FILE',
@@ -210,6 +214,24 @@ def codegen_main():
c_file = args.output
header_name = os.path.splitext(os.path.basename(c_file))[0] + '.h'
elif args.interface_info_header:
if args.output is None:
print_error('Using --interface-info-header requires --output')
if args.c_generate_object_manager:
print_error('--c-generate-object-manager is incompatible with '
'--interface-info-header')
h_file = args.output
header_name = os.path.basename(h_file)
elif args.interface_info_body:
if args.output is None:
print_error('Using --interface-info-body requires --output')
if args.c_generate_object_manager:
print_error('--c-generate-object-manager is incompatible with '
'--interface-info-body')
c_file = args.output
header_name = os.path.splitext(os.path.basename(c_file))[0] + '.h'
all_ifaces = []
input_files_basenames = []
@@ -254,6 +276,23 @@ def codegen_main():
outfile)
gen.generate()
if args.interface_info_header:
with open(h_file, 'w') as outfile:
gen = codegen.InterfaceInfoHeaderCodeGenerator(all_ifaces,
args.c_namespace,
header_name,
args.pragma_once,
outfile)
gen.generate()
if args.interface_info_body:
with open(c_file, 'w') as outfile:
gen = codegen.InterfaceInfoBodyCodeGenerator(all_ifaces,
args.c_namespace,
header_name,
outfile)
gen.generate()
sys.exit(0)
if __name__ == "__main__":