Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 1 | From a078b6ff1492e848ad1055764fb9a414abaf3e12 Mon Sep 17 00:00:00 2001 |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 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 |
| 5 | and lib-dynload |
| 6 | |
| 7 | Upstream-Status: Inappropriate [oe-core specific] |
| 8 | Signed-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 Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 14 | Modules/getpath.c | 22 ++++++++++++++-------- |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 15 | Python/getplatform.c | 10 ++++++++++ |
| 16 | Python/sysmodule.c | 2 ++ |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 17 | 6 files changed, 33 insertions(+), 12 deletions(-) |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 18 | |
| 19 | diff --git a/Include/pythonrun.h b/Include/pythonrun.h |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 20 | index 46091e0..61b2e15 100644 |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 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 *); |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 31 | PyAPI_FUNC(int) PyRun_AnyFileExFlags( |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 32 | diff --git a/Lib/site.py b/Lib/site.py |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 33 | index a065ab0..1d720ef 100644 |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 34 | --- a/Lib/site.py |
| 35 | +++ b/Lib/site.py |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 36 | @@ -335,12 +335,12 @@ def getsitepackages(prefixes=None): |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 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): |
| 51 | diff --git a/Makefile.pre.in b/Makefile.pre.in |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 52 | index 65665df..be49140 100644 |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 53 | --- a/Makefile.pre.in |
| 54 | +++ b/Makefile.pre.in |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 55 | @@ -143,7 +143,7 @@ LIBDIR= @libdir@ |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 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 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 64 | @@ -753,6 +753,7 @@ Modules/getpath.o: $(srcdir)/Modules/getpath.c Makefile |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 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 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 72 | @@ -868,7 +869,7 @@ regen-symbol: $(srcdir)/Include/graminit.h |
Brad Bishop | 1d80a2e | 2019-11-15 16:35:03 -0500 | [diff] [blame] | 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 |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 74 | |
| 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 |
| 81 | diff --git a/Modules/getpath.c b/Modules/getpath.c |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 82 | index b727f66..c003e46 100644 |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 83 | --- a/Modules/getpath.c |
| 84 | +++ b/Modules/getpath.c |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 85 | @@ -128,6 +128,7 @@ typedef struct { |
| 86 | wchar_t *exec_prefix; /* EXEC_PREFIX macro */ |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 87 | |
| 88 | wchar_t *lib_python; /* "lib/pythonX.Y" */ |
| 89 | + wchar_t *multilib_python; /* "lib[suffix]/pythonX.Y" */ |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 90 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 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, |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 94 | if (delim) { |
| 95 | *delim = L'\0'; |
| 96 | } |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 97 | - 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 Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 101 | } |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 102 | @@ -444,7 +445,7 @@ search_for_prefix(PyCalculatePath *calculate, _PyPathConfig *pathconfig, |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 103 | do { |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 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)) { |
| 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 Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 166 | 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 Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 173 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 174 | calculate->warnings = config->pathconfig_warnings; |
| 175 | calculate->pythonpath_env = config->pythonpath_env; |
| 176 | @@ -1216,6 +1221,7 @@ calculate_free(PyCalculatePath *calculate) |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 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); |
| 182 | } |
| 183 | |
| 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) |
| 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 | +} |
| 202 | diff --git a/Python/sysmodule.c b/Python/sysmodule.c |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 203 | index 5b0fb81..0dce754 100644 |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 204 | --- a/Python/sysmodule.c |
| 205 | +++ b/Python/sysmodule.c |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 206 | @@ -2668,6 +2668,8 @@ _PySys_InitCore(_PyRuntimeState *runtime, PyInterpreterState *interp, |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 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", |