Skip to content

Commit 43b3f16

Browse files
committed
Fix clingo bootstrapping on rhel + ppc64le
The system Python interpreter on rhel is patched to have slightly different names for some architectures. This makes it incompatible with manylinux generated extensions for ppc64le. To fix this issue when bootstrapping Spack we generate on-the-fly symbolic links to the name expected by the current interpreter if it differs from the default. Links: pypa/manylinux#687 https://src.fedoraproject.org/fork/churchyard/rpms/python3/blame/00274-fix-arch-names.patch?identifier=test_email-mktime
1 parent f71d93f commit 43b3f16

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

lib/spack/spack/bootstrap.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
from __future__ import print_function
66

77
import contextlib
8+
import fnmatch
89
import json
910
import os
11+
import os.path
12+
import re
1013
import sys
1114

1215
try:
@@ -80,6 +83,7 @@ def _try_import_from_store(module, abstract_spec_str):
8083
sys.path.extend(module_paths)
8184

8285
try:
86+
_fix_ext_suffix(candidate_spec)
8387
if _python_import(module):
8488
msg = ('[BOOTSTRAP MODULE {0}] The installed spec "{1}/{2}" '
8589
'provides the "{0}" Python module').format(
@@ -100,6 +104,55 @@ def _try_import_from_store(module, abstract_spec_str):
100104
return False
101105

102106

107+
def _fix_ext_suffix(candidate_spec):
108+
"""Fix the external suffixes of Python extensions on the fly for
109+
platforms that may need it
110+
111+
Args:
112+
candidate_spec (Spec): installed spec with a Python module
113+
to be checked.
114+
"""
115+
# Here we map target families to the patterns expected
116+
# by pristine CPython. Only architectures with known issues
117+
# are included. Known issues:
118+
#
119+
# [RHEL + ppc64le]: https://github.com/spack/spack/issues/25734
120+
#
121+
_suffix_to_be_checked = {
122+
'ppc64le': {
123+
'glob': '*.cpython-*-powerpc64le-linux-gnu.so',
124+
're': r'.cpython-[\w]*-powerpc64le-linux-gnu.so'
125+
}
126+
}
127+
128+
# If the current architecture is not problematic return
129+
generic_target = archspec.cpu.host().family
130+
if str(generic_target) not in _suffix_to_be_checked:
131+
return
132+
133+
# If there's no EXT_SUFFIX (Python < 3.5) or the suffix matches
134+
# the expectations, return since the package is surely good
135+
ext_suffix = sysconfig.get_config_var('EXT_SUFFIX')
136+
if ext_suffix is None:
137+
return
138+
139+
expected = _suffix_to_be_checked[str(generic_target)]
140+
if fnmatch.fnmatch(ext_suffix, expected['glob']):
141+
return
142+
143+
# If we are here it means the current interpreter expects different names
144+
# than pristine CPython. So:
145+
# 1. Find what we have
146+
# 2. Compute what we want
147+
# 3. Create symbolic links if they're not there already
148+
extensions_on_disk = fs.find(candidate_spec.prefix, expected['glob'])
149+
link_names = [re.sub(expected['re'], ext_suffix, s) for s in extensions_on_disk]
150+
for file_name, link_name in zip(extensions_on_disk, link_names):
151+
if os.path.exists(link_name):
152+
continue
153+
os.symlink(file_name, link_name)
154+
155+
103156
@_bootstrapper(type='buildcache')
104157
class _BuildcacheBootstrapper(object):
105158
"""Install the software needed during bootstrapping from a buildcache."""

0 commit comments

Comments
 (0)