Merge pull request #13717 from kimheino/master
[feed/packages.git] / lang / python / python3 / patches / 008-distutils-use-python-sysroot.patch
1 From e359a7a3c4f9e70360a068bef19c95938fdacede Mon Sep 17 00:00:00 2001
2 From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
3 Date: Wed, 23 Dec 2015 11:33:14 +0100
4 Subject: [PATCH] Adjust library/header paths for cross-compilation
5
6 When cross-compiling third-party extensions, the get_python_inc() or
7 get_python_lib() can be called, to return the path to headers or
8 libraries. However, they use the sys.prefix of the host Python, which
9 returns incorrect paths when cross-compiling (paths pointing to host
10 headers and libraries).
11
12 In order to fix this, we introduce the _python_sysroot, _python_prefix
13 and _python_exec_prefix variables, that allow to override these
14 values, and get correct header/library paths when cross-compiling
15 third-party Python modules.
16
17 Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
18 ---
19 Lib/distutils/command/build_ext.py | 5 ++++-
20 Lib/distutils/sysconfig.py | 15 +++++++++++----
21 2 files changed, 15 insertions(+), 5 deletions(-)
22
23 --- a/Lib/distutils/command/build_ext.py
24 +++ b/Lib/distutils/command/build_ext.py
25 @@ -234,7 +234,10 @@ class build_ext(Command):
26 if (sysconfig.get_config_var('Py_ENABLE_SHARED')):
27 if not sysconfig.python_build:
28 # building third party extensions
29 - self.library_dirs.append(sysconfig.get_config_var('LIBDIR'))
30 + libdir = sysconfig.get_config_var('LIBDIR')
31 + if "_python_sysroot" in os.environ:
32 + libdir = os.environ.get("_python_sysroot") + libdir
33 + self.library_dirs.append(libdir)
34 else:
35 # building python standard extensions
36 self.library_dirs.append('.')
37 --- a/Lib/distutils/sysconfig.py
38 +++ b/Lib/distutils/sysconfig.py
39 @@ -17,10 +17,17 @@ import sys
40 from .errors import DistutilsPlatformError
41
42 # These are needed in a couple of spots, so just compute them once.
43 -PREFIX = os.path.normpath(sys.prefix)
44 -EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
45 -BASE_PREFIX = os.path.normpath(sys.base_prefix)
46 -BASE_EXEC_PREFIX = os.path.normpath(sys.base_exec_prefix)
47 +if "_python_sysroot" in os.environ:
48 + _sysroot=os.environ.get('_python_sysroot')
49 + PREFIX = os.path.normpath(_sysroot + os.environ.get('_python_prefix'))
50 + EXEC_PREFIX = os.path.normpath(_sysroot + os.environ.get('_python_exec_prefix'))
51 + BASE_PREFIX = PREFIX
52 + BASE_EXEC_PREFIX = EXEC_PREFIX
53 +else:
54 + PREFIX = os.path.normpath(sys.prefix)
55 + EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
56 + BASE_PREFIX = os.path.normpath(sys.base_prefix)
57 + BASE_EXEC_PREFIX = os.path.normpath(sys.base_exec_prefix)
58
59 # Path to the base directory of the project. On Windows the binary may
60 # live in project/PCbuild/win32 or project/PCbuild/amd64.