diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index d5efed61b541e..7d4ac93ea2397 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -66,7 +66,7 @@ def download(path, url, probably_big, verbose): def _download(path, url, probably_big, verbose, exception): if probably_big or verbose: print("downloading {}".format(url)) - # see http://serverfault.com/questions/301128/how-to-download + # See http://serverfault.com/questions/301128/how-to-download. if sys.platform == 'win32': run(["PowerShell.exe", "/nologo", "-Command", "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;", @@ -79,7 +79,7 @@ def _download(path, url, probably_big, verbose, exception): else: option = "-s" run(["curl", option, - "-y", "30", "-Y", "10", # timeout if speed is < 10 bytes/sec for > 30 seconds + "-y", "30", "-Y", "10", # timeout if speed is < 10 bytes/sec for > 30 seconds "--connect-timeout", "30", # timeout if cannot connect within 30 seconds "--retry", "3", "-Sf", "-o", path, url], verbose=verbose, @@ -131,7 +131,7 @@ def run(args, verbose=False, exception=False, **kwargs): if verbose: print("running: " + ' '.join(args)) sys.stdout.flush() - # Use Popen here instead of call() as it apparently allows powershell on + # Use `Popen` here instead of `call()` as it apparently allows powershell on # Windows to not lock up waiting for input presumably. ret = subprocess.Popen(args, **kwargs) code = ret.wait() @@ -660,6 +660,7 @@ def bootstrap_binary(self): def build_bootstrap(self): """Build bootstrap""" + build_dir = os.path.join(self.build_dir, "bootstrap") if self.clean and os.path.exists(build_dir): shutil.rmtree(build_dir) @@ -680,7 +681,7 @@ def build_bootstrap(self): env["LIBRARY_PATH"] = os.path.join(self.bin_root(), "lib") + \ (os.pathsep + env["LIBRARY_PATH"]) \ if "LIBRARY_PATH" in env else "" - # preserve existing RUSTFLAGS + # Preserve existing `RUSTFLAGS`. env.setdefault("RUSTFLAGS", "") env["RUSTFLAGS"] += " -Cdebuginfo=2" @@ -748,7 +749,7 @@ def update_submodule(self, module, checked_out, recorded_submodules): "--init", "--recursive", "--progress", module], cwd=self.rust_root, verbose=self.verbose, exception=True) except RuntimeError: - # Some versions of git don't support --progress. + # Some versions of Git don't support `--progress`. run(["git", "submodule", "update", "--init", "--recursive", module], cwd=self.rust_root, verbose=self.verbose) @@ -763,7 +764,7 @@ def update_submodules(self): self.get_toml('submodules') == "false": return - # check the existence of 'git' command + # Check for the existence of the `git` executable. try: subprocess.check_output(['git', '--version']) except (subprocess.CalledProcessError, OSError): @@ -878,7 +879,7 @@ def bootstrap(help_triggered): args = [a for a in sys.argv if a != '-h' and a != '--help'] args, _ = parser.parse_known_args(args) - # Configure initial bootstrap + # Configure initial bootstrap. build = RustBuild() build.rust_root = args.src or os.path.abspath(os.path.join(__file__, '../../..')) build.verbose = args.verbose @@ -944,7 +945,7 @@ def main(): """Entry point for the bootstrap process""" start_time = time() - # x.py help ... + # `x.py help ...` if len(sys.argv) > 1 and sys.argv[1] == 'help': sys.argv = [sys.argv[0], '-h'] + sys.argv[2:] diff --git a/src/bootstrap/sanity.rs b/src/bootstrap/sanity.rs index 1760d655b3b4e..64e417bc2588b 100644 --- a/src/bootstrap/sanity.rs +++ b/src/bootstrap/sanity.rs @@ -1,4 +1,4 @@ -//! Sanity checking performed by rustbuild before actually executing anything. +//! Sanity-checking performed by rustbuild before actually executing anything. //! //! This module contains the implementation of ensuring that the build //! environment looks reasonable before progressing. This will verify that @@ -41,10 +41,10 @@ impl Finder { let mut cmd_exe = cmd.clone(); cmd_exe.push(".exe"); - if target.is_file() // some/path/git - || path.join(&cmd_exe).exists() // some/path/git.exe + if target.is_file() // `some/path/git` + || path.join(&cmd_exe).exists() // `some/path/git.exe` || target.join(&cmd_exe).exists() - // some/path/git/git.exe + // `some/path/git/git.exe` { return Some(target); } @@ -68,7 +68,7 @@ pub fn check(build: &mut Build) { // being unable to identify the files properly. See // https://github.com/rust-lang/rust/issues/34959 for more details. if cfg!(windows) && path.to_string_lossy().contains('\"') { - panic!("PATH contains invalid character '\"'"); + panic!("`PATH` contains invalid character '\"'"); } let mut cmd_finder = Finder::new(); @@ -78,7 +78,7 @@ pub fn check(build: &mut Build) { cmd_finder.must_have("git"); } - // We need cmake, but only if we're actually building LLVM or sanitizers. + // We need CMake, but only if we're actually building LLVM or sanitizers. let building_llvm = build .hosts .iter() @@ -92,7 +92,17 @@ pub fn check(build: &mut Build) { }) .any(|build_llvm_ourselves| build_llvm_ourselves); if building_llvm || build.config.sanitizers { - cmd_finder.must_have("cmake"); + // Choose CMake executable with the following priority: + // 1. `CMAKE` env var, if set. + // 2. `cmake3`, if it exists. + // 3. `cmake`. + if let Some(cmake_path) = env::var_os("CMAKE") { + cmd_finder.must_have(cmake_path); + } else if cmd_finder.maybe_have("cmake3").is_some() { + env::set_var("CMAKE", "cmake3"); + } else { + cmd_finder.must_have("cmake"); + } } // Ninja is currently only used for LLVM itself. @@ -105,7 +115,7 @@ pub fn check(build: &mut Build) { } } - // If ninja isn't enabled but we're building for MSVC then we try + // If Ninja isn't enabled but we're building for MSVC then we try // doubly hard to enable it. It was realized in #43767 that the msbuild // CMake generator for MSVC doesn't respect configuration options like // disabling LLVM assertions, which can often be quite important! @@ -182,7 +192,7 @@ pub fn check(build: &mut Build) { // Externally configured LLVM requires FileCheck to exist let filecheck = build.llvm_filecheck(build.build); if !filecheck.starts_with(&build.out) && !filecheck.exists() && build.config.codegen_tests { - panic!("FileCheck executable {:?} does not exist", filecheck); + panic!("FileCheck executable `{:?}` does not exist", filecheck); } for target in &build.targets { @@ -210,13 +220,16 @@ pub fn check(build: &mut Build) { match build.musl_root(*target) { Some(root) => { if fs::metadata(root.join("lib/libc.a")).is_err() { - panic!("couldn't find libc.a in musl dir: {}", root.join("lib").display()); + panic!( + "couldn't find `libc.a` in musl dir: {}", + root.join("lib").display() + ); } } None => panic!( - "when targeting MUSL either the rust.musl-root \ - option or the target.$TARGET.musl-root option must \ - be specified in config.toml" + "when targeting MUSL, either the `rust.musl-root` \ + option or the `target.$TARGET.musl-root` option must \ + be specified in `config.toml`" ), } } @@ -225,7 +238,8 @@ pub fn check(build: &mut Build) { // There are three builds of cmake on windows: MSVC, MinGW, and // Cygwin. The Cygwin build does not have generators for Visual // Studio, so detect that here and error. - let out = output(Command::new("cmake").arg("--help")); + let cmake_path = env::var("CMAKE").unwrap_or("cmake".into()); + let out = output(Command::new(cmake_path).arg("--help")); if !out.contains("Visual Studio") { panic!( " @@ -254,7 +268,7 @@ $ pacman -R cmake && pacman -S mingw-w64-x86_64-cmake if stage0.contains("\ndev:") { panic!( "bootstrapping from a dev compiler in a stable release, but \ - should only be bootstrapping from a released compiler!" + should only be bootstrapping from a released compiler!" ); } }