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