Joshua Nelson | 775c3c0 | 2022-07-31 19:02:31 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # Some systems don't have `python3` in their PATH. This isn't supported by x.py directly; |
Josh Stone | de8dedb | 2022-08-12 22:39:26 | [diff] [blame] | 3 | # they should use `x` or `x.ps1` instead. |
Alex Crichton | a270b80 | 2016-10-21 20:18:09 | [diff] [blame] | 4 | |
Titus Barik | 04e4d42 | 2017-04-30 20:10:31 | [diff] [blame] | 5 | # This file is only a "symlink" to bootstrap.py, all logic should go there. |
Vadim Petrochenkov | 11adac3 | 2017-03-03 02:27:07 | [diff] [blame] | 6 | |
Albert Larsan | 3011949 | 2023-05-01 13:46:31 | [diff] [blame] | 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. |
Jakub Beránek | 536516f | 2024-12-04 22:02:25 | [diff] [blame] | 9 | if __name__ == "__main__": |
Albert Larsan | 3011949 | 2023-05-01 13:46:31 | [diff] [blame] | 10 | import os |
| 11 | import sys |
Trevor Gross | cec95d7 | 2023-06-10 03:55:26 | [diff] [blame] | 12 | import warnings |
| 13 | from inspect import cleandoc |
| 14 | |
| 15 | major = sys.version_info.major |
| 16 | minor = sys.version_info.minor |
Joshua Nelson | c8cac2a | 2021-01-01 16:52:31 | [diff] [blame] | 17 | |
Albert Larsan | 3011949 | 2023-05-01 13:46:31 | [diff] [blame] | 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. |
Trevor Gross | cec95d7 | 2023-06-10 03:55:26 | [diff] [blame] | 22 | if major < 3: |
Joshua Nelson | c8cac2a | 2021-01-01 16:52:31 | [diff] [blame] | 23 | try: |
Albert Larsan | 3011949 | 2023-05-01 13:46:31 | [diff] [blame] | 24 | os.execvp("py", ["py", "-3"] + sys.argv) |
Joshua Nelson | c8cac2a | 2021-01-01 16:52:31 | [diff] [blame] | 25 | except OSError: |
Albert Larsan | 3011949 | 2023-05-01 13:46:31 | [diff] [blame] | 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 |
Joshua Nelson | c8cac2a | 2021-01-01 16:52:31 | [diff] [blame] | 31 | |
Trevor Gross | cec95d7 | 2023-06-10 03:55:26 | [diff] [blame] | 32 | # soft deprecation of old python versions |
| 33 | skip_check = os.environ.get("RUST_IGNORE_OLD_PYTHON") == "1" |
Nilstrieb | f799e78 | 2023-06-24 17:45:42 | [diff] [blame] | 34 | if not skip_check and (major < 3 or (major == 3 and minor < 6)): |
Jakub Beránek | 536516f | 2024-12-04 22:02:25 | [diff] [blame] | 35 | msg = cleandoc( |
| 36 | """ |
Trevor Gross | cec95d7 | 2023-06-10 03:55:26 | [diff] [blame] | 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` |
Jakub Beránek | 536516f | 2024-12-04 22:02:25 | [diff] [blame] | 43 | """.format(major, minor) |
| 44 | ) |
Trevor Gross | 9df0f5d | 2023-06-22 05:59:24 | [diff] [blame] | 45 | warnings.warn(msg, stacklevel=1) |
Trevor Gross | cec95d7 | 2023-06-10 03:55:26 | [diff] [blame] | 46 | |
Albert Larsan | 3011949 | 2023-05-01 13:46:31 | [diff] [blame] | 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")) |
Alex Crichton | a270b80 | 2016-10-21 20:18:09 | [diff] [blame] | 50 | |
Albert Larsan | 3011949 | 2023-05-01 13:46:31 | [diff] [blame] | 51 | import bootstrap |
Jakub Beránek | 536516f | 2024-12-04 22:02:25 | [diff] [blame] | 52 | |
Albert Larsan | 3011949 | 2023-05-01 13:46:31 | [diff] [blame] | 53 | bootstrap.main() |