[Spice-devel] [PATCH spice-common 3/9] codegen: Generate headers while generating code

Frediano Ziglio fziglio at redhat.com
Fri Mar 8 21:42:24 UTC 2019


> 
> On Sun, Mar 03, 2019 at 07:10:24PM +0000, Frediano Ziglio wrote:
> > 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          | 19 +++++++++++++++----
> >  spice_codegen.py            | 12 ++++++++++--
> >  4 files changed, 32 insertions(+), 17 deletions(-)
> > 
> > diff --git a/common/Makefile.am b/common/Makefile.am
> > index 3318009..3da5bad 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 \
> > +	--generated-header generated_client_marshallers.h $< $@ >/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 \
> > +    --generated-header generated_server_marshallers.h $< $@ >/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"
> 
> Is this hunk intentionally in this patch?
> 

Yes, the --include parameters are the same so now both header
and source includes client_marshallers.h.

> >  
> >  SPICE_BEGIN_DECLS
> >  
> > diff --git a/common/meson.build b/common/meson.build
> > index 156297b..9575568 100644
> > --- a/common/meson.build
> > +++ b/common/meson.build
> > @@ -65,8 +65,14 @@ 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',
> > +        '-P', '--client', '--include', 'client_marshallers.h',
> > +        '--generated-header', '@OUTPUT1@',
> > +        '@INPUT@', '@OUTPUT0@'
> > +      ]
> > +    ]
> >    ]
> >  
> >    spice_common_client_sources = [
> > @@ -116,8 +122,13 @@ 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',
> > +        '--generated-header', '@OUTPUT1@',
> > +        '--server'] + structs_args + ['--include', 'common/messages.h',
> > '@INPUT@', '@OUTPUT0@'
> > +      ]
> > +    ],
> >    ]
> >  
> >    spice_common_server_sources = []
> > diff --git a/spice_codegen.py b/spice_codegen.py
> > index 7e22092..4664740 100755
> > --- a/spice_codegen.py
> > +++ b/spice_codegen.py
> > @@ -175,6 +175,8 @@ parser.add_option("--ptrsize", dest="ptrsize",
> >                    help="set default pointer size", default="4")
> >  parser.add_option("--license", dest="license",
> >                    help="license to use for generated file(s) (LGPL/BSD)",
> >                    default="LGPL")
> > +parser.add_option("--generated-header", dest="generated_header",
> > metavar="FILE",
> > +                  help="Name of the file to generate the header")
> 
> 
> Bit unsure about the option name. --header-name maybe? Or just infer it
> from the .c file name?
> 

It's similar to --generate-enums and similars. Yes, on the other end this
option is an additional generation and has a parameter so it not a big
match indeed. The infer of the header is a good suggestion.
Maybe a --generate-also-header ?

> apart from this,
> Reviewed-by: Christophe Fergeau <cfergeau at redhat.com>
> 

Frediano


More information about the Spice-devel mailing list