aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/dependencies/base.py
diff options
context:
space:
mode:
authorEli Schwartz <eschwartz@archlinux.org>2022-02-27 21:28:31 -0500
committerEli Schwartz <eschwartz@archlinux.org>2022-04-13 17:27:09 -0400
commitb55349c2e9ac6f9e37e2fd6e7a8333f6893fbaa9 (patch)
tree96c13c307755d882c82e86836c0abf16755be52a /mesonbuild/dependencies/base.py
parentc649a2b8c59c9f49affca9bd89c126bfa0f54449 (diff)
downloadmeson-b55349c2e9ac6f9e37e2fd6e7a8333f6893fbaa9.zip
meson-b55349c2e9ac6f9e37e2fd6e7a8333f6893fbaa9.tar.gz
meson-b55349c2e9ac6f9e37e2fd6e7a8333f6893fbaa9.tar.bz2
dependencies: tighten type checking and fix cmake API violation for get_variable
dep.get_variable() only supports string values for pkg-config and config-tool, because those interfaces use text communication, and internal variables (from declare_dependency) operate the same way. CMake had an oddity, where get_variable doesn't document that it allows list values but apparently it miiiiiight work? Actually getting that kind of result would be dangerously inconsistent though. Also, CMake does not support lists so it's a lie. Strings that are *treated* as lists with `;` splitting don't count... We could do two things here: - raise an error - treat it as a string and return a string It's not clear what the use case of get_variable() on a maybe-list is, and should probably be a hard error. But that's controversial, so instead we just return the original `;`-delimited string. It is probably the wrong thing, but users are welcome to cope with that somehow on their own.
Diffstat (limited to 'mesonbuild/dependencies/base.py')
-rw-r--r--mesonbuild/dependencies/base.py14
1 files changed, 4 insertions, 10 deletions
diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py
index 7b85159..1242af7 100644
--- a/mesonbuild/dependencies/base.py
+++ b/mesonbuild/dependencies/base.py
@@ -216,7 +216,7 @@ class Dependency(HoldableObject):
def get_variable(self, *, cmake: T.Optional[str] = None, pkgconfig: T.Optional[str] = None,
configtool: T.Optional[str] = None, internal: T.Optional[str] = None,
default_value: T.Optional[str] = None,
- pkgconfig_define: T.Optional[T.List[str]] = None) -> T.Union[str, T.List[str]]:
+ pkgconfig_define: T.Optional[T.List[str]] = None) -> str:
if default_value is not None:
return default_value
raise DependencyException(f'No default provided for dependency {self!r}, which is not pkg-config, cmake, or config-tool based.')
@@ -232,7 +232,7 @@ class InternalDependency(Dependency):
libraries: T.List[T.Union['BuildTarget', 'CustomTarget']],
whole_libraries: T.List[T.Union['BuildTarget', 'CustomTarget']],
sources: T.Sequence[T.Union['FileOrString', 'CustomTarget', StructuredSources]],
- ext_deps: T.List[Dependency], variables: T.Dict[str, T.Any],
+ ext_deps: T.List[Dependency], variables: T.Dict[str, str],
d_module_versions: T.List[str], d_import_dirs: T.List['IncludeDirs']):
super().__init__(DependencyTypeName('internal'), {})
self.version = version
@@ -301,16 +301,10 @@ class InternalDependency(Dependency):
def get_variable(self, *, cmake: T.Optional[str] = None, pkgconfig: T.Optional[str] = None,
configtool: T.Optional[str] = None, internal: T.Optional[str] = None,
default_value: T.Optional[str] = None,
- pkgconfig_define: T.Optional[T.List[str]] = None) -> T.Union[str, T.List[str]]:
+ pkgconfig_define: T.Optional[T.List[str]] = None) -> str:
val = self.variables.get(internal, default_value)
if val is not None:
- # TODO: Try removing this assert by better typing self.variables
- if isinstance(val, str):
- return val
- if isinstance(val, list):
- for i in val:
- assert isinstance(i, str)
- return val
+ return val
raise DependencyException(f'Could not get an internal variable and no default provided for {self!r}')
def generate_link_whole_dependency(self) -> Dependency: