From c8d125653d0535624741c591397a2b9b4ae3bb43 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Thu, 28 Oct 2021 15:04:32 -0400 Subject: [PATCH] python.dependency(): Do not stop when first candidate is not found It has to lookup the dependency with required=False otherwise it raises an exception when the first candidate (pkg-config) failed. --- mesonbuild/modules/python.py | 7 ++++--- test cases/unit/101 python without pkgconfig/meson.build | 4 ++++ unittests/platformagnostictests.py | 4 ++++ 3 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 test cases/unit/101 python without pkgconfig/meson.build diff --git a/mesonbuild/modules/python.py b/mesonbuild/modules/python.py index f183177fe..18fe92613 100644 --- a/mesonbuild/modules/python.py +++ b/mesonbuild/modules/python.py @@ -500,11 +500,12 @@ class PythonInstallation(ExternalProgramHolder): if disabled: mlog.log('Dependency', mlog.bold('python'), 'skipped: feature', mlog.bold(feature), 'disabled') else: + new_kwargs = kwargs.copy() + new_kwargs['required'] = False + methods = process_method_kw({DependencyMethods.PKGCONFIG, DependencyMethods.SYSTEM}, kwargs) for d in python_factory(self.interpreter.environment, MachineChoice.BUILD if kwargs.get('native', False) else MachineChoice.HOST, - kwargs, - process_method_kw({DependencyMethods.PKGCONFIG, DependencyMethods.SYSTEM}, kwargs), - self): + new_kwargs, methods, self): dep = d() if dep.found(): break diff --git a/test cases/unit/101 python without pkgconfig/meson.build b/test cases/unit/101 python without pkgconfig/meson.build new file mode 100644 index 000000000..b3a0c42fb --- /dev/null +++ b/test cases/unit/101 python without pkgconfig/meson.build @@ -0,0 +1,4 @@ +project('python wihtout pkgconfig', 'c') + +# This unit test is ran with PKG_CONFIG=notfound +import('python').find_installation().dependency() diff --git a/unittests/platformagnostictests.py b/unittests/platformagnostictests.py index 1c52f63d7..25f3b1a2f 100644 --- a/unittests/platformagnostictests.py +++ b/unittests/platformagnostictests.py @@ -66,3 +66,7 @@ class PlatformAgnosticTests(BasePlatformTests): # platlib is allowed, only python.platlib is reserved. fname = write_file("option('platlib', type: 'string')") interp.process(fname) + + def test_python_dependency_without_pkgconfig(self): + testdir = os.path.join(self.unit_test_dir, '101 python without pkgconfig') + self.init(testdir, override_envvars={'PKG_CONFIG': 'notfound'})