diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2017-12-10 01:13:16 +0530 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek@centricular.com> | 2017-12-10 01:29:35 +0530 |
commit | 533e6669011ff0ea75e5e6bca5bf05de91bb5f46 (patch) | |
tree | 3ffb9aea44b7f913ddc83dd5929c9e9769cfa7f9 /mesonbuild | |
parent | 6f42f83867a52c1f9c61a2780dfd808a21984e41 (diff) | |
download | meson-533e6669011ff0ea75e5e6bca5bf05de91bb5f46.zip meson-533e6669011ff0ea75e5e6bca5bf05de91bb5f46.tar.gz meson-533e6669011ff0ea75e5e6bca5bf05de91bb5f46.tar.bz2 |
dependencies: Fix detection of link args on MSYS2
The sysconfig config variables are different on MSYS2 and the paths
are also different. We now also use the full path to the import or
static library instead of using -Lfoo -lpython35 etc.
Also obey the value of the 'static' keyword argument.
Diffstat (limited to 'mesonbuild')
-rw-r--r-- | mesonbuild/dependencies/misc.py | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/mesonbuild/dependencies/misc.py b/mesonbuild/dependencies/misc.py index 71962a3..f8626e7 100644 --- a/mesonbuild/dependencies/misc.py +++ b/mesonbuild/dependencies/misc.py @@ -21,6 +21,8 @@ import shlex import shutil import sysconfig +from pathlib import Path + from .. import mlog from .. import mesonlib from ..mesonlib import Popen_safe, extract_as_list @@ -603,6 +605,7 @@ class Python3Dependency(ExternalDependency): def __init__(self, environment, kwargs): super().__init__('python3', environment, None, kwargs) self.name = 'python3' + self.static = kwargs.get('static', False) # We can only be sure that it is Python 3 at this point self.version = '3' self.pkgdep = None @@ -658,6 +661,26 @@ class Python3Dependency(ExternalDependency): mlog.log('Unknown Windows Python platform {!r}'.format(pyplat)) return None + def get_windows_link_args(self): + pyplat = sysconfig.get_platform() + if pyplat.startswith('win'): + vernum = sysconfig.get_config_var('py_version_nodot') + if self.static: + libname = 'libpython{}.a'.format(vernum) + else: + libname = 'python{}.lib'.format(vernum) + lib = Path(sysconfig.get_config_var('base')) / 'libs' / libname + elif pyplat == 'mingw': + if self.static: + libname = sysconfig.get_config_var('LIBRARY') + else: + libname = sysconfig.get_config_var('LDLIBRARY') + lib = Path(sysconfig.get_config_var('LIBDIR')) / libname + if not lib.exists(): + mlog.log('Could not find Python3 library {!r}'.format(str(lib))) + return None + return [str(lib)] + def _find_libpy3_windows(self, env): ''' Find python3 libraries on Windows and also verify that the arch matches @@ -684,17 +707,19 @@ class Python3Dependency(ExternalDependency): 'found {}-bit'.format(arch, pyarch)) self.is_found = False return + # This can fail if the library is not found + largs = self.get_windows_link_args() + if largs is None: + self.is_found = False + return + self.link_args = largs + # Compile args inc = sysconfig.get_path('include') platinc = sysconfig.get_path('platinclude') self.compile_args = ['-I' + inc] if inc != 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.link_args = ['-L{}/libs'.format(basedir), - '-lpython{}'.format(vernum)] - self.version = sysconfig.get_config_var('py_version_short') + self.version = sysconfig.get_config_var('py_version') self.is_found = True def get_methods(self): |