From 702030a9cccf78b2ebdf2a6c85ea558163160dbc Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 10 Mar 2022 10:35:47 -0800 Subject: dependencies: Don't allow as_link_whole to complete with SharedLibraries Since a SharedLibrary can't be statically linked in, we shouldn't allow the method to complete. --- mesonbuild/dependencies/base.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'mesonbuild') diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py index 6f7cd2a..e239d66 100644 --- a/mesonbuild/dependencies/base.py +++ b/mesonbuild/dependencies/base.py @@ -317,8 +317,19 @@ class InternalDependency(Dependency): raise DependencyException(f'Could not get an internal variable and no default provided for {self!r}') def generate_link_whole_dependency(self) -> Dependency: + from ..build import SharedLibrary, CustomTarget, CustomTargetIndex new_dep = copy.deepcopy(self) - new_dep.whole_libraries += new_dep.libraries + for x in new_dep.libraries: + if isinstance(x, SharedLibrary): + raise MesonException('Cannot convert a dependency to link_whole when it contains a ' + 'SharedLibrary') + elif isinstance(x, (CustomTarget, CustomTargetIndex)) and x.links_dynamically(): + raise MesonException('Cannot convert a dependency to link_whole when it contains a ' + 'CustomTarget or CustomTargetIndex which is a shared library') + + # Mypy doesn't understand that the above is a TypeGuard + new_dep.whole_libraries += T.cast('T.List[T.Union[StaticLibrary, CustomTarget, CustomTargetIndex]]', + new_dep.libraries) new_dep.libraries = [] return new_dep -- cgit v1.1