[glib] gdbus-codegen: Add --output-directory flag



commit ee09bb704fe9ccb24d92dd86696a0e6bb8f0dc1a
Author: Patrick Griffis <tingping tingping se>
Date:   Thu Feb 16 21:03:18 2017 -0500

    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

 docs/reference/gio/gdbus-codegen.xml  |   17 ++++++++++++++++-
 gio/gdbus-2.0/codegen/codegen.py      |    8 +++++---
 gio/gdbus-2.0/codegen/codegen_main.py |   12 +++++++++---
 3 files changed, 30 insertions(+), 7 deletions(-)
---
diff --git a/docs/reference/gio/gdbus-codegen.xml b/docs/reference/gio/gdbus-codegen.xml
index 7c8fe31..27b25ff 100644
--- a/docs/reference/gio/gdbus-codegen.xml
+++ b/docs/reference/gio/gdbus-codegen.xml
@@ -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>
@@ -231,6 +237,15 @@
     </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>
         <para>
diff --git a/gio/gdbus-2.0/codegen/codegen.py b/gio/gdbus-2.0/codegen/codegen.py
index 6a3d9e5..3485c1a 100644
--- a/gio/gdbus-2.0/codegen/codegen.py
+++ b/gio/gdbus-2.0/codegen/codegen.py
@@ -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'
diff --git a/gio/gdbus-2.0/codegen/codegen_main.py b/gio/gdbus-2.0/codegen/codegen_main.py
index cc28c81..5725400 100755
--- a/gio/gdbus-2.0/codegen/codegen_main.py
+++ b/gio/gdbus-2.0/codegen/codegen_main.py
@@ -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()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]