aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Schwartz <eschwartz@archlinux.org>2022-01-12 18:42:44 -0500
committerDylan Baker <dylan@pnwbakers.com>2022-01-12 18:55:25 -0800
commitbda11fe25d1efe688d251148cb7cf7939cd50433 (patch)
treeba07e61221effca72c06ca9bcaf027ea1b18d4bf
parenteeb110ab024b505f326ae907393cae761666ace0 (diff)
downloadmeson-bda11fe25d1efe688d251148cb7cf7939cd50433.zip
meson-bda11fe25d1efe688d251148cb7cf7939cd50433.tar.gz
meson-bda11fe25d1efe688d251148cb7cf7939cd50433.tar.bz2
gome.gdbus_codegen: fix annotations argument for multiple annotations, harder
The original attempted fix only allowed configuration to succeed, but not building. It was modeled based on the gdbus-codegen documentation, which states: --annotate WHAT KEY VALUE WHAT KEY VALUE WHAT KEY VALUE Add annotation (may be used several times) which clearly indicates that gdbus-codegen accepts an --annotate flag that is followed by a multiple of 3 values, despite this not actually working. The manpage actually contradicts the --help text: --annotate ELEMENT KEY VALUE Used to inject D-Bus annotations into the given XML files. [] ... and gives examples that use multiple --annotate flags each with 3 arguments. To better understand what meson is supposed to do here, we should look at ef52e60936665c982cd17a4a17c2045b445d8e6d, which ported to typed_kwargs. There is actually a big chunk of code to handle annotations that got completely dropped, leading with a comment (that did not get dropped): "they are a list of lists of strings..." Reimplement this logic inside a validator/converter for the annotations kwarg container: - do not listify, we don't accept `annotations: ''` and listify is supposed to be for when either x or list[x] is valid - go back to checking for a list of exactly 3 values - allow a list of the aforementioned, in the traditionally expected form: [ ['foo1', 'foo2', 'foo3'], ['bar1', 'bar2', 'bar3'], ] - pass one --annotate flag per 3-value-list And add some better error reporting for the cause of errors when processing lists of lists.
-rw-r--r--mesonbuild/modules/gnome.py33
1 files changed, 27 insertions, 6 deletions
diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py
index e5990f0..267c2d4 100644
--- a/mesonbuild/modules/gnome.py
+++ b/mesonbuild/modules/gnome.py
@@ -134,7 +134,7 @@ if T.TYPE_CHECKING:
namespace: T.Optional[str]
object_manager: bool
build_by_default: bool
- annotations: T.List[str]
+ annotations: T.List[T.List[str]]
install_header: bool
install_dir: T.Optional[str]
docbook: T.Optional[str]
@@ -222,6 +222,27 @@ _MK_ENUMS_COMMON_KWS: T.List[KwargInfo] = [
KwargInfo('symbol_prefix', (str, NoneType)),
]
+def annotations_validator(annotations: T.List[T.Union[str, T.List[str]]]) -> T.Optional[str]:
+
+ """Validate gdbus-codegen annotations argument"""
+
+ badlist = 'must be made up of 3 strings for ELEMENT, KEY, and VALUE'
+
+ if all(isinstance(annot, str) for annot in annotations):
+ if len(annotations) == 3:
+ return None
+ else:
+ return badlist
+ elif not all(isinstance(annot, list) for annot in annotations):
+ for c, annot in enumerate(annotations):
+ if not isinstance(annot, list):
+ return f'element {c+1} must be a list'
+ else:
+ for c, annot in enumerate(annotations):
+ if len(annot) != 3 or not all(isinstance(i, str) for i in annot):
+ return f'element {c+1} {badlist}'
+ return None
+
# gresource compilation is broken due to the way
# the resource compiler and Ninja clash about it
#
@@ -1434,10 +1455,10 @@ class GnomeModule(ExtensionModule):
KwargInfo('namespace', (str, NoneType)),
KwargInfo('object_manager', bool, default=False),
KwargInfo(
- 'annotations', ContainerTypeInfo(list, str),
- listify=True,
+ 'annotations', ContainerTypeInfo(list, (list, str)),
default=[],
- validator=lambda x: 'must be made up of 3 strings for ELEMENT, KEY, and VALUE' if len(x) % 3 != 0 else None
+ validator=annotations_validator,
+ convertor=lambda x: [x] if x and isinstance(x[0], str) else x,
),
KwargInfo('install_header', bool, default=False, since='0.46.0'),
KwargInfo('install_dir', (str, NoneType), since='0.46.0'),
@@ -1477,9 +1498,9 @@ class GnomeModule(ExtensionModule):
build_by_default = kwargs['build_by_default']
# Annotations are a bit ugly in that they are a list of lists of strings...
- if kwargs['annotations']:
+ for annot in kwargs['annotations']:
cmd.append('--annotate')
- cmd.extend(kwargs['annotations'])
+ cmd.extend(annot)
targets = []
install_header = kwargs['install_header']