Skip to content

Commit 4def1bc

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 06c1da1 commit 4def1bc

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
@@ -1361,7 +1361,7 @@ def _get_supported_file_loaders():
13611361
13621362
Each item is a tuple (loader, suffixes).
13631363
"""
1364-
extensions = ExtensionFileLoader, _imp.extension_suffixes()
1364+
extensions = ExtensionFileLoader, _alternative_architectures(_imp.extension_suffixes())
13651365
source = SourceFileLoader, SOURCE_SUFFIXES
13661366
bytecode = SourcelessFileLoader, BYTECODE_SUFFIXES
13671367
return [extensions, source, bytecode]
@@ -1428,7 +1428,7 @@ def _setup(_bootstrap_module):
14281428

14291429
# Constants
14301430
setattr(self_module, '_relax_case', _make_relax_case())
1431-
EXTENSION_SUFFIXES.extend(_imp.extension_suffixes())
1431+
EXTENSION_SUFFIXES.extend(_alternative_architectures(_imp.extension_suffixes()))
14321432
if builtin_os == 'nt':
14331433
SOURCE_SUFFIXES.append('.pyw')
14341434
if '_d.pyd' in EXTENSION_SUFFIXES:
@@ -1441,3 +1441,39 @@ def _install(_bootstrap_module):
14411441
supported_loaders = _get_supported_file_loaders()
14421442
sys.path_hooks.extend([FileFinder.path_hook(*supported_loaders)])
14431443
sys.meta_path.append(PathFinder)
1444+
1445+
1446+
_ARCH_MAP = {
1447+
"-arm-linux-gnueabi.": "-arm-linux-gnueabihf.",
1448+
"-armeb-linux-gnueabi.": "-armeb-linux-gnueabihf.",
1449+
"-mips64-linux-gnu.": "-mips64-linux-gnuabi64.",
1450+
"-mips64el-linux-gnu.": "-mips64el-linux-gnuabi64.",
1451+
"-ppc-linux-gnu.": "-powerpc-linux-gnu.",
1452+
"-ppc-linux-gnuspe.": "-powerpc-linux-gnuspe.",
1453+
"-ppc64-linux-gnu.": "-powerpc64-linux-gnu.",
1454+
"-ppc64le-linux-gnu.": "-powerpc64le-linux-gnu.",
1455+
# The above, but the other way around:
1456+
"-arm-linux-gnueabihf.": "-arm-linux-gnueabi.",
1457+
"-armeb-linux-gnueabihf.": "-armeb-linux-gnueabi.",
1458+
"-mips64-linux-gnuabi64.": "-mips64-linux-gnu.",
1459+
"-mips64el-linux-gnuabi64.": "-mips64el-linux-gnu.",
1460+
"-powerpc-linux-gnu.": "-ppc-linux-gnu.",
1461+
"-powerpc-linux-gnuspe.": "-ppc-linux-gnuspe.",
1462+
"-powerpc64-linux-gnu.": "-ppc64-linux-gnu.",
1463+
"-powerpc64le-linux-gnu.": "-ppc64le-linux-gnu.",
1464+
}
1465+
1466+
1467+
def _alternative_architectures(suffixes):
1468+
"""Add a suffix with an alternative architecture name
1469+
to the list of suffixes so an extension built with
1470+
the default (upstream) setting is loadable with our Pythons
1471+
"""
1472+
1473+
for suffix in suffixes:
1474+
for original, alternative in _ARCH_MAP.items():
1475+
if original in suffix:
1476+
suffixes.append(suffix.replace(original, alternative))
1477+
return suffixes
1478+
1479+
return suffixes

0 commit comments

Comments
 (0)