diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py index 7c7e7a2b7..e67f4c086 100644 --- a/mesonbuild/dependencies/base.py +++ b/mesonbuild/dependencies/base.py @@ -503,7 +503,6 @@ class PkgConfigDependency(ExternalDependency): potential_pkgbin = ExternalProgram.from_cross_info(environment.cross_info, 'pkgconfig') if potential_pkgbin.found(): self.pkgbin = potential_pkgbin - PkgConfigDependency.class_pkgbin = self.pkgbin else: mlog.debug('Cross pkg-config %s not found.' % potential_pkgbin.name) # Only search for the native pkg-config the first time and diff --git a/run_unittests.py b/run_unittests.py index 8aa042538..5574b5f05 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -2751,6 +2751,32 @@ recommended as it is not supported on some platforms''') self.assertEqual(opts['debug'], True) self.assertEqual(opts['optimization'], '0') + @skipIfNoPkgconfig + @unittest.skipIf(is_windows(), 'Help needed with fixing this test on windows') + def test_native_dep_pkgconfig(self): + testdir = os.path.join(self.unit_test_dir, + '46 native dep pkgconfig var') + with tempfile.NamedTemporaryFile(mode='w', delete=False) as crossfile: + crossfile.write(textwrap.dedent( + '''[binaries] + pkgconfig = r'{0}' + + [properties] + + [host_machine] + system = 'linux' + cpu_family = 'arm' + cpu = 'armv7' + endian = 'little' + '''.format(os.path.join(testdir, 'cross_pkgconfig.py')))) + crossfile.flush() + self.meson_cross_file = crossfile.name + + os.environ['PKG_CONFIG_LIBDIR'] = os.path.join(testdir, + 'native_pkgconfig') + self.init(testdir, extra_args=['-Dstart_native=false']) + self.wipe() + self.init(testdir, extra_args=['-Dstart_native=true']) class FailureTests(BasePlatformTests): ''' diff --git a/test cases/unit/46 native dep pkgconfig var/cross_pkgconfig.py b/test cases/unit/46 native dep pkgconfig var/cross_pkgconfig.py new file mode 100755 index 000000000..f0d89ee3e --- /dev/null +++ b/test cases/unit/46 native dep pkgconfig var/cross_pkgconfig.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python3 + +import os +import sys +import subprocess + +environ = os.environ.copy() +environ['PKG_CONFIG_LIBDIR'] = os.path.join( + os.path.dirname(os.path.realpath(__file__)), 'cross_pkgconfig') + +sys.exit( + subprocess.run(['pkg-config'] + sys.argv[1:], env=environ).returncode) diff --git a/test cases/unit/46 native dep pkgconfig var/cross_pkgconfig/dep_tester.pc b/test cases/unit/46 native dep pkgconfig var/cross_pkgconfig/dep_tester.pc new file mode 100644 index 000000000..67d7afa62 --- /dev/null +++ b/test cases/unit/46 native dep pkgconfig var/cross_pkgconfig/dep_tester.pc @@ -0,0 +1,5 @@ +dep_type=cross + +Name: dependency() test +Description: dependency() test +Version: 0 diff --git a/test cases/unit/46 native dep pkgconfig var/meson.build b/test cases/unit/46 native dep pkgconfig var/meson.build new file mode 100644 index 000000000..d95dbcdbe --- /dev/null +++ b/test cases/unit/46 native dep pkgconfig var/meson.build @@ -0,0 +1,15 @@ +project('native dep pkgconfig test') + +if get_option('start_native') + dep_native = dependency('dep_tester', native: true, method: 'pkg-config') + dep_cross = dependency('dep_tester', native: false, method: 'pkg-config') +else + dep_cross = dependency('dep_tester', native: false, method: 'pkg-config') + dep_native = dependency('dep_tester', native: true, method: 'pkg-config') +endif + +dep_type = dep_native.get_pkgconfig_variable('dep_type') +assert(dep_type == 'native', 'Expected native') + +dep_type = dep_cross.get_pkgconfig_variable('dep_type') +assert(dep_type == 'cross', 'Expected cross') diff --git a/test cases/unit/46 native dep pkgconfig var/meson_options.txt b/test cases/unit/46 native dep pkgconfig var/meson_options.txt new file mode 100644 index 000000000..37006ddfd --- /dev/null +++ b/test cases/unit/46 native dep pkgconfig var/meson_options.txt @@ -0,0 +1,6 @@ +option( + 'start_native', + type : 'boolean', + value : 'false', + description : 'Start by creating a dependency() with native : true', +) diff --git a/test cases/unit/46 native dep pkgconfig var/native_pkgconfig/dep_tester.pc b/test cases/unit/46 native dep pkgconfig var/native_pkgconfig/dep_tester.pc new file mode 100644 index 000000000..affaa97b5 --- /dev/null +++ b/test cases/unit/46 native dep pkgconfig var/native_pkgconfig/dep_tester.pc @@ -0,0 +1,5 @@ +dep_type=native + +Name: dependency() test +Description: dependency() test +Version: 0