summaryrefslogtreecommitdiff
path: root/mesonbuild/interpreter
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2025-12-08 10:53:08 -0800
committerDylan Baker <dylan@pnwbakers.com>2025-12-17 12:46:50 -0800
commitbde1c23b4f3eb9eb63e835b722bb9bbcccc4c8c1 (patch)
tree3f7ef84071483aa7cdca5337615ea2259180b172 /mesonbuild/interpreter
parentf3d9a71a1bea661495c1d3c6004b26b4497fb1c9 (diff)
downloadmeson-bde1c23b4f3eb9eb63e835b722bb9bbcccc4c8c1.tar.gz
interpreter|build: Use typed_kwargs for build_target(dependencies)
What is basically impossible is to handle `SubprojectHolder`, because it's not a true holder but an interpreter object. Well, impossible without changing SubprojectHolder into a true holder, because it's avoiding the circular import becomes extremely convoluted otherwise, and refactoring is difficult because the held object is itself an Interpreter. It's a rather complex problem to solve gracefully. I've punted to avoid the complexity, it does mean that the error message is somewhat less exact. I don't think this is actually a huge problem because we've really guided people away from using `subproject()` and to instead use dependency fallbacks, which don't have this problem to begin with. This removes validation from the build layer, and puts it in interpreter. For code sharing reasons this means that `internal_dependency` also gets more fine grained error messages. The test case for this has been modified to use the `testcase expect_error` construct, and thus has been moved to the common tests directory. It's also been extended to cover both the library case, which gives coverage for the `extra_types` in `KwargInfo`
Diffstat (limited to 'mesonbuild/interpreter')
-rw-r--r--mesonbuild/interpreter/interpreter.py2
-rw-r--r--mesonbuild/interpreter/kwargs.py1
-rw-r--r--mesonbuild/interpreter/type_checking.py4
3 files changed, 6 insertions, 1 deletions
diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py
index 3a0cae041..3b87f48ea 100644
--- a/mesonbuild/interpreter/interpreter.py
+++ b/mesonbuild/interpreter/interpreter.py
@@ -3559,7 +3559,7 @@ class Interpreter(InterpreterBase, HoldableObject):
for l in target.compilers.keys():
dep = self.build.stdlibs[target.for_machine].get(l, None)
if dep:
- target.add_deps(dep)
+ target.add_deps([dep])
def check_sources_exist(self, subdir, sources):
for s in sources:
diff --git a/mesonbuild/interpreter/kwargs.py b/mesonbuild/interpreter/kwargs.py
index c08ceb759..1dee9a65c 100644
--- a/mesonbuild/interpreter/kwargs.py
+++ b/mesonbuild/interpreter/kwargs.py
@@ -337,6 +337,7 @@ class _BaseBuildTarget(TypedDict):
build_by_default: bool
build_rpath: str
+ dependencies: T.List[Dependency]
extra_files: T.List[FileOrString]
gnu_symbol_visibility: str
include_directories: T.List[build.IncludeDirs]
diff --git a/mesonbuild/interpreter/type_checking.py b/mesonbuild/interpreter/type_checking.py
index 478924828..7515cbcef 100644
--- a/mesonbuild/interpreter/type_checking.py
+++ b/mesonbuild/interpreter/type_checking.py
@@ -426,6 +426,9 @@ DEPENDENCIES_KW: KwargInfo[T.List[Dependency]] = KwargInfo(
ContainerTypeInfo(list, (Dependency, InternalDependency)),
listify=True,
default=[],
+ extra_types={
+ BuildTarget: lambda arg: f'Tried to use a build_target "{T.cast("BuildTarget", arg).name}" as a dependency. This should be in `link_with` or `link_whole` instead.',
+ },
)
D_MODULE_VERSIONS_KW: KwargInfo[T.List[T.Union[str, int]]] = KwargInfo(
@@ -721,6 +724,7 @@ _BUILD_TARGET_KWS: T.List[KwargInfo] = [
*_LANGUAGE_KWS,
BT_SOURCES_KW,
INCLUDE_DIRECTORIES.evolve(since_values={ContainerTypeInfo(list, str): '0.50.0'}),
+ DEPENDENCIES_KW,
INCLUDE_DIRECTORIES.evolve(name='d_import_dirs'),
_NAME_PREFIX_KW,
_NAME_PREFIX_KW.evolve(name='name_suffix', validator=_name_suffix_validator),