mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-26 15:36:14 +01:00
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
This commit is contained in:
parent
e59bce3c74
commit
c658d03b76
@ -35,6 +35,7 @@
|
|||||||
<arg><option>--c-generate-autocleanup</option> none|objects|all</arg>
|
<arg><option>--c-generate-autocleanup</option> none|objects|all</arg>
|
||||||
<arg><option>--output-directory</option> <replaceable>OUTDIR</replaceable></arg>
|
<arg><option>--output-directory</option> <replaceable>OUTDIR</replaceable></arg>
|
||||||
<arg><option>--generate-docbook</option> <replaceable>OUTFILES</replaceable></arg>
|
<arg><option>--generate-docbook</option> <replaceable>OUTFILES</replaceable></arg>
|
||||||
|
<arg><option>--pragma-once</option></arg>
|
||||||
<arg><option>--xml-files</option> <replaceable>FILE</replaceable></arg>
|
<arg><option>--xml-files</option> <replaceable>FILE</replaceable></arg>
|
||||||
<group choice="plain" rep="repeat">
|
<group choice="plain" rep="repeat">
|
||||||
<arg>
|
<arg>
|
||||||
@ -215,6 +216,17 @@
|
|||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term><option>--pragma-once</option></term>
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
If this option is passed, the
|
||||||
|
<ulink url="https://en.wikipedia.org/wiki/Pragma_once">#pragma once</ulink>
|
||||||
|
preprocessor directive is used instead of include guards.
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><option>--c-generate-object-manager</option></term>
|
<term><option>--c-generate-object-manager</option></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
|
@ -37,7 +37,8 @@ LICENSE_STR = '''/*
|
|||||||
|
|
||||||
class CodeGenerator:
|
class CodeGenerator:
|
||||||
def __init__(self, ifaces, namespace, interface_prefix, generate_objmanager,
|
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.docbook_gen = docbook_gen
|
||||||
self.generate_objmanager = generate_objmanager
|
self.generate_objmanager = generate_objmanager
|
||||||
self.generate_autocleanup = generate_autocleanup
|
self.generate_autocleanup = generate_autocleanup
|
||||||
@ -59,6 +60,7 @@ class CodeGenerator:
|
|||||||
self.ns_lower = ''
|
self.ns_lower = ''
|
||||||
self.interface_prefix = interface_prefix
|
self.interface_prefix = interface_prefix
|
||||||
self.header_guard = header_name.upper().replace('.', '_').replace('-', '_').replace('/', '_').replace(':', '_')
|
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(LICENSE_STR.format(config.VERSION))
|
||||||
self.h.write('\n')
|
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('\n')
|
||||||
self.h.write('#include <gio/gio.h>\n')
|
self.h.write('#include <gio/gio.h>\n')
|
||||||
self.h.write('\n')
|
self.h.write('\n')
|
||||||
@ -746,10 +753,12 @@ class CodeGenerator:
|
|||||||
# ----------------------------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
def generate_outro(self):
|
def generate_outro(self):
|
||||||
self.h.write('\n'
|
self.h.write('\n')
|
||||||
'G_END_DECLS\n'
|
self.h.write('G_END_DECLS\n')
|
||||||
'\n'
|
|
||||||
'#endif /* __%s__ */\n'%(self.header_guard))
|
if not self.use_pragma:
|
||||||
|
self.h.write('\n')
|
||||||
|
self.h.write('#endif /* __{!s}__ */\n'.format(self.header_guard))
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -163,6 +163,8 @@ def codegen_main():
|
|||||||
help='Generate autocleanup support')
|
help='Generate autocleanup support')
|
||||||
arg_parser.add_argument('--generate-docbook', metavar='OUTFILES',
|
arg_parser.add_argument('--generate-docbook', metavar='OUTFILES',
|
||||||
help='Generate Docbook in OUTFILES-org.Project.IFace.xml')
|
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',
|
arg_parser.add_argument('--annotate', nargs=3, action='append', metavar='WHAT KEY VALUE',
|
||||||
help='Add annotation (may be used several times)')
|
help='Add annotation (may be used several times)')
|
||||||
arg_parser.add_argument('--output-directory', metavar='OUTDIR', default='',
|
arg_parser.add_argument('--output-directory', metavar='OUTDIR', default='',
|
||||||
@ -204,7 +206,8 @@ def codegen_main():
|
|||||||
args.c_generate_autocleanup,
|
args.c_generate_autocleanup,
|
||||||
docbook_gen,
|
docbook_gen,
|
||||||
h, c,
|
h, c,
|
||||||
header_name)
|
header_name,
|
||||||
|
args.pragma_once)
|
||||||
ret = gen.generate()
|
ret = gen.generate()
|
||||||
h.close()
|
h.close()
|
||||||
c.close()
|
c.close()
|
||||||
|
Loading…
Reference in New Issue
Block a user