Commit Graph

35 Commits

Author SHA1 Message Date
Frediano Ziglio
c1b8dbbb9b Minor Python 3 updates
- Remove "u" prefix from strings;
- Raising strings as exception is not valid anymore;
- Convert generators to list where necessary;
- traceback.print_exc accept a limit as first argument, not
  a file (this even for Python 2).

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
2025-04-07 19:59:32 +00:00
Frediano Ziglio
a791a224e7 Update print syntax to Python 3
Never changed because possibly never hit these lines.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
2023-12-16 18:58:37 +00:00
Chris Mayo
8c0319e31d codegen: Use context manager when opening files
Signed-off-by: Chris Mayo <aklhfex@gmail.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2023-12-16 18:45:46 +00:00
Chris Mayo
29dacb5f53 Stop using Python six package
Signed-off-by: Chris Mayo <aklhfex@gmail.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2023-12-16 18:45:43 +00:00
Frediano Ziglio
60e0453698 codegen: Exit with error on error generating C structures
This was some left-over during development of C structure
generations (the single structure generation was skipped).

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2019-08-13 18:11:04 +01:00
Frediano Ziglio
4fc4c2db36 Do not check for HAVE_CONFIG_H
This should always be defined and including config.h is a requirement.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-05-02 09:33:05 +01:00
Frediano Ziglio
3cd3886b27 codegen: Allows to generate C declarations automatically
Allows to specify a @declare attribute for messages and structure
that can generate the needed C structures.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2019-03-18 13:01:58 +00:00
Frediano Ziglio
dac34baaab codegen: Generate headers while generating code
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@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2019-03-18 13:01:52 +00:00
Frediano Ziglio
af66a4ccad codegen: Factor out a function to write output file
This will be reused to generate C declaration automatically.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2019-03-15 15:46:17 +00:00
Frediano Ziglio
cb00ccfaab codegen: Rename --prefix parameter to --suffix
The option is used to add a suffix to public functions, not a
prefix.
Currently the option is not used (it was used to generate protocol
1 code).

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2019-03-08 21:22:58 +00:00
Frediano Ziglio
302e30ff43 codegen: Remove support for --ptrsize
This option was used in protocol 1 to generate 64 bit pointers.
A pointer in the protocol is an offset in the current message.
This allows the possibility to have messages with pointers with more
than 4GB. This feature was removed and not used in protocol 2.
The reason this feature was correctly removed in protocol 2 is that
having 64 bit pointers in the protocol would require messages larger
than 4GB which would cause:
- huge latency as a single message would take more than 4 seconds
  to be send in a 10Gb connection;
- huge memory requirements.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2019-03-08 11:09:02 +00:00
Frediano Ziglio
36fd7325e5 codegen: Fix license name
License reported for MIT was indeed a BSD 3-Clause license,
not a MIT one (https://opensource.org/licenses/BSD-3-Clause).

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2017-05-18 16:40:36 +01:00
Frediano Ziglio
1d527e21d5 codegen: Allows to specify license of generated files
Some headers for spice are distributed using MIT licenses.
Allows to generate such headers if needed.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Pavel Grunt <pgrunt@redhat.com>
2017-05-08 09:54:10 +01:00
Frediano Ziglio
0eb567e6fb codegen: Improve header guard generation
Until now, the same header guard was used for all generated .h files.
Now the header guard name is based on the name of the file being
generated so that it's different for each .h file.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2016-06-24 10:02:06 +01:00
Christophe Fergeau
806d3273fa codegen: Use "" rather than <> for cmdline includes
Includes specified on the command line are currently #included with <>
rather than "". However, they are usually spice-common headers, so it
makes more sense to include them using ""

Acked-by: Pavel Grunt <pgrunt@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2016-06-24 09:36:49 +01:00
Marc-André Lureau
1cd26b87c1 Revert "Remove files moved to spice-protocol"
This reverts commit 7665dcf1bb.

Also revert the related build-sys changes to fix the build.

codegen generated code depends on spice-common code (marshaller,
messages etc), it makes more sense to keep the generator along
this. Otherwise a newer protocol release will fail to build older
projects.

*.proto files are required as well, since it generates code that parent
modules depend on unconditionnaly.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2016-03-10 16:01:36 +01:00
Frediano Ziglio
7665dcf1bb Remove files moved to spice-protocol
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2015-08-11 10:26:06 +02:00
Christophe Fergeau
f4c729aad3 codegen: Fix enums.h generation with python3
Trying to generate enums.h with python3 results in
Traceback (most recent call last):
  File "./spice_codegen.py", line 217, in <module>
    write_enums(writer, options.generate_dissector)
  File "./spice_codegen.py", line 99, in write_enums
    write_channel_enums(writer, c, False, False)
  File "./spice_codegen.py", line 17, in write_channel_enums
    if len(messages) == 0:
TypeError: object of type 'filter' has no len()

filter() returns an enumerator object in python3 while it used to return
a list in python2. Using list(filter()) instead fixes that error.
I've checked that the generated enums.h is identical with python2 and
python3.
2015-07-23 10:29:10 +02:00
Christophe Fergeau
b216f66f10 codegen: Use six.PY3 rather than six.PY2
Older versions of python-six (at least 1.3.0) defined six.PY3 but not
six.PY2. six.PY2 is only used twice in straightforward tests so it's
easy to use six.PY3 instead.
2015-04-14 16:08:43 +02:00
Alexander Wauck
ba52c4cae2 Make spice_codegen.py work on both Python 2 and 3
This is a new version of my previous patch that does not include six.py.
It's still kind of big, but at least it's all spice-common changes now.
There are also a few other fixes that Christophe brought to my attention.
Note that six now needs to be installed on the system (python-six on
Fedora and Debian, six on PyPI).

This *should* be enough to make spice_codegen.py work on both Python 2
and Python 3.  The major changes are as follows:

 * cStringIO.StringIO -> io.StringIO
 * str vs. unicode updates (io.StringIO doesn't like str)
 * integer division
 * foo.has_key(bar) -> bar in foo
 * import internal_thing -> from . import internal_thing
 * removed from __future__ import with_statement
   (might break Python 2.5?)
 * changed some lambdas to list comprehensions (done by 2to3)
 * cast some_dict.keys() to list where needed (e.g. for sorting)
 * use normal type names with isinstance instead of types.WhateverType

Signed-off-by: Alexander Wauck <awauck@codeweavers.com>
2015-04-01 13:39:03 +02:00
Christophe Fergeau
b3a00f4411 marshaller: Use #include <> for headers in $srcdir/common
Since the (de)marshallers are now generated in $builddir and not in
$srcdir, when these generated files include a file located in
$srcdir/common, the compiler will find them thanks to a -I directive, so it
makes more sense to use <> rather than "" when including them.
2014-04-16 16:47:55 +02:00
Jonathon Jongsma
1450bb4ddb Be explicit about spice-common license
Use same license as spice-gtk and spice modules (LGPL 2.1) since those licenses
applied to the spice-common submodule in the past.  This makes it more clear
that if you use spice-common separately, the license is still LGPL.  Also
mention license and copyright in generated files.
2013-10-23 11:41:43 -05:00
Jonathon Jongsma
31ef0c626d codegen: Add a --generate-wireshark-dissector option
The wireshark protocol dissector is a bit out-of-date. Several new channel types
and enums have been added.  It would be nice if these values (and the
translation between the value and the name) could be automatically generated so
that updating the dissector was a slightly less manual process.  This patch adds
a commandline switch which generates both the enums and value-name lists in the
format that wireshark expects.
2013-10-23 11:41:43 -05:00
Marc-André Lureau
b6afcd632e codegen: include headers locally 2012-03-21 13:24:17 +01:00
Marc-André Lureau
2d4e0d2000 codegen: struct marshallers are not current function helper
This solves the issue of struct_marshallers being included within the
current ifdef/endif body, although they are independant functions.
2012-03-21 13:24:16 +01:00
Christophe Fergeau
da4768ae2b don't #include config.h in generated header files
7e30572ab adds a #include <config.h> to the beginning of generated
files. It also does this for generated headers and enums files,
which is not wanted, especially if it's an installed file. This
commit only adds this include for the non-header non-enum case
(hopefully, enums are only generated for use in a .h file).
2012-03-20 15:25:53 +01:00
Marc-André Lureau
5ae49c0d5b python: remove c-ism trailing ; 2012-03-20 15:25:53 +01:00
Christophe Fergeau
90f32ab823 add comment to beginning of autogenerated files 2012-03-20 15:25:52 +01:00
Christophe Fergeau
61b344d774 add config.h to autogenerated files too
Modify the python (de)marshaller generator to add #include
<config.h> at the beginning of the C files it generates
2012-03-20 15:25:52 +01:00
Alexander Larsson
13d9b32acc Make pointers 32bit in new protocol format 2012-03-20 15:25:45 +01:00
Alexander Larsson
bcc5cc0d91 Support extra prefix in code generators
This is require when we add a new spice.proto for the old (major 1)
protocol description.
2012-03-20 15:25:44 +01:00
Alexander Larsson
0349d2249d Support creating marshallers that are called indirectly
This is needed if we want to switch marshallers depending on what
major version the remote side has.
2012-03-20 15:25:44 +01:00
Alexander Larsson
9a9f1b8081 Allow multiple --include args 2012-03-20 15:25:43 +01:00
Alexander Larsson
e83ff054d7 Add support for generating message and structure marshallers 2012-03-20 15:25:43 +01:00
Alexander Larsson
e9b33a194e Add python code to automake system 2012-03-20 15:25:43 +01:00