]> git.lizzy.rs Git - rust.git/blob - x.py
Discover channel for artifact download
[rust.git] / x.py
1 #!/usr/bin/env bash
2
3 # Modern Linux and macOS systems commonly only have a thing called `python3` and
4 # not `python`, while Windows commonly does not have `python3`, so we cannot
5 # directly use python in the shebang and have it consistently work. Instead we
6 # embed some bash to look for a python to run the rest of the script.
7 #
8 # On Windows, `py -3` sometimes works. We need to try it first because `python3`
9 # sometimes tries to launch the app store on Windows.
10 '''':
11 for PYTHON in "py -3" python3 python python2; do
12     if command -v $PYTHON >/dev/null; then
13         exec $PYTHON "$0" "$@"
14         break
15     fi
16 done
17 echo "$0: error: did not find python installed" >&2
18 exit 1
19 '''
20
21 # The rest of this file is Python.
22 #
23 # This file is only a "symlink" to bootstrap.py, all logic should go there.
24
25 import os
26 import sys
27
28 # If this is python2, check if python3 is available and re-execute with that
29 # interpreter.
30 #
31 # `./x.py` would not normally benefit from this because the bash above tries
32 # python3 before 2, but this matters if someone ran `python x.py` and their
33 # system's `python` is python2.
34 if sys.version_info.major < 3:
35     try:
36         os.execvp("py", ["py", "-3"] + sys.argv)
37     except OSError:
38         try:
39             os.execvp("python3", ["python3"] + sys.argv)
40         except OSError:
41             # Python 3 isn't available, fall back to python 2
42             pass
43
44 rust_dir = os.path.dirname(os.path.abspath(__file__))
45 sys.path.append(os.path.join(rust_dir, "src", "bootstrap"))
46
47 import bootstrap
48 bootstrap.main()