Commit Graph

84 Commits

Author SHA1 Message Date
Lukáš Tyrychtr
a473d5aea0 mkenums: Allow , in a character literal
This required adding a higher precedence character literal choice.

Fixes #3103
2023-11-21 11:54:42 +00:00
Emmanuel Fleury
7e5607d534 Take double-quote characters into account when parsing trigraph
For now, the function parse_trigraph() defined in gobject/glib-mkenums
script was not taking double-quotes characters into account:

>>> parse_trigraph('name="eek, a comma"')
{'name': '"eek', 'a': None}

This patch take double-quotes characters into account:

>>> parse_trigraph('name="eek, a comma"')
{'name': 'eek, a comma'}

Closes issue #65
2023-05-30 15:22:05 +02:00
Patrick Monnerat
96fa9752b2 glib-mkenums: evaluate private symbols too
This allows them to be referenced in other symbols value computation.

In addition, this fixes the automatically assigned value of a public
symbol that is preceded by a private one:

        typedef enum {
          /*< private >*/
          ENUM_VALUE_PRIVATE,
          /*< public >*/
          ENUM_VALUE_PUBLIC,                    <--- value is 1, not 0.
        } SomeExampleEnum;
2022-11-01 15:46:13 +01:00
Patrick Monnerat
0120cd772a glib-mkenums: feature use of previous symbols in evaluation
Enum symbols can be defined with a value computed from previously
defined enum symbols. The current evaluator does not support this and
requires a literal integer expression.

This commit introduces a C symbol namespace that is filled along
code generation and provided as a local namespace for new symbols
evaluation, effectively allowing definitions such as:

	typedef enum {
	  a = 4;
	  b = a + 2;
	}  myenum;

to be successfully processed.
2022-11-01 02:12:26 +01:00
Seungha Yang
ebcc3c01db glib-mkenums: Specify output encoding as UTF-8 explicitly for non-English locale
Fixup regression introduced by
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2797
2022-08-16 04:53:34 +09:00
Philip Withnall
856aeba9e4 glib-mkenums: Parse and skip deprecation/availability annotations
Teach `glib-mkenums` how to parse and ignore:
 - `GLIB_AVAILABLE_ENUMERATOR_IN_x_xx`
 - `GLIB_DEPRECATED_ENUMERATOR_IN_x_xx`
 - `GLIB_DEPRECATED_ENUMERATOR_IN_x_xx_FOR(x)`

Future work could expose the deprecation/availability information as
substitutions in the template file, but this commit does not do that.

It does, however, add some unit tests for the annotations.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Fixes: #2327
2021-03-11 13:37:49 +00:00
Matthias Klumpp
1261461840 mkenums: Support public/private trigraphs again
This change was previously implemented in
9ba17d511e but got dropped during the
Python conversion of the Perl script.

See the commit message of this commit as well as
https://bugzilla.gnome.org/show_bug.cgi?id=782162
for more information.
This patch also adds a new test so we don't loose this feature again.
2021-01-10 20:51:54 +01:00
Matthias Klumpp
ca28a3fc29 trivial: Formatting changes 2021-01-10 18:59:45 +01:00
Aleksander Morgado
ec6056e3ab glib-mkenums: allow optional 'since' tag
The glib-mkenums program allows generating code to handle enums/flags
with very different purposes. One of its purposes could be generating
per-enum/flag methods to be exposed in a library API, and while doing
that, it would be nice to have a way to specify in which API version
the enum/flag was introduced, so that the same version could be shown
in the generated API methods.

E.g. From the following code:

    /**
     * QmiWmsMessageProtocol:
     * @QMI_WMS_MESSAGE_PROTOCOL_CDMA: CDMA.
     * @QMI_WMS_MESSAGE_PROTOCOL_WCDMA: WCDMA.
     *
     * Type of message protocol.
     *
     * Since: 1.0
     */
    typedef enum { /*< since=1.0 >*/
        QMI_WMS_MESSAGE_PROTOCOL_CDMA  = 0x00,
        QMI_WMS_MESSAGE_PROTOCOL_WCDMA = 0x01
    } QmiWmsMessageProtocol;

The template would allow us to generate a method documented like this,
including the Since tag with the value given in the mkenums 'since' tag.

    /**
     * qmi_wms_message_protocol_get_string:
     * @val: a QmiWmsMessageProtocol.
     *
     * Gets the nickname string for the #QmiWmsMessageProtocol specified at @val.
     *
     * Returns: (transfer none): a string with the nickname, or %NULL if not found. Do not free the returned value.
     * Since: 1.0
     */
    const gchar *qmi_wms_message_protocol_get_string (QmiWmsMessageProtocol val);

Signed-off-by: Aleksander Morgado <aleksander@aleksander.es>
2020-05-14 17:00:54 +02:00
Nirbheek Chauhan
17316b2c16 glib-mkenums: Support reading @rspfiles for arguments
This is needed on Windows where the argument list can exceed the
maximum command-line length when lots of sources are passed to
glib-mkenums.
2018-12-04 16:16:00 +05:30
Will Thompson
de62a95d5e
glib-mkenums: improve and correct argument documentation
ftail is not per-input-file, it is the footer for the entire output
file.

You cannot have fewer informations.
2018-08-10 17:18:36 +01:00
Will Thompson
7928fee2a8
glib-mkenums: don't support @filename@/@basename@ in fhead/ftail
As discussed in
https://gitlab.gnome.org/GNOME/glib/merge_requests/135#note_253986 it
doesn't really make sense to support these outside the templates for any
particular header file. Leave them unsubstituted, with a warning.
2018-08-10 17:05:59 +01:00
Peter Kjellerstedt
c0e6fa4f19 glib-mkenums: Ignore other per value options than 'skip' and 'nick'
If some other per value option was present than 'skip' or 'nick' then
a KeyError would occur. Ignoring such options matches the behaviour of
the old, Perl-based glib-mkenums.

Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>

https://gitlab.gnome.org/GNOME/glib/issues/1360
2018-06-25 13:39:13 +01:00
Sam Spilsbury
5e02a9f8af glib-mkenums: Don't go into an infinite loop trying to find a matching {
If we reach EOF before this happens, error out as opposed to
looping around forever.

https://bugzilla.gnome.org/show_bug.cgi?id=794506
2018-03-21 15:05:36 +00:00
Sam Spilsbury
7027a128c1 glib-mkenums: Don't treat typedef enum _SomeIdentifier {} as syntax error
Previously we were only detecting typedef\*senum\s*\{, which does not
handle the case where there is an entifier for the enum itself but
not the typedef. glib-mkenums would then attempt to read the next line
looking for a matching {, but in vain.

https://bugzilla.gnome.org/show_bug.cgi?id=794506
2018-03-21 15:05:36 +00:00
Philip Withnall
0a42a7cb74 glib-mkenums: Fix typos in a message and a comment
Signed-off-by: Philip Withnall <withnall@endlessm.com>
Reviewed-by: nobody
2018-03-21 15:03:14 +00:00
Patrick Welche
b6b74402d6 glib-mkenums: best effort attempt on non-utf8 encoded files.
Some source files aren't valid utf-8 containing for example
iso8859-1 accented characters in author's names.
Replace invalid data with a replacement '?' character and print a
warning to keep things working.
Based on a patch from Christoph Reiter in
https://bugzilla.gnome.org/show_bug.cgi?id=785113#c20
2017-12-13 13:40:43 +00:00
Sam Spilsbury
34148fc9b9 mkenums: Don't raise when unlinking a file that does not exist
Fixes https://bugzilla.gnome.org/show_bug.cgi?id=789637
2017-10-31 15:23:16 +00:00
Philip Withnall
9a319a126e glib-genmarshal/glib-mkenums: Add comment clarifying licensing
Clarify the licensing of the code generated by the two scripts in a
comment in the header of each generated file. The intention is that the
license of GLib does *not* apply to the generated files; but that they
are subject to the linking restrictions of the LGPL, since they link to
GLib and GLib is licensed under the LGPL. The generated files themselves
are under the license of whatever project they’re generated for.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

https://bugzilla.gnome.org/show_bug.cgi?id=788990
2017-10-25 12:39:23 +01:00
Emmanuele Bassi
9023fa350d Sort the list of files being processed by glib-mkenums
We should ensure a stable order when processing the files, regardless of
the order they were submitted on the command line, to increase the
chances of a reproducible build.

The old Perl-based version of glib-mkenums was fixed in commit 8686e430
to do the same.

https://bugzilla.gnome.org/show_bug.cgi?id=691436
2017-10-24 14:09:31 +01:00
Philip Withnall
fcfbaf8566 glib-mkenums: Add default comment template if none is provided
The fallback code for providing a default comment template only worked
if a template file was provided. It didn’t work if individual templates
were provided on the command line (and --comment wasn’t).

Signed-off-by: Philip Withnall <withnall@endlessm.com>

https://bugzilla.gnome.org/show_bug.cgi?id=788990
2017-10-19 11:29:04 +01:00
Philip Withnall
df7e4db65a glib-mkenums: Fix typo in version string
This is glib-mkenums, not glib-genmarshal.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2017-10-17 14:02:27 +01:00
Alberts Muktupāvels
8cc9950202 glib-mkenums: fix parsing of flags annotation
https://bugzilla.gnome.org/show_bug.cgi?id=779332
2017-08-01 10:24:44 +01:00
Emmanuele Bassi
ca69df0f16 Revert "glib-mkenums: fix parsing of /*< flags >*/ annotation"
This reverts commit 1672678bc4.

A more comprehensive fix will follow.
2017-08-01 10:11:09 +01:00
Christoph Reiter
867b5e6f90 glib-mkenums: Python2: use locale encoding when redirecting stdout
In case of Python 2 and stdout being redirected to a file, sys.stdout.encoding
is None and it defaults ASCII for encoding text.

To match the behaviour of Python 3, which uses the locale encoding also when
redirecting to a file, wrap sys.stdout with a StreamWriter using the
locale encoding.

https://bugzilla.gnome.org/show_bug.cgi?id=785113
2017-07-26 22:27:48 +02:00
Christoph Reiter
b92e15c75d glib-mkenums: fix encoding error when writing files
Instead of using NamedTemporaryFile, which doesn't take an encoding in Python 2
use mkstemp() to create a file and open it with io.open(), with a proper
encoding set.

https://bugzilla.gnome.org/show_bug.cgi?id=785113
2017-07-22 20:47:43 +02:00
Christoph Reiter
d88d1ba7e8 glib-mkenums: Don't use FileNotFoundError, it's Python 3 only.
https://bugzilla.gnome.org/show_bug.cgi?id=785113
2017-07-19 14:21:24 +02:00
Christoph Reiter
c2dace6b8b glib-mkenums: Use utf-8 for reading files
On Windows open() defaults to ANSI and on Python 2 it doesn't take
an encoding. Use io.open() instead which provides the same interface
on both Python versions.

https://bugzilla.gnome.org/show_bug.cgi?id=785113
2017-07-19 14:21:20 +02:00
Emmanuele Bassi
2219cfb92d mkenums: Keep compatibility with Python 2.x
Since every other tool in GLib is allowed to be used with Python 2.x,
glib-mkenums should follow suit.
2017-07-17 16:29:40 +01:00
Emmanuele Bassi
f18556749c mkenums: Skip unparsed lines
The old glib-mkenums just skipped lines it could not understand.
2017-07-17 16:11:19 +01:00
Emmanuele Bassi
4f17d1049f mkenums: Add missing --fprod handler
We are not generating the template for the --fprod command line
argument.
2017-07-17 11:15:06 +01:00
Emmanuele Bassi
3c03cc8f68 meson: Simplify the use of built tools
The Meson build has fallen a bit behind the Autotools one, when it comes
to the internally built tools like glib-mkenums and glib-genmarshals.

We don't need to generate gmarshal.strings any more, and since the
glib-genmarshal tool is now written in Python it can also be used when
cross-compiling, and without indirection, just like we use glib-mkenums.

We can also coalesce various rules into a simple array iteration, with
minimal changes to glib-mkenums, thus making the build a bit more
resilient and without unnecessary duplication.
2017-07-17 11:05:07 +01:00
Emmanuele Bassi
7ee050dc4b mkenums: Use the same reporting functions from genmarshal
We can reuse the same code to make error reporting stand out a bit more,
with colors and potentially with the ability to make warnings fatal.
2017-07-17 10:32:33 +01:00
Emmanuele Bassi
69515e9f5c mkenums: Skip files not found
The old glib-mkenums was more forgiving, and simply ignored any files it
could not find.

We're going to print a warning, as in the future we may want to allow
more strictness.
2017-07-17 10:24:32 +01:00
Emmanuele Bassi
77a3a96218 mkenums: Change ordering for template file and arguments
This is a bit of a hack to maintain some semblance of backward
compatibility with the old, Perl-based glib-mkenums. The old tool had an
implicit ordering on the arguments and templates; each argument was
parsed in order, and all the strings appended. This allowed developers
to write:

  glib-mkenums \
    --fhead ... \
    --template a-template-file.c.in \
    --ftail ...

And have the fhead be prepended to the file-head stanza in the template,
as well as the ftail be appended to the file-tail stanza in the
template.  Short of throwing away ArgumentParser and going over
sys.argv[] element by element, we can simulate that behaviour by
ensuring some ordering in how we build the template strings:

  - the head stanzas are always prepended to the template
  - the prod stanzas are always appended to the template
  - the tail stanzas are always appended to the template

Within each instance of the command line argument, we append each value
to the array in the order in which it appears on the command line.

This change fixes the libqmi build.
2017-07-17 09:37:21 +01:00
Emmanuele Bassi
35db045729 mkenums: Fix typo
There's a stray '~' that needs to be removed.
2017-07-16 17:25:08 +01:00
Emmanuele Bassi
69389bdc34 mkenums: Do not check for None
The symprefix variable can only be a string.
2017-07-16 12:06:34 +01:00
Emmanuele Bassi
af4a6457eb mkenums: Some arguments can be used multiple times
Some of the arguments that affect the generated result in glib-mkenums
can be used multiple times, to avoid embedding unnecessary newlines in
their values.

This change fixes the NetworkManager build.
2017-07-16 11:56:52 +01:00
Tim-Philipp Müller
8451f0b817 glib-mkenums: unescape \n etc. in command line arguments
Fixes generation of GStreamer enumtype files with autotools build.

https://bugzilla.gnome.org/show_bug.cgi?id=779332
2017-07-15 13:02:40 -04:00
Igor Gnatenko
a882c974d3 mkenums: pass string for re.sub() for real
Signed-off-by: Igor Gnatenko <ignatenko@src.gnome.org>
2017-07-15 15:33:17 +02:00
Igor Gnatenko
1a182df5d1 mkenums: don't try to call undefined function
argparse will take care about everything

Signed-off-by: Igor Gnatenko <ignatenko@src.gnome.org>
2017-07-15 15:33:17 +02:00
Igor Gnatenko
615238d0a4 mkenums: make string raw for real regex
Signed-off-by: Igor Gnatenko <ignatenko@src.gnome.org>
2017-07-15 15:33:17 +02:00
Igor Gnatenko
d753a411c0 mkenums: trivial style fixes
Signed-off-by: Igor Gnatenko <ignatenko@src.gnome.org>
2017-07-15 15:33:17 +02:00
Igor Gnatenko
112908d9e4 mkenums: fix main incompatibility with python2
Signed-off-by: Igor Gnatenko <ignatenko@src.gnome.org>
2017-07-15 15:27:31 +02:00
Emmanuele Bassi
4395a89777 Use env to run the Python-based tools
Otherwise overriding the Python interpreter with `--with-python` won't
work correctly.
2017-07-14 21:21:33 +01:00
Emmanuele Bassi
0f18a2ebda meson: Substitute the Python shebang
Just like we do with Autotools. This allows building glib-mkenums and
glib-genmarshal on older platforms that only have Python 2.
2017-07-14 20:43:19 +01:00
Tim-Philipp Müller
dbf0a56670 glib-mkenums: pick up /*< nick=xyz >*/ annotation again
... in glib-mkenums python port.

Was parsed correctly but then skipped due to inverted condition.

https://bugzilla.gnome.org/show_bug.cgi?id=779332
2017-07-13 19:03:39 -04:00
Matej Knopp
dc9b01fd64 glib-mkenums: add back missing --fprod option
... in glib-mkenums python port.

https://bugzilla.gnome.org/show_bug.cgi?id=779332
https://bugzilla.gnome.org/show_bug.cgi?id=783198
2017-07-13 19:03:39 -04:00
Matej Knopp
29f9fe041b glib-mkenums: Fix parsing of multiline comments
... in glib-mkenums python port.

https://bugzilla.gnome.org/show_bug.cgi?id=779332
https://bugzilla.gnome.org/show_bug.cgi?id=783198
2017-07-13 19:03:39 -04:00
Tim-Philipp Müller
1672678bc4 glib-mkenums: fix parsing of /*< flags >*/ annotation
Fixes get_type function generation for:

 - GMountMountFlags
 - GDriveStartFlags
 - GResourceLookupFlags
 - GSocketMsgFlags
 - GTlsDatabaseVerifyFlags
 - GTestDBusFlags

which were registered as enum types before, which broke
some unit tests.

Problem is that the flags annotation has no value, so
options.get('flags') would always return None even if
it was present.

https://bugzilla.gnome.org/show_bug.cgi?id=779332
2017-07-13 19:03:39 -04:00