1#!/usr/bin/env python3
2# Some systems don't have `python3` in their PATH. This isn't supported by x.py directly;
3# they should use `x` or `x.ps1` instead.
4
5# This file is only a "symlink" to bootstrap.py, all logic should go there.
6
7# Parts of `bootstrap.py` use the `multiprocessing` module, so this entry point
8# must use the normal `if __name__ == '__main__':` convention to avoid problems.
9if __name__ == "__main__":
10 import os
11 import sys
12 import warnings
13 from inspect import cleandoc
14
15 major = sys.version_info.major
16 minor = sys.version_info.minor
17
18 # If this is python2, check if python3 is available and re-execute with that
19 # interpreter. Only python3 allows downloading CI LLVM.
20 #
21 # This matters if someone's system `python` is python2.
22 if major < 3:
23 try:
24 os.execvp("py", ["py", "-3"] + sys.argv)
25 except OSError:
26 try:
27 os.execvp("python3", ["python3"] + sys.argv)
28 except OSError:
29 # Python 3 isn't available, fall back to python 2
30 pass
31
32 # soft deprecation of old python versions
33 skip_check = os.environ.get("RUST_IGNORE_OLD_PYTHON") == "1"
34 if not skip_check and (major < 3 or (major == 3 and minor < 6)):
35 msg = cleandoc(
36 """
37 Using python {}.{} but >= 3.6 is recommended. Your python version
38 should continue to work for the near future, but this will
39 eventually change. If python >= 3.6 is not available on your system,
40 please file an issue to help us understand timelines.
41
42 This message can be suppressed by setting `RUST_IGNORE_OLD_PYTHON=1`
43 """.format(major, minor)
44 )
45 warnings.warn(msg, stacklevel=1)
46
47 rust_dir = os.path.dirname(os.path.abspath(__file__))
48 # For the import below, have Python search in src/bootstrap first.
49 sys.path.insert(0, os.path.join(rust_dir, "src", "bootstrap"))
50
51 import bootstrap
52
53 bootstrap.main()