1 From 0fbdad1eaf541a8e92be81f39514cd249b3b0801 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 | 18 ++++++++++++------
15 Python/getplatform.c | 10 ++++++++++
16 Python/sysmodule.c | 2 ++
17 6 files changed, 31 insertions(+), 10 deletions(-)
19 diff --git a/Include/pythonrun.h b/Include/pythonrun.h
20 index 6f0c6fc..0a17edd 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_AnyFileFlags(FILE *, const char *, PyCompilerFlags *);
32 diff --git a/Lib/site.py b/Lib/site.py
33 index ffd132b..b55f6d8 100644
36 @@ -334,12 +334,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 6e81b2f..671a20e 100644
55 @@ -142,7 +142,7 @@ LIBDIR= @libdir@
57 INCLUDEDIR= @includedir@
58 CONFINCLUDEDIR= $(exec_prefix)/include
59 -SCRIPTDIR= $(prefix)/lib
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)"' \
69 -o $@ $(srcdir)/Modules/getpath.c
71 Programs/python.o: $(srcdir)/Programs/python.c
72 @@ -856,7 +857,7 @@ regen-opcode:
73 Python/compile.o Python/symtable.o Python/ast_unparse.o Python/ast.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 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 */
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" */
93 @@ -314,7 +315,7 @@ search_for_prefix(const _PyCoreConfig *core_config,
97 - joinpath(prefix, calculate->lib_python);
98 + joinpath(prefix, calculate->multilib_python);
99 joinpath(prefix, LANDMARK);
102 @@ -343,7 +344,7 @@ search_for_prefix(const _PyCoreConfig *core_config,
103 copy_absolute(prefix, calculate->argv0_path, MAXPATHLEN+1);
106 - joinpath(prefix, calculate->lib_python);
107 + joinpath(prefix, calculate->multilib_python);
108 joinpath(prefix, LANDMARK);
109 if (ismodule(prefix)) {
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)) {
120 @@ -427,7 +428,7 @@ search_for_exec_prefix(const _PyCoreConfig *core_config,
121 wcsncpy(exec_prefix, core_config->home, MAXPATHLEN);
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");
129 @@ -464,7 +465,7 @@ search_for_exec_prefix(const _PyCoreConfig *core_config,
130 copy_absolute(exec_prefix, calculate->argv0_path, MAXPATHLEN+1);
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)) {
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)) {
147 @@ -871,6 +872,10 @@ calculate_init(PyCalculatePath *calculate,
148 if (!calculate->lib_python) {
149 return DECODE_LOCALE_ERR("EXEC_PREFIX define", len);
151 + calculate->multilib_python = Py_DecodeLocale(LIB "/python" VERSION, &len);
152 + if (!calculate->multilib_python) {
153 + return DECODE_LOCALE_ERR("EXEC_PREFIX define", len);
155 return _Py_INIT_OK();
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);
166 diff --git a/Python/getplatform.c b/Python/getplatform.c
167 index 81a0f7a..d55396b 100644
168 --- a/Python/getplatform.c
169 +++ b/Python/getplatform.c
170 @@ -10,3 +10,13 @@ Py_GetPlatform(void)
184 diff --git a/Python/sysmodule.c b/Python/sysmodule.c
185 index 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",