diff --git a/docs/reference/gio/gdbus-codegen.rst b/docs/reference/gio/gdbus-codegen.rst index 8c6eab985..7fd5011b1 100644 --- a/docs/reference/gio/gdbus-codegen.rst +++ b/docs/reference/gio/gdbus-codegen.rst @@ -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* diff --git a/gio/gdbus-2.0/codegen/codegen.py b/gio/gdbus-2.0/codegen/codegen.py index b1c5fb929..2e8ef8e2a 100644 --- a/gio/gdbus-2.0/codegen/codegen.py +++ b/gio/gdbus-2.0/codegen/codegen.py @@ -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 \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 \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 \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 \n") + self.outfile.write( "#ifdef G_OS_UNIX\n" "# include \n" "#endif\n" "\n" ) diff --git a/gio/gdbus-2.0/codegen/codegen_main.py b/gio/gdbus-2.0/codegen/codegen_main.py index 58af5c654..d5353f570 100644 --- a/gio/gdbus-2.0/codegen/codegen_main.py +++ b/gio/gdbus-2.0/codegen/codegen_main.py @@ -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 diff --git a/gio/tests/codegen.py b/gio/tests/codegen.py index f66b92c8c..a18dcb1a9 100644 --- a/gio/tests/codegen.py +++ b/gio/tests/codegen.py @@ -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 ),