pkgconfig: Restore logging of pkg-config version

While at it, make more methods private by storing the version found on
the instance. That avoids having to call check_pkgconfig() as static
method from unittests.
pull/12227/head
Xavier Claessens 1 year ago committed by Xavier Claessens
parent 2a6245e6b3
commit 0eae4e0936
  1. 26
      mesonbuild/dependencies/pkgconfig.py
  2. 2
      unittests/linuxliketests.py

@ -92,11 +92,9 @@ class PkgConfigCLI(PkgConfigInterface):
def __init__(self, env: Environment, for_machine: MachineChoice, silent: bool) -> None:
super().__init__(env, for_machine)
# Store a copy of the pkg-config path on the object itself so it is
# stored in the pickled coredata and recovered.
self.pkgbin = self._detect_pkgbin(env, for_machine)
self._detect_pkgbin()
if self.pkgbin and not silent:
mlog.log('Found pkg-config:', mlog.green('YES'), mlog.blue(self.pkgbin.get_path()))
mlog.log('Found pkg-config:', mlog.green('YES'), mlog.bold(f'({self.pkgbin.get_path()})'), mlog.blue(self.pkgbin_version))
def found(self) -> bool:
return bool(self.pkgbin)
@ -177,18 +175,18 @@ class PkgConfigCLI(PkgConfigInterface):
# output using shlex.split rather than mesonlib.split_args
return shlex.split(cmd)
@staticmethod
def _detect_pkgbin(env: Environment, for_machine: MachineChoice) -> T.Optional[ExternalProgram]:
def _detect_pkgbin(self) -> None:
for potential_pkgbin in find_external_program(
env, for_machine, 'pkgconfig', 'Pkg-config',
env.default_pkgconfig, allow_default_for_cross=False):
version_if_ok = PkgConfigCLI.check_pkgconfig(env, potential_pkgbin)
self.env, self.for_machine, 'pkgconfig', 'Pkg-config',
self.env.default_pkgconfig, allow_default_for_cross=False):
version_if_ok = self._check_pkgconfig(potential_pkgbin)
if version_if_ok:
return potential_pkgbin
return None
self.pkgbin = potential_pkgbin
self.pkgbin_version = version_if_ok
return
self.pkgbin = None
@staticmethod
def check_pkgconfig(env: Environment, pkgbin: ExternalProgram) -> T.Optional[str]:
def _check_pkgconfig(self, pkgbin: ExternalProgram) -> T.Optional[str]:
if not pkgbin.found():
mlog.log(f'Did not find pkg-config by name {pkgbin.name!r}')
return None
@ -207,7 +205,7 @@ class PkgConfigCLI(PkgConfigInterface):
return None
except PermissionError:
msg = f'Found pkg-config {command_as_string!r} but didn\'t have permissions to run it.'
if not env.machines.build.is_windows():
if not self.env.machines.build.is_windows():
msg += '\n\nOn Unix-like systems this is often caused by scripts that are not executable.'
mlog.warning(msg)
return None

@ -174,7 +174,7 @@ class LinuxlikeTests(BasePlatformTests):
self.assertEqual(libhello_nolib.get_variable(pkgconfig='foo'), 'bar')
self.assertEqual(libhello_nolib.get_variable(pkgconfig='prefix'), self.prefix)
impl = libhello_nolib.pkgconfig
if not isinstance(impl, PkgConfigCLI) or version_compare(PkgConfigCLI.check_pkgconfig(env, impl.pkgbin),">=0.29.1"):
if not isinstance(impl, PkgConfigCLI) or version_compare(impl.pkgbin_version, ">=0.29.1"):
self.assertEqual(libhello_nolib.get_variable(pkgconfig='escaped_var'), r'hello\ world')
self.assertEqual(libhello_nolib.get_variable(pkgconfig='unescaped_var'), 'hello world')

Loading…
Cancel
Save