diff options
| author | Dylan Baker <dylan@pnwbakers.com> | 2023-09-29 15:49:40 -0700 |
|---|---|---|
| committer | Dylan Baker <dylan@pnwbakers.com> | 2023-10-17 08:09:06 -0700 |
| commit | e419184a9b2698983e3115e6552e67ac026a3ce1 (patch) | |
| tree | 36e2d3a19405cfe55f669887370327225d310f88 | |
| parent | d5bdcf1145065282dbd8b076e09d68330e1ddf2d (diff) | |
| download | meson-e419184a9b2698983e3115e6552e67ac026a3ce1.tar.gz | |
interpreter: use typed_kwargs for build_target.objects
| -rw-r--r-- | mesonbuild/interpreter/interpreter.py | 2 | ||||
| -rw-r--r-- | mesonbuild/interpreter/kwargs.py | 1 | ||||
| -rw-r--r-- | mesonbuild/interpreter/type_checking.py | 31 |
3 files changed, 33 insertions, 1 deletions
diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 223ebddba..7fb3c9234 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -3313,7 +3313,7 @@ class Interpreter(InterpreterBase, HoldableObject): sources = [s for s in sources if not isinstance(s, (build.BuildTarget, build.ExtractedObjects))] sources = self.source_strings_to_files(sources) - objs = extract_as_list(kwargs, 'objects') + objs = kwargs['objects'] kwargs['dependencies'] = extract_as_list(kwargs, 'dependencies') kwargs['extra_files'] = self.source_strings_to_files(kwargs['extra_files']) self.check_sources_exist(os.path.join(self.source_root, self.subdir), sources) diff --git a/mesonbuild/interpreter/kwargs.py b/mesonbuild/interpreter/kwargs.py index a4ebe98eb..17f7876a0 100644 --- a/mesonbuild/interpreter/kwargs.py +++ b/mesonbuild/interpreter/kwargs.py @@ -338,6 +338,7 @@ class _BaseBuildTarget(TypedDict): name_prefix: T.Optional[str] name_suffix: T.Optional[str] native: MachineChoice + objects: T.List[build.ObjectTypes] override_options: T.Dict[OptionKey, T.Union[str, int, bool, T.List[str]]] depend_files: NotRequired[T.List[File]] resources: T.List[str] diff --git a/mesonbuild/interpreter/type_checking.py b/mesonbuild/interpreter/type_checking.py index 6a4dda561..296baca31 100644 --- a/mesonbuild/interpreter/type_checking.py +++ b/mesonbuild/interpreter/type_checking.py @@ -25,6 +25,7 @@ NoneType: T.Type[None] = type(None) if T.TYPE_CHECKING: from typing_extensions import Literal + from ..build import ObjectTypes from ..interpreterbase import TYPE_var from ..mesonlib import EnvInitValueType @@ -549,6 +550,24 @@ _JAVA_LANG_KW: KwargInfo[T.List[str]] = _BASE_LANG_KW.evolve( deprecated_message='This does not, and never has, done anything. It should be removed' ) +def _objects_validator(vals: T.List[ObjectTypes]) -> T.Optional[str]: + non_objects: T.List[str] = [] + + for val in vals: + if isinstance(val, ExtractedObjects): + continue + elif isinstance(val, (str, File)): + if not compilers.is_object(val): + non_objects.append(str(val)) + else: + non_objects.extend(o for o in val.get_outputs() if not compilers.is_object(o)) + + if non_objects: + return f'File{"s" if len(non_objects) > 1 else ""}: "{", ".join(non_objects)}" are not objects' + + return None + + # Applies to all build_target like classes _ALL_TARGET_KWS: T.List[KwargInfo] = [ OVERRIDE_OPTIONS_KW, @@ -559,6 +578,17 @@ _ALL_TARGET_KWS: T.List[KwargInfo] = [ KwargInfo('implicit_include_directories', bool, default=True, since='0.42.0'), NATIVE_KW, KwargInfo('resources', ContainerTypeInfo(list, str), default=[], listify=True), + KwargInfo( + 'objects', + ContainerTypeInfo(list, (str, File, CustomTarget, CustomTargetIndex, GeneratedList, ExtractedObjects)), + listify=True, + default=[], + validator=_objects_validator, + since_values={ + ContainerTypeInfo(list, (GeneratedList, CustomTarget, CustomTargetIndex)): + ('1.1.0', 'generated sources as positional "objects" arguments') + }, + ), ] @@ -581,6 +611,7 @@ _NAME_PREFIX_KW: KwargInfo[T.Optional[T.Union[str, T.List]]] = KwargInfo( 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, |
