Skip to content

Commit 8eed6b1

Browse files
frenzymadnesshroncok
authored andcommitted
00353: Original names for architectures with different names downstream
https://fedoraproject.org/wiki/Changes/Python_Upstream_Architecture_Names Pythons in RHEL/Fedora used different names for some architectures than upstream and other distros (for example ppc64 vs. powerpc64). This was patched in patch 274, now it is sedded if %with legacy_archnames. That meant that an extension built with the default upstream settings (on other distro or as an manylinux wheel) could not been found by Python on RHEL/Fedora because it had a different suffix. This patch adds the legacy names to importlib so Python is able to import extensions with a legacy architecture name in its file name. It work both ways, so it support both %with and %without legacy_archnames. WARNING: This patch has no effect on Python built with bootstrap enabled because Python/importlib_external.h is not regenerated and therefore Python during bootstrap contains importlib from upstream without this feature. It's possible to include Python/importlib_external.h to this patch but it'd make rebasing a nightmare because it's basically a binary file. Co-authored-by: Miro Hrončok <miro@hroncok.cz>
1 parent 816d02c commit 8eed6b1

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

Lib/importlib/_bootstrap_external.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,7 +1484,7 @@ def _get_supported_file_loaders():
14841484
14851485
Each item is a tuple (loader, suffixes).
14861486
"""
1487-
extensions = ExtensionFileLoader, _imp.extension_suffixes()
1487+
extensions = ExtensionFileLoader, _alternative_architectures(_imp.extension_suffixes())
14881488
source = SourceFileLoader, SOURCE_SUFFIXES
14891489
bytecode = SourcelessFileLoader, BYTECODE_SUFFIXES
14901490
return [extensions, source, bytecode]
@@ -1547,7 +1547,7 @@ def _setup(_bootstrap_module):
15471547

15481548
# Constants
15491549
setattr(self_module, '_relax_case', _make_relax_case())
1550-
EXTENSION_SUFFIXES.extend(_imp.extension_suffixes())
1550+
EXTENSION_SUFFIXES.extend(_alternative_architectures(_imp.extension_suffixes()))
15511551
if builtin_os == 'nt':
15521552
SOURCE_SUFFIXES.append('.pyw')
15531553
if '_d.pyd' in EXTENSION_SUFFIXES:
@@ -1560,3 +1560,39 @@ def _install(_bootstrap_module):
15601560
supported_loaders = _get_supported_file_loaders()
15611561
sys.path_hooks.extend([FileFinder.path_hook(*supported_loaders)])
15621562
sys.meta_path.append(PathFinder)
1563+
1564+
1565+
_ARCH_MAP = {
1566+
"-arm-linux-gnueabi.": "-arm-linux-gnueabihf.",
1567+
"-armeb-linux-gnueabi.": "-armeb-linux-gnueabihf.",
1568+
"-mips64-linux-gnu.": "-mips64-linux-gnuabi64.",
1569+
"-mips64el-linux-gnu.": "-mips64el-linux-gnuabi64.",
1570+
"-ppc-linux-gnu.": "-powerpc-linux-gnu.",
1571+
"-ppc-linux-gnuspe.": "-powerpc-linux-gnuspe.",
1572+
"-ppc64-linux-gnu.": "-powerpc64-linux-gnu.",
1573+
"-ppc64le-linux-gnu.": "-powerpc64le-linux-gnu.",
1574+
# The above, but the other way around:
1575+
"-arm-linux-gnueabihf.": "-arm-linux-gnueabi.",
1576+
"-armeb-linux-gnueabihf.": "-armeb-linux-gnueabi.",
1577+
"-mips64-linux-gnuabi64.": "-mips64-linux-gnu.",
1578+
"-mips64el-linux-gnuabi64.": "-mips64el-linux-gnu.",
1579+
"-powerpc-linux-gnu.": "-ppc-linux-gnu.",
1580+
"-powerpc-linux-gnuspe.": "-ppc-linux-gnuspe.",
1581+
"-powerpc64-linux-gnu.": "-ppc64-linux-gnu.",
1582+
"-powerpc64le-linux-gnu.": "-ppc64le-linux-gnu.",
1583+
}
1584+
1585+
1586+
def _alternative_architectures(suffixes):
1587+
"""Add a suffix with an alternative architecture name
1588+
to the list of suffixes so an extension built with
1589+
the default (upstream) setting is loadable with our Pythons
1590+
"""
1591+
1592+
for suffix in suffixes:
1593+
for original, alternative in _ARCH_MAP.items():
1594+
if original in suffix:
1595+
suffixes.append(suffix.replace(original, alternative))
1596+
return suffixes
1597+
1598+
return suffixes

0 commit comments

Comments
 (0)