summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/python/python3/0001-Do-not-hardcode-lib-as-location-for-site-packages-an.patch
blob: 112c979441f5958a7220c6e4552d1656958b4440 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
From a078b6ff1492e848ad1055764fb9a414abaf3e12 Mon Sep 17 00:00:00 2001
From: Alexander Kanavin <alex.kanavin@gmail.com>
Date: Tue, 5 Feb 2019 15:52:02 +0100
Subject: [PATCH] Do not hardcode "lib" as location for modules, site-packages
 and lib-dynload

Upstream-Status: Inappropriate [oe-core specific]
Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com>

---
 Include/pythonrun.h  |  2 ++
 Lib/site.py          |  4 ++--
 Makefile.pre.in      |  5 +++--
 Modules/getpath.c    | 22 ++++++++++++++--------
 Python/getplatform.c | 10 ++++++++++
 Python/sysmodule.c   |  2 ++
 6 files changed, 33 insertions(+), 12 deletions(-)

diff --git a/Include/pythonrun.h b/Include/pythonrun.h
index 46091e0..61b2e15 100644
--- a/Include/pythonrun.h
+++ b/Include/pythonrun.h
@@ -7,6 +7,8 @@
 extern "C" {
 #endif
 
+PyAPI_FUNC(const char *) Py_GetLib(void);
+
 #ifndef Py_LIMITED_API
 PyAPI_FUNC(int) PyRun_SimpleStringFlags(const char *, PyCompilerFlags *);
 PyAPI_FUNC(int) PyRun_AnyFileExFlags(
diff --git a/Lib/site.py b/Lib/site.py
index a065ab0..1d720ef 100644
--- a/Lib/site.py
+++ b/Lib/site.py
@@ -335,12 +335,12 @@ def getsitepackages(prefixes=None):
         seen.add(prefix)
 
         if os.sep == '/':
-            sitepackages.append(os.path.join(prefix, "lib",
+            sitepackages.append(os.path.join(prefix, sys.lib,
                                         "python%d.%d" % sys.version_info[:2],
                                         "site-packages"))
         else:
             sitepackages.append(prefix)
-            sitepackages.append(os.path.join(prefix, "lib", "site-packages"))
+            sitepackages.append(os.path.join(prefix, sys.lib, "site-packages"))
     return sitepackages
 
 def addsitepackages(known_paths, prefixes=None):
diff --git a/Makefile.pre.in b/Makefile.pre.in
index 65665df..be49140 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -143,7 +143,7 @@ LIBDIR=		@libdir@
 MANDIR=		@mandir@
 INCLUDEDIR=	@includedir@
 CONFINCLUDEDIR=	$(exec_prefix)/include
-SCRIPTDIR=	$(prefix)/lib
+SCRIPTDIR=	@libdir@
 ABIFLAGS=	@ABIFLAGS@
 
 # Detailed destination directories
@@ -753,6 +753,7 @@ Modules/getpath.o: $(srcdir)/Modules/getpath.c Makefile
 		-DEXEC_PREFIX='"$(exec_prefix)"' \
 		-DVERSION='"$(VERSION)"' \
 		-DVPATH='"$(VPATH)"' \
+		-DLIB='"$(LIB)"' \
 		-o $@ $(srcdir)/Modules/getpath.c
 
 Programs/python.o: $(srcdir)/Programs/python.c
@@ -868,7 +869,7 @@ regen-symbol: $(srcdir)/Include/graminit.h
 Python/compile.o Python/symtable.o Python/ast_unparse.o Python/ast.o Python/future.o Parser/parsetok.o: $(srcdir)/Include/graminit.h $(srcdir)/Include/Python-ast.h
 
 Python/getplatform.o: $(srcdir)/Python/getplatform.c
-		$(CC) -c $(PY_CORE_CFLAGS) -DPLATFORM='"$(MACHDEP)"' -o $@ $(srcdir)/Python/getplatform.c
+		$(CC) -c $(PY_CORE_CFLAGS) -DPLATFORM='"$(MACHDEP)"' -DLIB='"$(LIB)"' -o $@ $(srcdir)/Python/getplatform.c
 
 Python/importdl.o: $(srcdir)/Python/importdl.c
 		$(CC) -c $(PY_CORE_CFLAGS) -I$(DLINCLDIR) -o $@ $(srcdir)/Python/importdl.c
diff --git a/Modules/getpath.c b/Modules/getpath.c
index b727f66..c003e46 100644
--- a/Modules/getpath.c
+++ b/Modules/getpath.c
@@ -128,6 +128,7 @@ typedef struct {
     wchar_t *exec_prefix;              /* EXEC_PREFIX macro */
 
     wchar_t *lib_python;               /* "lib/pythonX.Y" */
+    wchar_t *multilib_python;               /* "lib[suffix]/pythonX.Y" */
 
     int prefix_found;         /* found platform independent libraries? */
     int exec_prefix_found;    /* found the platform dependent libraries? */
@@ -386,7 +387,7 @@ search_for_prefix(PyCalculatePath *calculate, _PyPathConfig *pathconfig,
         if (delim) {
             *delim = L'\0';
         }
-        status = joinpath(prefix, calculate->lib_python, prefix_len);
+        status = joinpath(prefix, calculate->multilib_python, prefix_len);
         if (_PyStatus_EXCEPTION(status)) {
             return status;
         }
@@ -444,7 +445,7 @@ search_for_prefix(PyCalculatePath *calculate, _PyPathConfig *pathconfig,
     do {
         /* Path: <argv0_path or substring> / <lib_python> / LANDMARK */
         size_t n = wcslen(prefix);
-        status = joinpath(prefix, calculate->lib_python, prefix_len);
+        status = joinpath(prefix, calculate->multilib_python, prefix_len);
         if (_PyStatus_EXCEPTION(status)) {
             return status;
         }
@@ -467,7 +468,7 @@ search_for_prefix(PyCalculatePath *calculate, _PyPathConfig *pathconfig,
     if (safe_wcscpy(prefix, calculate->prefix, prefix_len) < 0) {
         return PATHLEN_ERR();
     }
-    status = joinpath(prefix, calculate->lib_python, prefix_len);
+    status = joinpath(prefix, calculate->multilib_python, prefix_len);
     if (_PyStatus_EXCEPTION(status)) {
         return status;
     }
@@ -510,7 +511,7 @@ calculate_prefix(PyCalculatePath *calculate, _PyPathConfig *pathconfig,
         if (safe_wcscpy(prefix, calculate->prefix, prefix_len) < 0) {
             return PATHLEN_ERR();
         }
-        status = joinpath(prefix, calculate->lib_python, prefix_len);
+        status = joinpath(prefix, calculate->multilib_python, prefix_len);
         if (_PyStatus_EXCEPTION(status)) {
             return status;
         }
@@ -635,7 +636,7 @@ search_for_exec_prefix(PyCalculatePath *calculate, _PyPathConfig *pathconfig,
                 return PATHLEN_ERR();
             }
         }
-        status = joinpath(exec_prefix, calculate->lib_python, exec_prefix_len);
+        status = joinpath(exec_prefix, calculate->multilib_python, exec_prefix_len);
         if (_PyStatus_EXCEPTION(status)) {
             return status;
         }
@@ -667,7 +668,7 @@ search_for_exec_prefix(PyCalculatePath *calculate, _PyPathConfig *pathconfig,
     do {
         /* Path: <argv0_path or substring> / <lib_python> / "lib-dynload" */
         size_t n = wcslen(exec_prefix);
-        status = joinpath(exec_prefix, calculate->lib_python, exec_prefix_len);
+        status = joinpath(exec_prefix, calculate->multilib_python, exec_prefix_len);
         if (_PyStatus_EXCEPTION(status)) {
             return status;
         }
@@ -689,7 +690,7 @@ search_for_exec_prefix(PyCalculatePath *calculate, _PyPathConfig *pathconfig,
     if (safe_wcscpy(exec_prefix, calculate->exec_prefix, exec_prefix_len) < 0) {
         return PATHLEN_ERR();
     }
-    status = joinpath(exec_prefix, calculate->lib_python, exec_prefix_len);
+    status = joinpath(exec_prefix, calculate->multilib_python, exec_prefix_len);
     if (_PyStatus_EXCEPTION(status)) {
         return status;
     }
@@ -928,7 +929,7 @@ calculate_argv0_path(PyCalculatePath *calculate, const wchar_t *program_full_pat
             return PATHLEN_ERR();
         }
         reduce(argv0_path);
-        status = joinpath(argv0_path, calculate->lib_python, argv0_path_len);
+        status = joinpath(argv0_path, calculate->multilib_python, argv0_path_len);
         if (_PyStatus_EXCEPTION(status)) {
             PyMem_RawFree(wbuf);
             return status;
@@ -1201,6 +1202,10 @@ calculate_init(PyCalculatePath *calculate, const PyConfig *config)
     if (!calculate->lib_python) {
         return DECODE_LOCALE_ERR("EXEC_PREFIX define", len);
     }
+    calculate->multilib_python = Py_DecodeLocale(LIB "/python" VERSION, &len);
+    if (!calculate->multilib_python) {
+        return DECODE_LOCALE_ERR("EXEC_PREFIX define", len);
+    }
 
     calculate->warnings = config->pathconfig_warnings;
     calculate->pythonpath_env = config->pythonpath_env;
@@ -1216,6 +1221,7 @@ calculate_free(PyCalculatePath *calculate)
     PyMem_RawFree(calculate->prefix);
     PyMem_RawFree(calculate->exec_prefix);
     PyMem_RawFree(calculate->lib_python);
+    PyMem_RawFree(calculate->multilib_python);
     PyMem_RawFree(calculate->path_env);
 }
 
diff --git a/Python/getplatform.c b/Python/getplatform.c
index 81a0f7a..d55396b 100644
--- a/Python/getplatform.c
+++ b/Python/getplatform.c
@@ -10,3 +10,13 @@ Py_GetPlatform(void)
 {
     return PLATFORM;
 }
+
+#ifndef LIB
+#define LIB "lib"
+#endif
+
+const char *
+Py_GetLib(void)
+{
+	return LIB;
+}
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 5b0fb81..0dce754 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -2668,6 +2668,8 @@ _PySys_InitCore(_PyRuntimeState *runtime, PyInterpreterState *interp,
                         PyUnicode_FromString(Py_GetCopyright()));
     SET_SYS_FROM_STRING("platform",
                         PyUnicode_FromString(Py_GetPlatform()));
+    SET_SYS_FROM_STRING("lib",
+                        PyUnicode_FromString(Py_GetLib()));
     SET_SYS_FROM_STRING("maxsize",
                         PyLong_FromSsize_t(PY_SSIZE_T_MAX));
     SET_SYS_FROM_STRING("float_info",