diff --git a/x.py b/x.py index 928a7496cb70e..7c5b665a10391 100755 --- a/x.py +++ b/x.py @@ -2,10 +2,11 @@ # Some systems don't have `python3` in their PATH. This isn't supported by x.py directly; # they should use `x` or `x.ps1` instead. -# This file is only a "symlink" to bootstrap.py, all logic should go there. +# This file is only a "symlink" to bootstrap.py; all logic should go there. # Parts of `bootstrap.py` use the `multiprocessing` module, so this entry point # must use the normal `if __name__ == '__main__':` convention to avoid problems. + if __name__ == "__main__": import os import sys @@ -29,7 +30,7 @@ # Python 3 isn't available, fall back to python 2 pass - # soft deprecation of old python versions + # Soft deprecation of old python versions skip_check = os.environ.get("RUST_IGNORE_OLD_PYTHON") == "1" if not skip_check and (major < 3 or (major == 3 and minor < 6)): msg = cleandoc( @@ -40,14 +41,25 @@ please file an issue to help us understand timelines. This message can be suppressed by setting `RUST_IGNORE_OLD_PYTHON=1` - """.format(major, minor) + """.format(major, minor) ) - warnings.warn(msg, stacklevel=1) + warnings.warn(msg, stacklevel=2) rust_dir = os.path.dirname(os.path.abspath(__file__)) + bootstrap_path = os.path.join(rust_dir, "src", "bootstrap") + + # Ensure bootstrap directory exists for clearer errors + if not os.path.isdir(bootstrap_path): + sys.exit( + "Error: expected bootstrap directory not found at {}".format(bootstrap_path) + ) + # For the import below, have Python search in src/bootstrap first. - sys.path.insert(0, os.path.join(rust_dir, "src", "bootstrap")) + sys.path.insert(0, bootstrap_path) - import bootstrap + try: + import bootstrap + except ImportError as e: + sys.exit("Error importing bootstrap module: {}".format(e)) bootstrap.main()