aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/dependencies
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
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')
-rw-r--r--mesonbuild/dependencies/base.py14
-rw-r--r--mesonbuild/dependencies/cmake.py16
-rw-r--r--mesonbuild/dependencies/configtool.py2
-rw-r--r--mesonbuild/dependencies/pkgconfig.py2
4 files changed, 17 insertions, 17 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:
diff --git a/mesonbuild/dependencies/cmake.py b/mesonbuild/dependencies/cmake.py
index e9a4aa3..1ae7071 100644
--- a/mesonbuild/dependencies/cmake.py
+++ b/mesonbuild/dependencies/cmake.py
@@ -627,17 +627,23 @@ class CMakeDependency(ExternalDependency):
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 cmake and self.traceparser is not None:
try:
v = self.traceparser.vars[cmake]
except KeyError:
pass
else:
- if len(v) == 1:
- return v[0]
- elif v:
- return v
+ # CMake does NOT have a list datatype. We have no idea whether
+ # anything is a string or a string-separated-by-; Internally,
+ # we treat them as the latter and represent everything as a
+ # list, because it is convenient when we are mostly handling
+ # imported targets, which have various properties that are
+ # actually lists.
+ #
+ # As a result we need to convert them back to strings when grabbing
+ # raw variables the user requested.
+ return ';'.join(v)
if default_value is not None:
return default_value
raise DependencyException(f'Could not get cmake variable and no default provided for {self!r}')
diff --git a/mesonbuild/dependencies/configtool.py b/mesonbuild/dependencies/configtool.py
index 7dccee4..3e8f212 100644
--- a/mesonbuild/dependencies/configtool.py
+++ b/mesonbuild/dependencies/configtool.py
@@ -155,7 +155,7 @@ class ConfigToolDependency(ExternalDependency):
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 configtool:
# In the not required case '' (empty string) will be returned if the
# variable is not found. Since '' is a valid value to return we
diff --git a/mesonbuild/dependencies/pkgconfig.py b/mesonbuild/dependencies/pkgconfig.py
index 55a364c..1777f3a 100644
--- a/mesonbuild/dependencies/pkgconfig.py
+++ b/mesonbuild/dependencies/pkgconfig.py
@@ -478,7 +478,7 @@ class PkgConfigDependency(ExternalDependency):
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 pkgconfig:
try:
return self.get_pkgconfig_variable(pkgconfig, pkgconfig_define or [], default_value)