[next] telepathy-glib: Add multiple-inclusion guards to generated client-side code

Simon McVittie smcv at kemper.freedesktop.org
Mon May 7 08:43:25 PDT 2012


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

Author: Simon McVittie <simon.mcvittie at collabora.co.uk>
Date:   Fri May  4 12:19:19 2012 +0100

Add multiple-inclusion guards to generated client-side code

Reviewed-by: Xavier Claessens <xavier.claessens at collabora.co.uk>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=49384

---

 telepathy-glib/codegen.am |    1 +
 tools/glib-client-gen.py  |   13 ++++++++++++-
 2 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/telepathy-glib/codegen.am b/telepathy-glib/codegen.am
index 02fe35d..cd9a2ae 100644
--- a/telepathy-glib/codegen.am
+++ b/telepathy-glib/codegen.am
@@ -298,6 +298,7 @@ _gen/tp-cli-%-body.h: _gen/tp-spec-%.xml \
 	$(PYTHON) $(tools_dir)/glib-client-gen.py \
 		$$subclass $$subclass_assert \
 		--group `echo $* | tr - _` \
+		--guard "TP_GEN_TP_CLI_`echo $* | tr a-z- A-Z_`_H_INCLUDED" \
 		--iface-quark-prefix=TP_IFACE_QUARK \
 		--tp-proxy-api=0.7.6 \
 		--deprecation-attribute=_TP_GNUC_DEPRECATED \
diff --git a/tools/glib-client-gen.py b/tools/glib-client-gen.py
index c94bd2c..6b2b97f 100644
--- a/tools/glib-client-gen.py
+++ b/tools/glib-client-gen.py
@@ -71,6 +71,8 @@ class Generator(object):
         self.deprecation_attribute = opts.get('--deprecation-attribute',
                 'G_GNUC_DEPRECATED')
 
+        self.guard = opts.get('--guard', None)
+
     def h(self, s):
         if isinstance(s, unicode):
             s = s.encode('utf-8')
@@ -1171,6 +1173,11 @@ class Generator(object):
 
     def __call__(self):
 
+        if self.guard is not None:
+            self.h('#ifndef %s' % self.guard)
+            self.h('#define %s' % self.guard)
+            self.h('')
+
         self.h('G_BEGIN_DECLS')
         self.h('')
 
@@ -1229,6 +1236,10 @@ class Generator(object):
         self.h('G_END_DECLS')
         self.h('')
 
+        if self.guard is not None:
+            self.h('#endif /* defined (%s) */' % self.guard)
+            self.h('')
+
         file_set_contents(self.basename + '.h', '\n'.join(self.__header))
         file_set_contents(self.basename + '-body.h', '\n'.join(self.__body))
         file_set_contents(self.basename + '-gtk-doc.h', '\n'.join(self.__docs))
@@ -1242,7 +1253,7 @@ if __name__ == '__main__':
                                ['group=', 'subclass=', 'subclass-assert=',
                                 'iface-quark-prefix=', 'tp-proxy-api=',
                                 'generate-reentrant=', 'deprecate-reentrant=',
-                                'deprecation-attribute='])
+                                'deprecation-attribute=', 'guard='])
 
     opts = {}
 



More information about the telepathy-commits mailing list