aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.com>2023-08-15 21:03:07 -0400
committerXavier Claessens <xclaesse@gmail.com>2023-09-18 13:51:27 -0400
commitdec85c41a9e5d6f8bb2c4431a78a0a9ade3651fd (patch)
treea48a2884201f444833d74aec8f352924c77b644a
parent30d7f506c7ffe4af52feab1a68263a4bd8d78c8a (diff)
downloadmeson-dec85c41a9e5d6f8bb2c4431a78a0a9ade3651fd.zip
meson-dec85c41a9e5d6f8bb2c4431a78a0a9ade3651fd.tar.gz
meson-dec85c41a9e5d6f8bb2c4431a78a0a9ade3651fd.tar.bz2
Remove get_configtool_variable()
This also makes it more consistent with get_pkgconfig_variable() which always return empty value instead of failing when the variable does not exist. Linking that to self.required makes no sense and was never documented any way.
-rw-r--r--mesonbuild/dependencies/base.py7
-rw-r--r--mesonbuild/dependencies/configtool.py28
-rw-r--r--mesonbuild/interpreter/interpreterobjects.py8
-rw-r--r--test cases/unit/114 empty project/expected_mods.json1
-rw-r--r--unittests/failuretests.py2
5 files changed, 13 insertions, 33 deletions
diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py
index 6da9a66..c4861ff 100644
--- a/mesonbuild/dependencies/base.py
+++ b/mesonbuild/dependencies/base.py
@@ -193,9 +193,6 @@ class Dependency(HoldableObject):
def get_exe_args(self, compiler: 'Compiler') -> T.List[str]:
return []
- def get_configtool_variable(self, variable_name: str) -> str:
- raise DependencyException(f'{self.name!r} is not a config-tool dependency')
-
def get_partial_dependency(self, *, compile_args: bool = False,
link_args: bool = False, links: bool = False,
includes: bool = False, sources: bool = False) -> 'Dependency':
@@ -292,10 +289,6 @@ class InternalDependency(Dependency):
return True
return any(d.is_built() for d in self.ext_deps)
- def get_configtool_variable(self, variable_name: str) -> str:
- raise DependencyException('Method "get_configtool_variable()" is '
- 'invalid for an internal dependency')
-
def get_partial_dependency(self, *, compile_args: bool = False,
link_args: bool = False, links: bool = False,
includes: bool = False, sources: bool = False,
diff --git a/mesonbuild/dependencies/configtool.py b/mesonbuild/dependencies/configtool.py
index bd6a9ff..3c52356 100644
--- a/mesonbuild/dependencies/configtool.py
+++ b/mesonbuild/dependencies/configtool.py
@@ -154,17 +154,6 @@ class ConfigToolDependency(ExternalDependency):
def get_variable_args(self, variable_name: str) -> T.List[str]:
return [f'--{variable_name}']
- def get_configtool_variable(self, variable_name: str) -> str:
- p, out, _ = Popen_safe(self.config + self.get_variable_args(variable_name))
- if p.returncode != 0:
- if self.required:
- raise DependencyException(
- 'Could not get variable "{}" for dependency {}'.format(
- variable_name, self.name))
- variable = out.strip()
- mlog.debug(f'Got config-tool variable {variable_name} : {variable}')
- return variable
-
@staticmethod
def log_tried() -> str:
return 'config-tool'
@@ -174,18 +163,11 @@ class ConfigToolDependency(ExternalDependency):
default_value: T.Optional[str] = None,
pkgconfig_define: PkgConfigDefineType = 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
- # set required to True here to force and error, and use the
- # finally clause to ensure it's restored.
- restore = self.required
- self.required = True
- try:
- return self.get_configtool_variable(configtool)
- except DependencyException:
- pass
- finally:
- self.required = restore
+ p, out, _ = Popen_safe(self.config + self.get_variable_args(configtool))
+ if p.returncode == 0:
+ variable = out.strip()
+ mlog.debug(f'Got config-tool variable {configtool} : {variable}')
+ return variable
if default_value is not None:
return default_value
raise DependencyException(f'Could not get config-tool variable and no default provided for {self!r}')
diff --git a/mesonbuild/interpreter/interpreterobjects.py b/mesonbuild/interpreter/interpreterobjects.py
index a76a0cb..46b4cc1 100644
--- a/mesonbuild/interpreter/interpreterobjects.py
+++ b/mesonbuild/interpreter/interpreterobjects.py
@@ -506,7 +506,13 @@ class DependencyHolder(ObjectHolder[Dependency]):
@noKwargs
@typed_pos_args('dependency.get_config_tool_variable', str)
def configtool_method(self, args: T.Tuple[str], kwargs: TYPE_kwargs) -> str:
- return self.held_object.get_configtool_variable(args[0])
+ from ..dependencies.configtool import ConfigToolDependency
+ if not isinstance(self.held_object, ConfigToolDependency):
+ raise InvalidArguments(f'{self.held_object.get_name()!r} is not a config-tool dependency')
+ return self.held_object.get_variable(
+ configtool=args[0],
+ default_value='',
+ )
@FeatureNew('dependency.partial_dependency', '0.46.0')
@noPosargs
diff --git a/test cases/unit/114 empty project/expected_mods.json b/test cases/unit/114 empty project/expected_mods.json
index 6cd65c3..7463bcb 100644
--- a/test cases/unit/114 empty project/expected_mods.json
+++ b/test cases/unit/114 empty project/expected_mods.json
@@ -188,7 +188,6 @@
"mesonbuild.dependencies",
"mesonbuild.dependencies.base",
"mesonbuild.dependencies.detect",
- "mesonbuild.dependencies.pkgconfig",
"mesonbuild.depfile",
"mesonbuild.envconfig",
"mesonbuild.environment",
diff --git a/unittests/failuretests.py b/unittests/failuretests.py
index 1fe29a2..2b7c73e 100644
--- a/unittests/failuretests.py
+++ b/unittests/failuretests.py
@@ -247,7 +247,7 @@ class FailureTests(BasePlatformTests):
dep = declare_dependency(dependencies : zlib_dep)
dep.get_configtool_variable('foo')
'''
- self.assertMesonRaises(code, "Method.*configtool.*is invalid.*internal")
+ self.assertMesonRaises(code, ".* is not a config-tool dependency")
def test_objc_cpp_detection(self):
'''