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
This commit is contained in:
Philip Withnall 2021-03-10 19:48:22 +00:00
parent c80528f17b
commit 856aeba9e4
2 changed files with 84 additions and 2 deletions

View File

@ -219,6 +219,7 @@ def parse_entries(file, file_name):
m = re.match(r'''\s*
(\w+)\s* # name
(\s+[A-Z]+_(?:AVAILABLE|DEPRECATED)_ENUMERATOR_IN_[0-9_]+(?:_FOR\s*\(\s*\w+\s*\))?\s*)? # availability
(?:=( # value
\s*\w+\s*\(.*\)\s* # macro with multiple args
| # OR
@ -231,12 +232,15 @@ def parse_entries(file, file_name):
if m:
groups = m.groups()
name = groups[0]
availability = None
value = None
options = None
if len(groups) > 1:
value = groups[1]
availability = groups[1]
if len(groups) > 2:
options = groups[2]
value = groups[2]
if len(groups) > 3:
options = groups[3]
if flags is None and value is not None and '<<' in value:
seenbitshift = 1

View File

@ -650,6 +650,84 @@ comment: {standard_bottom_comment}
"0",
)
def test_available_in(self):
"""Test GLIB_AVAILABLE_ENUMERATOR_IN_2_68 handling
https://gitlab.gnome.org/GNOME/glib/-/issues/2327"""
h_contents = """
typedef enum {
G_DBUS_SERVER_FLAGS_AUTHENTICATION_REQUIRE_SAME_USER GLIB_AVAILABLE_ENUMERATOR_IN_2_68 = (1<<2)
} GDBusServerFlags;
"""
result = self.runMkenumsWithHeader(h_contents)
self.assertEqual("", result.err)
self.assertSingleEnum(
result,
"GDBusServerFlags",
"g_dbus_server_flags",
"G_DBUS_SERVER_FLAGS",
"DBUS_SERVER_FLAGS",
"G",
"",
"flags",
"Flags",
"FLAGS",
"G_DBUS_SERVER_FLAGS_AUTHENTICATION_REQUIRE_SAME_USER",
"user",
"4",
)
def test_deprecated_in(self):
"""Test GLIB_DEPRECATED_ENUMERATOR_IN_2_68 handling
https://gitlab.gnome.org/GNOME/glib/-/issues/2327"""
h_contents = """
typedef enum {
G_DBUS_SERVER_FLAGS_AUTHENTICATION_REQUIRE_SAME_USER GLIB_DEPRECATED_ENUMERATOR_IN_2_68 = (1<<2)
} GDBusServerFlags;
"""
result = self.runMkenumsWithHeader(h_contents)
self.assertEqual("", result.err)
self.assertSingleEnum(
result,
"GDBusServerFlags",
"g_dbus_server_flags",
"G_DBUS_SERVER_FLAGS",
"DBUS_SERVER_FLAGS",
"G",
"",
"flags",
"Flags",
"FLAGS",
"G_DBUS_SERVER_FLAGS_AUTHENTICATION_REQUIRE_SAME_USER",
"user",
"4",
)
def test_deprecated_in_for(self):
"""Test GLIB_DEPRECATED_ENUMERATOR_IN_2_68_FOR() handling
https://gitlab.gnome.org/GNOME/glib/-/issues/2327"""
h_contents = """
typedef enum {
G_DBUS_SERVER_FLAGS_AUTHENTICATION_REQUIRE_SAME_USER GLIB_DEPRECATED_ENUMERATOR_IN_2_68_FOR(G_DBUS_SERVER_FLAGS_AUTHENTICATION_REQUIRE_SAME_USER2) = (1<<2)
} GDBusServerFlags;
"""
result = self.runMkenumsWithHeader(h_contents)
self.assertEqual("", result.err)
self.assertSingleEnum(
result,
"GDBusServerFlags",
"g_dbus_server_flags",
"G_DBUS_SERVER_FLAGS",
"DBUS_SERVER_FLAGS",
"G",
"",
"flags",
"Flags",
"FLAGS",
"G_DBUS_SERVER_FLAGS_AUTHENTICATION_REQUIRE_SAME_USER",
"user",
"4",
)
class TestRspMkenums(TestMkenums):
"""Run all tests again in @rspfile mode"""