Skip to content

Commit 18ec4a9

Browse files
committed
Auto merge of rust-lang#80625 - jyn514:python-what-python, r=Mark-Simulacrum
Choose the version of python at runtime (portable version) r? `@Mark-Simulacrum` Fixed version of rust-lang#80585. The goal is to avoid giving 'error: python3 required' when downloading LLVM from CI and instead default to python3 where possible. This has some minor overhead when you have `python` as python2, but almost nothing compared to actually running the build.
2 parents 4e208f6 + c8cac2a commit 18ec4a9

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

x.py

+16
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@
44

55
import os
66
import sys
7+
8+
# If this is python2, check if python3 is available and re-execute with that
9+
# interpreter.
10+
if sys.version_info.major < 3:
11+
try:
12+
# On Windows, `py -3` sometimes works.
13+
# Try this first, because 'python3' sometimes tries to launch the app
14+
# store on Windows
15+
os.execvp("py", ["py", "-3"] + sys.argv)
16+
except OSError:
17+
try:
18+
os.execvp("python3", ["python3"] + sys.argv)
19+
except OSError:
20+
# Python 3 isn't available, fall back to python 2
21+
pass
22+
723
rust_dir = os.path.dirname(os.path.abspath(__file__))
824
sys.path.append(os.path.join(rust_dir, "src", "bootstrap"))
925

0 commit comments

Comments
 (0)