diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2020-01-08 14:05:03 -0800 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2020-01-29 09:11:24 -0800 |
commit | bc2bfcacbd625905530a3b700a25298e985562a4 (patch) | |
tree | 35d8d5c794ac15da69e14faffa5ec1c0f65b505a | |
parent | 626f73416fe09427130d358c2ff499c07b52018f (diff) | |
download | meson-bc2bfcacbd625905530a3b700a25298e985562a4.zip meson-bc2bfcacbd625905530a3b700a25298e985562a4.tar.gz meson-bc2bfcacbd625905530a3b700a25298e985562a4.tar.bz2 |
dependencies: Use DependencyFactory for gmock
-rw-r--r-- | mesonbuild/dependencies/__init__.py | 4 | ||||
-rw-r--r-- | mesonbuild/dependencies/dev.py | 43 |
2 files changed, 25 insertions, 22 deletions
diff --git a/mesonbuild/dependencies/__init__.py b/mesonbuild/dependencies/__init__.py index 18f1915..e7342af 100644 --- a/mesonbuild/dependencies/__init__.py +++ b/mesonbuild/dependencies/__init__.py @@ -20,7 +20,7 @@ from .base import ( # noqa: F401 ExternalDependency, NotFoundDependency, ExternalLibrary, ExtraFrameworkDependency, InternalDependency, PkgConfigDependency, CMakeDependency, find_external_dependency, get_dep_identifier, packages, _packages_accept_language, DependencyFactory) -from .dev import GMockDependency, ValgrindDependency, gtest_factory, llvm_factory +from .dev import ValgrindDependency, gmock_factory, gtest_factory, llvm_factory from .coarrays import CoarrayDependency from .mpi import MPIDependency from .scalapack import ScalapackDependency @@ -33,7 +33,7 @@ from .ui import GLDependency, GnuStepDependency, Qt4Dependency, Qt5Dependency, S packages.update({ # From dev: 'gtest': gtest_factory, - 'gmock': GMockDependency, + 'gmock': gmock_factory, 'llvm': llvm_factory, 'valgrind': ValgrindDependency, diff --git a/mesonbuild/dependencies/dev.py b/mesonbuild/dependencies/dev.py index e8d462f..649975a 100644 --- a/mesonbuild/dependencies/dev.py +++ b/mesonbuild/dependencies/dev.py @@ -15,7 +15,6 @@ # This file contains the detection logic for external dependencies useful for # development purposes, such as testing, debugging, etc.. -import functools import glob import os import re @@ -26,11 +25,13 @@ from ..mesonlib import version_compare, stringlistify, extract_as_list, MachineC from ..environment import get_llvm_tool_names from .base import ( DependencyException, DependencyMethods, ExternalDependency, PkgConfigDependency, - strip_system_libdirs, ConfigToolDependency, CMakeDependency, process_method_kw, - DependencyFactory, + strip_system_libdirs, ConfigToolDependency, CMakeDependency, DependencyFactory, ) from .misc import ThreadDependency +if T.TYPE_CHECKING: + from .. environment import Environment + def get_shared_library_suffix(environment, for_machine: MachineChoice): """This is only guaranteed to work for languages that compile to machine @@ -112,9 +113,9 @@ class GTestDependencyPC(PkgConfigDependency): super().__init__(name, environment, kwargs) -class GMockDependency(ExternalDependency): - def __init__(self, environment, kwargs): - super().__init__('gmock', environment, kwargs, language='cpp') +class GMockDependencySystem(ExternalDependency): + def __init__(self, name: str, environment, kwargs): + super().__init__(name, environment, kwargs, language='cpp') self.main = kwargs.get('main', False) self._add_sub_dependency(ThreadDependency, environment, kwargs) @@ -171,25 +172,20 @@ class GMockDependency(ExternalDependency): def log_tried(self): return 'system' - @classmethod - def _factory(cls, environment, kwargs): - methods = process_method_kw(cls.get_methods(), kwargs) - candidates = [] - - if DependencyMethods.PKGCONFIG in methods: - pcname = 'gmock_main' if kwargs.get('main', False) else 'gmock' - candidates.append(functools.partial(PkgConfigDependency, pcname, environment, kwargs)) - - if DependencyMethods.SYSTEM in methods: - candidates.append(functools.partial(GMockDependency, environment, kwargs)) - - return candidates - @staticmethod def get_methods(): return [DependencyMethods.PKGCONFIG, DependencyMethods.SYSTEM] +class GMockDependencyPC(PkgConfigDependency): + + def __init__(self, name: str, environment: 'Environment', kwargs: T.Dict[str, T.Any]): + assert name == 'gmock' + if kwargs.get('main'): + name = 'gmock_main' + super().__init__(name, environment, kwargs) + + class LLVMDependencyConfigTool(ConfigToolDependency): """ LLVM uses a special tool, llvm-config, which has arguments for getting @@ -453,3 +449,10 @@ gtest_factory = DependencyFactory( pkgconfig_class=GTestDependencyPC, system_class=GTestDependencySystem, ) + +gmock_factory = DependencyFactory( + 'gmock', + [DependencyMethods.PKGCONFIG, DependencyMethods.SYSTEM], + pkgconfig_class=GMockDependencyPC, + system_class=GMockDependencySystem, +) |