diff options
Diffstat (limited to 'mesonbuild/dependencies')
-rw-r--r-- | mesonbuild/dependencies/base.py | 102 | ||||
-rw-r--r-- | mesonbuild/dependencies/boost.py | 28 | ||||
-rw-r--r-- | mesonbuild/dependencies/dev.py | 22 | ||||
-rw-r--r-- | mesonbuild/dependencies/misc.py | 12 | ||||
-rw-r--r-- | mesonbuild/dependencies/ui.py | 13 |
5 files changed, 79 insertions, 98 deletions
diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py index 9a14232..4c0d410 100644 --- a/mesonbuild/dependencies/base.py +++ b/mesonbuild/dependencies/base.py @@ -239,10 +239,13 @@ class InternalDependency(Dependency): final_link_args, final_libraries, final_whole_libraries, final_sources, final_deps) +class HasNativeKwarg: + def __init__(self, kwargs): + self.for_machine = MachineChoice.BUILD if kwargs.get('native', False) else MachineChoice.HOST -class ExternalDependency(Dependency): +class ExternalDependency(Dependency, HasNativeKwarg): def __init__(self, type_name, environment, language, kwargs): - super().__init__(type_name, kwargs) + Dependency.__init__(self, type_name, kwargs) self.env = environment self.name = type_name # default self.is_found = False @@ -255,18 +258,12 @@ class ExternalDependency(Dependency): self.static = kwargs.get('static', False) if not isinstance(self.static, bool): raise DependencyException('Static keyword must be boolean') - # Is this dependency for cross-compilation? - if 'native' in kwargs and self.env.is_cross_build(): - self.want_cross = not kwargs['native'] - else: - self.want_cross = self.env.is_cross_build() + # 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 - if self.want_cross: - compilers = self.env.coredata.cross_compilers - else: - compilers = self.env.coredata.compilers + 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: @@ -561,18 +558,13 @@ class PkgConfigDependency(ExternalDependency): # stored in the pickled coredata and recovered. self.pkgbin = None - if not self.want_cross and environment.is_cross_build(): - for_machine = MachineChoice.BUILD - else: - for_machine = MachineChoice.HOST - # Create an iterator of options def search(): # Lookup in cross or machine file. - potential_pkgpath = environment.binaries[for_machine].lookup_entry('pkgconfig') + potential_pkgpath = environment.binaries[self.for_machine].lookup_entry('pkgconfig') if potential_pkgpath is not None: mlog.debug('Pkg-config binary for {} specified from cross file, native file, ' - 'or env var as {}'.format(for_machine, potential_pkgpath)) + 'or env var as {}'.format(self.for_machine, potential_pkgpath)) yield ExternalProgram.from_entry('pkgconfig', potential_pkgpath) # We never fallback if the user-specified option is no good, so # stop returning options. @@ -580,42 +572,42 @@ class PkgConfigDependency(ExternalDependency): mlog.debug('Pkg-config binary missing from cross or native file, or env var undefined.') # Fallback on hard-coded defaults. # TODO prefix this for the cross case instead of ignoring thing. - if environment.machines.matches_build_machine(for_machine): + if environment.machines.matches_build_machine(self.for_machine): for potential_pkgpath in environment.default_pkgconfig: mlog.debug('Trying a default pkg-config fallback at', potential_pkgpath) yield ExternalProgram(potential_pkgpath, silent=True) # Only search for pkg-config for each machine the first time and store # the result in the class definition - if PkgConfigDependency.class_pkgbin[for_machine] is False: - mlog.debug('Pkg-config binary for %s is cached as not found.' % for_machine) - elif PkgConfigDependency.class_pkgbin[for_machine] is not None: - mlog.debug('Pkg-config binary for %s is cached.' % for_machine) + if PkgConfigDependency.class_pkgbin[self.for_machine] is False: + mlog.debug('Pkg-config binary for %s is cached as not found.' % self.for_machine) + elif PkgConfigDependency.class_pkgbin[self.for_machine] is not None: + mlog.debug('Pkg-config binary for %s is cached.' % self.for_machine) else: - assert PkgConfigDependency.class_pkgbin[for_machine] is None - mlog.debug('Pkg-config binary for %s is not cached.' % for_machine) + assert PkgConfigDependency.class_pkgbin[self.for_machine] is None + mlog.debug('Pkg-config binary for %s is not cached.' % self.for_machine) for potential_pkgbin in search(): mlog.debug('Trying pkg-config binary {} for machine {} at {}' - .format(potential_pkgbin.name, for_machine, potential_pkgbin.command)) + .format(potential_pkgbin.name, self.for_machine, potential_pkgbin.command)) version_if_ok = self.check_pkgconfig(potential_pkgbin) if not version_if_ok: continue if not self.silent: mlog.log('Found pkg-config:', mlog.bold(potential_pkgbin.get_path()), '(%s)' % version_if_ok) - PkgConfigDependency.class_pkgbin[for_machine] = potential_pkgbin + PkgConfigDependency.class_pkgbin[self.for_machine] = potential_pkgbin break else: if not self.silent: mlog.log('Found Pkg-config:', mlog.red('NO')) # Set to False instead of None to signify that we've already # searched for it and not found it - PkgConfigDependency.class_pkgbin[for_machine] = False + PkgConfigDependency.class_pkgbin[self.for_machine] = False - self.pkgbin = PkgConfigDependency.class_pkgbin[for_machine] + self.pkgbin = PkgConfigDependency.class_pkgbin[self.for_machine] if self.pkgbin is False: self.pkgbin = None - msg = 'Pkg-config binary for machine %s not found. Giving up.' % for_machine + msg = 'Pkg-config binary for machine %s not found. Giving up.' % self.for_machine if self.required: raise DependencyException(msg) else: @@ -665,12 +657,7 @@ class PkgConfigDependency(ExternalDependency): else: env = env.copy() - if not self.want_cross and self.env.is_cross_build(): - for_machine = MachineChoice.BUILD - else: - for_machine = MachineChoice.HOST - - extra_paths = self.env.coredata.builtins_per_machine[for_machine]['pkg_config_path'].value + extra_paths = self.env.coredata.builtins_per_machine[self.for_machine]['pkg_config_path'].value new_pkg_config_path = ':'.join([p for p in extra_paths]) mlog.debug('PKG_CONFIG_PATH: ' + new_pkg_config_path) env['PKG_CONFIG_PATH'] = new_pkg_config_path @@ -1059,7 +1046,7 @@ class CMakeDependency(ExternalDependency): # List of successfully found modules self.found_modules = [] - self.cmakebin, self.cmakevers, for_machine = self.find_cmake_binary(environment, self.want_cross, self.silent) + self.cmakebin, self.cmakevers, for_machine = self.find_cmake_binary(environment, self.for_machine, self.silent) if self.cmakebin is False: self.cmakebin = None msg = 'No CMake binary for machine %s not found. Giving up.' % for_machine @@ -1068,9 +1055,9 @@ class CMakeDependency(ExternalDependency): mlog.debug(msg) return - if CMakeDependency.class_cmakeinfo[for_machine] is None: - CMakeDependency.class_cmakeinfo[for_machine] = self._get_cmake_info() - self.cmakeinfo = CMakeDependency.class_cmakeinfo[for_machine] + if CMakeDependency.class_cmakeinfo[self.for_machine] is None: + CMakeDependency.class_cmakeinfo[self.for_machine] = self._get_cmake_info() + self.cmakeinfo = CMakeDependency.class_cmakeinfo[self.for_machine] if self.cmakeinfo is None: raise self._gen_exception('Unable to obtain CMake system information') @@ -1082,24 +1069,16 @@ class CMakeDependency(ExternalDependency): if cm_path: cm_args.append('-DCMAKE_MODULE_PATH=' + ';'.join(cm_path)) - pref_path = self.env.coredata.builtins_per_machine[for_machine]['cmake_prefix_path'].value + pref_path = self.env.coredata.builtins_per_machine[self.for_machine]['cmake_prefix_path'].value if pref_path: cm_args.append('-DCMAKE_PREFIX_PATH={}'.format(';'.join(pref_path))) - if not self._preliminary_find_check(name, cm_path, pref_path, environment.machines[for_machine]): + if not self._preliminary_find_check(name, cm_path, pref_path, environment.machines[self.for_machine]): return self._detect_dep(name, modules, cm_args) - @staticmethod - def find_cmake_binary(environment: Environment, want_cross: bool = False, silent: bool = False) -> Tuple[str, str, MachineChoice]: - # When finding dependencies for cross-compiling, we don't care about - # the 'native' CMake binary - # TODO: Test if this works as expected - if environment.is_cross_build() and not want_cross: - for_machine = MachineChoice.BUILD - else: - for_machine = MachineChoice.HOST - + @classmethod + def find_cmake_binary(cls, environment: Environment, for_machine: MachineChoice, silent: bool = False) -> Tuple[str, str, MachineChoice]: # Create an iterator of options def search(): # Lookup in cross or machine file. @@ -1130,7 +1109,7 @@ class CMakeDependency(ExternalDependency): for potential_cmakebin in search(): mlog.debug('Trying CMake binary {} for machine {} at {}' .format(potential_cmakebin.name, for_machine, potential_cmakebin.command)) - version_if_ok = CMakeDependency.check_cmake(potential_cmakebin) + version_if_ok = cls.check_cmake(potential_cmakebin) if not version_if_ok: continue if not silent: @@ -2098,6 +2077,8 @@ class DubDependency(ExternalDependency): class ExternalProgram: windows_exts = ('exe', 'msc', 'com', 'bat', 'cmd') + # An 'ExternalProgram' always runs on the build machine + for_machine = MachineChoice.BUILD def __init__(self, name: str, command: typing.Optional[typing.List[str]] = None, silent: bool = False, search_dir: typing.Optional[str] = None): @@ -2479,7 +2460,7 @@ def get_dep_identifier(name, kwargs) -> Tuple: identifier = (name, ) for key, value in kwargs.items(): # 'version' is irrelevant for caching; the caller must check version matches - # 'native' is handled above with `want_cross` + # 'native' is handled above with `for_machine` # 'required' is irrelevant for caching; the caller handles it separately # 'fallback' subprojects cannot be cached -- they must be initialized # 'default_options' is only used in fallback case @@ -2520,12 +2501,9 @@ def find_external_dependency(name, env, kwargs): # display the dependency name with correct casing display_name = display_name_map.get(lname, lname) - # if this isn't a cross-build, it's uninteresting if native: is used or not - if not env.is_cross_build(): - type_text = 'Dependency' - else: - type_text = 'Native' if kwargs.get('native', False) else 'Cross' - type_text += ' dependency' + for_machine = MachineChoice.BUILD if kwargs.get('native', False) else MachineChoice.HOST + + type_text = PerMachine('Build-time', 'Run-time')[for_machine] + ' dependency' # build a list of dependency methods to try candidates = _build_external_dependency_list(name, env, kwargs) @@ -2648,12 +2626,12 @@ def _build_external_dependency_list(name, env: Environment, kwargs: Dict[str, An return candidates -def strip_system_libdirs(environment, link_args): +def strip_system_libdirs(environment, for_machine: MachineChoice, link_args): """Remove -L<system path> arguments. leaving these in will break builds where a user has a version of a library in the system path, and a different version not in the system path if they want to link against the non-system path version. """ - exclude = {'-L{}'.format(p) for p in environment.get_compiler_system_dirs()} + exclude = {'-L{}'.format(p) for p in environment.get_compiler_system_dirs(for_machine)} return [l for l in link_args if l not in exclude] diff --git a/mesonbuild/dependencies/boost.py b/mesonbuild/dependencies/boost.py index a955b6a..5c9e0b5 100644 --- a/mesonbuild/dependencies/boost.py +++ b/mesonbuild/dependencies/boost.py @@ -123,13 +123,13 @@ class BoostDependency(ExternalDependency): self.libdir = os.environ['BOOST_LIBRARYDIR'] if self.boost_root is None: - if mesonlib.for_windows(self.env): + if self.env.machines[self.for_machine].is_windows(): self.boost_roots = self.detect_win_roots() else: self.boost_roots = self.detect_nix_roots() if self.incdir is None: - if mesonlib.for_windows(self.env): + if self.env.machines[self.for_machine].is_windows(): self.incdir = self.detect_win_incdir() else: self.incdir = self.detect_nix_incdir() @@ -268,7 +268,7 @@ class BoostDependency(ExternalDependency): pass # 2. Fall back to the old method else: - if mesonlib.for_windows(self.env): + if self.env.machines[self.for_machine].is_windows(): self.detect_lib_modules_win() else: self.detect_lib_modules_nix() @@ -289,8 +289,8 @@ class BoostDependency(ExternalDependency): def compiler_tag(self): tag = None - compiler = self.env.detect_cpp_compiler(self.want_cross) - if mesonlib.for_windows(self.env): + compiler = self.env.detect_cpp_compiler(self.for_machine) + if self.env.machines[self.for_machine].is_windows(): if compiler.get_id() in ['msvc', 'clang-cl']: comp_ts_version = compiler.get_toolset_version() compiler_ts = comp_ts_version.split('.') @@ -304,10 +304,10 @@ class BoostDependency(ExternalDependency): if not self.is_multithreading: return '' - if mesonlib.for_darwin(self.env): + if self.env.machines[self.for_machine].is_darwin(): # - Mac: requires -mt for multithreading, so should not fall back to non-mt libraries. return '-mt' - elif mesonlib.for_windows(self.env): + elif self.env.machines[self.for_machine].is_windows(): # - Windows: requires -mt for multithreading, so should not fall back to non-mt libraries. return '-mt' else: @@ -323,12 +323,12 @@ class BoostDependency(ExternalDependency): def arch_tag(self): # currently only applies to windows msvc installed binaries - if self.env.detect_cpp_compiler(self.want_cross).get_id() not in ['msvc', 'clang-cl']: + if self.env.detect_cpp_compiler(self.for_machine).get_id() not in ['msvc', 'clang-cl']: return '' # pre-compiled binaries only added arch tag for versions > 1.64 if float(self.version) < 1.65: return '' - arch = detect_cpu_family(self.env.coredata.compilers) + arch = detect_cpu_family(self.env.coredata.compilers.host) if arch == 'x86': return '-x32' elif arch == 'x86_64': @@ -340,16 +340,16 @@ class BoostDependency(ExternalDependency): # FIXME - how to handle different distributions, e.g. for Mac? Currently we handle homebrew and macports, but not fink. def abi_tags(self): - if mesonlib.for_windows(self.env): + if self.env.machines[self.for_machine].is_windows(): return [self.versioned_abi_tag(), self.threading_tag()] else: return [self.threading_tag()] def sourceforge_dir(self): - if self.env.detect_cpp_compiler(self.want_cross).get_id() != 'msvc': + if self.env.detect_cpp_compiler(self.for_machine).get_id() != 'msvc': return None - comp_ts_version = self.env.detect_cpp_compiler(self.want_cross).get_toolset_version() - arch = detect_cpu_family(self.env.coredata.compilers) + comp_ts_version = self.env.detect_cpp_compiler(self.for_machine).get_toolset_version() + arch = detect_cpu_family(self.env.coredata.compilers.host) if arch == 'x86': return 'lib32-msvc-{}'.format(comp_ts_version) elif arch == 'x86_64': @@ -437,7 +437,7 @@ class BoostDependency(ExternalDependency): def detect_lib_modules_nix(self): if self.static: libsuffix = 'a' - elif mesonlib.for_darwin(self.env): + elif self.env.machines[self.for_machine].is_darwin(): libsuffix = 'dylib' else: libsuffix = 'so' diff --git a/mesonbuild/dependencies/dev.py b/mesonbuild/dependencies/dev.py index 19991c3..5fd547b 100644 --- a/mesonbuild/dependencies/dev.py +++ b/mesonbuild/dependencies/dev.py @@ -24,20 +24,21 @@ from .. import mesonlib, mlog from ..mesonlib import version_compare, stringlistify, extract_as_list, MachineChoice from .base import ( DependencyException, DependencyMethods, ExternalDependency, PkgConfigDependency, - strip_system_libdirs, ConfigToolDependency, CMakeDependency + strip_system_libdirs, ConfigToolDependency, CMakeDependency, HasNativeKwarg ) from .misc import ThreadDependency from typing import List, Tuple -def get_shared_library_suffix(environment, native): +def get_shared_library_suffix(environment, for_machine: MachineChoice): """This is only gauranteed to work for languages that compile to machine code, not for languages like C# that use a bytecode and always end in .dll """ - if mesonlib.for_windows(native, environment): + m = environment.machines[for_machine] + if m.is_windows(): return '.dll' - elif mesonlib.for_darwin(native, environment): + elif m.is_darwin(): return '.dylib' return '.so' @@ -203,6 +204,10 @@ class LLVMDependencyConfigTool(ConfigToolDependency): __cpp_blacklist = {'-DNDEBUG'} def __init__(self, environment, kwargs): + # Already called by `super().__init__`, but need `self.for_machine` + # before `super().__init__` is called. + HasNativeKwarg.__init__(self, kwargs) + # Ordered list of llvm-config binaries to try. Start with base, then try # newest back to oldest (3.5 is arbitrary), and finally the devel version. # Please note that llvm-config-6.0 is a development snapshot and it should @@ -227,8 +232,7 @@ class LLVMDependencyConfigTool(ConfigToolDependency): # of bits in the isa that llvm targets, for example, on x86_64 # and aarch64 the name will be llvm-config-64, on x86 and arm # it will be llvm-config-32. - m = MachineChoice.BUILD if environment.is_cross_build() and kwargs.get('native', True) else MachineChoice.HOST - if environment.machines[m].is_64_bit: + if environment.machines[self.for_machine].is_64_bit: self.tools.append('llvm-config-64') else: self.tools.append('llvm-config-32') @@ -256,7 +260,7 @@ class LLVMDependencyConfigTool(ConfigToolDependency): self._set_new_link_args(environment) else: self._set_old_link_args() - self.link_args = strip_system_libdirs(environment, self.link_args) + self.link_args = strip_system_libdirs(environment, self.for_machine, self.link_args) self.link_args = self.__fix_bogus_link_args(self.link_args) self._add_sub_dependency(ThreadDependency, environment, kwargs) @@ -271,7 +275,7 @@ class LLVMDependencyConfigTool(ConfigToolDependency): "-L IBPATH:...", if we're using an msvc like compilers convert that to "/LIBPATH", otherwise to "-L ..." """ - cpp = self.env.coredata.compilers['cpp'] + cpp = self.env.coredata.compilers[self.for_machine]['cpp'] new_args = [] for arg in args: @@ -316,7 +320,7 @@ class LLVMDependencyConfigTool(ConfigToolDependency): try: self.__check_libfiles(True) except DependencyException: - lib_ext = get_shared_library_suffix(environment, self.native) + lib_ext = get_shared_library_suffix(environment, self.for_machine) libdir = self.get_config_value(['--libdir'], 'link_args')[0] # Sort for reproducability matches = sorted(glob.iglob(os.path.join(libdir, 'libLLVM*{}'.format(lib_ext)))) diff --git a/mesonbuild/dependencies/misc.py b/mesonbuild/dependencies/misc.py index 72ba7b3..a537716 100644 --- a/mesonbuild/dependencies/misc.py +++ b/mesonbuild/dependencies/misc.py @@ -213,7 +213,7 @@ class MPIDependency(ExternalDependency): if not self.is_found and mesonlib.is_windows(): # only Intel Fortran compiler is compatible with Microsoft MPI at this time. - if language == 'fortran' and environment.detect_fortran_compiler(False).name_string() != 'intel': + if language == 'fortran' and environment.detect_fortran_compiler(self.for_machine).name_string() != 'intel': return result = self._try_msmpi() if result is not None: @@ -228,7 +228,7 @@ class MPIDependency(ExternalDependency): result = [] multi_args = ('-I', ) if self.language == 'fortran': - fc = self.env.coredata.compilers['fortran'] + fc = self.env.coredata.compilers[self.for_machine]['fortran'] multi_args += fc.get_module_incdir_args() include_next = False @@ -325,7 +325,7 @@ class MPIDependency(ExternalDependency): if 'MSMPI_INC' not in os.environ: return incdir = os.environ['MSMPI_INC'] - arch = detect_cpu_family(self.env.coredata.compilers) + arch = detect_cpu_family(self.env.coredata.compilers.host) if arch == 'x86': if 'MSMPI_LIB32' not in os.environ: return @@ -396,7 +396,7 @@ class Python3Dependency(ExternalDependency): def __init__(self, environment, kwargs): super().__init__('python3', environment, None, kwargs) - if self.want_cross: + if not environment.machines.matches_build_machine(self.for_machine): return self.name = 'python3' @@ -480,7 +480,7 @@ class Python3Dependency(ExternalDependency): if pyarch is None: self.is_found = False return - arch = detect_cpu_family(env.coredata.compilers) + arch = detect_cpu_family(env.coredata.compilers.host) if arch == 'x86': arch = '32' elif arch == 'x86_64': @@ -560,7 +560,7 @@ class PcapDependency(ExternalDependency): def get_pcap_lib_version(ctdep): # Since we seem to need to run a program to discover the pcap version, # we can't do that when cross-compiling - if ctdep.want_cross: + if not ctdep.env.machines.matches_build_machine(ctdep.for_machine): return None v = ctdep.clib_compiler.get_return_value('pcap_lib_version', 'string', diff --git a/mesonbuild/dependencies/ui.py b/mesonbuild/dependencies/ui.py index b1fa632..f96668b 100644 --- a/mesonbuild/dependencies/ui.py +++ b/mesonbuild/dependencies/ui.py @@ -23,8 +23,7 @@ from collections import OrderedDict from .. import mlog from .. import mesonlib from ..mesonlib import ( - MesonException, Popen_safe, extract_as_list, for_windows, - version_compare_many + MesonException, Popen_safe, extract_as_list, version_compare_many ) from ..environment import detect_cpu @@ -38,13 +37,13 @@ class GLDependency(ExternalDependency): def __init__(self, environment, kwargs): super().__init__('gl', environment, None, kwargs) - if mesonlib.for_darwin(self.want_cross, self.env): + if self.env.machines[self.for_machine].is_darwin(): self.is_found = True # FIXME: Use AppleFrameworks dependency self.link_args = ['-framework', 'OpenGL'] # FIXME: Detect version using self.clib_compiler return - if mesonlib.for_windows(self.want_cross, self.env): + if self.env.machines[self.for_machine].is_windows(): self.is_found = True # FIXME: Use self.clib_compiler.find_library() self.link_args = ['-lopengl32'] @@ -310,7 +309,7 @@ class QtBaseDependency(ExternalDependency): language=self.language) modules['Core'] = core - if for_windows(self.env.is_cross_build(), self.env) and self.qtmain: + if self.env.machines[self.for_machine].is_windows() and self.qtmain: # Check if we link with debug binaries debug_lib_name = self.qtpkgname + 'Core' + self._get_modules_lib_suffix(True) is_debug = False @@ -414,7 +413,7 @@ class QtBaseDependency(ExternalDependency): break self.link_args.append(libfile) - if for_windows(self.env.is_cross_build(), self.env) and self.qtmain: + if self.env.machines[self.for_machine].is_windows() and self.qtmain: if not self._link_with_qtmain(is_debug, libdir): self.is_found = False @@ -422,7 +421,7 @@ class QtBaseDependency(ExternalDependency): def _get_modules_lib_suffix(self, is_debug): suffix = '' - if for_windows(self.env.is_cross_build(), self.env): + if self.env.machines[self.for_machine].is_windows(): if is_debug: suffix += 'd' if self.qtver == '4': |