blob: ea75262c4f6657a20f5bab4dee847e6bd9ea3d68 [file] [log] [blame]
Brad Bishop19323692019-04-05 15:28:33 -04001From 0fbdad1eaf541a8e92be81f39514cd249b3b0801 Mon Sep 17 00:00:00 2001
2From: 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 +++--
14 Modules/getpath.c | 18 ++++++++++++------
15 Python/getplatform.c | 10 ++++++++++
16 Python/sysmodule.c | 2 ++
17 6 files changed, 31 insertions(+), 10 deletions(-)
18
19diff --git a/Include/pythonrun.h b/Include/pythonrun.h
20index 6f0c6fc..0a17edd 100644
21--- 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 *);
31 PyAPI_FUNC(int) PyRun_AnyFileFlags(FILE *, const char *, PyCompilerFlags *);
32diff --git a/Lib/site.py b/Lib/site.py
33index ffd132b..b55f6d8 100644
34--- a/Lib/site.py
35+++ b/Lib/site.py
36@@ -334,12 +334,12 @@ def getsitepackages(prefixes=None):
37 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
52index 6e81b2f..671a20e 100644
53--- a/Makefile.pre.in
54+++ b/Makefile.pre.in
55@@ -142,7 +142,7 @@ LIBDIR= @libdir@
56 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
64@@ -768,6 +768,7 @@ Modules/getpath.o: $(srcdir)/Modules/getpath.c Makefile
65 -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
72@@ -856,7 +857,7 @@ regen-opcode:
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
82index e6a3e8e..0c62af6 100644
83--- a/Modules/getpath.c
84+++ b/Modules/getpath.c
85@@ -123,6 +123,7 @@ typedef struct {
86 wchar_t *exec_prefix; /* EXEC_PREFIX define */
87
88 wchar_t *lib_python; /* "lib/pythonX.Y" */
89+ wchar_t *multilib_python; /* "lib[suffix]/pythonX.Y" */
90 wchar_t argv0_path[MAXPATHLEN+1];
91 wchar_t zip_path[MAXPATHLEN+1]; /* ".../lib/pythonXY.zip" */
92
93@@ -314,7 +315,7 @@ search_for_prefix(const _PyCoreConfig *core_config,
94 if (delim) {
95 *delim = L'\0';
96 }
97- joinpath(prefix, calculate->lib_python);
98+ joinpath(prefix, calculate->multilib_python);
99 joinpath(prefix, LANDMARK);
100 return 1;
101 }
102@@ -343,7 +344,7 @@ search_for_prefix(const _PyCoreConfig *core_config,
103 copy_absolute(prefix, calculate->argv0_path, MAXPATHLEN+1);
104 do {
105 n = wcslen(prefix);
106- joinpath(prefix, calculate->lib_python);
107+ joinpath(prefix, calculate->multilib_python);
108 joinpath(prefix, LANDMARK);
109 if (ismodule(prefix)) {
110 return 1;
111@@ -355,7 +356,7 @@ search_for_prefix(const _PyCoreConfig *core_config,
112 /* Look at configure's PREFIX */
113 wcsncpy(prefix, calculate->prefix, MAXPATHLEN);
114 prefix[MAXPATHLEN] = L'\0';
115- joinpath(prefix, calculate->lib_python);
116+ joinpath(prefix, calculate->multilib_python);
117 joinpath(prefix, LANDMARK);
118 if (ismodule(prefix)) {
119 return 1;
120@@ -427,7 +428,7 @@ search_for_exec_prefix(const _PyCoreConfig *core_config,
121 wcsncpy(exec_prefix, core_config->home, MAXPATHLEN);
122 }
123 exec_prefix[MAXPATHLEN] = L'\0';
124- joinpath(exec_prefix, calculate->lib_python);
125+ joinpath(exec_prefix, calculate->multilib_python);
126 joinpath(exec_prefix, L"lib-dynload");
127 return 1;
128 }
129@@ -464,7 +465,7 @@ search_for_exec_prefix(const _PyCoreConfig *core_config,
130 copy_absolute(exec_prefix, calculate->argv0_path, MAXPATHLEN+1);
131 do {
132 n = wcslen(exec_prefix);
133- joinpath(exec_prefix, calculate->lib_python);
134+ joinpath(exec_prefix, calculate->multilib_python);
135 joinpath(exec_prefix, L"lib-dynload");
136 if (isdir(exec_prefix)) {
137 return 1;
138@@ -476,7 +477,7 @@ search_for_exec_prefix(const _PyCoreConfig *core_config,
139 /* Look at configure's EXEC_PREFIX */
140 wcsncpy(exec_prefix, calculate->exec_prefix, MAXPATHLEN);
141 exec_prefix[MAXPATHLEN] = L'\0';
142- joinpath(exec_prefix, calculate->lib_python);
143+ joinpath(exec_prefix, calculate->multilib_python);
144 joinpath(exec_prefix, L"lib-dynload");
145 if (isdir(exec_prefix)) {
146 return 1;
147@@ -871,6 +872,10 @@ calculate_init(PyCalculatePath *calculate,
148 if (!calculate->lib_python) {
149 return DECODE_LOCALE_ERR("EXEC_PREFIX define", len);
150 }
151+ calculate->multilib_python = Py_DecodeLocale(LIB "/python" VERSION, &len);
152+ if (!calculate->multilib_python) {
153+ return DECODE_LOCALE_ERR("EXEC_PREFIX define", len);
154+ }
155 return _Py_INIT_OK();
156 }
157
158@@ -882,6 +887,7 @@ calculate_free(PyCalculatePath *calculate)
159 PyMem_RawFree(calculate->prefix);
160 PyMem_RawFree(calculate->exec_prefix);
161 PyMem_RawFree(calculate->lib_python);
162+ PyMem_RawFree(calculate->multilib_python);
163 PyMem_RawFree(calculate->path_env);
164 }
165
166diff --git a/Python/getplatform.c b/Python/getplatform.c
167index 81a0f7a..d55396b 100644
168--- a/Python/getplatform.c
169+++ b/Python/getplatform.c
170@@ -10,3 +10,13 @@ Py_GetPlatform(void)
171 {
172 return PLATFORM;
173 }
174+
175+#ifndef LIB
176+#define LIB "lib"
177+#endif
178+
179+const char *
180+Py_GetLib(void)
181+{
182+ return LIB;
183+}
184diff --git a/Python/sysmodule.c b/Python/sysmodule.c
185index efe5b29..de77b17 100644
186--- a/Python/sysmodule.c
187+++ b/Python/sysmodule.c
188@@ -2319,6 +2319,8 @@ _PySys_BeginInit(PyObject **sysmod)
189 PyUnicode_FromString(Py_GetCopyright()));
190 SET_SYS_FROM_STRING("platform",
191 PyUnicode_FromString(Py_GetPlatform()));
192+ SET_SYS_FROM_STRING("lib",
193+ PyUnicode_FromString(Py_GetLib()));
194 SET_SYS_FROM_STRING("maxsize",
195 PyLong_FromSsize_t(PY_SSIZE_T_MAX));
196 SET_SYS_FROM_STRING("float_info",