Blame SOURCES/00353-architecture-names-upstream-downstream.patch

fa50f4
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
fa50f4
From: Lumir Balhar <lbalhar@redhat.com>
fa50f4
Date: Tue, 4 Aug 2020 12:04:03 +0200
fa50f4
Subject: [PATCH] 00353: Original names for architectures with different names
fa50f4
 downstream
fa50f4
MIME-Version: 1.0
fa50f4
Content-Type: text/plain; charset=UTF-8
fa50f4
Content-Transfer-Encoding: 8bit
fa50f4
fa50f4
https://fedoraproject.org/wiki/Changes/Python_Upstream_Architecture_Names
fa50f4
fa50f4
Pythons in RHEL/Fedora used different names for some architectures
fa50f4
than upstream and other distros (for example ppc64 vs. powerpc64).
fa50f4
This was patched in patch 274, now it is sedded if %with legacy_archnames.
fa50f4
fa50f4
That meant that an extension built with the default upstream settings
fa50f4
(on other distro or as an manylinux wheel) could not been found by Python
fa50f4
on RHEL/Fedora because it had a different suffix.
fa50f4
This patch adds the legacy names to importlib so Python is able
fa50f4
to import extensions with a legacy architecture name in its
fa50f4
file name.
fa50f4
It work both ways, so it support both %with and %without legacy_archnames.
fa50f4
fa50f4
WARNING: This patch has no effect on Python built with bootstrap
fa50f4
enabled because Python/importlib_external.h is not regenerated
fa50f4
and therefore Python during bootstrap contains importlib from
fa50f4
upstream without this feature. It's possible to include
fa50f4
Python/importlib_external.h to this patch but it'd make rebasing
fa50f4
a nightmare because it's basically a binary file.
fa50f4
fa50f4
Co-authored-by: Miro HronĨok <miro@hroncok.cz>
fa50f4
---
fa50f4
 Lib/importlib/_bootstrap_external.py | 40 ++++++++++++++++++++++++++--
fa50f4
 1 file changed, 38 insertions(+), 2 deletions(-)
fa50f4
fa50f4
diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py
fa50f4
index 9feec50842..5bb2454a5c 100644
fa50f4
--- a/Lib/importlib/_bootstrap_external.py
fa50f4
+++ b/Lib/importlib/_bootstrap_external.py
fa50f4
@@ -1361,7 +1361,7 @@ def _get_supported_file_loaders():
fa50f4
 
fa50f4
     Each item is a tuple (loader, suffixes).
fa50f4
     """
fa50f4
-    extensions = ExtensionFileLoader, _imp.extension_suffixes()
fa50f4
+    extensions = ExtensionFileLoader, _alternative_architectures(_imp.extension_suffixes())
fa50f4
     source = SourceFileLoader, SOURCE_SUFFIXES
fa50f4
     bytecode = SourcelessFileLoader, BYTECODE_SUFFIXES
fa50f4
     return [extensions, source, bytecode]
fa50f4
@@ -1428,7 +1428,7 @@ def _setup(_bootstrap_module):
fa50f4
 
fa50f4
     # Constants
fa50f4
     setattr(self_module, '_relax_case', _make_relax_case())
fa50f4
-    EXTENSION_SUFFIXES.extend(_imp.extension_suffixes())
fa50f4
+    EXTENSION_SUFFIXES.extend(_alternative_architectures(_imp.extension_suffixes()))
fa50f4
     if builtin_os == 'nt':
fa50f4
         SOURCE_SUFFIXES.append('.pyw')
fa50f4
         if '_d.pyd' in EXTENSION_SUFFIXES:
fa50f4
@@ -1441,3 +1441,39 @@ def _install(_bootstrap_module):
fa50f4
     supported_loaders = _get_supported_file_loaders()
fa50f4
     sys.path_hooks.extend([FileFinder.path_hook(*supported_loaders)])
fa50f4
     sys.meta_path.append(PathFinder)
fa50f4
+
fa50f4
+
fa50f4
+_ARCH_MAP = {
fa50f4
+    "-arm-linux-gnueabi.": "-arm-linux-gnueabihf.",
fa50f4
+    "-armeb-linux-gnueabi.": "-armeb-linux-gnueabihf.",
fa50f4
+    "-mips64-linux-gnu.": "-mips64-linux-gnuabi64.",
fa50f4
+    "-mips64el-linux-gnu.": "-mips64el-linux-gnuabi64.",
fa50f4
+    "-ppc-linux-gnu.": "-powerpc-linux-gnu.",
fa50f4
+    "-ppc-linux-gnuspe.": "-powerpc-linux-gnuspe.",
fa50f4
+    "-ppc64-linux-gnu.": "-powerpc64-linux-gnu.",
fa50f4
+    "-ppc64le-linux-gnu.": "-powerpc64le-linux-gnu.",
fa50f4
+    # The above, but the other way around:
fa50f4
+    "-arm-linux-gnueabihf.": "-arm-linux-gnueabi.",
fa50f4
+    "-armeb-linux-gnueabihf.": "-armeb-linux-gnueabi.",
fa50f4
+    "-mips64-linux-gnuabi64.": "-mips64-linux-gnu.",
fa50f4
+    "-mips64el-linux-gnuabi64.": "-mips64el-linux-gnu.",
fa50f4
+    "-powerpc-linux-gnu.": "-ppc-linux-gnu.",
fa50f4
+    "-powerpc-linux-gnuspe.": "-ppc-linux-gnuspe.",
fa50f4
+    "-powerpc64-linux-gnu.": "-ppc64-linux-gnu.",
fa50f4
+    "-powerpc64le-linux-gnu.": "-ppc64le-linux-gnu.",
fa50f4
+}
fa50f4
+
fa50f4
+
fa50f4
+def _alternative_architectures(suffixes):
fa50f4
+    """Add a suffix with an alternative architecture name
fa50f4
+    to the list of suffixes so an extension built with
fa50f4
+    the default (upstream) setting is loadable with our Pythons
fa50f4
+    """
fa50f4
+
fa50f4
+    for suffix in suffixes:
fa50f4
+        for original, alternative in _ARCH_MAP.items():
fa50f4
+            if original in suffix:
fa50f4
+                suffixes.append(suffix.replace(original, alternative))
fa50f4
+                return suffixes
fa50f4
+
fa50f4
+    return suffixes