diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py index 9664215c0..7a10d694f 100644 --- a/mesonbuild/dependencies/base.py +++ b/mesonbuild/dependencies/base.py @@ -25,6 +25,7 @@ import textwrap import platform import itertools import ctypes +import typing from typing import Any, Dict, List, Tuple from enum import Enum from pathlib import Path, PurePath @@ -73,6 +74,8 @@ class Dependency: @classmethod def _process_method_kw(cls, kwargs): method = kwargs.get('method', 'auto') + if isinstance(method, DependencyMethods): + return method if method not in [e.value for e in DependencyMethods]: raise DependencyException('method {!r} is invalid'.format(method)) method = DependencyMethods(method) @@ -176,6 +179,20 @@ class Dependency: """ raise RuntimeError('Unreachable code in partial_dependency called') + def _add_sub_dependency(self, dep_type: typing.Type['Dependency'], env: Environment, + kwargs: typing.Dict[str, typing.Any], *, + method: DependencyMethods = DependencyMethods.AUTO) -> None: + """Add an internal dependency of of the given type. + + This method is intended to simplify cases of adding a dependency on + another dependency type (such as threads). This will by default set + the method back to auto, but the 'method' keyword argument can be + used to overwrite this behavior. + """ + kwargs = kwargs.copy() + kwargs['method'] = method + self.ext_deps.append(dep_type(env, kwargs)) + class InternalDependency(Dependency): def __init__(self, version, incdirs, compile_args, link_args, libraries, whole_libraries, sources, ext_deps): diff --git a/mesonbuild/dependencies/boost.py b/mesonbuild/dependencies/boost.py index f5b95f5b3..0de137232 100644 --- a/mesonbuild/dependencies/boost.py +++ b/mesonbuild/dependencies/boost.py @@ -105,7 +105,7 @@ class BoostDependency(ExternalDependency): self.requested_modules = self.get_requested(kwargs) if 'thread' in self.requested_modules: - self.ext_deps.append(ThreadDependency(environment, kwargs)) + self._add_sub_dependency(ThreadDependency, environment, kwargs) self.boost_root = None self.boost_roots = [] diff --git a/mesonbuild/dependencies/dev.py b/mesonbuild/dependencies/dev.py index c911cfa56..5ee85bf9c 100644 --- a/mesonbuild/dependencies/dev.py +++ b/mesonbuild/dependencies/dev.py @@ -46,7 +46,7 @@ class GTestDependency(ExternalDependency): self.main = kwargs.get('main', False) self.src_dirs = ['/usr/src/gtest/src', '/usr/src/googletest/googletest/src'] self.detect() - self.ext_deps.append(ThreadDependency(environment, kwargs)) + self._add_sub_dependency(ThreadDependency, environment, kwargs) def detect(self): gtest_detect = self.clib_compiler.find_library("gtest", self.env, []) @@ -117,7 +117,7 @@ class GMockDependency(ExternalDependency): def __init__(self, environment, kwargs): super().__init__('gmock', environment, 'cpp', kwargs) self.main = kwargs.get('main', False) - self.ext_deps.append(ThreadDependency(environment, kwargs)) + self._add_sub_dependency(ThreadDependency, environment, kwargs) # If we are getting main() from GMock, we definitely # want to avoid linking in main() from GTest @@ -256,7 +256,7 @@ class LLVMDependency(ConfigToolDependency): self._set_old_link_args() self.link_args = strip_system_libdirs(environment, self.link_args) self.link_args = self.__fix_bogus_link_args(self.link_args) - self.ext_deps.append(ThreadDependency(environment, kwargs)) + self._add_sub_dependency(ThreadDependency, environment, kwargs) @staticmethod def __fix_bogus_link_args(args): diff --git a/test cases/frameworks/15 llvm/meson.build b/test cases/frameworks/15 llvm/meson.build index b43bb8713..fc750842b 100644 --- a/test cases/frameworks/15 llvm/meson.build +++ b/test cases/frameworks/15 llvm/meson.build @@ -1,6 +1,6 @@ project('llvmtest', ['c', 'cpp'], default_options : ['c_std=c99']) -d = dependency('llvm', required : false) +d = dependency('llvm', required : false, method : 'config-tool') if not d.found() d = dependency('llvm', required : false, static : true) if not d.found() diff --git a/test cases/frameworks/2 gtest/meson.build b/test cases/frameworks/2 gtest/meson.build index e5418e963..3f30215de 100644 --- a/test cases/frameworks/2 gtest/meson.build +++ b/test cases/frameworks/2 gtest/meson.build @@ -4,7 +4,7 @@ gtest = dependency('gtest', main : true, required : false) if not gtest.found() error('MESON_SKIP_TEST: gtest not installed.') endif -gtest_nomain = dependency('gtest', main : false) +gtest_nomain = dependency('gtest', main : false, method : 'system') e = executable('testprog', 'test.cc', dependencies : gtest) test('gtest test', e) diff --git a/test cases/frameworks/3 gmock/meson.build b/test cases/frameworks/3 gmock/meson.build index 516547fc7..58591aeba 100644 --- a/test cases/frameworks/3 gmock/meson.build +++ b/test cases/frameworks/3 gmock/meson.build @@ -3,7 +3,7 @@ project('gmock test', 'cpp') # Using gmock without gtest is a pain so just # don't support that then. -gtest = dependency('gtest', main : true, required : false) +gtest = dependency('gtest', main : true, required : false, method : 'system') if not gtest.found() error('MESON_SKIP_TEST: gtest not installed.') endif