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

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