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

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