[next] telepathy-glib: Make sure to not use single includes in generated code

Xavier Claessens xclaesse at kemper.freedesktop.org
Tue Jun 26 03:21:33 PDT 2012


Module: telepathy-glib
Branch: next
Commit: 9bcf8a2dde664c05d4a4919901012b52ce1c1b72
URL:    http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=9bcf8a2dde664c05d4a4919901012b52ce1c1b72

Author: Xavier Claessens <xavier.claessens at collabora.co.uk>
Date:   Thu Jun  7 15:41:06 2012 +0200

Make sure to not use single includes in generated code

If an extension iface has properties, its header will include
dbus-properties-mixin.h, which is not allowed outside tp-glib itself.

Since the generated header does not expose the mixin, move the include
to .c file, and use the meta header if single includes are not allowed.

---

 examples/extensions/Makefile.am    |    1 -
 telepathy-glib/base-contact-list.c |    1 +
 telepathy-glib/codegen.am          |    2 +-
 telepathy-glib/presence-mixin.c    |    1 +
 tools/glib-ginterface-gen.py       |   24 ++++++++++++++++++------
 5 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/examples/extensions/Makefile.am b/examples/extensions/Makefile.am
index 5f8d2fd..a916d32 100644
--- a/examples/extensions/Makefile.am
+++ b/examples/extensions/Makefile.am
@@ -139,7 +139,6 @@ _gen/svc-connection.c: _gen/connection.xml \
 	$(AM_V_GEN)$(PYTHON) $(tools_dir)/glib-ginterface-gen.py \
 		--filename=_gen/svc-connection \
 		--signal-marshal-prefix=_example_ext \
-		--include='<telepathy-glib/telepathy-glib.h>' \
 		--not-implemented-func='tp_dbus_g_method_return_not_implemented' \
 		--allow-unstable \
 		$< Example_Svc_
diff --git a/telepathy-glib/base-contact-list.c b/telepathy-glib/base-contact-list.c
index d2d1bfd..8af54b5 100644
--- a/telepathy-glib/base-contact-list.c
+++ b/telepathy-glib/base-contact-list.c
@@ -25,6 +25,7 @@
 
 #include <telepathy-glib/contacts-mixin.h>
 #include <telepathy-glib/dbus.h>
+#include <telepathy-glib/dbus-properties-mixin.h>
 #include <telepathy-glib/handle-repo-dynamic.h>
 #include <telepathy-glib/handle-repo-static.h>
 #include <telepathy-glib/interfaces.h>
diff --git a/telepathy-glib/codegen.am b/telepathy-glib/codegen.am
index 4135d16..9f7118f 100644
--- a/telepathy-glib/codegen.am
+++ b/telepathy-glib/codegen.am
@@ -250,7 +250,7 @@ _gen/tp-svc-%.c: _gen/tp-spec-%.xml \
 	$(AM_V_GEN)$(PYTHON) $(tools_dir)/glib-ginterface-gen.py \
 		--filename=_gen/tp-svc-$* \
 		--signal-marshal-prefix=_tp \
-		--include='<telepathy-glib/dbus.h>' \
+		--allow-single-include \
 		--not-implemented-func='tp_dbus_g_method_return_not_implemented' \
 		$< Tp_Svc_
 
diff --git a/telepathy-glib/presence-mixin.c b/telepathy-glib/presence-mixin.c
index 1408e98..95d8d52 100644
--- a/telepathy-glib/presence-mixin.c
+++ b/telepathy-glib/presence-mixin.c
@@ -253,6 +253,7 @@
 #include <string.h>
 
 #include <telepathy-glib/base-connection.h>
+#include <telepathy-glib/dbus-properties-mixin.h>
 #include <telepathy-glib/enums.h>
 #include <telepathy-glib/errors.h>
 #include <telepathy-glib/gtypes.h>
diff --git a/tools/glib-ginterface-gen.py b/tools/glib-ginterface-gen.py
index 87fa6f5..39d6c02 100644
--- a/tools/glib-ginterface-gen.py
+++ b/tools/glib-ginterface-gen.py
@@ -47,7 +47,7 @@ class Generator(object):
 
     def __init__(self, dom, prefix, basename, signal_marshal_prefix,
                  headers, end_headers, not_implemented_func,
-                 allow_havoc):
+                 allow_havoc, allow_single_include):
         self.dom = dom
         self.__header = []
         self.__body = []
@@ -83,6 +83,7 @@ class Generator(object):
         self.end_headers = end_headers
         self.not_implemented_func = not_implemented_func
         self.allow_havoc = allow_havoc
+        self.allow_single_include = allow_single_include
 
     def h(self, s):
         if isinstance(s, unicode):
@@ -741,15 +742,21 @@ class Generator(object):
         self.h('#include <glib-object.h>')
         self.h('#include <dbus/dbus-glib.h>')
 
-        if self.have_properties(nodes):
-            self.h('#include <telepathy-glib/dbus-properties-mixin.h>')
-
         self.h('')
         self.h('G_BEGIN_DECLS')
         self.h('')
 
         self.b('#include "%s.h"' % self.basename)
         self.b('')
+
+        if self.allow_single_include:
+            self.b('#include <telepathy-glib/dbus.h>')
+            if self.have_properties(nodes):
+                self.b('#include <telepathy-glib/dbus-properties-mixin.h>')
+        else:
+            self.b('#include <telepathy-glib/telepathy-glib.h>')
+        self.b('')
+
         for header in self.headers:
             self.b('#include %s' % header)
         self.b('')
@@ -802,7 +809,8 @@ if __name__ == '__main__':
                                ['filename=', 'signal-marshal-prefix=',
                                 'include=', 'include-end=',
                                 'allow-unstable',
-                                'not-implemented-func='])
+                                'not-implemented-func=',
+                                "allow-single-include"])
 
     try:
         prefix = argv[1]
@@ -815,6 +823,7 @@ if __name__ == '__main__':
     end_headers = []
     not_implemented_func = ''
     allow_havoc = False
+    allow_single_include = False
 
     for option, value in options:
         if option == '--filename':
@@ -833,6 +842,8 @@ if __name__ == '__main__':
             not_implemented_func = value
         elif option == '--allow-unstable':
             allow_havoc = True
+        elif option == '--allow-single-include':
+            allow_single_include = True
 
     try:
         dom = xml.dom.minidom.parse(argv[0])
@@ -840,4 +851,5 @@ if __name__ == '__main__':
         cmdline_error()
 
     Generator(dom, prefix, basename, signal_marshal_prefix, headers,
-              end_headers, not_implemented_func, allow_havoc)()
+              end_headers, not_implemented_func, allow_havoc,
+              allow_single_include)()



More information about the telepathy-commits mailing list