diff options
| author | Dylan Baker <dylan@pnwbakers.com> | 2025-12-05 09:15:06 -0800 |
|---|---|---|
| committer | Dylan Baker <dylan@pnwbakers.com> | 2025-12-17 14:04:17 -0800 |
| commit | a152da9206891caad17fd9271aff04073e811784 (patch) | |
| tree | dfbcf9fd6eb8be2906ec0f140691d48841c1e753 /mesonbuild/build.py | |
| parent | 7a1655acd29e5ba50a2951ad6c8db934fa7a6eb9 (diff) | |
| download | meson-a152da9206891caad17fd9271aff04073e811784.tar.gz | |
build|interpreter: use typed_kwargs for link_with
This replaces the long explanation of `external_library`s in the
`link_with` parameter to the simpler one used by declare_dependency.
Additionally, declare_dependency now checks that a target is linkable
when adding it. This just catches the problem before it goes down into
the build layer giving a better error message.
There is a bug in the declare_dependency annotations, in that they don't
mark Executable as acceptable. So I've fixed that.
Diffstat (limited to 'mesonbuild/build.py')
| -rw-r--r-- | mesonbuild/build.py | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 50d83fa9f..f32010917 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -796,7 +796,7 @@ class BuildTarget(Target): self.external_deps: T.List[dependencies.Dependency] = [] self.include_dirs: T.List['IncludeDirs'] = [] self.link_language = kwargs.get('link_language') - self.link_targets: T.List[LibTypes] = [] + self.link_targets: T.List[BuildTargetTypes] = [] self.link_whole_targets: T.List[StaticTargetTypes] = [] self.depend_files: T.List[File] = [] self.link_depends: T.List[T.Union[File, BuildTargetTypes]] = [] @@ -1468,18 +1468,6 @@ class BuildTarget(Target): def link(self, targets: T.List[BuildTargetTypes]) -> None: for t in targets: - if not isinstance(t, (Target, CustomTargetIndex)): - if isinstance(t, dependencies.ExternalLibrary): - raise MesonException(textwrap.dedent('''\ - An external library was used in link_with keyword argument, which - is reserved for libraries built as part of this project. External - libraries must be passed using the dependencies keyword argument - instead, because they are conceptually "external dependencies", - just like those detected with the dependency() function. - ''')) - raise InvalidArguments(f'{t!r} is not a target.') - if not t.is_linkable_target(): - raise InvalidArguments(f"Link target '{t!s}' is not linkable.") if isinstance(self, StaticLibrary) and self.install and t.is_internal(): # When we're a static library and we link_with to an # internal/convenience library, promote to link_whole. @@ -2758,6 +2746,10 @@ class BothLibraries(SecondLevelHolder): def get_id(self) -> str: return self.get_default_object().get_id() + def is_linkable_target(self) -> bool: + # For polymorphism with build targets + return True + class CommandBase: depend_files: T.List[File] |
