Skip to content

Commit 3ae8244

Browse files
committed
Fix upstream QEMU build from a venv
This code should have been added to the base class not just the CHERI one.
1 parent e110d69 commit 3ae8244

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

pycheribuild/projects/build_qemu.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,25 @@ def setup(self):
315315
"--make=" + self.make_args.command,
316316
],
317317
)
318+
python_bin = sys.executable
319+
python_search_path = self.config.dollar_path_with_other_tools
320+
# Python from a venv cannot be used for QEMU builds, use the base installation instead.
321+
if sys.prefix != sys.base_prefix:
322+
python_bin = sys.executable.replace(sys.prefix, sys.base_prefix)
323+
python_search_path = python_search_path.replace(sys.prefix, sys.base_prefix)
324+
py3_version = get_program_version(
325+
Path(python_bin),
326+
config=self.config,
327+
regex=re.compile(rb"Python\s+(\d+)\.(\d+)\.?(\d+)?"),
328+
)
329+
# QEMU tests are not compatible with 3.12 yet, try to use an older version in that case
330+
if py3_version >= (3, 12, 0):
331+
for minor_version in (11, 10, 9):
332+
found = shutil.which(f"python3.{minor_version}", path=python_search_path)
333+
if found:
334+
python_bin = found
335+
break
336+
self.configure_args.append(f"--python={python_bin}")
318337

319338
if self.config.create_compilation_db:
320339
self.make_args.set(V=1) # Otherwise bear can't parse the compiler output
@@ -505,25 +524,6 @@ def setup(self):
505524
# Linux/BSD-user is not supported for CHERI (yet)
506525
self.configure_args.append("--disable-bsd-user")
507526
self.configure_args.append("--disable-linux-user")
508-
python_bin = sys.executable
509-
python_search_path = self.config.dollar_path_with_other_tools
510-
# Python from a venv cannot be used for QEMU builds, use the base installation instead.
511-
if sys.prefix != sys.base_prefix:
512-
python_bin = sys.executable.replace(sys.prefix, sys.base_prefix)
513-
python_search_path = python_search_path.replace(sys.prefix, sys.base_prefix)
514-
py3_version = get_program_version(
515-
Path(python_bin),
516-
config=self.config,
517-
regex=re.compile(rb"Python\s+(\d+)\.(\d+)\.?(\d+)?"),
518-
)
519-
# QEMU tests are not compatible with 3.12 yet, try to use an older version in that case
520-
if py3_version >= (3, 12, 0):
521-
for minor_version in (11, 10, 9):
522-
found = shutil.which(f"python3.{minor_version}", path=python_search_path)
523-
if found:
524-
python_bin = found
525-
break
526-
self.configure_args.append(f"--python={python_bin}")
527527

528528
# TODO: tests:
529529
# noinspection PyUnreachableCode

0 commit comments

Comments
 (0)