From 1abdd9dd61d152e70e36fba0a2575bcc7370fb01 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Fri, 29 Sep 2023 15:00:29 -0700 Subject: [PATCH] interpreter: use typed_kwargs for build_target.name_suffix --- mesonbuild/build.py | 2 +- mesonbuild/interpreter/kwargs.py | 1 + mesonbuild/interpreter/type_checking.py | 7 +++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 086527df1..05ec9deb7 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -1191,7 +1191,7 @@ class BuildTarget(Target): raise InvalidArguments('name_prefix must be a string.') self.prefix = name_prefix self.name_prefix_set = True - if 'name_suffix' in kwargs: + if kwargs.get('name_suffix') is not None: name_suffix = kwargs['name_suffix'] if isinstance(name_suffix, list): if name_suffix: diff --git a/mesonbuild/interpreter/kwargs.py b/mesonbuild/interpreter/kwargs.py index b4af9abc2..afd8ece1a 100644 --- a/mesonbuild/interpreter/kwargs.py +++ b/mesonbuild/interpreter/kwargs.py @@ -336,6 +336,7 @@ class _BaseBuildTarget(TypedDict): link_depends: T.List[T.Union[str, File, build.CustomTarget, build.CustomTargetIndex, build.BuildTarget]] link_language: T.Optional[str] name_prefix: T.Optional[str] + name_suffix: T.Optional[str] native: MachineChoice override_options: T.Dict[OptionKey, T.Union[str, int, bool, T.List[str]]] depend_files: NotRequired[T.List[File]] diff --git a/mesonbuild/interpreter/type_checking.py b/mesonbuild/interpreter/type_checking.py index 6cae9cd81..f24268c01 100644 --- a/mesonbuild/interpreter/type_checking.py +++ b/mesonbuild/interpreter/type_checking.py @@ -567,6 +567,12 @@ def _name_validator(arg: T.Optional[T.Union[str, T.List]]) -> T.Optional[str]: return None +def _name_suffix_validator(arg: T.Optional[T.Union[str, T.List]]) -> T.Optional[str]: + if arg == '': + return 'must nt be a empty string. An empty array may be passed if you want Meson to use the default behavior.' + return _name_validator(arg) + + _NAME_PREFIX_KW: KwargInfo[T.Optional[T.Union[str, T.List]]] = KwargInfo( 'name_prefix', (str, NoneType, list), @@ -581,6 +587,7 @@ _BUILD_TARGET_KWS: T.List[KwargInfo] = [ BT_SOURCES_KW, INCLUDE_DIRECTORIES.evolve(name='d_import_dirs'), _NAME_PREFIX_KW, + _NAME_PREFIX_KW.evolve(name='name_suffix', validator=_name_suffix_validator), RUST_CRATE_TYPE_KW, KwargInfo('d_debug', ContainerTypeInfo(list, (str, int)), default=[], listify=True), D_MODULE_VERSIONS_KW,