From bda11fe25d1efe688d251148cb7cf7939cd50433 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Wed, 12 Jan 2022 18:42:44 -0500 Subject: [PATCH] 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. --- mesonbuild/modules/gnome.py | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index e5990f087..267c2d4e5 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']