From b842b0b04aa8678f98cbec5f7022e75636ddf4a3 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Fri, 5 Apr 2019 16:19:30 -0700 Subject: [PATCH 1/3] dependencies: Add ext_deps to all dependencies I'll be using this later, but it seems useful to allow dependencies to that have special handlers to declare that they depend on other dependencies. This should allow us to stop treating threads special internally and just make it a normal dependency. --- mesonbuild/build.py | 1 + mesonbuild/dependencies/base.py | 1 + 2 files changed, 2 insertions(+) diff --git a/mesonbuild/build.py b/mesonbuild/build.py index bcd1754e6..020c47b58 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -1035,6 +1035,7 @@ This will become a hard error in a future Meson release.''') if dep not in self.external_deps: self.external_deps.append(dep) self.process_sourcelist(dep.get_sources()) + self.add_deps(dep.ext_deps) elif isinstance(dep, BuildTarget): raise InvalidArguments('''Tried to use a build target as a dependency. You probably should put it in link_with instead.''') diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py index af4b13fad..032fe60a6 100644 --- a/mesonbuild/dependencies/base.py +++ b/mesonbuild/dependencies/base.py @@ -115,6 +115,7 @@ class Dependency: self.raw_link_args = None self.sources = [] self.methods = self._process_method_kw(kwargs) + self.ext_deps = [] # type: List[Dependency] def __repr__(self): s = '<{0} {1}: {2}>' From 6ad7fbf9509dd68792df7df08b785967a067d4c4 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Fri, 5 Apr 2019 16:41:08 -0700 Subject: [PATCH 2/3] dependencies/misc: don't special case threads Instad of having special casing of threads in the backends and everywehre else, do what we did for openmp, create a real dependency. Then make use of the fact that dependencies can now have sub dependencies to add threads. --- mesonbuild/backend/backends.py | 2 -- mesonbuild/backend/ninjabackend.py | 5 ----- mesonbuild/compilers/c.py | 4 ---- mesonbuild/dependencies/base.py | 3 --- mesonbuild/dependencies/boost.py | 6 +++--- mesonbuild/dependencies/dev.py | 13 ++++--------- mesonbuild/dependencies/misc.py | 5 ++--- 7 files changed, 9 insertions(+), 29 deletions(-) diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index d752ac4d9..124d40f5d 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -643,8 +643,6 @@ class Backend: commands += dep.get_exe_args(compiler) # For 'automagic' deps: Boost and GTest. Also dependency('threads'). # pkg-config puts the thread flags itself via `Cflags:` - if dep.need_threads(): - commands += compiler.thread_flags(self.environment) # Fortran requires extra include directives. if compiler.language == 'fortran': for lt in target.link_targets: diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 64ea5a65c..a3b9ce8b2 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -2511,7 +2511,6 @@ rule FORTRAN_DEP_HACK%s if not isinstance(target, build.StaticLibrary): # For 'automagic' deps: Boost and GTest. Also dependency('threads'). # pkg-config puts the thread flags itself via `Cflags:` - need_threads = False commands += target.link_args # External deps must be last because target link libraries may depend on them. @@ -2519,14 +2518,10 @@ rule FORTRAN_DEP_HACK%s # Extend without reordering or de-dup to preserve `-L -l` sets # https://github.com/mesonbuild/meson/issues/1718 commands.extend_preserving_lflags(dep.get_link_args()) - need_threads |= dep.need_threads() for d in target.get_dependencies(): if isinstance(d, build.StaticLibrary): for dep in d.get_external_deps(): - need_threads |= dep.need_threads() commands.extend_preserving_lflags(dep.get_link_args()) - if need_threads: - commands += linker.thread_link_flags(self.environment) # Add link args specific to this BuildTarget type that must not be overridden by dependencies commands += self.get_target_type_link_args_post_dependencies(target, linker) diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py index bcf8243b9..0a6e3b3a6 100644 --- a/mesonbuild/compilers/c.py +++ b/mesonbuild/compilers/c.py @@ -433,13 +433,9 @@ class CCompiler(Compiler): for d in dependencies: # Add compile flags needed by dependencies args += d.get_compile_args() - if d.need_threads(): - args += self.thread_flags(env) if mode == 'link': # Add link flags needed to find dependencies args += d.get_link_args() - if d.need_threads(): - args += self.thread_link_flags(env) args += self._get_basic_compiler_args(env, mode) diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py index 032fe60a6..aae257282 100644 --- a/mesonbuild/dependencies/base.py +++ b/mesonbuild/dependencies/base.py @@ -153,9 +153,6 @@ class Dependency: def get_exe_args(self, compiler): return [] - def need_threads(self): - return False - def get_pkgconfig_variable(self, variable_name, kwargs): raise DependencyException('{!r} is not a pkgconfig dependency'.format(self.name)) diff --git a/mesonbuild/dependencies/boost.py b/mesonbuild/dependencies/boost.py index 6a8050ddb..62a652a70 100644 --- a/mesonbuild/dependencies/boost.py +++ b/mesonbuild/dependencies/boost.py @@ -22,6 +22,7 @@ from .. import mesonlib from ..environment import detect_cpu_family from .base import (DependencyException, ExternalDependency) +from .misc import ThreadDependency # On windows 3 directory layouts are supported: # * The default layout (versioned) installed: @@ -103,6 +104,8 @@ class BoostDependency(ExternalDependency): self.is_multithreading = threading == "multi" self.requested_modules = self.get_requested(kwargs) + if 'thread' in self.requested_modules: + self.ext_deps.append(ThreadDependency(environment, kwargs)) self.boost_root = None self.boost_roots = [] @@ -488,9 +491,6 @@ class BoostDependency(ExternalDependency): def get_sources(self): return [] - def need_threads(self): - return 'thread' in self.requested_modules - # Generated with boost_names.py BOOST_LIBS = [ diff --git a/mesonbuild/dependencies/dev.py b/mesonbuild/dependencies/dev.py index 57a6a965e..fb7b01723 100644 --- a/mesonbuild/dependencies/dev.py +++ b/mesonbuild/dependencies/dev.py @@ -26,6 +26,7 @@ from .base import ( DependencyException, DependencyMethods, ExternalDependency, PkgConfigDependency, strip_system_libdirs, ConfigToolDependency, ) +from .misc import ThreadDependency def get_shared_library_suffix(environment, native): @@ -45,6 +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)) def detect(self): gtest_detect = self.clib_compiler.find_library("gtest", self.env, []) @@ -83,9 +85,6 @@ class GTestDependency(ExternalDependency): return True return False - def need_threads(self): - return True - def log_info(self): if self.prebuilt: return 'prebuilt' @@ -118,6 +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)) # If we are getting main() from GMock, we definitely # want to avoid linking in main() from GTest @@ -167,9 +167,6 @@ class GMockDependency(ExternalDependency): self.is_found = False - def need_threads(self): - return True - def log_info(self): if self.prebuilt: return 'prebuilt' @@ -262,6 +259,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)) @staticmethod def __fix_bogus_link_args(args): @@ -399,9 +397,6 @@ class LLVMDependency(ConfigToolDependency): self.module_details.append(mod + status) - def need_threads(self): - return True - def log_details(self): if self.module_details: return 'modules: ' + ', '.join(self.module_details) diff --git a/mesonbuild/dependencies/misc.py b/mesonbuild/dependencies/misc.py index 76eccfbf4..5721cc3b0 100644 --- a/mesonbuild/dependencies/misc.py +++ b/mesonbuild/dependencies/misc.py @@ -385,9 +385,8 @@ class ThreadDependency(ExternalDependency): super().__init__('threads', environment, None, kwargs) self.name = 'threads' self.is_found = True - - def need_threads(self): - return True + self.compile_args = self.clib_compiler.thread_flags(environment) + self.link_args = self.clib_compiler.thread_link_flags(environment) class Python3Dependency(ExternalDependency): From 63090605a5c7f905491dccb663be8bca7d935489 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Fri, 5 Apr 2019 16:42:44 -0700 Subject: [PATCH 3/3] dependencies/dev: Use ext_deps for GTest in GMock Rather than assigning the gtest variables to gmock, just set gtest as a sub dependency. --- mesonbuild/dependencies/dev.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/mesonbuild/dependencies/dev.py b/mesonbuild/dependencies/dev.py index fb7b01723..c911cfa56 100644 --- a/mesonbuild/dependencies/dev.py +++ b/mesonbuild/dependencies/dev.py @@ -132,10 +132,7 @@ class GMockDependency(ExternalDependency): if not gtest_dep.is_found: self.is_found = False return - - self.compile_args = gtest_dep.compile_args - self.link_args = gtest_dep.link_args - self.sources = gtest_dep.sources + self.ext_deps.append(gtest_dep) # GMock may be a library or just source. # Work with both.