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:
Simon McVittie
2024-02-06 13:48:45 +00:00
parent 5e8f053d33
commit fc7942f46b
4 changed files with 34 additions and 23 deletions

View File

@@ -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"
)