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