diff options
| author | Dylan Baker <dylan@pnwbakers.com> | 2025-09-23 11:44:03 -0700 |
|---|---|---|
| committer | Dylan Baker <dylan@pnwbakers.com> | 2025-09-24 14:47:19 -0700 |
| commit | 6cb9d898ebb5d0f1d619d4937b1c316400802609 (patch) | |
| tree | 742759976a501b87db968bfc21b8a29adf2c3a04 | |
| parent | 97e9e2fb66895d2fc1b4a714a428468aeebf9648 (diff) | |
| download | meson-6cb9d898ebb5d0f1d619d4937b1c316400802609.tar.gz | |
ast/introspection: remove keyword arguments from build targets that are UnknownValue
It is not the build layer's job to handle ast types, so instead filter
out UnknownValues before passing them to the build layer, then fix up
any special values we need in the ast layer. This reveals that some of
what we were previously doing only works because the build layer is
pretty much untyped, if it was typed it would have screamed loudly.
| -rw-r--r-- | mesonbuild/ast/interpreter.py | 4 | ||||
| -rw-r--r-- | mesonbuild/ast/introspection.py | 14 | ||||
| -rw-r--r-- | mesonbuild/build.py | 12 | ||||
| -rw-r--r-- | mesonbuild/mintro.py | 2 |
4 files changed, 18 insertions, 14 deletions
diff --git a/mesonbuild/ast/interpreter.py b/mesonbuild/ast/interpreter.py index 86b644259..524f33193 100644 --- a/mesonbuild/ast/interpreter.py +++ b/mesonbuild/ast/interpreter.py @@ -109,8 +109,8 @@ class IntrospectionBuildTarget(MesonInterpreterObject): typename: str defined_in: str subdir: str - build_by_default: bool - installed: bool + build_by_default: T.Union[bool, UnknownValue] + installed: T.Union[bool, UnknownValue] outputs: T.List[str] source_nodes: T.List[BaseNode] extra_files: BaseNode diff --git a/mesonbuild/ast/introspection.py b/mesonbuild/ast/introspection.py index 6ffc6adbe..9278476b0 100644 --- a/mesonbuild/ast/introspection.py +++ b/mesonbuild/ast/introspection.py @@ -257,7 +257,7 @@ class IntrospectionInterpreter(AstInterpreter): # Make sure nothing can crash when creating the build class kwargs_reduced = {k: v for k, v in kwargs.items() if k in targetclass.known_kwargs and k in {'install', 'build_by_default', 'build_always', 'name_prefix'}} kwargs_reduced = {k: v.value if isinstance(v, ElementaryNode) else v for k, v in kwargs_reduced.items()} - kwargs_reduced = {k: v for k, v in kwargs_reduced.items() if not isinstance(v, BaseNode)} + kwargs_reduced = {k: v for k, v in kwargs_reduced.items() if not isinstance(v, (BaseNode, UnknownValue))} for_machine = MachineChoice.BUILD if kwargs.get('native', False) else MachineChoice.HOST objects: T.List[T.Any] = [] empty_sources: T.List[T.Any] = [] @@ -267,6 +267,14 @@ class IntrospectionInterpreter(AstInterpreter): self.environment, self.coredata.compilers[for_machine], kwargs_reduced) target.process_compilers_late() + build_by_default: T.Union[UnknownValue, bool] = target.build_by_default + if 'build_by_default' in kwargs and isinstance(kwargs['build_by_default'], UnknownValue): + build_by_default = kwargs['build_by_default'] + + install: T.Union[UnknownValue, bool] = target.should_install() + if 'install' in kwargs and isinstance(kwargs['install'], UnknownValue): + install = kwargs['install'] + new_target = IntrospectionBuildTarget( name=target.get_basename(), machine=target.for_machine.get_lower_case_name(), @@ -274,8 +282,8 @@ class IntrospectionInterpreter(AstInterpreter): typename=target.get_typename(), defined_in=os.path.normpath(os.path.join(self.source_root, self.subdir, environment.build_filename)), subdir=self.subdir, - build_by_default=target.build_by_default, - installed=target.should_install(), + build_by_default=build_by_default, + installed=install, outputs=target.get_outputs(), source_nodes=source_nodes, extra_files=extraf_nodes, diff --git a/mesonbuild/build.py b/mesonbuild/build.py index b43532006..c827359a0 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -33,7 +33,7 @@ from .compilers import ( is_header, is_object, is_source, clink_langs, sort_clink, all_languages, is_known_suffix, detect_static_linker, LANGUAGES_USING_LDFLAGS ) -from .interpreterbase import FeatureNew, FeatureDeprecated, UnknownValue +from .interpreterbase import FeatureNew, FeatureDeprecated if T.TYPE_CHECKING: from typing_extensions import Literal, TypedDict @@ -650,7 +650,7 @@ class Target(HoldableObject, metaclass=abc.ABCMeta): def process_kwargs_base(self, kwargs: T.Dict[str, T.Any]) -> None: if 'build_by_default' in kwargs: self.build_by_default = kwargs['build_by_default'] - if not isinstance(self.build_by_default, (bool, UnknownValue)): + if not isinstance(self.build_by_default, bool): raise InvalidArguments('build_by_default must be a boolean value.') if not self.build_by_default and kwargs.get('install', False): @@ -1225,9 +1225,7 @@ class BuildTarget(Target): self.resources = resources if kwargs.get('name_prefix') is not None: name_prefix = kwargs['name_prefix'] - if isinstance(name_prefix, UnknownValue): - pass - elif isinstance(name_prefix, list): + if isinstance(name_prefix, list): if name_prefix: raise InvalidArguments('name_prefix array must be empty to signify default.') else: @@ -1237,9 +1235,7 @@ class BuildTarget(Target): self.name_prefix_set = True if kwargs.get('name_suffix') is not None: name_suffix = kwargs['name_suffix'] - if isinstance(name_suffix, UnknownValue): - pass - elif isinstance(name_suffix, list): + if isinstance(name_suffix, list): if name_suffix: raise InvalidArguments('name_suffix array must be empty to signify default.') else: diff --git a/mesonbuild/mintro.py b/mesonbuild/mintro.py index 9f7eb33ac..b4505fdb9 100644 --- a/mesonbuild/mintro.py +++ b/mesonbuild/mintro.py @@ -174,7 +174,7 @@ def get_target_dir(coredata: cdata.CoreData, subdir: str) -> str: return subdir def list_targets_from_source(intr: IntrospectionInterpreter) -> T.List[T.Dict[str, object]]: - tlist = [] + tlist: T.List[T.Dict[str, object]] = [] root_dir = Path(intr.source_root).resolve() for i in intr.targets: |
