diff options
author | Xavier Claessens <xavier.claessens@collabora.com> | 2023-06-06 12:10:35 -0400 |
---|---|---|
committer | Xavier Claessens <xclaesse@gmail.com> | 2023-08-03 16:27:52 -0400 |
commit | 183e4b8e903c6c4c057d09549e669d6292478a4e (patch) | |
tree | 02e0e2306ef78a797d992914c4badd2c34b180ed /unittests | |
parent | f077cb2ee3fba55fc0e1be327ad791c19f3c3b5e (diff) | |
download | meson-183e4b8e903c6c4c057d09549e669d6292478a4e.zip meson-183e4b8e903c6c4c057d09549e669d6292478a4e.tar.gz meson-183e4b8e903c6c4c057d09549e669d6292478a4e.tar.bz2 |
PkgConfigDependency: Move CLI handling into its own abstraction
This makes the code cleaner and will allow to have other implementations
in the future.
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/internaltests.py | 38 | ||||
-rw-r--r-- | unittests/linuxliketests.py | 7 |
2 files changed, 18 insertions, 27 deletions
diff --git a/unittests/internaltests.py b/unittests/internaltests.py index 672a5a0..86a30f8 100644 --- a/unittests/internaltests.py +++ b/unittests/internaltests.py @@ -47,7 +47,7 @@ from mesonbuild.mesonlib import ( OptionType ) from mesonbuild.interpreter.type_checking import in_set_validator, NoneType -from mesonbuild.dependencies.pkgconfig import PkgConfigDependency +from mesonbuild.dependencies.pkgconfig import PkgConfigDependency, PkgConfigInterface, PkgConfigCLI from mesonbuild.programs import ExternalProgram import mesonbuild.modules.pkgconfig @@ -640,22 +640,19 @@ class InternalTests(unittest.TestCase): create_static_lib(p1 / 'libdl.a') create_static_lib(p1 / 'librt.a') - def fake_call_pkgbin(self, args, env=None): - if '--libs' not in args: - return 0, '', '' - if args[-1] == 'foo': - return 0, f'-L{p2.as_posix()} -lfoo -L{p1.as_posix()} -lbar', '' - if args[-1] == 'bar': - return 0, f'-L{p2.as_posix()} -lbar', '' - if args[-1] == 'internal': - return 0, f'-L{p1.as_posix()} -lpthread -lm -lc -lrt -ldl', '' - - old_call = PkgConfigDependency._call_pkgbin - old_check = PkgConfigDependency.check_pkgconfig - PkgConfigDependency._call_pkgbin = fake_call_pkgbin - PkgConfigDependency.check_pkgconfig = lambda x, _: pkgbin - # Test begins - try: + class FakeInstance(PkgConfigCLI): + def _call_pkgbin(self, args, env=None): + if '--libs' not in args: + return 0, '', '' + if args[-1] == 'foo': + return 0, f'-L{p2.as_posix()} -lfoo -L{p1.as_posix()} -lbar', '' + if args[-1] == 'bar': + return 0, f'-L{p2.as_posix()} -lbar', '' + if args[-1] == 'internal': + return 0, f'-L{p1.as_posix()} -lpthread -lm -lc -lrt -ldl', '' + + with mock.patch.object(PkgConfigInterface, 'instance') as instance_method: + instance_method.return_value = FakeInstance(env, MachineChoice.HOST, silent=True) kwargs = {'required': True, 'silent': True} foo_dep = PkgConfigDependency('foo', env, kwargs) self.assertEqual(foo_dep.get_link_args(), @@ -670,13 +667,6 @@ class InternalTests(unittest.TestCase): for link_arg in link_args: for lib in ('pthread', 'm', 'c', 'dl', 'rt'): self.assertNotIn(f'lib{lib}.a', link_arg, msg=link_args) - finally: - # Test ends - PkgConfigDependency._call_pkgbin = old_call - PkgConfigDependency.check_pkgconfig = old_check - # Reset dependency class to ensure that in-process configure doesn't mess up - PkgConfigDependency.pkgbin_cache = {} - PkgConfigDependency.class_pkgbin = PerMachine(None, None) def test_version_compare(self): comparefunc = mesonbuild.mesonlib.version_compare_many diff --git a/unittests/linuxliketests.py b/unittests/linuxliketests.py index 7ebb575..bd73857 100644 --- a/unittests/linuxliketests.py +++ b/unittests/linuxliketests.py @@ -45,7 +45,7 @@ from mesonbuild.compilers.c import AppleClangCCompiler from mesonbuild.compilers.cpp import AppleClangCPPCompiler from mesonbuild.compilers.objc import AppleClangObjCCompiler from mesonbuild.compilers.objcpp import AppleClangObjCPPCompiler -from mesonbuild.dependencies.pkgconfig import PkgConfigDependency +from mesonbuild.dependencies.pkgconfig import PkgConfigDependency, PkgConfigCLI import mesonbuild.modules.pkgconfig PKG_CONFIG = os.environ.get('PKG_CONFIG', 'pkg-config') @@ -173,7 +173,8 @@ class LinuxlikeTests(BasePlatformTests): self.assertEqual(libhello_nolib.get_compile_args(), []) self.assertEqual(libhello_nolib.get_pkgconfig_variable('foo', [], None), 'bar') self.assertEqual(libhello_nolib.get_pkgconfig_variable('prefix', [], None), self.prefix) - if version_compare(PkgConfigDependency.check_pkgconfig(env, libhello_nolib.pkgbin),">=0.29.1"): + impl = libhello_nolib.pkgconfig + if not isinstance(impl, PkgConfigCLI) or version_compare(PkgConfigCLI.check_pkgconfig(env, impl.pkgbin),">=0.29.1"): 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') @@ -1168,7 +1169,7 @@ class LinuxlikeTests(BasePlatformTests): # Regression test: This used to modify the value of `pkg_config_path` # option, adding the meson-uninstalled directory to it. - PkgConfigDependency.setup_env({}, env, MachineChoice.HOST, uninstalled=True) + PkgConfigCLI.setup_env({}, env, MachineChoice.HOST, uninstalled=True) pkg_config_path = env.coredata.options[OptionKey('pkg_config_path')].value self.assertEqual(pkg_config_path, [pkg_dir]) |