1 From a078b6ff1492e848ad1055764fb9a414abaf3e12 Mon Sep 17 00:00:00 2001
2 From: Alexander Kanavin <alex.kanavin@gmail.com>
3 Date: Tue, 5 Feb 2019 15:52:02 +0100
4 Subject: [PATCH] Do not hardcode "lib" as location for modules, site-packages
7 Upstream-Status: Inappropriate [oe-core specific]
8 Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com>
11 Include/pythonrun.h | 2 ++
13 Makefile.pre.in | 5 +++--
14 Modules/getpath.c | 22 ++++++++++++++--------
15 Python/getplatform.c | 10 ++++++++++
16 Python/sysmodule.c | 2 ++
17 6 files changed, 33 insertions(+), 12 deletions(-)
19 diff --git a/Include/pythonrun.h b/Include/pythonrun.h
20 index 46091e0..61b2e15 100644
21 --- a/Include/pythonrun.h
22 +++ b/Include/pythonrun.h
27 +PyAPI_FUNC(const char *) Py_GetLib(void);
29 #ifndef Py_LIMITED_API
30 PyAPI_FUNC(int) PyRun_SimpleStringFlags(const char *, PyCompilerFlags *);
31 PyAPI_FUNC(int) PyRun_AnyFileExFlags(
32 diff --git a/Lib/site.py b/Lib/site.py
33 index a065ab0..1d720ef 100644
36 @@ -335,12 +335,12 @@ def getsitepackages(prefixes=None):
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],
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"))
50 def addsitepackages(known_paths, prefixes=None):
51 diff --git a/Makefile.pre.in b/Makefile.pre.in
52 index 65665df..be49140 100644
55 @@ -143,7 +143,7 @@ LIBDIR= @libdir@
57 INCLUDEDIR= @includedir@
58 CONFINCLUDEDIR= $(exec_prefix)/include
59 -SCRIPTDIR= $(prefix)/lib
63 # Detailed destination directories
64 @@ -753,6 +753,7 @@ Modules/getpath.o: $(srcdir)/Modules/getpath.c Makefile
65 -DEXEC_PREFIX='"$(exec_prefix)"' \
66 -DVERSION='"$(VERSION)"' \
67 -DVPATH='"$(VPATH)"' \
69 -o $@ $(srcdir)/Modules/getpath.c
71 Programs/python.o: $(srcdir)/Programs/python.c
72 @@ -868,7 +869,7 @@ regen-symbol: $(srcdir)/Include/graminit.h
73 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
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
79 Python/importdl.o: $(srcdir)/Python/importdl.c
80 $(CC) -c $(PY_CORE_CFLAGS) -I$(DLINCLDIR) -o $@ $(srcdir)/Python/importdl.c
81 diff --git a/Modules/getpath.c b/Modules/getpath.c
82 index b727f66..c003e46 100644
83 --- a/Modules/getpath.c
84 +++ b/Modules/getpath.c
85 @@ -128,6 +128,7 @@ typedef struct {
86 wchar_t *exec_prefix; /* EXEC_PREFIX macro */
88 wchar_t *lib_python; /* "lib/pythonX.Y" */
89 + wchar_t *multilib_python; /* "lib[suffix]/pythonX.Y" */
91 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,
97 - status = joinpath(prefix, calculate->lib_python, prefix_len);
98 + status = joinpath(prefix, calculate->multilib_python, prefix_len);
99 if (_PyStatus_EXCEPTION(status)) {
102 @@ -444,7 +445,7 @@ search_for_prefix(PyCalculatePath *calculate, _PyPathConfig *pathconfig,
104 /* 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)) {
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();
115 - status = joinpath(prefix, calculate->lib_python, prefix_len);
116 + status = joinpath(prefix, calculate->multilib_python, prefix_len);
117 if (_PyStatus_EXCEPTION(status)) {
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();
124 - status = joinpath(prefix, calculate->lib_python, prefix_len);
125 + status = joinpath(prefix, calculate->multilib_python, prefix_len);
126 if (_PyStatus_EXCEPTION(status)) {
129 @@ -635,7 +636,7 @@ search_for_exec_prefix(PyCalculatePath *calculate, _PyPathConfig *pathconfig,
130 return PATHLEN_ERR();
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)) {
138 @@ -667,7 +668,7 @@ search_for_exec_prefix(PyCalculatePath *calculate, _PyPathConfig *pathconfig,
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)) {
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();
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)) {
156 @@ -928,7 +929,7 @@ calculate_argv0_path(PyCalculatePath *calculate, const wchar_t *program_full_pat
157 return PATHLEN_ERR();
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)) {
165 @@ -1201,6 +1202,10 @@ calculate_init(PyCalculatePath *calculate, const PyConfig *config)
166 if (!calculate->lib_python) {
167 return DECODE_LOCALE_ERR("EXEC_PREFIX define", len);
169 + calculate->multilib_python = Py_DecodeLocale(LIB "/python" VERSION, &len);
170 + if (!calculate->multilib_python) {
171 + return DECODE_LOCALE_ERR("EXEC_PREFIX define", len);
174 calculate->warnings = config->pathconfig_warnings;
175 calculate->pythonpath_env = config->pythonpath_env;
176 @@ -1216,6 +1221,7 @@ calculate_free(PyCalculatePath *calculate)
177 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);
184 diff --git a/Python/getplatform.c b/Python/getplatform.c
185 index 81a0f7a..d55396b 100644
186 --- a/Python/getplatform.c
187 +++ b/Python/getplatform.c
188 @@ -10,3 +10,13 @@ Py_GetPlatform(void)
202 diff --git a/Python/sysmodule.c b/Python/sysmodule.c
203 index 5b0fb81..0dce754 100644
204 --- a/Python/sysmodule.c
205 +++ b/Python/sysmodule.c
206 @@ -2668,6 +2668,8 @@ _PySys_InitCore(_PyRuntimeState *runtime, PyInterpreterState *interp,
207 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",