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

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