summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2023-09-29 14:59:29 -0700
committerDylan Baker <dylan@pnwbakers.com>2023-10-17 08:09:06 -0700
commit9f80a069ec215f41b289f11ca8dd1f24c88fed97 (patch)
treeaf4562c7bfed05af734495dc2b837ca73b8d9ee2
parent4386419a861240e8719b86e4a125902b7ff77644 (diff)
downloadmeson-9f80a069ec215f41b289f11ca8dd1f24c88fed97.tar.gz
interpreter: use typed_kwargs for build_target.name_prefix
-rw-r--r--mesonbuild/build.py2
-rw-r--r--mesonbuild/interpreter/kwargs.py1
-rw-r--r--mesonbuild/interpreter/type_checking.py15
3 files changed, 17 insertions, 1 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
index dbfbea81b..086527df1 100644
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -1181,7 +1181,7 @@ class BuildTarget(Target):
if not os.path.isfile(trial):
raise InvalidArguments(f'Tried to add non-existing resource {r}.')
self.resources = resources
- if 'name_prefix' in kwargs:
+ if kwargs.get('name_prefix') is not None:
name_prefix = kwargs['name_prefix']
if isinstance(name_prefix, list):
if name_prefix:
diff --git a/mesonbuild/interpreter/kwargs.py b/mesonbuild/interpreter/kwargs.py
index 477bc232e..b4af9abc2 100644
--- a/mesonbuild/interpreter/kwargs.py
+++ b/mesonbuild/interpreter/kwargs.py
@@ -335,6 +335,7 @@ class _BaseBuildTarget(TypedDict):
implicit_include_directories: bool
link_depends: T.List[T.Union[str, File, build.CustomTarget, build.CustomTargetIndex, build.BuildTarget]]
link_language: T.Optional[str]
+ name_prefix: 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 8286b97e1..6cae9cd81 100644
--- a/mesonbuild/interpreter/type_checking.py
+++ b/mesonbuild/interpreter/type_checking.py
@@ -560,12 +560,27 @@ _ALL_TARGET_KWS: T.List[KwargInfo] = [
NATIVE_KW,
]
+
+def _name_validator(arg: T.Optional[T.Union[str, T.List]]) -> T.Optional[str]:
+ if isinstance(arg, list) and arg:
+ return 'must be empty when passed as an array to signify the default value.'
+ return None
+
+
+_NAME_PREFIX_KW: KwargInfo[T.Optional[T.Union[str, T.List]]] = KwargInfo(
+ 'name_prefix',
+ (str, NoneType, list),
+ validator=_name_validator,
+ convertor=lambda x: None if isinstance(x, list) else x,
+)
+
# Applies to all build_target classes except jar
_BUILD_TARGET_KWS: T.List[KwargInfo] = [
*_ALL_TARGET_KWS,
*_LANGUAGE_KWS,
BT_SOURCES_KW,
INCLUDE_DIRECTORIES.evolve(name='d_import_dirs'),
+ _NAME_PREFIX_KW,
RUST_CRATE_TYPE_KW,
KwargInfo('d_debug', ContainerTypeInfo(list, (str, int)), default=[], listify=True),
D_MODULE_VERSIONS_KW,