Skip to content

Commit c325700

Browse files
committed
QEMU: prefer python 3.11 over 3.12 if both are available
The QEMU testsuite does not work with python 3.12 yet.
1 parent 98b5081 commit c325700

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

pycheribuild/projects/build_qemu.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
# SUCH DAMAGE.
2929
#
3030
import os
31+
import re
32+
import shutil
3133
import sys
3234
import typing
3335
from contextlib import suppress
@@ -49,6 +51,7 @@
4951
)
5052
from .simple_project import BoolConfigOption, SimpleProject, _cached_get_homebrew_prefix
5153
from ..config.compilation_targets import BaremetalFreestandingTargetInfo, CompilationTargets
54+
from ..processutils import get_program_version
5255
from ..utils import OSInfo
5356

5457

@@ -490,6 +493,26 @@ def setup(self):
490493
# Linux/BSD-user is not supported for CHERI (yet)
491494
self.configure_args.append("--disable-bsd-user")
492495
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+
493516
# TODO: tests:
494517
# noinspection PyUnreachableCode
495518
if False:

0 commit comments

Comments
 (0)