[Spice-devel] [PATCH spice-common v3 2/5] codegen: Generate headers while generating code

Frediano Ziglio fziglio at redhat.com
Mon Mar 11 13:59:11 UTC 2019


Python script generates code and header together however allowed
to save only one of them.
Allows to save both of them together to reduce number of time
we call Python script.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 common/Makefile.am          | 16 ++++++----------
 common/client_marshallers.h |  2 +-
 common/meson.build          | 17 +++++++++++++----
 spice_codegen.py            | 15 +++++++++++++--
 4 files changed, 33 insertions(+), 17 deletions(-)

diff --git a/common/Makefile.am b/common/Makefile.am
index 3318009..0ad448b 100644
--- a/common/Makefile.am
+++ b/common/Makefile.am
@@ -112,21 +112,17 @@ MARSHALLERS_DEPS =					\
 generated_client_demarshallers.c: $(top_srcdir)/spice.proto $(MARSHALLERS_DEPS)
 	$(AM_V_GEN)$(PYTHON) $(top_srcdir)/spice_codegen.py --generate-demarshallers --client --include common/messages.h $< $@ >/dev/null
 
-generated_client_marshallers.h: $(top_srcdir)/spice.proto $(MARSHALLERS_DEPS)
-	$(AM_V_GEN)$(PYTHON) $(top_srcdir)/spice_codegen.py --generate-marshallers -P --client --include common/messages.h -H $< $@ >/dev/null
-
-generated_client_marshallers.c: $(top_srcdir)/spice.proto $(MARSHALLERS_DEPS)
-	$(AM_V_GEN)$(PYTHON) $(top_srcdir)/spice_codegen.py --generate-marshallers -P --include client_marshallers.h --client $< $@ >/dev/null
+generated_client_marshallers.c generated_client_marshallers.h: $(top_srcdir)/spice.proto $(MARSHALLERS_DEPS)
+	$(AM_V_GEN)$(PYTHON) $(top_srcdir)/spice_codegen.py --generate-marshallers -P --include client_marshallers.h --client \
+	--generate-header $< $@ >/dev/null
 
 generated_server_demarshallers.c: $(top_srcdir)/spice.proto $(MARSHALLERS_DEPS)
 	$(AM_V_GEN)$(PYTHON) $(top_srcdir)/spice_codegen.py --generate-demarshallers --server --include common/messages.h $< $@ >/dev/null
 
 STRUCTS = -M String -M Rect -M Point -M DisplayBase -M Fill -M Opaque -M Copy -M Blend -M Blackness -M Whiteness -M Invers -M Rop3 -M Stroke -M Text -M Transparent -M AlphaBlend -M Composite
-generated_server_marshallers.c: $(top_srcdir)/spice.proto $(MARSHALLERS_DEPS)
-	$(AM_V_GEN)$(PYTHON) $(top_srcdir)/spice_codegen.py --generate-marshallers $(STRUCTS) --server --include common/messages.h $< $@ >/dev/null
-
-generated_server_marshallers.h: $(top_srcdir)/spice.proto $(MARSHALLERS_DEPS)
-	$(AM_V_GEN)$(PYTHON) $(top_srcdir)/spice_codegen.py --generate-marshallers $(STRUCTS) --server --include common/messages.h -H $< $@ >/dev/null
+generated_server_marshallers.c generated_server_marshallers.h: $(top_srcdir)/spice.proto $(MARSHALLERS_DEPS)
+	$(AM_V_GEN)$(PYTHON) $(top_srcdir)/spice_codegen.py --generate-marshallers $(STRUCTS) --server --include common/messages.h \
+    --generate-header $< $@ >/dev/null
 
 EXTRA_DIST =				\
 	$(CLIENT_MARSHALLERS)		\
diff --git a/common/client_marshallers.h b/common/client_marshallers.h
index f082934..b67b98e 100644
--- a/common/client_marshallers.h
+++ b/common/client_marshallers.h
@@ -21,9 +21,9 @@
 
 #include <spice/protocol.h>
 
+#include "messages.h"
 #include "common/generated_client_marshallers.h"
 #include "marshaller.h"
-#include "messages.h"
 
 SPICE_BEGIN_DECLS
 
diff --git a/common/meson.build b/common/meson.build
index 156297b..b1e58c5 100644
--- a/common/meson.build
+++ b/common/meson.build
@@ -65,8 +65,13 @@ spice_common_dep = declare_dependency(link_with : spice_common_lib,
 if spice_common_generate_client_code
   targets = [
     ['client_demarshallers', spice_proto, 'generated_client_demarshallers.c', ['--generate-demarshallers', '--client', '--include', 'common/messages.h', '@INPUT@', '@OUTPUT@']],
-    ['client_marshalers', spice_proto, 'generated_client_marshallers.c', ['--generate-marshallers', '-P', '--client', '--include', 'client_marshallers.h', '@INPUT@', '@OUTPUT@']],
-    ['client_marshallers_h', spice_proto, 'generated_client_marshallers.h', ['--generate-marshallers', '-P', '--client', '--include', 'common/messages.h', '-H', '@INPUT@', '@OUTPUT@']],
+    ['client_marshallers', spice_proto,
+      ['generated_client_marshallers.c', 'generated_client_marshallers.h'],
+      ['--generate-marshallers', '--generate-header',
+        '-P', '--client', '--include', 'client_marshallers.h',
+        '@INPUT@', '@OUTPUT0@'
+      ]
+    ]
   ]
 
   spice_common_client_sources = [
@@ -116,8 +121,12 @@ if spice_common_generate_server_code
 
   targets = [
     ['server_demarshallers', spice_proto, 'generated_server_demarshallers.c', ['--generate-demarshallers', '--server', '--include', 'common/messages.h', '@INPUT@', '@OUTPUT@']],
-    ['server_marshallers', spice_proto, 'generated_server_marshallers.c', ['--generate-marshallers', '--server'] + structs_args + ['--include', 'common/messages.h', '@INPUT@', '@OUTPUT@']],
-    ['server_marshallers_h', spice_proto, 'generated_server_marshallers.h', ['--generate-marshallers', '--server'] + structs_args + ['--include', 'common/messages.h', '-H', '@INPUT@', '@OUTPUT@']],
+    ['server_marshallers', spice_proto,
+      ['generated_server_marshallers.c', 'generated_server_marshallers.h'],
+      ['--generate-marshallers', '--generate-header',
+        '--server'] + structs_args + ['--include', 'common/messages.h', '@INPUT@', '@OUTPUT0@'
+      ]
+    ],
   ]
 
   spice_common_server_sources = []
diff --git a/spice_codegen.py b/spice_codegen.py
index 8049820..54d655d 100755
--- a/spice_codegen.py
+++ b/spice_codegen.py
@@ -173,6 +173,9 @@ parser.add_option("--suffix", dest="suffix",
                   help="set public symbol suffix", default="")
 parser.add_option("--license", dest="license",
                   help="license to use for generated file(s) (LGPL/BSD)", default="LGPL")
+parser.add_option("--generate-header",
+                  action="store_true", dest="generate_header", default=False,
+                  help="Generate also the header")
 
 (options, args) = parser.parse_args()
 
@@ -192,7 +195,11 @@ if proto == None:
 codegen.set_prefix(proto.name)
 writer = codegen.CodeWriter()
 writer.header = codegen.CodeWriter()
-writer.header.set_option("dest_file", dest_file)
+if options.generate_header:
+    filename = os.path.splitext(dest_file)[0] + '.h'
+    writer.header.set_option("dest_file", filename)
+else:
+    writer.header.set_option("dest_file", dest_file)
 writer.set_option("source", os.path.basename(proto_file))
 
 if options.license == "LGPL":
@@ -256,7 +263,7 @@ writer.writeln("/* this is a file autogenerated by spice_codegen.py */")
 writer.write(license)
 writer.header.writeln("/* this is a file autogenerated by spice_codegen.py */")
 writer.header.write(license)
-if not options.header and not options.generate_enums:
+if not options.generate_enums:
     writer.writeln("#ifdef HAVE_CONFIG_H")
     writer.writeln("#include <config.h>")
     writer.writeln("#endif")
@@ -311,4 +318,8 @@ if options.header:
 else:
     content = writer.getvalue()
 write_content(dest_file, content, options.keep_identical_file)
+if options.generate_header:
+    content = writer.header.getvalue()
+    filename = writer.header.options["dest_file"]
+    write_content(filename, content, options.keep_identical_file)
 sys.exit(0)
-- 
2.20.1



More information about the Spice-devel mailing list