blob: 928a7496cb70ef2a6caf8e890fb09f12883a26e3 [file] [log] [blame]
Joshua Nelson775c3c02022-07-31 19:02:311#!/usr/bin/env python3
2# Some systems don't have `python3` in their PATH. This isn't supported by x.py directly;
Josh Stonede8dedb2022-08-12 22:39:263# they should use `x` or `x.ps1` instead.
Alex Crichtona270b802016-10-21 20:18:094
Titus Barik04e4d422017-04-30 20:10:315# This file is only a "symlink" to bootstrap.py, all logic should go there.
Vadim Petrochenkov11adac32017-03-03 02:27:076
Albert Larsan30119492023-05-01 13:46:317# Parts of `bootstrap.py` use the `multiprocessing` module, so this entry point
8# must use the normal `if __name__ == '__main__':` convention to avoid problems.
Jakub Beránek536516f2024-12-04 22:02:259if __name__ == "__main__":
Albert Larsan30119492023-05-01 13:46:3110 import os
11 import sys
Trevor Grosscec95d72023-06-10 03:55:2612 import warnings
13 from inspect import cleandoc
14
15 major = sys.version_info.major
16 minor = sys.version_info.minor
Joshua Nelsonc8cac2a2021-01-01 16:52:3117
Albert Larsan30119492023-05-01 13:46:3118 # 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.
Trevor Grosscec95d72023-06-10 03:55:2622 if major < 3:
Joshua Nelsonc8cac2a2021-01-01 16:52:3123 try:
Albert Larsan30119492023-05-01 13:46:3124 os.execvp("py", ["py", "-3"] + sys.argv)
Joshua Nelsonc8cac2a2021-01-01 16:52:3125 except OSError:
Albert Larsan30119492023-05-01 13:46:3126 try:
27 os.execvp("python3", ["python3"] + sys.argv)
28 except OSError:
29 # Python 3 isn't available, fall back to python 2
30 pass
Joshua Nelsonc8cac2a2021-01-01 16:52:3131
Trevor Grosscec95d72023-06-10 03:55:2632 # soft deprecation of old python versions
33 skip_check = os.environ.get("RUST_IGNORE_OLD_PYTHON") == "1"
Nilstriebf799e782023-06-24 17:45:4234 if not skip_check and (major < 3 or (major == 3 and minor < 6)):
Jakub Beránek536516f2024-12-04 22:02:2535 msg = cleandoc(
36 """
Trevor Grosscec95d72023-06-10 03:55:2637 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`
Jakub Beránek536516f2024-12-04 22:02:2543 """.format(major, minor)
44 )
Trevor Gross9df0f5d2023-06-22 05:59:2445 warnings.warn(msg, stacklevel=1)
Trevor Grosscec95d72023-06-10 03:55:2646
Albert Larsan30119492023-05-01 13:46:3147 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"))
Alex Crichtona270b802016-10-21 20:18:0950
Albert Larsan30119492023-05-01 13:46:3151 import bootstrap
Jakub Beránek536516f2024-12-04 22:02:2552
Albert Larsan30119492023-05-01 13:46:3153 bootstrap.main()