aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/dependencies/misc.py
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2017-06-05 03:29:40 +0530
committerNirbheek Chauhan <nirbheek@centricular.com>2017-06-09 20:21:01 +0530
commit0c83f8352d288134ede8f4b8854e455007ce02b7 (patch)
tree61044ab368b3e57540f2b43fba1418f4d2652a78 /mesonbuild/dependencies/misc.py
parent22cfd44221ada3219d9096e15dc8b00d32e0f9f6 (diff)
downloadmeson-0c83f8352d288134ede8f4b8854e455007ce02b7.zip
meson-0c83f8352d288134ede8f4b8854e455007ce02b7.tar.gz
meson-0c83f8352d288134ede8f4b8854e455007ce02b7.tar.bz2
dependencies: Add a new class ExternalDependency
This class now consolidates a lot of the logic that each external dependency was duplicating in its class definition. All external dependencies now set: * self.version * self.compile_args and self.link_args * self.is_found (if found) * self.sources * etc And the abstract ExternalDependency class defines the methods that will fetch those properties. Some classes still override that for various reasons, but those should also be migrated to properties as far as possible. Next step is to consolidate and standardize the way in which we call 'configuration binaries' such as sdl2-config, llvm-config, pkg-config, etc. Currently each class has to duplicate code involved with that even though the format is very similar. Currently only pkg-config supports multiple version requirements, and some classes don't even properly check the version requirement. That will also become easier now.
Diffstat (limited to 'mesonbuild/dependencies/misc.py')
-rw-r--r--mesonbuild/dependencies/misc.py73
1 files changed, 24 insertions, 49 deletions
diff --git a/mesonbuild/dependencies/misc.py b/mesonbuild/dependencies/misc.py
index 6a76ba6..1356ec8 100644
--- a/mesonbuild/dependencies/misc.py
+++ b/mesonbuild/dependencies/misc.py
@@ -23,25 +23,19 @@ from .. import mlog
from .. import mesonlib
from ..environment import detect_cpu_family
-from .base import Dependency, DependencyException, DependencyMethods, ExtraFrameworkDependency, PkgConfigDependency
+from .base import DependencyException, DependencyMethods
+from .base import ExternalDependency, ExtraFrameworkDependency, PkgConfigDependency
-class BoostDependency(Dependency):
+class BoostDependency(ExternalDependency):
# Some boost libraries have different names for
# their sources and libraries. This dict maps
# between the two.
name2lib = {'test': 'unit_test_framework'}
def __init__(self, environment, kwargs):
- Dependency.__init__(self, 'boost', kwargs)
- self.name = 'boost'
- self.environment = environment
+ super().__init__('boost', environment, 'cpp', kwargs)
self.libdir = ''
- self.static = kwargs.get('static', False)
- if 'native' in kwargs and environment.is_cross_build():
- self.want_cross = not kwargs['native']
- else:
- self.want_cross = environment.is_cross_build()
try:
self.boost_root = os.environ['BOOST_ROOT']
if not os.path.isabs(self.boost_root):
@@ -72,7 +66,7 @@ class BoostDependency(Dependency):
self.detect_version()
self.requested_modules = self.get_requested(kwargs)
module_str = ', '.join(self.requested_modules)
- if self.version is not None:
+ if self.is_found:
self.detect_src_modules()
self.detect_lib_modules()
self.validate_requested()
@@ -83,9 +77,6 @@ class BoostDependency(Dependency):
mlog.log('Dependency Boost (%s) found:' % module_str, mlog.green('YES'), info)
else:
mlog.log("Dependency Boost (%s) found:" % module_str, mlog.red('NO'))
- if 'cpp' not in self.environment.coredata.compilers:
- raise DependencyException('Tried to use Boost but a C++ compiler is not defined.')
- self.cpp_compiler = self.environment.coredata.compilers['cpp']
def detect_win_root(self):
globtext = 'c:\\local\\boost_*'
@@ -130,7 +121,7 @@ class BoostDependency(Dependency):
# names in order to handle cases like cross-compiling where we
# might have a different sysroot.
if not include_dir.endswith(('/usr/include', '/usr/local/include')):
- args.append("".join(self.cpp_compiler.get_include_args(include_dir, True)))
+ args.append("".join(self.compiler.get_include_args(include_dir, True)))
return args
def get_requested(self, kwargs):
@@ -147,17 +138,10 @@ class BoostDependency(Dependency):
if m not in self.src_modules:
raise DependencyException('Requested Boost module "%s" not found.' % m)
- def found(self):
- return self.version is not None
-
- def get_version(self):
- return self.version
-
def detect_version(self):
try:
ifile = open(os.path.join(self.boost_inc_subdir, 'version.hpp'))
except FileNotFoundError:
- self.version = None
return
with ifile:
for line in ifile:
@@ -165,8 +149,8 @@ class BoostDependency(Dependency):
ver = line.split()[-1]
ver = ver[1:-1]
self.version = ver.replace('_', '.')
+ self.is_found = True
return
- self.version = None
def detect_src_modules(self):
for entry in os.listdir(self.boost_inc_subdir):
@@ -180,7 +164,7 @@ class BoostDependency(Dependency):
return self.detect_lib_modules_nix()
def detect_lib_modules_win(self):
- arch = detect_cpu_family(self.environment.coredata.compilers)
+ arch = detect_cpu_family(self.env.coredata.compilers)
# Guess the libdir
if arch == 'x86':
gl = 'lib32*'
@@ -254,10 +238,10 @@ class BoostDependency(Dependency):
module = BoostDependency.name2lib.get(module, module)
libname = 'boost_' + module
# The compiler's library detector is the most reliable so use that first.
- default_detect = self.cpp_compiler.find_library(libname, self.environment, [])
+ default_detect = self.compiler.find_library(libname, self.env, [])
if default_detect is not None:
if module == 'unit_testing_framework':
- emon_args = self.cpp_compiler.find_library('boost_test_exec_monitor')
+ emon_args = self.compiler.find_library('boost_test_exec_monitor')
else:
emon_args = None
args += default_detect
@@ -286,9 +270,9 @@ class BoostDependency(Dependency):
return 'thread' in self.requested_modules
-class ThreadDependency(Dependency):
+class ThreadDependency(ExternalDependency):
def __init__(self, environment, kwargs):
- super().__init__('threads', {})
+ super().__init__('threads', environment, None, {})
self.name = 'threads'
self.is_found = True
mlog.log('Dependency', mlog.bold(self.name), 'found:', mlog.green('YES'))
@@ -300,19 +284,18 @@ class ThreadDependency(Dependency):
return 'unknown'
-class Python3Dependency(Dependency):
+class Python3Dependency(ExternalDependency):
def __init__(self, environment, kwargs):
- super().__init__('python3', kwargs)
+ super().__init__('python3', environment, None, kwargs)
self.name = 'python3'
- self.is_found = False
# We can only be sure that it is Python 3 at this point
self.version = '3'
if DependencyMethods.PKGCONFIG in self.methods:
try:
pkgdep = PkgConfigDependency('python3', environment, kwargs)
if pkgdep.found():
- self.cargs = pkgdep.cargs
- self.libs = pkgdep.libs
+ self.compile_args = pkgdep.get_compile_args()
+ self.link_args = pkgdep.get_link_args()
self.version = pkgdep.get_version()
self.is_found = True
return
@@ -324,10 +307,11 @@ class Python3Dependency(Dependency):
elif mesonlib.is_osx() and DependencyMethods.EXTRAFRAMEWORK in self.methods:
# In OSX the Python 3 framework does not have a version
# number in its name.
- fw = ExtraFrameworkDependency('python', False, None, kwargs)
+ fw = ExtraFrameworkDependency('python', False, None, self.env,
+ self.language, kwargs)
if fw.found():
- self.cargs = fw.get_compile_args()
- self.libs = fw.get_link_args()
+ self.compile_args = fw.get_compile_args()
+ self.link_args = fw.get_link_args()
self.is_found = True
if self.is_found:
mlog.log('Dependency', mlog.bold(self.name), 'found:', mlog.green('YES'))
@@ -359,23 +343,17 @@ class Python3Dependency(Dependency):
return
inc = sysconfig.get_path('include')
platinc = sysconfig.get_path('platinclude')
- self.cargs = ['-I' + inc]
+ self.compile_args = ['-I' + inc]
if inc != platinc:
- self.cargs.append('-I' + platinc)
+ self.compile_args.append('-I' + platinc)
# Nothing exposes this directly that I coulf find
basedir = sysconfig.get_config_var('base')
vernum = sysconfig.get_config_var('py_version_nodot')
- self.libs = ['-L{}/libs'.format(basedir),
- '-lpython{}'.format(vernum)]
+ self.link_args = ['-L{}/libs'.format(basedir),
+ '-lpython{}'.format(vernum)]
self.version = sysconfig.get_config_var('py_version_short')
self.is_found = True
- def get_compile_args(self):
- return self.cargs
-
- def get_link_args(self):
- return self.libs
-
def get_methods(self):
if mesonlib.is_windows():
return [DependencyMethods.PKGCONFIG, DependencyMethods.SYSCONFIG]
@@ -383,6 +361,3 @@ class Python3Dependency(Dependency):
return [DependencyMethods.PKGCONFIG, DependencyMethods.EXTRAFRAMEWORK]
else:
return [DependencyMethods.PKGCONFIG]
-
- def get_version(self):
- return self.version