churchyard / rpms / python36

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