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

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