dependencies: don't pass kwargs from get_pkgconfig_variable

This is a layering violation, we're relying on the way the interpreter
handles keyword arguments. Instead, pass them as free variables,
destructuring in the interpreter
pull/9850/head
Dylan Baker 3 years ago committed by Eli Schwartz
parent ab9c0c1735
commit 6b272973e0
  1. 9
      mesonbuild/dependencies/base.py
  2. 2
      mesonbuild/dependencies/boost.py
  3. 28
      mesonbuild/dependencies/pkgconfig.py
  4. 12
      mesonbuild/dependencies/qt.py
  5. 2
      mesonbuild/interpreter/interpreterobjects.py
  6. 2
      mesonbuild/modules/gnome.py
  7. 12
      unittests/linuxliketests.py

@ -27,6 +27,7 @@ from ..mesonlib import version_compare_many
from ..interpreterbase import FeatureDeprecated
if T.TYPE_CHECKING:
from .._typing import ImmutableListProtocol
from ..compilers.compilers import Compiler
from ..environment import Environment
from ..build import BuildTarget, CustomTarget
@ -162,7 +163,9 @@ class Dependency(HoldableObject):
def get_exe_args(self, compiler: 'Compiler') -> T.List[str]:
return []
def get_pkgconfig_variable(self, variable_name: str, kwargs: T.Dict[str, T.Any]) -> str:
def get_pkgconfig_variable(self, variable_name: str,
define_variable: 'ImmutableListProtocol[str]',
default: T.Optional[str]) -> str:
raise DependencyException(f'{self.name!r} is not a pkgconfig dependency')
def get_configtool_variable(self, variable_name: str) -> str:
@ -254,7 +257,9 @@ class InternalDependency(Dependency):
return True
return any(d.is_built() for d in self.ext_deps)
def get_pkgconfig_variable(self, variable_name: str, kwargs: T.Dict[str, T.Any]) -> str:
def get_pkgconfig_variable(self, variable_name: str,
define_variable: 'ImmutableListProtocol[str]',
default: T.Optional[str]) -> str:
raise DependencyException('Method "get_pkgconfig_variable()" is '
'invalid for an internal dependency')

@ -648,7 +648,7 @@ class BoostDependency(SystemDependency):
try:
boost_pc = PkgConfigDependency('boost', self.env, {'required': False})
if boost_pc.found():
boost_root = boost_pc.get_pkgconfig_variable('prefix', {'default': None})
boost_root = boost_pc.get_pkgconfig_variable('prefix', [], None)
if boost_root:
roots += [Path(boost_root)]
except DependencyException:

@ -24,6 +24,7 @@ import typing as T
if T.TYPE_CHECKING:
from ..environment import Environment
from .._typing import ImmutableListProtocol
class PkgConfigDependency(ExternalDependency):
# The class's copy of the pkg-config path. Avoids having to search for it
@ -380,18 +381,13 @@ class PkgConfigDependency(ExternalDependency):
raise DependencyException(f'Could not generate libs for {self.name}:\n\n{out_raw}')
self.link_args, self.raw_link_args = self._search_libs(out, out_raw)
def get_pkgconfig_variable(self, variable_name: str, kwargs: T.Dict[str, T.Union[str, T.List[str]]]) -> str:
def get_pkgconfig_variable(self, variable_name: str,
define_variable: 'ImmutableListProtocol[str]',
default: T.Optional[str]) -> str:
options = ['--variable=' + variable_name, self.name]
if 'define_variable' in kwargs:
definition = kwargs.get('define_variable', [])
if not isinstance(definition, list):
raise DependencyException('define_variable takes a list')
if len(definition) != 2 or not all(isinstance(i, str) for i in definition):
raise DependencyException('define_variable must be made up of 2 strings for VARIABLENAME and VARIABLEVALUE')
options = ['--define-variable=' + '='.join(definition)] + options
if define_variable:
options = ['--define-variable=' + '='.join(define_variable)] + options
ret, out, err = self._call_pkgbin(options)
variable = ''
@ -406,9 +402,8 @@ class PkgConfigDependency(ExternalDependency):
if not variable:
ret, out, _ = self._call_pkgbin(['--print-variables', self.name])
if not re.search(r'^' + variable_name + r'$', out, re.MULTILINE):
if 'default' in kwargs:
assert isinstance(kwargs['default'], str)
variable = kwargs['default']
if default:
variable = default
else:
mlog.warning(f"pkgconfig variable '{variable_name}' not defined for dependency {self.name}.")
@ -483,13 +478,8 @@ class PkgConfigDependency(ExternalDependency):
default_value: T.Optional[str] = None,
pkgconfig_define: T.Optional[T.List[str]] = None) -> T.Union[str, T.List[str]]:
if pkgconfig:
kwargs: T.Dict[str, T.Union[str, T.List[str]]] = {}
if default_value is not None:
kwargs['default'] = default_value
if pkgconfig_define is not None:
kwargs['define_variable'] = pkgconfig_define
try:
return self.get_pkgconfig_variable(pkgconfig, kwargs)
return self.get_pkgconfig_variable(pkgconfig, pkgconfig_define or [], default_value)
except DependencyException:
pass
if default_value is not None:

@ -181,7 +181,7 @@ class QtPkgConfigDependency(_QtBase, PkgConfigDependency, metaclass=abc.ABCMeta)
self.is_found = False
return
if self.private_headers:
qt_inc_dir = mod.get_pkgconfig_variable('includedir', {})
qt_inc_dir = mod.get_pkgconfig_variable('includedir', [], None)
mod_private_dir = os.path.join(qt_inc_dir, 'Qt' + m)
if not os.path.isdir(mod_private_dir):
# At least some versions of homebrew don't seem to set this
@ -203,7 +203,7 @@ class QtPkgConfigDependency(_QtBase, PkgConfigDependency, metaclass=abc.ABCMeta)
if arg == f'-l{debug_lib_name}' or arg.endswith(f'{debug_lib_name}.lib') or arg.endswith(f'{debug_lib_name}.a'):
is_debug = True
break
libdir = self.get_pkgconfig_variable('libdir', {})
libdir = self.get_pkgconfig_variable('libdir', [], None)
if not self._link_with_qtmain(is_debug, libdir):
self.is_found = False
return
@ -211,7 +211,7 @@ class QtPkgConfigDependency(_QtBase, PkgConfigDependency, metaclass=abc.ABCMeta)
self.bindir = self.get_pkgconfig_host_bins(self)
if not self.bindir:
# If exec_prefix is not defined, the pkg-config file is broken
prefix = self.get_pkgconfig_variable('exec_prefix', {})
prefix = self.get_pkgconfig_variable('exec_prefix', [], None)
if prefix:
self.bindir = os.path.join(prefix, 'bin')
@ -387,7 +387,7 @@ class Qt4PkgConfigDependency(QtPkgConfigDependency):
applications = ['moc', 'uic', 'rcc', 'lupdate', 'lrelease']
for application in applications:
try:
return os.path.dirname(core.get_pkgconfig_variable(f'{application}_location', {}))
return os.path.dirname(core.get_pkgconfig_variable(f'{application}_location', [], None))
except mesonlib.MesonException:
pass
return None
@ -400,7 +400,7 @@ class Qt5PkgConfigDependency(QtPkgConfigDependency):
@staticmethod
def get_pkgconfig_host_bins(core: PkgConfigDependency) -> str:
return core.get_pkgconfig_variable('host_bins', {})
return core.get_pkgconfig_variable('host_bins', [], None)
def get_private_includes(self, mod_inc_dir: str, module: str) -> T.List[str]:
return _qt_get_private_includes(mod_inc_dir, module, self.version)
@ -410,7 +410,7 @@ class Qt6PkgConfigDependency(QtPkgConfigDependency):
@staticmethod
def get_pkgconfig_host_bins(core: PkgConfigDependency) -> str:
return core.get_pkgconfig_variable('host_bins', {})
return core.get_pkgconfig_variable('host_bins', [], None)
def get_private_includes(self, mod_inc_dir: str, module: str) -> T.List[str]:
return _qt_get_private_includes(mod_inc_dir, module, self.version)

@ -464,7 +464,7 @@ class DependencyHolder(ObjectHolder[Dependency]):
@permittedKwargs({'define_variable', 'default'})
@typed_pos_args('dependency.get_pkgconfig_variable', str)
def pkgconfig_method(self, args: T.Tuple[str], kwargs: TYPE_kwargs) -> str:
return self.held_object.get_pkgconfig_variable(args[0], kwargs)
return self.held_object.get_pkgconfig_variable(args[0], **kwargs)
@FeatureNew('dependency.get_configtool_variable', '0.44.0')
@FeatureDeprecated('dependency.get_configtool_variable', '0.56.0',

@ -325,7 +325,7 @@ class GnomeModule(ExtensionModule):
# Check if pkgconfig has a variable
dep = self._get_dep(state, depname, native=True, required=False)
if dep.found() and dep.type_name == 'pkgconfig':
value = dep.get_pkgconfig_variable(varname, {})
value = dep.get_pkgconfig_variable(varname, [], None)
if value:
return ExternalProgram(name, [value])

@ -148,18 +148,18 @@ class LinuxlikeTests(BasePlatformTests):
self.assertTrue(foo_dep.found())
self.assertEqual(foo_dep.get_version(), '1.0')
self.assertIn('-lfoo', foo_dep.get_link_args())
self.assertEqual(foo_dep.get_pkgconfig_variable('foo', {}), 'bar')
self.assertPathEqual(foo_dep.get_pkgconfig_variable('datadir', {}), '/usr/data')
self.assertEqual(foo_dep.get_pkgconfig_variable('foo', [], None), 'bar')
self.assertPathEqual(foo_dep.get_pkgconfig_variable('datadir', [], None), '/usr/data')
libhello_nolib = PkgConfigDependency('libhello_nolib', env, kwargs)
self.assertTrue(libhello_nolib.found())
self.assertEqual(libhello_nolib.get_link_args(), [])
self.assertEqual(libhello_nolib.get_compile_args(), [])
self.assertEqual(libhello_nolib.get_pkgconfig_variable('foo', {}), 'bar')
self.assertEqual(libhello_nolib.get_pkgconfig_variable('prefix', {}), self.prefix)
self.assertEqual(libhello_nolib.get_pkgconfig_variable('foo', [], None), 'bar')
self.assertEqual(libhello_nolib.get_pkgconfig_variable('prefix', [], None), self.prefix)
if version_compare(libhello_nolib.check_pkgconfig(libhello_nolib.pkgbin),">=0.29.1"):
self.assertEqual(libhello_nolib.get_pkgconfig_variable('escaped_var', {}), r'hello\ world')
self.assertEqual(libhello_nolib.get_pkgconfig_variable('unescaped_var', {}), 'hello world')
self.assertEqual(libhello_nolib.get_pkgconfig_variable('escaped_var', [], None), r'hello\ world')
self.assertEqual(libhello_nolib.get_pkgconfig_variable('unescaped_var', [], None), 'hello world')
cc = detect_c_compiler(env, MachineChoice.HOST)
if cc.get_id() in {'gcc', 'clang'}:

Loading…
Cancel
Save