Mike Frysinger | ce0b8c0 | 2019-07-11 00:40:18 -0400 | [diff] [blame^] | 1 | Extensions should be installed to the targets libdir. This is important if e.g. host |
| 2 | has a 64bit /usr/lib64, but the target is 32bit and has $ROOT/usr/lib. Make sure we |
| 3 | respect the target's lib structure by getting the libdir name from Makefile. |
| 4 | |
| 5 | --- a/Lib/distutils/command/install.py |
| 6 | +++ b/Lib/distutils/command/install.py |
| 7 | @@ -38,8 +38,8 @@ |
| 8 | |
| 9 | INSTALL_SCHEMES = { |
| 10 | 'unix_prefix': { |
| 11 | - 'purelib': '$base/@@GENTOO_LIBDIR@@/python$py_version_short/site-packages', |
| 12 | - 'platlib': '$platbase/@@GENTOO_LIBDIR@@/python$py_version_short/site-packages', |
| 13 | + 'purelib': '$base/$libdirname/python$py_version_short/site-packages', |
| 14 | + 'platlib': '$platbase/$libdirname/python$py_version_short/site-packages', |
| 15 | 'headers': '$base/include/python$py_version_short$abiflags/$dist_name', |
| 16 | 'scripts': '$base/bin', |
| 17 | 'data' : '$base', |
| 18 | @@ -289,6 +289,8 @@ |
| 19 | # everything else. |
| 20 | self.config_vars['base'] = self.install_base |
| 21 | self.config_vars['platbase'] = self.install_platbase |
| 22 | + if not self.user and self.home is None: |
| 23 | + self.config_vars['libdirname'] = self.install_libdirname |
| 24 | |
| 25 | if DEBUG: |
| 26 | from pprint import pprint |
| 27 | @@ -394,6 +396,10 @@ |
| 28 | |
| 29 | self.install_base = self.prefix |
| 30 | self.install_platbase = self.exec_prefix |
| 31 | + self.install_libdirname = os.path.basename(get_config_vars('LIBDIR')[0]) |
| 32 | + if self.install_libdirname is None: |
| 33 | + self.install_libdirname = '@@GENTOO_LIBDIR@@' |
| 34 | + |
| 35 | self.select_scheme("unix_prefix") |
| 36 | |
| 37 | def finalize_other(self): |
| 38 | --- a/Lib/distutils/command/build_ext.py |
| 39 | +++ b/Lib/distutils/command/build_ext.py |
| 40 | @@ -201,7 +201,8 @@ |
| 41 | if (sysconfig.get_config_var('Py_ENABLE_SHARED')): |
| 42 | if not sysconfig.python_build: |
| 43 | # building third party extensions |
| 44 | - self.library_dirs.append(sysconfig.get_config_var('LIBDIR')) |
| 45 | + sysroot = os.getenv('SYSROOT', '') |
| 46 | + self.library_dirs.append(sysroot + sysconfig.get_config_var('LIBDIR')) |
| 47 | else: |
| 48 | # building python standard extensions |
| 49 | self.library_dirs.append('.') |
| 50 | --- a/Lib/distutils/sysconfig.py |
| 51 | +++ b/Lib/distutils/sysconfig.py |
| 52 | @@ -12,6 +12,8 @@ |
| 53 | """ |
| 54 | |
| 55 | import _imp |
| 56 | +import glob |
| 57 | +import imp |
| 58 | import os |
| 59 | import re |
| 60 | import sys |
| 61 | @@ -19,11 +20,20 @@ |
| 62 | from .errors import DistutilsPlatformError |
| 63 | |
| 64 | # These are needed in a couple of spots, so just compute them once. |
| 65 | +SYSROOT = os.getenv('SYSROOT', '') |
| 66 | PREFIX = os.path.normpath(sys.prefix) |
| 67 | EXEC_PREFIX = os.path.normpath(sys.exec_prefix) |
| 68 | BASE_PREFIX = os.path.normpath(sys.base_prefix) |
| 69 | BASE_EXEC_PREFIX = os.path.normpath(sys.base_exec_prefix) |
| 70 | |
| 71 | +# Make sure we respect the user specified SYSROOT environment variable. |
| 72 | +# This is the first step to get distutils to crosscompile stuff. |
| 73 | +if SYSROOT: |
| 74 | + PREFIX = os.path.normpath(SYSROOT + os.path.sep + PREFIX) |
| 75 | + EXEC_PREFIX = os.path.normpath(SYSROOT + os.path.sep + EXEC_PREFIX) |
| 76 | + BASE_PREFIX = os.path.normpath(SYSROOT + os.path.sep + BASE_PREFIX) |
| 77 | + BASE_EXEC_PREFIX = os.path.normpath(SYSROOT + os.path.sep + BASE_EXEC_PREFIX) |
| 78 | + |
| 79 | # Path to the base directory of the project. On Windows the binary may |
| 80 | # live in project/PCBuild/win32 or project/PCBuild/amd64. |
| 81 | # set for cross builds |
| 82 | @@ -114,6 +122,12 @@ def get_python_lib( |
| 83 | |
| 84 | If 'prefix' is supplied, use it instead of sys.base_prefix or |
| 85 | sys.base_exec_prefix -- i.e., ignore 'plat_specific'. |
| 86 | + |
| 87 | + For the posix system we can not always assume the host's notion of the |
| 88 | + libdir is the same for the target. e.g. compiling on an x86_64 system |
| 89 | + will use 'lib64' but an arm 32bit target will use 'lib'. So encode all |
| 90 | + the known lists of dirs and search them all (starting with the host one |
| 91 | + so that native builds work just fine). |
| 92 | """ |
| 93 | if prefix is None: |
| 94 | if standard_lib: |
| 95 | @@ -130,8 +144,19 @@ def get_python_lib( |
| 96 | prefix = plat_specific and EXEC_PREFIX or PREFIX |
| 97 | |
| 98 | if os.name == "posix": |
| 99 | - libpython = os.path.join(prefix, |
| 100 | - "@@GENTOO_LIBDIR@@", "python" + get_python_version()) |
| 101 | + # Search known Gentoo vars first. |
| 102 | + libpython = None |
| 103 | + if SYSROOT: |
| 104 | + abi = os.environ.get('ABI') |
| 105 | + libdir = os.environ.get('LIBDIR_%s' % abi) |
| 106 | + if libdir: |
| 107 | + libpython = os.path.join(prefix, libdir, "python" + get_python_version()) |
| 108 | + if not libpython: |
| 109 | + # Fallback to hardcoded search. |
| 110 | + for libdir in ['@@GENTOO_LIBDIR@@', 'lib64', 'lib32', 'libx32', 'lib']: |
| 111 | + libpython = os.path.join(prefix, libdir, "python" + get_python_version()) |
| 112 | + if os.path.exists(libpython): |
| 113 | + break |
| 114 | if standard_lib: |
| 115 | return libpython |
| 116 | else: |
| 117 | @@ -409,6 +434,11 @@ |
| 118 | )) |
| 119 | _temp = __import__(name, globals(), locals(), ['build_time_vars'], 0) |
| 120 | build_time_vars = _temp.build_time_vars |
| 121 | + lib_dir = get_python_lib(plat_specific=1, standard_lib=1) |
| 122 | + sysconfig_path = glob.glob(os.path.join(lib_dir, '_sysconfigdata_*.py')) |
| 123 | + if sysconfig_path: |
| 124 | + sysconfig_module = imp.load_source('_sysconfigdata', sysconfig_path[0]) |
| 125 | + build_time_vars = sysconfig_module.build_time_vars |
| 126 | global _config_vars |
| 127 | _config_vars = {} |
| 128 | _config_vars.update(build_time_vars) |