mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-23 12:41:50 +01:00
gdbus-codegen: If writing body to stdout, don't try to include header
If we're writing the body to standard output, we cannot know what the filename of the corresponding header is going to be, but it seems vanishingly unlikely that it will be either `stdout.h` (which we would traditionally have generated) or `-.h` (which we would have generated since !3886). This makes some of the output snippets sufficiently short that black(1) requires that they are folded into a single line. Signed-off-by: Simon McVittie <smcv@collabora.com>
This commit is contained in:
parent
5e8f053d33
commit
fc7942f46b
@ -297,8 +297,16 @@ The following options are supported:
|
||||
only one file.
|
||||
|
||||
Since GLib 2.80, if *OUTFILE* is the literal string ``-``, the header
|
||||
or source code will be written to standard output. To write to a file
|
||||
starting with ``-``, it should be prefixed with ``./``.
|
||||
or source code will be written to standard output.
|
||||
|
||||
For ``--body`` and ``--interface-info-body``, the generated code will not
|
||||
automatically ``#include`` a corresponding header file when writing to
|
||||
standard output, because there is no obvious name for that header file.
|
||||
This might make it necessary to use ``cc -include foo.h``, or generate a
|
||||
filename like ``foo-impl.h`` and ``#include`` it into a wrapper ``.c`` file.
|
||||
|
||||
In the rare situation that the intended output filename starts with ``-``,
|
||||
it should be prefixed with ``./``.
|
||||
|
||||
``--annotate`` *ELEMENT* *KEY* *VALUE*
|
||||
|
||||
|
@ -1124,15 +1124,13 @@ class InterfaceInfoBodyCodeGenerator:
|
||||
|
||||
self.outfile.write("\n")
|
||||
self.outfile.write(
|
||||
"#ifdef HAVE_CONFIG_H\n"
|
||||
'# include "config.h"\n'
|
||||
"#endif\n"
|
||||
"\n"
|
||||
'#include "%s"\n'
|
||||
"\n"
|
||||
"#include <string.h>\n" % (self.header_name)
|
||||
"#ifdef HAVE_CONFIG_H\n" '# include "config.h"\n' "#endif\n" "\n"
|
||||
)
|
||||
self.outfile.write("\n")
|
||||
|
||||
if self.header_name:
|
||||
self.outfile.write('#include "%s"\n\n' % (self.header_name))
|
||||
|
||||
self.outfile.write("#include <string.h>\n\n")
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------
|
||||
|
||||
@ -1472,20 +1470,21 @@ class CodeGenerator:
|
||||
def generate_body_preamble(self):
|
||||
basenames = ", ".join(self.input_files_basenames)
|
||||
self.outfile.write(LICENSE_STR.format(config.VERSION, basenames))
|
||||
|
||||
if self.symbol_decoration_define is not None:
|
||||
self.outfile.write("\n")
|
||||
self.outfile.write("#define %s\n" % self.symbol_decoration_define)
|
||||
|
||||
self.outfile.write("\n")
|
||||
self.outfile.write(
|
||||
"#ifdef HAVE_CONFIG_H\n"
|
||||
'# include "config.h"\n'
|
||||
"#endif\n"
|
||||
"\n"
|
||||
'#include "%s"\n'
|
||||
"\n"
|
||||
"#include <string.h>\n" % (self.header_name)
|
||||
"#ifdef HAVE_CONFIG_H\n" '# include "config.h"\n' "#endif\n" "\n"
|
||||
)
|
||||
|
||||
if self.header_name:
|
||||
self.outfile.write('#include "%s"\n\n' % (self.header_name))
|
||||
|
||||
self.outfile.write("#include <string.h>\n")
|
||||
|
||||
self.outfile.write(
|
||||
"#ifdef G_OS_UNIX\n" "# include <gio/gunixfdlist.h>\n" "#endif\n" "\n"
|
||||
)
|
||||
|
@ -336,7 +336,11 @@ def codegen_main():
|
||||
print_error("Using --body requires --output")
|
||||
|
||||
c_file = args.output
|
||||
header_name = os.path.splitext(os.path.basename(c_file))[0] + ".h"
|
||||
|
||||
if c_file == "-":
|
||||
header_name = ""
|
||||
else:
|
||||
header_name = os.path.splitext(os.path.basename(c_file))[0] + ".h"
|
||||
elif args.interface_info_header:
|
||||
if args.output is None:
|
||||
print_error("Using --interface-info-header requires --output")
|
||||
@ -358,7 +362,11 @@ def codegen_main():
|
||||
)
|
||||
|
||||
c_file = args.output
|
||||
header_name = os.path.splitext(os.path.basename(c_file))[0] + ".h"
|
||||
|
||||
if c_file == "-":
|
||||
header_name = ""
|
||||
else:
|
||||
header_name = os.path.splitext(os.path.basename(c_file))[0] + ".h"
|
||||
|
||||
# Check the minimum GLib version. The minimum --glib-min-required is 2.30,
|
||||
# because that’s when gdbus-codegen was introduced. Support 1, 2 or 3
|
||||
|
@ -409,8 +409,6 @@ G_END_DECLS
|
||||
|
||||
{standard_config_h_include}
|
||||
|
||||
#include "-.h"
|
||||
|
||||
{standard_header_includes}
|
||||
|
||||
{private_gvalues_getters}
|
||||
@ -432,8 +430,6 @@ G_END_DECLS
|
||||
|
||||
{standard_config_h_include}
|
||||
|
||||
#include "-.h"
|
||||
|
||||
{interface_info_header_includes}""".format(
|
||||
**result.subs
|
||||
),
|
||||
|
Loading…
Reference in New Issue
Block a user