dependencies: Don't assume self.compiler is a C compiler

All dependencies were using find_library, has_header, get_define, etc on
self.compiler assuming that it's a compiler that outputs and consumes
C-like libraries. This is not true for D (and in the future, for Rust)
since although they can consume C libraries, they do not use the
C ecosystem.

For such purposes, we now have self.clib_compiler. Nothing uses
self.compiler anymore as a result, and it has been removed.
pull/3528/merge
Nirbheek Chauhan 7 years ago committed by Nirbheek Chauhan
parent ebda6ef9c8
commit d737488150
  1. 2
      mesonbuild/compilers/__init__.py
  2. 6
      mesonbuild/compilers/compilers.py
  3. 30
      mesonbuild/dependencies/base.py
  4. 12
      mesonbuild/dependencies/boost.py
  5. 6
      mesonbuild/dependencies/dev.py
  6. 4
      mesonbuild/dependencies/misc.py
  7. 2
      mesonbuild/dependencies/platform.py
  8. 12
      mesonbuild/dependencies/ui.py
  9. 2
      mesonbuild/modules/python.py

@ -27,6 +27,7 @@ __all__ = [
'all_languages',
'base_options',
'clib_langs',
'clike_langs',
'c_suffixes',
'cpp_suffixes',
@ -103,6 +104,7 @@ from .compilers import (
ICC_STANDARD,
all_languages,
base_options,
clib_langs,
clike_langs,
c_suffixes,
cpp_suffixes,

@ -48,9 +48,13 @@ lang_suffixes = {
all_languages = lang_suffixes.keys()
cpp_suffixes = lang_suffixes['cpp'] + ('h',)
c_suffixes = lang_suffixes['c'] + ('h',)
# List of languages that by default consume and output libraries following the
# C ABI; these can generally be used interchangebly
clib_langs = ('objcpp', 'cpp', 'objc', 'c', 'fortran',)
# List of languages that can be linked with C code directly by the linker
# used in build.py:process_compilers() and build.py:get_dynamic_linker()
clike_langs = ('d', 'objcpp', 'cpp', 'objc', 'c', 'fortran', )
# XXX: Add Rust to this?
clike_langs = ('d',) + clib_langs
clike_suffixes = ()
for _l in clike_langs + ('vala',):
clike_suffixes += lang_suffixes[_l]

@ -27,6 +27,7 @@ from pathlib import PurePath
from .. import mlog
from .. import mesonlib
from ..compilers import clib_langs, clike_langs
from ..mesonlib import MesonException, OrderedSet
from ..mesonlib import Popen_safe, version_compare_many, version_compare, listify
@ -219,6 +220,7 @@ class ExternalDependency(Dependency):
self.want_cross = not kwargs['native']
else:
self.want_cross = self.env.is_cross_build()
self.clib_compiler = None
# Set the compiler that will be used by this dependency
# This is only used for configuration checks
if self.want_cross:
@ -229,19 +231,20 @@ class ExternalDependency(Dependency):
# else try to pick something that looks usable.
if self.language:
if self.language not in compilers:
m = self.name.capitalize() + ' requires a {} compiler'
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.compiler = compilers[self.language]
self.clib_compiler = compilers[self.language]
else:
# Try to find a compiler that this dependency can use for compiler
# checks. It's ok if we don't find one.
for lang in ('c', 'cpp', 'objc', 'objcpp', 'fortran', 'd'):
self.compiler = compilers.get(lang, None)
if self.compiler:
# 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
def get_compiler(self):
return self.compiler
return self.clib_compiler
def get_partial_dependency(self, *, compile_args=False, link_args=False,
links=False, includes=False, sources=False):
@ -603,12 +606,11 @@ class PkgConfigDependency(ExternalDependency):
libpaths.add(lib[2:])
continue
elif lib.startswith('-l'):
if self.compiler:
args = self.compiler.find_library(lib[2:], self.env,
list(libpaths), libtype)
# If no compiler is set on the dependency, the project only
# uses a non-clike language such as Rust, C#, Python, etc. In
# this case, all we can do is limp along.
if self.clib_compiler:
args = self.clib_compiler.find_library(lib[2:], self.env,
list(libpaths), libtype)
# If the project only uses a non-clib language such as D, Rust,
# C#, Python, etc, all we can do is limp along.
else:
args = None
if args:

@ -185,7 +185,7 @@ class BoostDependency(ExternalDependency):
def detect_nix_roots(self):
return [os.path.abspath(os.path.join(x, '..'))
for x in self.compiler.get_default_include_dirs()]
for x in self.clib_compiler.get_default_include_dirs()]
def detect_win_roots(self):
res = []
@ -243,8 +243,8 @@ class BoostDependency(ExternalDependency):
# and http://stackoverflow.com/questions/37218953/isystem-on-a-system-include-directory-causes-errors
# for more details
if include_dir and include_dir not in self.compiler.get_default_include_dirs():
args.append("".join(self.compiler.get_include_args(include_dir, True)))
if include_dir and include_dir not in self.clib_compiler.get_default_include_dirs():
args.append("".join(self.clib_compiler.get_include_args(include_dir, True)))
return args
def get_requested(self, kwargs):
@ -256,7 +256,7 @@ class BoostDependency(ExternalDependency):
def detect_headers_and_version(self):
try:
version = self.compiler.get_define('BOOST_LIB_VERSION', '#include <boost/version.hpp>', self.env, self.get_compile_args(), [])
version = self.clib_compiler.get_define('BOOST_LIB_VERSION', '#include <boost/version.hpp>', self.env, self.get_compile_args(), [])
except mesonlib.EnvironmentException:
return
except TypeError:
@ -361,7 +361,7 @@ class BoostDependency(ExternalDependency):
for module in self.requested_modules:
libname = 'boost_' + module + tag
args = self.compiler.find_library(libname, self.env, self.extra_lib_dirs())
args = self.clib_compiler.find_library(libname, self.env, self.extra_lib_dirs())
if args is None:
mlog.debug("Couldn\'t find library '{}' for boost module '{}' (ABI tag = '{}')".format(libname, module, tag))
all_found = False
@ -476,7 +476,7 @@ class BoostDependency(ExternalDependency):
def get_link_args(self):
args = []
for dir in self.extra_lib_dirs():
args += self.compiler.get_linker_search_args(dir)
args += self.clib_compiler.get_linker_search_args(dir)
for lib in self.requested_modules:
args += self.lib_modules['boost_' + lib]
return args

@ -36,8 +36,8 @@ class GTestDependency(ExternalDependency):
def detect(self):
self.version = '1.something_maybe'
gtest_detect = self.compiler.find_library("gtest", self.env, [])
gtest_main_detect = self.compiler.find_library("gtest_main", self.env, [])
gtest_detect = self.clib_compiler.find_library("gtest", self.env, [])
gtest_main_detect = self.clib_compiler.find_library("gtest_main", self.env, [])
if gtest_detect and (not self.main or gtest_main_detect):
self.is_found = True
self.compile_args = []
@ -83,7 +83,7 @@ class GMockDependency(ExternalDependency):
self.version = '1.something_maybe'
# GMock may be a library or just source.
# Work with both.
gmock_detect = self.compiler.find_library("gmock", self.env, [])
gmock_detect = self.clib_compiler.find_library("gmock", self.env, [])
if gmock_detect:
self.is_found = True
self.compile_args = []

@ -258,7 +258,7 @@ class OpenMPDependency(ExternalDependency):
super().__init__('openmp', environment, language, kwargs)
self.is_found = False
try:
openmp_date = self.compiler.get_define('_OPENMP', '', self.env, [], [self])
openmp_date = self.clib_compiler.get_define('_OPENMP', '', self.env, [], [self])
except mesonlib.EnvironmentException as e:
mlog.debug('OpenMP support not available in the compiler')
mlog.debug(e)
@ -266,7 +266,7 @@ class OpenMPDependency(ExternalDependency):
if openmp_date:
self.version = self.VERSIONS[openmp_date]
if self.compiler.has_header('omp.h', '', self.env, dependencies=[self]):
if self.clib_compiler.has_header('omp.h', '', self.env, dependencies=[self]):
self.is_found = True
else:
mlog.log(mlog.yellow('WARNING:'), 'OpenMP found but omp.h missing.')

@ -29,7 +29,7 @@ class AppleFrameworks(ExternalDependency):
if not modules:
raise DependencyException("AppleFrameworks dependency requires at least one module.")
self.frameworks = modules
# FIXME: Use self.compiler to check if the frameworks are available
# FIXME: Use self.clib_compiler to check if the frameworks are available
for f in self.frameworks:
self.link_args += ['-framework', f]

@ -43,14 +43,14 @@ class GLDependency(ExternalDependency):
self.is_found = True
# FIXME: Use AppleFrameworks dependency
self.link_args = ['-framework', 'OpenGL']
# FIXME: Detect version using self.compiler
# FIXME: Detect version using self.clib_compiler
self.version = '1'
return
if mesonlib.is_windows():
self.is_found = True
# FIXME: Use self.compiler.find_library()
# FIXME: Use self.clib_compiler.find_library()
self.link_args = ['-lopengl32']
# FIXME: Detect version using self.compiler
# FIXME: Detect version using self.clib_compiler
self.version = '1'
return
@ -547,7 +547,7 @@ class VulkanDependency(ExternalDependency):
inc_path = os.path.join(self.vulkan_sdk, inc_dir)
header = os.path.join(inc_path, 'vulkan', 'vulkan.h')
lib_path = os.path.join(self.vulkan_sdk, lib_dir)
find_lib = self.compiler.find_library(lib_name, environment, lib_path)
find_lib = self.clib_compiler.find_library(lib_name, environment, lib_path)
if not find_lib:
raise DependencyException('VULKAN_SDK point to invalid directory (no lib)')
@ -567,8 +567,8 @@ class VulkanDependency(ExternalDependency):
return
else:
# simply try to guess it, usually works on linux
libs = self.compiler.find_library('vulkan', environment, [])
if libs is not None and self.compiler.has_header('vulkan/vulkan.h', '', environment):
libs = self.clib_compiler.find_library('vulkan', environment, [])
if libs is not None and self.clib_compiler.has_header('vulkan/vulkan.h', '', environment):
self.type_name = 'system'
self.is_found = True
self.version = 1 # TODO

@ -125,7 +125,7 @@ class PythonDependency(ExternalDependency):
libname += self.variables['ABIFLAGS']
libdirs = []
largs = self.compiler.find_library(libname, environment, libdirs)
largs = self.clib_compiler.find_library(libname, environment, libdirs)
self.is_found = largs is not None

Loading…
Cancel
Save