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

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