|
28 | 28 | # SUCH DAMAGE.
|
29 | 29 | #
|
30 | 30 | import os
|
| 31 | +import re |
| 32 | +import shutil |
31 | 33 | import sys
|
32 | 34 | import typing
|
33 | 35 | from contextlib import suppress
|
|
49 | 51 | )
|
50 | 52 | from .simple_project import BoolConfigOption, SimpleProject, _cached_get_homebrew_prefix
|
51 | 53 | from ..config.compilation_targets import BaremetalFreestandingTargetInfo, CompilationTargets
|
| 54 | +from ..processutils import get_program_version |
52 | 55 | from ..utils import OSInfo
|
53 | 56 |
|
54 | 57 |
|
@@ -490,6 +493,26 @@ def setup(self):
|
490 | 493 | # Linux/BSD-user is not supported for CHERI (yet)
|
491 | 494 | self.configure_args.append("--disable-bsd-user")
|
492 | 495 | self.configure_args.append("--disable-linux-user")
|
| 496 | + python_bin = sys.executable |
| 497 | + python_search_path = self.config.dollar_path_with_other_tools |
| 498 | + # Python from a venv cannot be used for QEMU builds, use the base installation instead. |
| 499 | + if sys.prefix != sys.base_prefix: |
| 500 | + python_bin = sys.executable.replace(sys.prefix, sys.base_prefix) |
| 501 | + python_search_path = python_search_path.replace(sys.prefix, sys.base_prefix) |
| 502 | + py3_version = get_program_version( |
| 503 | + Path(python_bin), |
| 504 | + config=self.config, |
| 505 | + regex=re.compile(b"Python\\s+(\\d+)\\.(\\d+)\\.?(\\d+)?"), |
| 506 | + ) |
| 507 | + # QEMU tests are not compatible with 3.12 yet, try to use an older version in that case |
| 508 | + if py3_version >= (3, 12, 0): |
| 509 | + for minor_version in (11, 10, 9): |
| 510 | + found = shutil.which(f"python3.{minor_version}", path=python_search_path) |
| 511 | + if found: |
| 512 | + python_bin = found |
| 513 | + break |
| 514 | + self.configure_args.append(f"--python={python_bin}") |
| 515 | + |
493 | 516 | # TODO: tests:
|
494 | 517 | # noinspection PyUnreachableCode
|
495 | 518 | if False:
|
|
0 commit comments