From d52f89ea80d56c283f3f77ce90697538753fe355 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Wed, 30 May 2012 11:57:27 +0200 Subject: [PATCH] Add single-include #error in generated headers https://bugs.freedesktop.org/show_bug.cgi?id=49384 --- telepathy-glib/codegen.am | 7 +++++++ tools/glib-client-gen.py | 8 +++++++- tools/glib-ginterface-gen.py | 14 +++++++++++--- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/telepathy-glib/codegen.am b/telepathy-glib/codegen.am index 26caaef..b7d59d2 100644 --- a/telepathy-glib/codegen.am +++ b/telepathy-glib/codegen.am @@ -130,6 +130,11 @@ nodist_libtelepathy_glib_internal_la_SOURCES = \ # Generated stuff +SINGLE_INCLUDE ="\#if !defined (_TP_IN_META_HEADER) && !defined (_TP_COMPILATION)\n\ +\#error \"Only and can be included directly.\"\n\ +\#endif\n\ +" + DROP_NAMESPACE = sed -e 's@xmlns:tp="http://telepathy\.freedesktop\.org/wiki/DbusSpec.extensions-v0"@@g' tools_dir = $(top_srcdir)/tools @@ -220,6 +225,7 @@ _gen/tp-svc-%.c: _gen/tp-spec-%.xml \ --signal-marshal-prefix=_tp \ --include='' \ --not-implemented-func='tp_dbus_g_method_return_not_implemented' \ + --single-include=$(SINGLE_INCLUDE) \ $< Tp_Svc_ # do nothing, output as a side-effect @@ -310,6 +316,7 @@ _gen/tp-cli-%-body.h: _gen/tp-spec-%.xml \ --deprecation-attribute=_TP_GNUC_DEPRECATED \ --deprecate-reentrant=TP_DISABLE_DEPRECATED \ --generate-reentrant=_gen/reentrant-methods.list \ + --single-include=$(SINGLE_INCLUDE) \ $< Tp_Cli _gen/tp-cli-$* # vim:set ft=automake: diff --git a/tools/glib-client-gen.py b/tools/glib-client-gen.py index 6b2b97f..94271bb 100644 --- a/tools/glib-client-gen.py +++ b/tools/glib-client-gen.py @@ -73,6 +73,8 @@ class Generator(object): self.guard = opts.get('--guard', None) + self.single_include = opts.get('--single-include', None) + def h(self, s): if isinstance(s, unicode): s = s.encode('utf-8') @@ -1173,6 +1175,9 @@ class Generator(object): def __call__(self): + if self.single_include is not None: + self.h(self.single_include.replace("\\n ", '\n')) + if self.guard is not None: self.h('#ifndef %s' % self.guard) self.h('#define %s' % self.guard) @@ -1253,7 +1258,8 @@ if __name__ == '__main__': ['group=', 'subclass=', 'subclass-assert=', 'iface-quark-prefix=', 'tp-proxy-api=', 'generate-reentrant=', 'deprecate-reentrant=', - 'deprecation-attribute=', 'guard=']) + 'deprecation-attribute=', 'guard=', + 'single-include=']) opts = {} diff --git a/tools/glib-ginterface-gen.py b/tools/glib-ginterface-gen.py index 7843977..0f71ab8 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, 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.single_include = single_include def h(self, s): if isinstance(s, unicode): @@ -735,6 +736,9 @@ class Generator(object): nodes = self.dom.getElementsByTagName('node') nodes.sort(cmp_by_name) + if self.single_include is not None: + self.h(self.single_include.replace("\\n ", '\n')) + self.h('#include ') self.h('#include ') @@ -799,7 +803,8 @@ if __name__ == '__main__': ['filename=', 'signal-marshal-prefix=', 'include=', 'include-end=', 'allow-unstable', - 'not-implemented-func=']) + 'not-implemented-func=', + 'single-include=']) try: prefix = argv[1] @@ -812,6 +817,7 @@ if __name__ == '__main__': end_headers = [] not_implemented_func = '' allow_havoc = False + single_include = None for option, value in options: if option == '--filename': @@ -830,6 +836,8 @@ if __name__ == '__main__': not_implemented_func = value elif option == '--allow-unstable': allow_havoc = True + elif option == '--single-include': + single_include = value try: dom = xml.dom.minidom.parse(argv[0]) @@ -837,4 +845,4 @@ 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, single_include)() -- 1.7.9.5