diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2020-01-08 16:30:06 -0800 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2020-01-29 09:11:24 -0800 |
commit | 5d630c663c125b1e62cb88bd01054f1253c92bbe (patch) | |
tree | 0fb3da62d48c7ac29b2b62de977d30561003053c /mesonbuild/dependencies/misc.py | |
parent | a8817a8e68c2d592b36b9cd42e20a27511051f7e (diff) | |
download | meson-5d630c663c125b1e62cb88bd01054f1253c92bbe.zip meson-5d630c663c125b1e62cb88bd01054f1253c92bbe.tar.gz meson-5d630c663c125b1e62cb88bd01054f1253c92bbe.tar.bz2 |
dependencies: Use a factory for NetCDF
This uses a custom factory because that makes more sense here, since we
need logic to decide what pkg-config files to look for
Diffstat (limited to 'mesonbuild/dependencies/misc.py')
-rw-r--r-- | mesonbuild/dependencies/misc.py | 58 |
1 files changed, 17 insertions, 41 deletions
diff --git a/mesonbuild/dependencies/misc.py b/mesonbuild/dependencies/misc.py index c979005..6a05ef1 100644 --- a/mesonbuild/dependencies/misc.py +++ b/mesonbuild/dependencies/misc.py @@ -36,51 +36,27 @@ if T.TYPE_CHECKING: from .base import DependencyType # noqa: F401 -class NetCDFDependency(ExternalDependency): +@factory_methods({DependencyMethods.PKGCONFIG, DependencyMethods.CMAKE}) +def netcdf_factory(env: 'Environment', for_machine: 'MachineChoice', + kwargs: T.Dict[str, T.Any], methods: T.List[DependencyMethods]) -> T.List['DependencyType']: + language = kwargs.get('language', 'c') + if language not in ('c', 'cpp', 'fortran'): + raise DependencyException('Language {} is not supported with NetCDF.'.format(language)) - def __init__(self, environment, kwargs): - language = kwargs.get('language', 'c') - super().__init__('netcdf', environment, kwargs, language=language) - kwargs['required'] = False - kwargs['silent'] = True - self.is_found = False - methods = listify(self.methods) - - if language not in ('c', 'cpp', 'fortran'): - raise DependencyException('Language {} is not supported with NetCDF.'.format(language)) - - if set([DependencyMethods.AUTO, DependencyMethods.PKGCONFIG]).intersection(methods): - pkgconfig_files = ['netcdf'] + candidates = [] # type: T.List['DependencyType'] - if language == 'fortran': - pkgconfig_files.append('netcdf-fortran') + if DependencyMethods.PKGCONFIG in methods: + pkgconfig_files = ['netcdf'] + if language == 'fortran': + pkgconfig_files.append('netcdf-fortran') - self.compile_args = [] - self.link_args = [] - self.pcdep = [] - for pkg in pkgconfig_files: - pkgdep = PkgConfigDependency(pkg, environment, kwargs, language=self.language) - if pkgdep.found(): - self.compile_args.extend(pkgdep.get_compile_args()) - self.link_args.extend(pkgdep.get_link_args()) - self.version = pkgdep.get_version() - self.is_found = True - self.pcdep.append(pkgdep) - if self.is_found: - return + for pkg in pkgconfig_files: + candidates.append(functools.partial(PkgConfigDependency, pkg, env, kwargs, language=language)) - if set([DependencyMethods.AUTO, DependencyMethods.CMAKE]).intersection(methods): - cmakedep = CMakeDependency('NetCDF', environment, kwargs, language=self.language) - if cmakedep.found(): - self.compile_args = cmakedep.get_compile_args() - self.link_args = cmakedep.get_link_args() - self.version = cmakedep.get_version() - self.is_found = True - return + if DependencyMethods.CMAKE in methods: + candidates.append(functools.partial(CMakeDependency, 'NetCDF', env, kwargs, language=language)) - @staticmethod - def get_methods(): - return [DependencyMethods.AUTO, DependencyMethods.PKGCONFIG, DependencyMethods.CMAKE] + return candidates class OpenMPDependency(ExternalDependency): @@ -485,7 +461,7 @@ def shaderc_factory(env: 'Environment', for_machine: 'MachineChoice', candidates.extend(c) if DependencyMethods.SYSTEM in methods: - candidates.append(functools.partial(ShadercDependency, environment, kwargs)) + candidates.append(functools.partial(ShadercDependency, env, kwargs)) return candidates |