aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/dependencies/base.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2020-01-09 12:37:51 -0800
committerDylan Baker <dylan@pnwbakers.com>2020-01-29 09:11:24 -0800
commit081de4bfbc42262684b01ed61d4caa055600a917 (patch)
tree5fa84568a0184ed6ab054b9b9ed9626fc960404e /mesonbuild/dependencies/base.py
parentfbad73c939a3c7f7f27994a81d68f4a9082c06a0 (diff)
downloadmeson-081de4bfbc42262684b01ed61d4caa055600a917.zip
meson-081de4bfbc42262684b01ed61d4caa055600a917.tar.gz
meson-081de4bfbc42262684b01ed61d4caa055600a917.tar.bz2
dependencies: Split detect_compiler out of dependency
We need it for dependency factories as well.
Diffstat (limited to 'mesonbuild/dependencies/base.py')
-rw-r--r--mesonbuild/dependencies/base.py43
1 files changed, 24 insertions, 19 deletions
diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py
index c38786b..0a2ba9a 100644
--- a/mesonbuild/dependencies/base.py
+++ b/mesonbuild/dependencies/base.py
@@ -38,6 +38,7 @@ from ..mesonlib import Popen_safe, version_compare_many, version_compare, listif
from ..mesonlib import Version, LibType
if T.TYPE_CHECKING:
+ from ..compilers.compilers import Compiler # noqa: F401
DependencyType = T.TypeVar('DependencyType', bound='Dependency')
# These must be defined in this file to avoid cyclical references.
@@ -296,25 +297,7 @@ class ExternalDependency(Dependency, HasNativeKwarg):
raise DependencyException('Static keyword must be boolean')
# Is this dependency to be run on the build platform?
HasNativeKwarg.__init__(self, kwargs)
- self.clib_compiler = None
- # Set the compiler that will be used by this dependency
- # This is only used for configuration checks
- compilers = self.env.coredata.compilers[self.for_machine]
- # Set the compiler for this dependency if a language is specified,
- # else try to pick something that looks usable.
- if self.language:
- if self.language not in compilers:
- m = self.name.capitalize() + ' requires a {0} compiler, but ' \
- '{0} is not in the list of project languages'
- raise DependencyException(m.format(self.language.capitalize()))
- self.clib_compiler = compilers[self.language]
- else:
- # Try to find a compiler that can find C libraries for
- # running compiler.find_library()
- for lang in clib_langs:
- self.clib_compiler = compilers.get(lang, None)
- if self.clib_compiler:
- break
+ self.clib_compiler = detect_compiler(self.name, environment, self.for_machine, self.language)
def get_compiler(self):
return self.clib_compiler
@@ -2504,3 +2487,25 @@ def factory_methods(methods: T.Set[DependencyMethods]) -> 'FactoryType':
return wrapped
return inner
+
+
+def detect_compiler(name: str, env: Environment, for_machine: MachineChoice,
+ language: T.Optional[str]) -> T.Optional['Compiler']:
+ """Given a language and environment find the compiler used."""
+ compilers = env.coredata.compilers[for_machine]
+
+ # Set the compiler for this dependency if a language is specified,
+ # else try to pick something that looks usable.
+ if language:
+ if language not in compilers:
+ m = name.capitalize() + ' requires a {0} compiler, but ' \
+ '{0} is not in the list of project languages'
+ raise DependencyException(m.format(language.capitalize()))
+ return compilers[language]
+ else:
+ for lang in clib_langs:
+ try:
+ return compilers[lang]
+ except KeyError:
+ continue
+ return None