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

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