diff options
author | Vincent Fazio <vfazio@gmail.com> | 2024-10-16 22:01:42 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-16 22:01:42 (GMT) |
commit | aecbc2e6f40f8066f478c2d0f3be5b550e36cfd3 (patch) | |
tree | c696c759f5ab92089bcf02a08ed9a43afdf317b5 /Lib/sysconfig | |
parent | aab3210271136ad8e8fecd927b806602c463e1f2 (diff) | |
download | cpython-aecbc2e6f40f8066f478c2d0f3be5b550e36cfd3.zip cpython-aecbc2e6f40f8066f478c2d0f3be5b550e36cfd3.tar.gz cpython-aecbc2e6f40f8066f478c2d0f3be5b550e36cfd3.tar.bz2 |
gh-115382: Fix cross compiles when host and target use same SOABI
Co-authored-by: Erlend E. Aasland <erlend@python.org>
Diffstat (limited to 'Lib/sysconfig')
-rw-r--r-- | Lib/sysconfig/__init__.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/Lib/sysconfig/__init__.py b/Lib/sysconfig/__init__.py index 80aef34..43f9276 100644 --- a/Lib/sysconfig/__init__.py +++ b/Lib/sysconfig/__init__.py @@ -340,7 +340,20 @@ def _init_posix(vars): """Initialize the module as appropriate for POSIX systems.""" # _sysconfigdata is generated at build time, see _generate_posix_vars() name = _get_sysconfigdata_name() - _temp = __import__(name, globals(), locals(), ['build_time_vars'], 0) + + # For cross builds, the path to the target's sysconfigdata must be specified + # so it can be imported. It cannot be in PYTHONPATH, as foreign modules in + # sys.path can cause crashes when loaded by the host interpreter. + # Rely on truthiness as a valueless env variable is still an empty string. + # See OS X note in _generate_posix_vars re _sysconfigdata. + if (path := os.environ.get('_PYTHON_SYSCONFIGDATA_PATH')): + from importlib.machinery import FileFinder, SourceFileLoader, SOURCE_SUFFIXES + from importlib.util import module_from_spec + spec = FileFinder(path, (SourceFileLoader, SOURCE_SUFFIXES)).find_spec(name) + _temp = module_from_spec(spec) + spec.loader.exec_module(_temp) + else: + _temp = __import__(name, globals(), locals(), ['build_time_vars'], 0) build_time_vars = _temp.build_time_vars vars.update(build_time_vars) |