Skip to content

Commit

Permalink
interpreter: use typed_kwargs for build_target.name_prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
dcbaker committed Oct 17, 2023
1 parent 4386419 commit 9f80a06
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mesonbuild/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ def process_kwargs(self, kwargs):
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:
Expand Down
1 change: 1 addition & 0 deletions mesonbuild/interpreter/kwargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down
15 changes: 15 additions & 0 deletions mesonbuild/interpreter/type_checking.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,12 +560,27 @@ def link_whole_validator(values: T.List[T.Union[StaticLibrary, CustomTarget, Cus
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,
Expand Down

0 comments on commit 9f80a06

Please sign in to comment.