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.
pull/12227/head
Xavier Claessens 1 year ago committed by Xavier Claessens
parent 30d7f506c7
commit dec85c41a9
  1. 7
      mesonbuild/dependencies/base.py
  2. 28
      mesonbuild/dependencies/configtool.py
  3. 8
      mesonbuild/interpreter/interpreterobjects.py
  4. 1
      test cases/unit/114 empty project/expected_mods.json
  5. 2
      unittests/failuretests.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,

@ -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}')

@ -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

@ -188,7 +188,6 @@
"mesonbuild.dependencies",
"mesonbuild.dependencies.base",
"mesonbuild.dependencies.detect",
"mesonbuild.dependencies.pkgconfig",
"mesonbuild.depfile",
"mesonbuild.envconfig",
"mesonbuild.environment",

@ -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):
'''

Loading…
Cancel
Save