blob: 112c979441f5958a7220c6e4552d1656958b4440 [file] [log] [blame]
Andrew Geissler82c905d2020-04-13 13:39:40 -05001From a078b6ff1492e848ad1055764fb9a414abaf3e12 Mon Sep 17 00:00:00 2001
Brad Bishop19323692019-04-05 15:28:33 -04002From: Alexander Kanavin <alex.kanavin@gmail.com>
3Date: Tue, 5 Feb 2019 15:52:02 +0100
4Subject: [PATCH] Do not hardcode "lib" as location for modules, site-packages
5 and lib-dynload
6
7Upstream-Status: Inappropriate [oe-core specific]
8Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com>
9
10---
11 Include/pythonrun.h | 2 ++
12 Lib/site.py | 4 ++--
13 Makefile.pre.in | 5 +++--
Andrew Geissler82c905d2020-04-13 13:39:40 -050014 Modules/getpath.c | 22 ++++++++++++++--------
Brad Bishop19323692019-04-05 15:28:33 -040015 Python/getplatform.c | 10 ++++++++++
16 Python/sysmodule.c | 2 ++
Andrew Geissler82c905d2020-04-13 13:39:40 -050017 6 files changed, 33 insertions(+), 12 deletions(-)
Brad Bishop19323692019-04-05 15:28:33 -040018
19diff --git a/Include/pythonrun.h b/Include/pythonrun.h
Andrew Geissler82c905d2020-04-13 13:39:40 -050020index 46091e0..61b2e15 100644
Brad Bishop19323692019-04-05 15:28:33 -040021--- a/Include/pythonrun.h
22+++ b/Include/pythonrun.h
23@@ -7,6 +7,8 @@
24 extern "C" {
25 #endif
26
27+PyAPI_FUNC(const char *) Py_GetLib(void);
28+
29 #ifndef Py_LIMITED_API
30 PyAPI_FUNC(int) PyRun_SimpleStringFlags(const char *, PyCompilerFlags *);
Andrew Geissler82c905d2020-04-13 13:39:40 -050031 PyAPI_FUNC(int) PyRun_AnyFileExFlags(
Brad Bishop19323692019-04-05 15:28:33 -040032diff --git a/Lib/site.py b/Lib/site.py
Andrew Geissler82c905d2020-04-13 13:39:40 -050033index a065ab0..1d720ef 100644
Brad Bishop19323692019-04-05 15:28:33 -040034--- a/Lib/site.py
35+++ b/Lib/site.py
Andrew Geissler82c905d2020-04-13 13:39:40 -050036@@ -335,12 +335,12 @@ def getsitepackages(prefixes=None):
Brad Bishop19323692019-04-05 15:28:33 -040037 seen.add(prefix)
38
39 if os.sep == '/':
40- sitepackages.append(os.path.join(prefix, "lib",
41+ sitepackages.append(os.path.join(prefix, sys.lib,
42 "python%d.%d" % sys.version_info[:2],
43 "site-packages"))
44 else:
45 sitepackages.append(prefix)
46- sitepackages.append(os.path.join(prefix, "lib", "site-packages"))
47+ sitepackages.append(os.path.join(prefix, sys.lib, "site-packages"))
48 return sitepackages
49
50 def addsitepackages(known_paths, prefixes=None):
51diff --git a/Makefile.pre.in b/Makefile.pre.in
Andrew Geissler82c905d2020-04-13 13:39:40 -050052index 65665df..be49140 100644
Brad Bishop19323692019-04-05 15:28:33 -040053--- a/Makefile.pre.in
54+++ b/Makefile.pre.in
Andrew Geissler82c905d2020-04-13 13:39:40 -050055@@ -143,7 +143,7 @@ LIBDIR= @libdir@
Brad Bishop19323692019-04-05 15:28:33 -040056 MANDIR= @mandir@
57 INCLUDEDIR= @includedir@
58 CONFINCLUDEDIR= $(exec_prefix)/include
59-SCRIPTDIR= $(prefix)/lib
60+SCRIPTDIR= @libdir@
61 ABIFLAGS= @ABIFLAGS@
62
63 # Detailed destination directories
Andrew Geissler82c905d2020-04-13 13:39:40 -050064@@ -753,6 +753,7 @@ Modules/getpath.o: $(srcdir)/Modules/getpath.c Makefile
Brad Bishop19323692019-04-05 15:28:33 -040065 -DEXEC_PREFIX='"$(exec_prefix)"' \
66 -DVERSION='"$(VERSION)"' \
67 -DVPATH='"$(VPATH)"' \
68+ -DLIB='"$(LIB)"' \
69 -o $@ $(srcdir)/Modules/getpath.c
70
71 Programs/python.o: $(srcdir)/Programs/python.c
Andrew Geissler82c905d2020-04-13 13:39:40 -050072@@ -868,7 +869,7 @@ regen-symbol: $(srcdir)/Include/graminit.h
Brad Bishop1d80a2e2019-11-15 16:35:03 -050073 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
Brad Bishop19323692019-04-05 15:28:33 -040074
75 Python/getplatform.o: $(srcdir)/Python/getplatform.c
76- $(CC) -c $(PY_CORE_CFLAGS) -DPLATFORM='"$(MACHDEP)"' -o $@ $(srcdir)/Python/getplatform.c
77+ $(CC) -c $(PY_CORE_CFLAGS) -DPLATFORM='"$(MACHDEP)"' -DLIB='"$(LIB)"' -o $@ $(srcdir)/Python/getplatform.c
78
79 Python/importdl.o: $(srcdir)/Python/importdl.c
80 $(CC) -c $(PY_CORE_CFLAGS) -I$(DLINCLDIR) -o $@ $(srcdir)/Python/importdl.c
81diff --git a/Modules/getpath.c b/Modules/getpath.c
Andrew Geissler82c905d2020-04-13 13:39:40 -050082index b727f66..c003e46 100644
Brad Bishop19323692019-04-05 15:28:33 -040083--- a/Modules/getpath.c
84+++ b/Modules/getpath.c
Andrew Geissler82c905d2020-04-13 13:39:40 -050085@@ -128,6 +128,7 @@ typedef struct {
86 wchar_t *exec_prefix; /* EXEC_PREFIX macro */
Brad Bishop19323692019-04-05 15:28:33 -040087
88 wchar_t *lib_python; /* "lib/pythonX.Y" */
89+ wchar_t *multilib_python; /* "lib[suffix]/pythonX.Y" */
Brad Bishop19323692019-04-05 15:28:33 -040090
Andrew Geissler82c905d2020-04-13 13:39:40 -050091 int prefix_found; /* found platform independent libraries? */
92 int exec_prefix_found; /* found the platform dependent libraries? */
93@@ -386,7 +387,7 @@ search_for_prefix(PyCalculatePath *calculate, _PyPathConfig *pathconfig,
Brad Bishop19323692019-04-05 15:28:33 -040094 if (delim) {
95 *delim = L'\0';
96 }
Andrew Geissler82c905d2020-04-13 13:39:40 -050097- status = joinpath(prefix, calculate->lib_python, prefix_len);
98+ status = joinpath(prefix, calculate->multilib_python, prefix_len);
99 if (_PyStatus_EXCEPTION(status)) {
100 return status;
Brad Bishop19323692019-04-05 15:28:33 -0400101 }
Andrew Geissler82c905d2020-04-13 13:39:40 -0500102@@ -444,7 +445,7 @@ search_for_prefix(PyCalculatePath *calculate, _PyPathConfig *pathconfig,
Brad Bishop19323692019-04-05 15:28:33 -0400103 do {
Andrew Geissler82c905d2020-04-13 13:39:40 -0500104 /* Path: <argv0_path or substring> / <lib_python> / LANDMARK */
105 size_t n = wcslen(prefix);
106- status = joinpath(prefix, calculate->lib_python, prefix_len);
107+ status = joinpath(prefix, calculate->multilib_python, prefix_len);
108 if (_PyStatus_EXCEPTION(status)) {
109 return status;
110 }
111@@ -467,7 +468,7 @@ search_for_prefix(PyCalculatePath *calculate, _PyPathConfig *pathconfig,
112 if (safe_wcscpy(prefix, calculate->prefix, prefix_len) < 0) {
113 return PATHLEN_ERR();
114 }
115- status = joinpath(prefix, calculate->lib_python, prefix_len);
116+ status = joinpath(prefix, calculate->multilib_python, prefix_len);
117 if (_PyStatus_EXCEPTION(status)) {
118 return status;
119 }
120@@ -510,7 +511,7 @@ calculate_prefix(PyCalculatePath *calculate, _PyPathConfig *pathconfig,
121 if (safe_wcscpy(prefix, calculate->prefix, prefix_len) < 0) {
122 return PATHLEN_ERR();
123 }
124- status = joinpath(prefix, calculate->lib_python, prefix_len);
125+ status = joinpath(prefix, calculate->multilib_python, prefix_len);
126 if (_PyStatus_EXCEPTION(status)) {
127 return status;
128 }
129@@ -635,7 +636,7 @@ search_for_exec_prefix(PyCalculatePath *calculate, _PyPathConfig *pathconfig,
130 return PATHLEN_ERR();
131 }
132 }
133- status = joinpath(exec_prefix, calculate->lib_python, exec_prefix_len);
134+ status = joinpath(exec_prefix, calculate->multilib_python, exec_prefix_len);
135 if (_PyStatus_EXCEPTION(status)) {
136 return status;
137 }
138@@ -667,7 +668,7 @@ search_for_exec_prefix(PyCalculatePath *calculate, _PyPathConfig *pathconfig,
139 do {
140 /* Path: <argv0_path or substring> / <lib_python> / "lib-dynload" */
141 size_t n = wcslen(exec_prefix);
142- status = joinpath(exec_prefix, calculate->lib_python, exec_prefix_len);
143+ status = joinpath(exec_prefix, calculate->multilib_python, exec_prefix_len);
144 if (_PyStatus_EXCEPTION(status)) {
145 return status;
146 }
147@@ -689,7 +690,7 @@ search_for_exec_prefix(PyCalculatePath *calculate, _PyPathConfig *pathconfig,
148 if (safe_wcscpy(exec_prefix, calculate->exec_prefix, exec_prefix_len) < 0) {
149 return PATHLEN_ERR();
150 }
151- status = joinpath(exec_prefix, calculate->lib_python, exec_prefix_len);
152+ status = joinpath(exec_prefix, calculate->multilib_python, exec_prefix_len);
153 if (_PyStatus_EXCEPTION(status)) {
154 return status;
155 }
156@@ -928,7 +929,7 @@ calculate_argv0_path(PyCalculatePath *calculate, const wchar_t *program_full_pat
157 return PATHLEN_ERR();
158 }
159 reduce(argv0_path);
160- status = joinpath(argv0_path, calculate->lib_python, argv0_path_len);
161+ status = joinpath(argv0_path, calculate->multilib_python, argv0_path_len);
162 if (_PyStatus_EXCEPTION(status)) {
163 PyMem_RawFree(wbuf);
164 return status;
165@@ -1201,6 +1202,10 @@ calculate_init(PyCalculatePath *calculate, const PyConfig *config)
Brad Bishop19323692019-04-05 15:28:33 -0400166 if (!calculate->lib_python) {
167 return DECODE_LOCALE_ERR("EXEC_PREFIX define", len);
168 }
169+ calculate->multilib_python = Py_DecodeLocale(LIB "/python" VERSION, &len);
170+ if (!calculate->multilib_python) {
171+ return DECODE_LOCALE_ERR("EXEC_PREFIX define", len);
172+ }
Brad Bishop19323692019-04-05 15:28:33 -0400173
Andrew Geissler82c905d2020-04-13 13:39:40 -0500174 calculate->warnings = config->pathconfig_warnings;
175 calculate->pythonpath_env = config->pythonpath_env;
176@@ -1216,6 +1221,7 @@ calculate_free(PyCalculatePath *calculate)
Brad Bishop19323692019-04-05 15:28:33 -0400177 PyMem_RawFree(calculate->prefix);
178 PyMem_RawFree(calculate->exec_prefix);
179 PyMem_RawFree(calculate->lib_python);
180+ PyMem_RawFree(calculate->multilib_python);
181 PyMem_RawFree(calculate->path_env);
182 }
183
184diff --git a/Python/getplatform.c b/Python/getplatform.c
185index 81a0f7a..d55396b 100644
186--- a/Python/getplatform.c
187+++ b/Python/getplatform.c
188@@ -10,3 +10,13 @@ Py_GetPlatform(void)
189 {
190 return PLATFORM;
191 }
192+
193+#ifndef LIB
194+#define LIB "lib"
195+#endif
196+
197+const char *
198+Py_GetLib(void)
199+{
200+ return LIB;
201+}
202diff --git a/Python/sysmodule.c b/Python/sysmodule.c
Andrew Geissler82c905d2020-04-13 13:39:40 -0500203index 5b0fb81..0dce754 100644
Brad Bishop19323692019-04-05 15:28:33 -0400204--- a/Python/sysmodule.c
205+++ b/Python/sysmodule.c
Andrew Geissler82c905d2020-04-13 13:39:40 -0500206@@ -2668,6 +2668,8 @@ _PySys_InitCore(_PyRuntimeState *runtime, PyInterpreterState *interp,
Brad Bishop19323692019-04-05 15:28:33 -0400207 PyUnicode_FromString(Py_GetCopyright()));
208 SET_SYS_FROM_STRING("platform",
209 PyUnicode_FromString(Py_GetPlatform()));
210+ SET_SYS_FROM_STRING("lib",
211+ PyUnicode_FromString(Py_GetLib()));
212 SET_SYS_FROM_STRING("maxsize",
213 PyLong_FromSsize_t(PY_SSIZE_T_MAX));
214 SET_SYS_FROM_STRING("float_info",