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

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