Merge pull request #9331 from dibdot/travelmate
[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 diff --git a/Lib/distutils/command/build_ext.py b/Lib/distutils/command/build_ext.py
24 index 74de782d8a..d0c847b365 100644
25 --- a/Lib/distutils/command/build_ext.py
26 +++ b/Lib/distutils/command/build_ext.py
27 @@ -234,7 +234,10 @@ class build_ext(Command):
28 if (sysconfig.get_config_var('Py_ENABLE_SHARED')):
29 if not sysconfig.python_build:
30 # building third party extensions
31 - self.library_dirs.append(sysconfig.get_config_var('LIBDIR'))
32 + libdir = sysconfig.get_config_var('LIBDIR')
33 + if "_python_sysroot" in os.environ:
34 + libdir = os.environ.get("_python_sysroot") + libdir
35 + self.library_dirs.append(libdir)
36 else:
37 # building python standard extensions
38 self.library_dirs.append('.')
39 diff --git a/Lib/distutils/sysconfig.py b/Lib/distutils/sysconfig.py
40 index 2bcd1dd288..422c13fa4f 100644
41 --- a/Lib/distutils/sysconfig.py
42 +++ b/Lib/distutils/sysconfig.py
43 @@ -17,10 +17,17 @@ import sys
44 from .errors import DistutilsPlatformError
45
46 # These are needed in a couple of spots, so just compute them once.
47 -PREFIX = os.path.normpath(sys.prefix)
48 -EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
49 -BASE_PREFIX = os.path.normpath(sys.base_prefix)
50 -BASE_EXEC_PREFIX = os.path.normpath(sys.base_exec_prefix)
51 +if "_python_sysroot" in os.environ:
52 + _sysroot=os.environ.get('_python_sysroot')
53 + PREFIX = os.path.normpath(_sysroot + os.environ.get('_python_prefix'))
54 + EXEC_PREFIX = os.path.normpath(_sysroot + os.environ.get('_python_exec_prefix'))
55 + BASE_PREFIX = PREFIX
56 + BASE_EXEC_PREFIX = EXEC_PREFIX
57 +else:
58 + PREFIX = os.path.normpath(sys.prefix)
59 + EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
60 + BASE_PREFIX = os.path.normpath(sys.base_prefix)
61 + BASE_EXEC_PREFIX = os.path.normpath(sys.base_exec_prefix)
62
63 # Path to the base directory of the project. On Windows the binary may
64 # live in project/PCbuild/win32 or project/PCbuild/amd64.
65 --
66 2.13.5
67