Commit ee09bb70 authored by Patrick Griffis's avatar Patrick Griffis

gdbus-codegen: Add --output-directory flag

This is useful with Meson where files are generated in subdirs

https://bugzilla.gnome.org/show_bug.cgi?id=778801
parent 00124517
......@@ -33,6 +33,7 @@
<arg><option>--c-namespace</option> <replaceable>YourProject</replaceable></arg>
<arg><option>--c-generate-object-manager</option></arg>
<arg><option>--c-generate-autocleanup</option> none|objects|all</arg>
<arg><option>--output-directory</option> <replaceable>OUTDIR</replaceable></arg>
<arg><option>--generate-docbook</option> <replaceable>OUTFILES</replaceable></arg>
<arg><option>--xml-files</option> <replaceable>FILE</replaceable></arg>
<group choice="plain" rep="repeat">
......@@ -187,7 +188,12 @@
<para>
Generate C code for all D-Bus interfaces and put it in
<filename>OUTFILES.c</filename> and
<filename>OUTFILES.h</filename>.
<filename>OUTFILES.h</filename> including any sub-directories. If you want the files to
be output in a different location use <option>--output-directory</option> as <filename>OUTFILES.h</filename>
including sub-directories will be referenced from <filename>OUTFILES.c</filename>.
</para>
<para>
The full paths would then be <literal>$(OUTDIR)/$(dirname $OUTFILES)/$(basename $OUTFILES).{c,h}</literal>.
</para>
</listitem>
</varlistentry>
......@@ -230,6 +236,15 @@
</listitem>
</varlistentry>
<varlistentry>
<term><option>--output-directory</option> <replaceable>OUTDIR</replaceable></term>
<listitem>
<para>
Directory to output generated source to. Equivalent to changing directory before generation.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--annotate</option> <replaceable>ELEMENT</replaceable> <replaceable>KEY</replaceable> <replaceable>VALUE</replaceable></term>
<listitem>
......
......@@ -28,13 +28,15 @@ from . import dbustypes
# ----------------------------------------------------------------------------------------------------
class CodeGenerator:
def __init__(self, ifaces, namespace, interface_prefix, generate_objmanager, generate_autocleanup, docbook_gen, h, c):
def __init__(self, ifaces, namespace, interface_prefix, generate_objmanager,
generate_autocleanup, docbook_gen, h, c, header_name):
self.docbook_gen = docbook_gen
self.generate_objmanager = generate_objmanager
self.generate_autocleanup = generate_autocleanup
self.ifaces = ifaces
self.h = h
self.c = c
self.header_name = header_name
self.namespace = namespace
if len(namespace) > 0:
if utils.is_ugly_case(namespace):
......@@ -48,7 +50,7 @@ class CodeGenerator:
self.ns_upper = ''
self.ns_lower = ''
self.interface_prefix = interface_prefix
self.header_guard = self.h.name.upper().replace('.', '_').replace('-', '_').replace('/', '_')
self.header_guard = header_name.upper().replace('.', '_').replace('-', '_').replace('/', '_')
# ----------------------------------------------------------------------------------------------------
......@@ -67,7 +69,7 @@ class CodeGenerator:
'#include "%s"\n'
'\n'
'#include <string.h>\n'
%(self.h.name))
%(self.header_name))
self.c.write('#ifdef G_OS_UNIX\n'
'# include <gio/gunixfdlist.h>\n'
......
......@@ -21,6 +21,7 @@
import sys
import optparse
from os import path
from . import config
from . import utils
......@@ -162,6 +163,8 @@ def codegen_main():
help='Generate Docbook in OUTFILES-org.Project.IFace.xml')
arg_parser.add_option('', '--annotate', nargs=3, action='append', metavar='WHAT KEY VALUE',
help='Add annotation (may be used several times)')
arg_parser.add_option('', '--output-directory', metavar='OUTDIR', default='',
help='Location to output generated files')
(opts, args) = arg_parser.parse_args();
all_ifaces = []
......@@ -185,15 +188,18 @@ def codegen_main():
c_code = opts.generate_c_code
if c_code:
h = open(c_code + '.h', 'w')
c = open(c_code + '.c', 'w')
outdir = opts.output_directory
header_name = c_code + '.h'
h = open(path.join(outdir, header_name), 'w')
c = open(path.join(outdir, c_code + '.c'), 'w')
gen = codegen.CodeGenerator(all_ifaces,
opts.c_namespace,
opts.interface_prefix,
opts.c_generate_object_manager,
opts.c_generate_autocleanup,
docbook_gen,
h, c);
h, c,
header_name)
ret = gen.generate()
h.close()
c.close()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment