From dec85c41a9e5d6f8bb2c4431a78a0a9ade3651fd Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Tue, 15 Aug 2023 21:03:07 -0400 Subject: [PATCH] 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. --- mesonbuild/dependencies/base.py | 7 ----- mesonbuild/dependencies/configtool.py | 28 ++++--------------- mesonbuild/interpreter/interpreterobjects.py | 8 +++++- .../unit/114 empty project/expected_mods.json | 1 - unittests/failuretests.py | 2 +- 5 files changed, 13 insertions(+), 33 deletions(-) diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py index 6da9a6665..c4861ff12 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 bd6a9ff73..3c5235601 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 a76a0cbd9..46b4cc1e5 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 6cd65c315..7463bcb12 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 1fe29a266..2b7c73ea5 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): '''