Skip to content

Commit 093aafb

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 <[email protected]>
1 parent a63d0e3 commit 093aafb

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
@@ -1645,7 +1645,7 @@ def _get_supported_file_loaders():
16451645
16461646
Each item is a tuple (loader, suffixes).
16471647
"""
1648-
extensions = ExtensionFileLoader, _imp.extension_suffixes()
1648+
extensions = ExtensionFileLoader, _alternative_architectures(_imp.extension_suffixes())
16491649
source = SourceFileLoader, SOURCE_SUFFIXES
16501650
bytecode = SourcelessFileLoader, BYTECODE_SUFFIXES
16511651
return [extensions, source, bytecode]
@@ -1701,7 +1701,7 @@ def _setup(_bootstrap_module):
17011701

17021702
# Constants
17031703
setattr(self_module, '_relax_case', _make_relax_case())
1704-
EXTENSION_SUFFIXES.extend(_imp.extension_suffixes())
1704+
EXTENSION_SUFFIXES.extend(_alternative_architectures(_imp.extension_suffixes()))
17051705
if builtin_os == 'nt':
17061706
SOURCE_SUFFIXES.append('.pyw')
17071707
if '_d.pyd' in EXTENSION_SUFFIXES:
@@ -1714,3 +1714,39 @@ def _install(_bootstrap_module):
17141714
supported_loaders = _get_supported_file_loaders()
17151715
sys.path_hooks.extend([FileFinder.path_hook(*supported_loaders)])
17161716
sys.meta_path.append(PathFinder)
1717+
1718+
1719+
_ARCH_MAP = {
1720+
"-arm-linux-gnueabi.": "-arm-linux-gnueabihf.",
1721+
"-armeb-linux-gnueabi.": "-armeb-linux-gnueabihf.",
1722+
"-mips64-linux-gnu.": "-mips64-linux-gnuabi64.",
1723+
"-mips64el-linux-gnu.": "-mips64el-linux-gnuabi64.",
1724+
"-ppc-linux-gnu.": "-powerpc-linux-gnu.",
1725+
"-ppc-linux-gnuspe.": "-powerpc-linux-gnuspe.",
1726+
"-ppc64-linux-gnu.": "-powerpc64-linux-gnu.",
1727+
"-ppc64le-linux-gnu.": "-powerpc64le-linux-gnu.",
1728+
# The above, but the other way around:
1729+
"-arm-linux-gnueabihf.": "-arm-linux-gnueabi.",
1730+
"-armeb-linux-gnueabihf.": "-armeb-linux-gnueabi.",
1731+
"-mips64-linux-gnuabi64.": "-mips64-linux-gnu.",
1732+
"-mips64el-linux-gnuabi64.": "-mips64el-linux-gnu.",
1733+
"-powerpc-linux-gnu.": "-ppc-linux-gnu.",
1734+
"-powerpc-linux-gnuspe.": "-ppc-linux-gnuspe.",
1735+
"-powerpc64-linux-gnu.": "-ppc64-linux-gnu.",
1736+
"-powerpc64le-linux-gnu.": "-ppc64le-linux-gnu.",
1737+
}
1738+
1739+
1740+
def _alternative_architectures(suffixes):
1741+
"""Add a suffix with an alternative architecture name
1742+
to the list of suffixes so an extension built with
1743+
the default (upstream) setting is loadable with our Pythons
1744+
"""
1745+
1746+
for suffix in suffixes:
1747+
for original, alternative in _ARCH_MAP.items():
1748+
if original in suffix:
1749+
suffixes.append(suffix.replace(original, alternative))
1750+
return suffixes
1751+
1752+
return suffixes

0 commit comments

Comments
 (0)