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

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