mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-19 15:18:55 +02:00
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:
@@ -219,6 +219,7 @@ def parse_entries(file, file_name):
|
|||||||
|
|
||||||
m = re.match(r'''\s*
|
m = re.match(r'''\s*
|
||||||
(\w+)\s* # name
|
(\w+)\s* # name
|
||||||
|
(\s+[A-Z]+_(?:AVAILABLE|DEPRECATED)_ENUMERATOR_IN_[0-9_]+(?:_FOR\s*\(\s*\w+\s*\))?\s*)? # availability
|
||||||
(?:=( # value
|
(?:=( # value
|
||||||
\s*\w+\s*\(.*\)\s* # macro with multiple args
|
\s*\w+\s*\(.*\)\s* # macro with multiple args
|
||||||
| # OR
|
| # OR
|
||||||
@@ -231,12 +232,15 @@ def parse_entries(file, file_name):
|
|||||||
if m:
|
if m:
|
||||||
groups = m.groups()
|
groups = m.groups()
|
||||||
name = groups[0]
|
name = groups[0]
|
||||||
|
availability = None
|
||||||
value = None
|
value = None
|
||||||
options = None
|
options = None
|
||||||
if len(groups) > 1:
|
if len(groups) > 1:
|
||||||
value = groups[1]
|
availability = groups[1]
|
||||||
if len(groups) > 2:
|
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:
|
if flags is None and value is not None and '<<' in value:
|
||||||
seenbitshift = 1
|
seenbitshift = 1
|
||||||
|
|
||||||
|
@@ -650,6 +650,84 @@ comment: {standard_bottom_comment}
|
|||||||
"0",
|
"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):
|
class TestRspMkenums(TestMkenums):
|
||||||
"""Run all tests again in @rspfile mode"""
|
"""Run all tests again in @rspfile mode"""
|
||||||
|
Reference in New Issue
Block a user