From c658d03b76a97055de83fdb0cf4a1080ee97da6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1igo=20Mart=C3=ADnez?= Date: Wed, 3 Jan 2018 17:01:30 +0100 Subject: [PATCH] gdbus-codegen: Add support for pragma inclusion guard The #pragma once is widely supported preprocessor directive that can be used instead of include guards. This adds support for using optionally this directive instead of include guards. https://bugzilla.gnome.org/show_bug.cgi?id=791015 --- docs/reference/gio/gdbus-codegen.xml | 12 ++++++++++++ gio/gdbus-2.0/codegen/codegen.py | 23 ++++++++++++++++------- gio/gdbus-2.0/codegen/codegen_main.py | 5 ++++- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/docs/reference/gio/gdbus-codegen.xml b/docs/reference/gio/gdbus-codegen.xml index 56a3bc56f..9d5f3ce6d 100644 --- a/docs/reference/gio/gdbus-codegen.xml +++ b/docs/reference/gio/gdbus-codegen.xml @@ -35,6 +35,7 @@ none|objects|all OUTDIR OUTFILES + FILE @@ -215,6 +216,17 @@ + + + + + If this option is passed, the + #pragma once + preprocessor directive is used instead of include guards. + + + + diff --git a/gio/gdbus-2.0/codegen/codegen.py b/gio/gdbus-2.0/codegen/codegen.py index e508da120..ffb2d3773 100644 --- a/gio/gdbus-2.0/codegen/codegen.py +++ b/gio/gdbus-2.0/codegen/codegen.py @@ -37,7 +37,8 @@ LICENSE_STR = '''/* class CodeGenerator: def __init__(self, ifaces, namespace, interface_prefix, generate_objmanager, - generate_autocleanup, docbook_gen, h, c, header_name): + generate_autocleanup, docbook_gen, h, c, header_name, + use_pragma): self.docbook_gen = docbook_gen self.generate_objmanager = generate_objmanager self.generate_autocleanup = generate_autocleanup @@ -59,6 +60,7 @@ class CodeGenerator: self.ns_lower = '' self.interface_prefix = interface_prefix self.header_guard = header_name.upper().replace('.', '_').replace('-', '_').replace('/', '_').replace(':', '_') + self.use_pragma = use_pragma # ---------------------------------------------------------------------------------------------------- @@ -224,8 +226,13 @@ class CodeGenerator: self.h.write(LICENSE_STR.format(config.VERSION)) self.h.write('\n') - self.h.write('#ifndef __{!s}__\n'.format(self.header_guard)) - self.h.write('#define __{!s}__\n'.format(self.header_guard)) + + if self.use_pragma: + self.h.write('#pragma once\n') + else: + self.h.write('#ifndef __{!s}__\n'.format(self.header_guard)) + self.h.write('#define __{!s}__\n'.format(self.header_guard)) + self.h.write('\n') self.h.write('#include \n') self.h.write('\n') @@ -746,10 +753,12 @@ class CodeGenerator: # ---------------------------------------------------------------------------------------------------- def generate_outro(self): - self.h.write('\n' - 'G_END_DECLS\n' - '\n' - '#endif /* __%s__ */\n'%(self.header_guard)) + self.h.write('\n') + self.h.write('G_END_DECLS\n') + + if not self.use_pragma: + self.h.write('\n') + self.h.write('#endif /* __{!s}__ */\n'.format(self.header_guard)) # ---------------------------------------------------------------------------------------------------- diff --git a/gio/gdbus-2.0/codegen/codegen_main.py b/gio/gdbus-2.0/codegen/codegen_main.py index 24e4bcbbe..8f69c78aa 100755 --- a/gio/gdbus-2.0/codegen/codegen_main.py +++ b/gio/gdbus-2.0/codegen/codegen_main.py @@ -163,6 +163,8 @@ def codegen_main(): help='Generate autocleanup support') arg_parser.add_argument('--generate-docbook', metavar='OUTFILES', help='Generate Docbook in OUTFILES-org.Project.IFace.xml') + arg_parser.add_argument('--pragma-once', action='store_true', + help='Use "pragma once" as the inclusion guard') arg_parser.add_argument('--annotate', nargs=3, action='append', metavar='WHAT KEY VALUE', help='Add annotation (may be used several times)') arg_parser.add_argument('--output-directory', metavar='OUTDIR', default='', @@ -204,7 +206,8 @@ def codegen_main(): args.c_generate_autocleanup, docbook_gen, h, c, - header_name) + header_name, + args.pragma_once) ret = gen.generate() h.close() c.close()