Skip to content

Commit ce7af22

Browse files
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 f1d7f25 commit ce7af22

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
@@ -1629,7 +1629,7 @@ def _get_supported_file_loaders():
16291629
16301630
Each item is a tuple (loader, suffixes).
16311631
"""
1632-
extensions = ExtensionFileLoader, _imp.extension_suffixes()
1632+
extensions = ExtensionFileLoader, _alternative_architectures(_imp.extension_suffixes())
16331633
source = SourceFileLoader, SOURCE_SUFFIXES
16341634
bytecode = SourcelessFileLoader, BYTECODE_SUFFIXES
16351635
return [extensions, source, bytecode]
@@ -1693,7 +1693,7 @@ def _setup(_bootstrap_module):
16931693

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

0 commit comments

Comments
 (0)