diff options
| author | Mark Rousskov <mark.simulacrum@gmail.com> | 2019-12-22 17:42:04 -0500 |
|---|---|---|
| committer | Mark Rousskov <mark.simulacrum@gmail.com> | 2019-12-22 17:42:47 -0500 |
| commit | a06baa56b95674fc626b3c3fd680d6a65357fe60 (patch) | |
| tree | cd9d867c2ca3cff5c1d6b3bd73377c44649fb075 /src/bootstrap | |
| parent | 8eb7c58dbb7b32701af113bc58722d0d1fefb1eb (diff) | |
| download | rust-a06baa56b95674fc626b3c3fd680d6a65357fe60.tar.gz rust-a06baa56b95674fc626b3c3fd680d6a65357fe60.zip | |
Format the world
Diffstat (limited to 'src/bootstrap')
| -rw-r--r-- | src/bootstrap/bin/llvm-config-wrapper.rs | 2 | ||||
| -rw-r--r-- | src/bootstrap/bin/main.rs | 2 | ||||
| -rw-r--r-- | src/bootstrap/bin/rustc.rs | 46 | ||||
| -rw-r--r-- | src/bootstrap/bin/rustdoc.rs | 16 | ||||
| -rw-r--r-- | src/bootstrap/bin/sccache-plus-cl.rs | 12 | ||||
| -rw-r--r-- | src/bootstrap/builder.rs | 128 | ||||
| -rw-r--r-- | src/bootstrap/builder/tests.rs | 379 | ||||
| -rw-r--r-- | src/bootstrap/cache.rs | 46 | ||||
| -rw-r--r-- | src/bootstrap/cc_detect.rs | 61 | ||||
| -rw-r--r-- | src/bootstrap/channel.rs | 31 | ||||
| -rw-r--r-- | src/bootstrap/check.rs | 89 | ||||
| -rw-r--r-- | src/bootstrap/clean.rs | 12 | ||||
| -rw-r--r-- | src/bootstrap/compile.rs | 272 | ||||
| -rw-r--r-- | src/bootstrap/config.rs | 69 | ||||
| -rw-r--r-- | src/bootstrap/dist.rs | 1010 | ||||
| -rw-r--r-- | src/bootstrap/doc.rs | 163 | ||||
| -rw-r--r-- | src/bootstrap/flags.rs | 97 | ||||
| -rw-r--r-- | src/bootstrap/job.rs | 56 | ||||
| -rw-r--r-- | src/bootstrap/lib.rs | 251 | ||||
| -rw-r--r-- | src/bootstrap/metadata.rs | 25 | ||||
| -rw-r--r-- | src/bootstrap/native.rs | 235 | ||||
| -rw-r--r-- | src/bootstrap/sanity.rs | 103 | ||||
| -rw-r--r-- | src/bootstrap/test.rs | 488 | ||||
| -rw-r--r-- | src/bootstrap/tool.rs | 203 | ||||
| -rw-r--r-- | src/bootstrap/toolstate.rs | 65 | ||||
| -rw-r--r-- | src/bootstrap/util.rs | 129 |
26 files changed, 1836 insertions, 2154 deletions
diff --git a/src/bootstrap/bin/llvm-config-wrapper.rs b/src/bootstrap/bin/llvm-config-wrapper.rs index 5e3625eb22e..cf77af44ff6 100644 --- a/src/bootstrap/bin/llvm-config-wrapper.rs +++ b/src/bootstrap/bin/llvm-config-wrapper.rs @@ -2,8 +2,8 @@ // `src/bootstrap/native.rs` for why this is needed when compiling LLD. use std::env; -use std::process::{self, Stdio, Command}; use std::io::{self, Write}; +use std::process::{self, Command, Stdio}; fn main() { let real_llvm_config = env::var_os("LLVM_CONFIG_REAL").unwrap(); diff --git a/src/bootstrap/bin/main.rs b/src/bootstrap/bin/main.rs index 138b7f4b261..b67486c9628 100644 --- a/src/bootstrap/bin/main.rs +++ b/src/bootstrap/bin/main.rs @@ -7,7 +7,7 @@ use std::env; -use bootstrap::{Config, Build}; +use bootstrap::{Build, Config}; fn main() { let args = env::args().skip(1).collect::<Vec<_>>(); diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index 475f2e90463..a34ec44566b 100644 --- a/src/bootstrap/bin/rustc.rs +++ b/src/bootstrap/bin/rustc.rs @@ -27,9 +27,7 @@ fn main() { // Detect whether or not we're a build script depending on whether --target // is passed (a bit janky...) - let target = args.windows(2) - .find(|w| &*w[0] == "--target") - .and_then(|w| w[1].to_str()); + let target = args.windows(2).find(|w| &*w[0] == "--target").and_then(|w| w[1].to_str()); let version = args.iter().find(|w| &**w == "-vV"); let verbose = match env::var("RUSTC_VERBOSE") { @@ -57,19 +55,16 @@ fn main() { dylib_path.insert(0, PathBuf::from(&libdir)); let mut cmd = Command::new(rustc); - cmd.args(&args) - .env(bootstrap::util::dylib_path_var(), - env::join_paths(&dylib_path).unwrap()); + cmd.args(&args).env(bootstrap::util::dylib_path_var(), env::join_paths(&dylib_path).unwrap()); // Get the name of the crate we're compiling, if any. - let crate_name = args.windows(2) - .find(|args| args[0] == "--crate-name") - .and_then(|args| args[1].to_str()); + let crate_name = + args.windows(2).find(|args| args[0] == "--crate-name").and_then(|args| args[1].to_str()); if let Some(crate_name) = crate_name { if let Some(target) = env::var_os("RUSTC_TIME") { - if target == "all" || - target.into_string().unwrap().split(",").any(|c| c.trim() == crate_name) + if target == "all" + || target.into_string().unwrap().split(",").any(|c| c.trim() == crate_name) { cmd.arg("-Ztime"); } @@ -101,15 +96,22 @@ fn main() { // `compiler_builtins` are unconditionally compiled with panic=abort to // workaround undefined references to `rust_eh_unwind_resume` generated // otherwise, see issue https://github.com/rust-lang/rust/issues/43095. - if crate_name == Some("panic_abort") || - crate_name == Some("compiler_builtins") && stage != "0" { + if crate_name == Some("panic_abort") + || crate_name == Some("compiler_builtins") && stage != "0" + { cmd.arg("-C").arg("panic=abort"); } // Set various options from config.toml to configure how we're building // code. let debug_assertions = match env::var("RUSTC_DEBUG_ASSERTIONS") { - Ok(s) => if s == "true" { "y" } else { "n" }, + Ok(s) => { + if s == "true" { + "y" + } else { + "n" + } + } Err(..) => "n", }; @@ -178,17 +180,17 @@ fn main() { if env::var_os("RUSTC_PRINT_STEP_TIMINGS").is_some() { if let Some(crate_name) = crate_name { let start = Instant::now(); - let status = cmd - .status() - .unwrap_or_else(|_| panic!("\n\n failed to run {:?}", cmd)); + let status = cmd.status().unwrap_or_else(|_| panic!("\n\n failed to run {:?}", cmd)); let dur = start.elapsed(); let is_test = args.iter().any(|a| a == "--test"); - eprintln!("[RUSTC-TIMING] {} test:{} {}.{:03}", - crate_name, - is_test, - dur.as_secs(), - dur.subsec_nanos() / 1_000_000); + eprintln!( + "[RUSTC-TIMING] {} test:{} {}.{:03}", + crate_name, + is_test, + dur.as_secs(), + dur.subsec_nanos() / 1_000_000 + ); match status.code() { Some(i) => std::process::exit(i), diff --git a/src/bootstrap/bin/rustdoc.rs b/src/bootstrap/bin/rustdoc.rs index 6937fb922de..8c8b33a4e4e 100644 --- a/src/bootstrap/bin/rustdoc.rs +++ b/src/bootstrap/bin/rustdoc.rs @@ -3,9 +3,9 @@ //! See comments in `src/bootstrap/rustc.rs` for more information. use std::env; -use std::process::Command; -use std::path::PathBuf; use std::ffi::OsString; +use std::path::PathBuf; +use std::process::Command; fn main() { let args = env::args_os().skip(1).collect::<Vec<_>>(); @@ -35,8 +35,7 @@ fn main() { .arg("dox") .arg("--sysroot") .arg(&sysroot) - .env(bootstrap::util::dylib_path_var(), - env::join_paths(&dylib_path).unwrap()); + .env(bootstrap::util::dylib_path_var(), env::join_paths(&dylib_path).unwrap()); // Force all crates compiled by this compiler to (a) be unstable and (b) // allow the `rustc_private` feature to link to other unstable crates @@ -55,8 +54,7 @@ fn main() { if let Some(version) = env::var_os("RUSTDOC_CRATE_VERSION") { // This "unstable-options" can be removed when `--crate-version` is stabilized if !has_unstable { - cmd.arg("-Z") - .arg("unstable-options"); + cmd.arg("-Z").arg("unstable-options"); } cmd.arg("--crate-version").arg(version); has_unstable = true; @@ -66,8 +64,7 @@ fn main() { if let Some(_) = env::var_os("RUSTDOC_GENERATE_REDIRECT_PAGES") { // This "unstable-options" can be removed when `--generate-redirect-pages` is stabilized if !has_unstable { - cmd.arg("-Z") - .arg("unstable-options"); + cmd.arg("-Z").arg("unstable-options"); } cmd.arg("--generate-redirect-pages"); has_unstable = true; @@ -77,8 +74,7 @@ fn main() { if let Some(ref x) = env::var_os("RUSTDOC_RESOURCE_SUFFIX") { // This "unstable-options" can be removed when `--resource-suffix` is stabilized if !has_unstable { - cmd.arg("-Z") - .arg("unstable-options"); + cmd.arg("-Z").arg("unstable-options"); } cmd.arg("--resource-suffix").arg(x); } diff --git a/src/bootstrap/bin/sccache-plus-cl.rs b/src/bootstrap/bin/sccache-plus-cl.rs index f40eec83ddf..554c2dd4d81 100644 --- a/src/bootstrap/bin/sccache-plus-cl.rs +++ b/src/bootstrap/bin/sccache-plus-cl.rs @@ -8,12 +8,12 @@ fn main() { env::set_var("CXX", env::var_os("SCCACHE_CXX").unwrap()); let mut cfg = cc::Build::new(); cfg.cargo_metadata(false) - .out_dir("/") - .target(&target) - .host(&target) - .opt_level(0) - .warnings(false) - .debug(false); + .out_dir("/") + .target(&target) + .host(&target) + .opt_level(0) + .warnings(false) + .debug(false); let compiler = cfg.get_compiler(); // Invoke sccache with said compiler diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index bd0462fca6d..a2dca66697d 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -24,7 +24,7 @@ use crate::native; use crate::test; use crate::tool; use crate::util::{self, add_lib_path, exe, libdir}; -use crate::{Build, DocTests, Mode, GitRepo}; +use crate::{Build, DocTests, GitRepo, Mode}; pub use crate::Compiler; @@ -122,11 +122,7 @@ impl PathSet { fn path(&self, builder: &Builder<'_>) -> PathBuf { match self { - PathSet::Set(set) => set - .iter() - .next() - .unwrap_or(&builder.build.src) - .to_path_buf(), + PathSet::Set(set) => set.iter().next().unwrap_or(&builder.build.src).to_path_buf(), PathSet::Suite(path) => PathBuf::from(path), } } @@ -180,10 +176,8 @@ impl StepDescription { } fn run(v: &[StepDescription], builder: &Builder<'_>, paths: &[PathBuf]) { - let should_runs = v - .iter() - .map(|desc| (desc.should_run)(ShouldRun::new(builder))) - .collect::<Vec<_>>(); + let should_runs = + v.iter().map(|desc| (desc.should_run)(ShouldRun::new(builder))).collect::<Vec<_>>(); // sanity checks on rules for (desc, should_run) in v.iter().zip(&should_runs) { @@ -280,8 +274,7 @@ impl<'a> ShouldRun<'a> { // multiple aliases for the same job pub fn paths(mut self, paths: &[&str]) -> Self { - self.paths - .insert(PathSet::Set(paths.iter().map(PathBuf::from).collect())); + self.paths.insert(PathSet::Set(paths.iter().map(PathBuf::from).collect())); self } @@ -354,11 +347,9 @@ impl<'a> Builder<'a> { tool::Miri, native::Lld ), - Kind::Check | Kind::Clippy | Kind::Fix | Kind::Format => describe!( - check::Std, - check::Rustc, - check::Rustdoc - ), + Kind::Check | Kind::Clippy | Kind::Fix | Kind::Format => { + describe!(check::Std, check::Rustc, check::Rustdoc) + } Kind::Test => describe!( crate::toolstate::ToolStateCheck, test::Tidy, @@ -549,9 +540,7 @@ impl<'a> Builder<'a> { /// obtained through this function, since it ensures that they are valid /// (i.e., built and assembled). pub fn compiler(&self, stage: u32, host: Interned<String>) -> Compiler { - self.ensure(compile::Assemble { - target_compiler: Compiler { stage, host }, - }) + self.ensure(compile::Assemble { target_compiler: Compiler { stage, host } }) } /// Similar to `compiler`, except handles the full-bootstrap option to @@ -627,9 +616,10 @@ impl<'a> Builder<'a> { self.rustc_snapshot_libdir() } else { match self.config.libdir_relative() { - Some(relative_libdir) if compiler.stage >= 1 - => self.sysroot(compiler).join(relative_libdir), - _ => self.sysroot(compiler).join(libdir(&compiler.host)) + Some(relative_libdir) if compiler.stage >= 1 => { + self.sysroot(compiler).join(relative_libdir) + } + _ => self.sysroot(compiler).join(libdir(&compiler.host)), } } } @@ -644,9 +634,8 @@ impl<'a> Builder<'a> { libdir(&self.config.build).as_ref() } else { match self.config.libdir_relative() { - Some(relative_libdir) if compiler.stage >= 1 - => relative_libdir, - _ => libdir(&compiler.host).as_ref() + Some(relative_libdir) if compiler.stage >= 1 => relative_libdir, + _ => libdir(&compiler.host).as_ref(), } } } @@ -657,9 +646,8 @@ impl<'a> Builder<'a> { /// For example this returns `lib` on Unix and Windows. pub fn sysroot_libdir_relative(&self, compiler: Compiler) -> &Path { match self.config.libdir_relative() { - Some(relative_libdir) if compiler.stage >= 1 - => relative_libdir, - _ => Path::new("lib") + Some(relative_libdir) if compiler.stage >= 1 => relative_libdir, + _ => Path::new("lib"), } } @@ -681,9 +669,7 @@ impl<'a> Builder<'a> { if compiler.is_snapshot(self) { self.initial_rustc.clone() } else { - self.sysroot(compiler) - .join("bin") - .join(exe("rustc", &compiler.host)) + self.sysroot(compiler).join("bin").join(exe("rustc", &compiler.host)) } } @@ -740,17 +726,10 @@ impl<'a> Builder<'a> { self.clear_if_dirty(&my_out, &rustdoc); } - cargo - .env("CARGO_TARGET_DIR", out_dir) - .arg(cmd) - .arg("-Zconfig-profile"); + cargo.env("CARGO_TARGET_DIR", out_dir).arg(cmd).arg("-Zconfig-profile"); let profile_var = |name: &str| { - let profile = if self.config.rust_optimize { - "RELEASE" - } else { - "DEV" - }; + let profile = if self.config.rust_optimize { "RELEASE" } else { "DEV" }; format!("CARGO_PROFILE_{}_{}", profile, name) }; @@ -762,8 +741,7 @@ impl<'a> Builder<'a> { } if cmd != "install" { - cargo.arg("--target") - .arg(target); + cargo.arg("--target").arg(target); } else { assert_eq!(target, compiler.host); } @@ -801,14 +779,14 @@ impl<'a> Builder<'a> { } match mode { - Mode::Std | Mode::ToolBootstrap | Mode::ToolStd => {}, + Mode::Std | Mode::ToolBootstrap | Mode::ToolStd => {} Mode::Rustc | Mode::Codegen | Mode::ToolRustc => { // Build proc macros both for the host and the target if target != compiler.host && cmd != "check" { cargo.arg("-Zdual-proc-macros"); rustflags.arg("-Zdual-proc-macros"); } - }, + } } // This tells Cargo (and in turn, rustc) to output more complete @@ -884,11 +862,7 @@ impl<'a> Builder<'a> { assert!(!use_snapshot || stage == 0 || self.local_rebuild); let maybe_sysroot = self.sysroot(compiler); - let sysroot = if use_snapshot { - self.rustc_snapshot_sysroot() - } else { - &maybe_sysroot - }; + let sysroot = if use_snapshot { self.rustc_snapshot_sysroot() } else { &maybe_sysroot }; let libdir = self.rustc_libdir(compiler); // Customize the compiler we're running. Specify the compiler to cargo @@ -902,10 +876,7 @@ impl<'a> Builder<'a> { .env("RUSTC", self.out.join("bootstrap/debug/rustc")) .env("RUSTC_REAL", self.rustc(compiler)) .env("RUSTC_STAGE", stage.to_string()) - .env( - "RUSTC_DEBUG_ASSERTIONS", - self.config.rust_debug_assertions.to_string(), - ) + .env("RUSTC_DEBUG_ASSERTIONS", self.config.rust_debug_assertions.to_string()) .env("RUSTC_SYSROOT", &sysroot) .env("RUSTC_LIBDIR", &libdir) .env("RUSTDOC", self.out.join("bootstrap/debug/rustdoc")) @@ -948,7 +919,6 @@ impl<'a> Builder<'a> { // to change a flag in a binary? if self.config.rust_rpath && util::use_host_linker(&target) { let rpath = if target.contains("apple") { - // Note that we need to take one extra step on macOS to also pass // `-Wl,-instal_name,@rpath/...` to get things to work right. To // do that we pass a weird flag to the compiler to get it to do @@ -980,8 +950,9 @@ impl<'a> Builder<'a> { let debuginfo_level = match mode { Mode::Rustc | Mode::Codegen => self.config.rust_debuginfo_level_rustc, Mode::Std => self.config.rust_debuginfo_level_std, - Mode::ToolBootstrap | Mode::ToolStd | - Mode::ToolRustc => self.config.rust_debuginfo_level_tools, + Mode::ToolBootstrap | Mode::ToolStd | Mode::ToolRustc => { + self.config.rust_debuginfo_level_tools + } }; cargo.env(profile_var("DEBUG"), debuginfo_level.to_string()); @@ -1102,14 +1073,11 @@ impl<'a> Builder<'a> { cargo.env(format!("CC_{}", target), &cc); let cflags = self.cflags(target, GitRepo::Rustc).join(" "); - cargo - .env(format!("CFLAGS_{}", target), cflags.clone()); + cargo.env(format!("CFLAGS_{}", target), cflags.clone()); if let Some(ar) = self.ar(target) { let ranlib = format!("{} s", ar.display()); - cargo - .env(format!("AR_{}", target), ar) - .env(format!("RANLIB_{}", target), ranlib); + cargo.env(format!("AR_{}", target), ar).env(format!("RANLIB_{}", target), ranlib); } if let Ok(cxx) = self.cxx(target) { @@ -1120,15 +1088,14 @@ impl<'a> Builder<'a> { } } - if mode == Mode::Std - && self.config.extended - && compiler.is_final_stage(self) - { + if mode == Mode::Std && self.config.extended && compiler.is_final_stage(self) { rustflags.arg("-Zsave-analysis"); - cargo.env("RUST_SAVE_ANALYSIS_CONFIG", - "{\"output_file\": null,\"full_docs\": false,\ + cargo.env( + "RUST_SAVE_ANALYSIS_CONFIG", + "{\"output_file\": null,\"full_docs\": false,\ \"pub_only\": true,\"reachable_only\": false,\ - \"distro_crate\": true,\"signatures\": false,\"borrow_data\": false}"); + \"distro_crate\": true,\"signatures\": false,\"borrow_data\": false}", + ); } // For `cargo doc` invocations, make rustdoc print the Rust version into the docs @@ -1182,8 +1149,7 @@ impl<'a> Builder<'a> { } match (mode, self.config.rust_codegen_units_std, self.config.rust_codegen_units) { - (Mode::Std, Some(n), _) | - (_, _, Some(n)) => { + (Mode::Std, Some(n), _) | (_, _, Some(n)) => { cargo.env(profile_var("CODEGEN_UNITS"), n.to_string()); } _ => { @@ -1217,10 +1183,7 @@ impl<'a> Builder<'a> { rustflags.arg("-Cprefer-dynamic"); } - Cargo { - command: cargo, - rustflags, - } + Cargo { command: cargo, rustflags } } /// Ensure that a given step is built, returning its output. This will @@ -1231,10 +1194,7 @@ impl<'a> Builder<'a> { let mut stack = self.stack.borrow_mut(); for stack_step in stack.iter() { // should skip - if stack_step - .downcast_ref::<S>() - .map_or(true, |stack_step| *stack_step != step) - { + if stack_step.downcast_ref::<S>().map_or(true, |stack_step| *stack_step != step) { continue; } let mut out = String::new(); @@ -1277,11 +1237,7 @@ impl<'a> Builder<'a> { let cur_step = stack.pop().expect("step stack empty"); assert_eq!(cur_step.downcast_ref(), Some(&step)); } - self.verbose(&format!( - "{}< {:?}", - " ".repeat(self.stack.borrow().len()), - step - )); + self.verbose(&format!("{}< {:?}", " ".repeat(self.stack.borrow().len()), step)); self.cache.put(step, out.clone()); out } @@ -1344,7 +1300,9 @@ impl Cargo { } pub fn args<I, S>(&mut self, args: I) -> &mut Cargo - where I: IntoIterator<Item=S>, S: AsRef<OsStr> + where + I: IntoIterator<Item = S>, + S: AsRef<OsStr>, { for arg in args { self.arg(arg.as_ref()); diff --git a/src/bootstrap/builder/tests.rs b/src/bootstrap/builder/tests.rs index b9d97fb8b76..5fefb972866 100644 --- a/src/bootstrap/builder/tests.rs +++ b/src/bootstrap/builder/tests.rs @@ -11,12 +11,10 @@ fn configure(host: &[&str], target: &[&str]) -> Config { config.skip_only_host_steps = false; config.dry_run = true; // try to avoid spurious failures in dist where we create/delete each others file - let dir = config.out.join("tmp-rustbuild-tests").join( - &thread::current() - .name() - .unwrap_or("unknown") - .replace(":", "-"), - ); + let dir = config + .out + .join("tmp-rustbuild-tests") + .join(&thread::current().name().unwrap_or("unknown").replace(":", "-")); t!(fs::create_dir_all(&dir)); config.out = dir; config.build = INTERNER.intern_str("A"); @@ -46,26 +44,15 @@ fn dist_baseline() { let a = INTERNER.intern_str("A"); - assert_eq!( - first(builder.cache.all::<dist::Docs>()), - &[dist::Docs { host: a },] - ); - assert_eq!( - first(builder.cache.all::<dist::Mingw>()), - &[dist::Mingw { host: a },] - ); + assert_eq!(first(builder.cache.all::<dist::Docs>()), &[dist::Docs { host: a },]); + assert_eq!(first(builder.cache.all::<dist::Mingw>()), &[dist::Mingw { host: a },]); assert_eq!( first(builder.cache.all::<dist::Rustc>()), - &[dist::Rustc { - compiler: Compiler { host: a, stage: 2 } - },] + &[dist::Rustc { compiler: Compiler { host: a, stage: 2 } },] ); assert_eq!( first(builder.cache.all::<dist::Std>()), - &[dist::Std { - compiler: Compiler { host: a, stage: 1 }, - target: a, - },] + &[dist::Std { compiler: Compiler { host: a, stage: 1 }, target: a },] ); assert_eq!(first(builder.cache.all::<dist::Src>()), &[dist::Src]); } @@ -81,10 +68,7 @@ fn dist_with_targets() { assert_eq!( first(builder.cache.all::<dist::Docs>()), - &[ - dist::Docs { host: a }, - dist::Docs { host: b }, - ] + &[dist::Docs { host: a }, dist::Docs { host: b },] ); assert_eq!( first(builder.cache.all::<dist::Mingw>()), @@ -92,21 +76,13 @@ fn dist_with_targets() { ); assert_eq!( first(builder.cache.all::<dist::Rustc>()), - &[dist::Rustc { - compiler: Compiler { host: a, stage: 2 } - },] + &[dist::Rustc { compiler: Compiler { host: a, stage: 2 } },] ); assert_eq!( first(builder.cache.all::<dist::Std>()), &[ - dist::Std { - compiler: Compiler { host: a, stage: 1 }, - target: a, - }, - dist::Std { - compiler: Compiler { host: a, stage: 2 }, - target: b, - }, + dist::Std { compiler: Compiler { host: a, stage: 1 }, target: a }, + dist::Std { compiler: Compiler { host: a, stage: 2 }, target: b }, ] ); assert_eq!(first(builder.cache.all::<dist::Src>()), &[dist::Src]); @@ -123,10 +99,7 @@ fn dist_with_hosts() { assert_eq!( first(builder.cache.all::<dist::Docs>()), - &[ - dist::Docs { host: a }, - dist::Docs { host: b }, - ] + &[dist::Docs { host: a }, dist::Docs { host: b },] ); assert_eq!( first(builder.cache.all::<dist::Mingw>()), @@ -135,25 +108,15 @@ fn dist_with_hosts() { assert_eq!( first(builder.cache.all::<dist::Rustc>()), &[ - dist::Rustc { - compiler: Compiler { host: a, stage: 2 } - }, - dist::Rustc { - compiler: Compiler { host: b, stage: 2 } - }, + dist::Rustc { compiler: Compiler { host: a, stage: 2 } }, + dist::Rustc { compiler: Compiler { host: b, stage: 2 } }, ] ); assert_eq!( first(builder.cache.all::<dist::Std>()), &[ - dist::Std { - compiler: Compiler { host: a, stage: 1 }, - target: a, - }, - dist::Std { - compiler: Compiler { host: a, stage: 1 }, - target: b, - }, + dist::Std { compiler: Compiler { host: a, stage: 1 }, target: a }, + dist::Std { compiler: Compiler { host: a, stage: 1 }, target: b }, ] ); assert_eq!(first(builder.cache.all::<dist::Src>()), &[dist::Src]); @@ -172,23 +135,13 @@ fn dist_only_cross_host() { assert_eq!( first(builder.cache.all::<dist::Rustc>()), - &[ - dist::Rustc { - compiler: Compiler { host: b, stage: 2 } - }, - ] + &[dist::Rustc { compiler: Compiler { host: b, stage: 2 } },] ); assert_eq!( first(builder.cache.all::<compile::Rustc>()), &[ - compile::Rustc { - compiler: Compiler { host: a, stage: 0 }, - target: a, - }, - compile::Rustc { - compiler: Compiler { host: a, stage: 1 }, - target: b, - }, + compile::Rustc { compiler: Compiler { host: a, stage: 0 }, target: a }, + compile::Rustc { compiler: Compiler { host: a, stage: 1 }, target: b }, ] ); } @@ -205,46 +158,25 @@ fn dist_with_targets_and_hosts() { assert_eq!( first(builder.cache.all::<dist::Docs>()), - &[ - dist::Docs { host: a }, - dist::Docs { host: b }, - dist::Docs { host: c }, - ] + &[dist::Docs { host: a }, dist::Docs { host: b }, dist::Docs { host: c },] ); assert_eq!( first(builder.cache.all::<dist::Mingw>()), - &[ - dist::Mingw { host: a }, - dist::Mingw { host: b }, - dist::Mingw { host: c }, - ] + &[dist::Mingw { host: a }, dist::Mingw { host: b }, dist::Mingw { host: c },] ); assert_eq!( first(builder.cache.all::<dist::Rustc>()), &[ - dist::Rustc { - compiler: Compiler { host: a, stage: 2 } - }, - dist::Rustc { - compiler: Compiler { host: b, stage: 2 } - }, + dist::Rustc { compiler: Compiler { host: a, stage: 2 } }, + dist::Rustc { compiler: Compiler { host: b, stage: 2 } }, ] ); assert_eq!( first(builder.cache.all::<dist::Std>()), &[ - dist::Std { - compiler: Compiler { host: a, stage: 1 }, - target: a, - }, - dist::Std { - compiler: Compiler { host: a, stage: 1 }, - target: b, - }, - dist::Std { - compiler: Compiler { host: a, stage: 2 }, - target: c, - }, + dist::Std { compiler: Compiler { host: a, stage: 1 }, target: a }, + dist::Std { compiler: Compiler { host: a, stage: 1 }, target: b }, + dist::Std { compiler: Compiler { host: a, stage: 2 }, target: c }, ] ); assert_eq!(first(builder.cache.all::<dist::Src>()), &[dist::Src]); @@ -264,36 +196,19 @@ fn dist_with_target_flag() { assert_eq!( first(builder.cache.all::<dist::Docs>()), - &[ - dist::Docs { host: a }, - dist::Docs { host: b }, - dist::Docs { host: c }, - ] + &[dist::Docs { host: a }, dist::Docs { host: b }, dist::Docs { host: c },] ); assert_eq!( first(builder.cache.all::<dist::Mingw>()), - &[ - dist::Mingw { host: a }, - dist::Mingw { host: b }, - dist::Mingw { host: c }, - ] + &[dist::Mingw { host: a }, dist::Mingw { host: b }, dist::Mingw { host: c },] ); assert_eq!(first(builder.cache.all::<dist::Rustc>()), &[]); assert_eq!( first(builder.cache.all::<dist::Std>()), &[ - dist::Std { - compiler: Compiler { host: a, stage: 1 }, - target: a, - }, - dist::Std { - compiler: Compiler { host: a, stage: 1 }, - target: b, - }, - dist::Std { - compiler: Compiler { host: a, stage: 2 }, - target: c, - }, + dist::Std { compiler: Compiler { host: a, stage: 1 }, target: a }, + dist::Std { compiler: Compiler { host: a, stage: 1 }, target: b }, + dist::Std { compiler: Compiler { host: a, stage: 2 }, target: c }, ] ); assert_eq!(first(builder.cache.all::<dist::Src>()), &[]); @@ -310,10 +225,7 @@ fn dist_with_same_targets_and_hosts() { assert_eq!( first(builder.cache.all::<dist::Docs>()), - &[ - dist::Docs { host: a }, - dist::Docs { host: b }, - ] + &[dist::Docs { host: a }, dist::Docs { host: b },] ); assert_eq!( first(builder.cache.all::<dist::Mingw>()), @@ -322,68 +234,35 @@ fn dist_with_same_targets_and_hosts() { assert_eq!( first(builder.cache.all::<dist::Rustc>()), &[ - dist::Rustc { - compiler: Compiler { host: a, stage: 2 } - }, - dist::Rustc { - compiler: Compiler { host: b, stage: 2 } - }, + dist::Rustc { compiler: Compiler { host: a, stage: 2 } }, + dist::Rustc { compiler: Compiler { host: b, stage: 2 } }, ] ); assert_eq!( first(builder.cache.all::<dist::Std>()), &[ - dist::Std { - compiler: Compiler { host: a, stage: 1 }, - target: a, - }, - dist::Std { - compiler: Compiler { host: a, stage: 1 }, - target: b, - }, + dist::Std { compiler: Compiler { host: a, stage: 1 }, target: a }, + dist::Std { compiler: Compiler { host: a, stage: 1 }, target: b }, ] ); assert_eq!(first(builder.cache.all::<dist::Src>()), &[dist::Src]); assert_eq!( first(builder.cache.all::<compile::Std>()), &[ - compile::Std { - compiler: Compiler { host: a, stage: 0 }, - target: a, - }, - compile::Std { - compiler: Compiler { host: a, stage: 1 }, - target: a, - }, - compile::Std { - compiler: Compiler { host: a, stage: 2 }, - target: a, - }, - compile::Std { - compiler: Compiler { host: a, stage: 1 }, - target: b, - }, - compile::Std { - compiler: Compiler { host: a, stage: 2 }, - target: b, - }, + compile::Std { compiler: Compiler { host: a, stage: 0 }, target: a }, + compile::Std { compiler: Compiler { host: a, stage: 1 }, target: a }, + compile::Std { compiler: Compiler { host: a, stage: 2 }, target: a }, + compile::Std { compiler: Compiler { host: a, stage: 1 }, target: b }, + compile::Std { compiler: Compiler { host: a, stage: 2 }, target: b }, ] ); assert_eq!( first(builder.cache.all::<compile::Assemble>()), &[ - compile::Assemble { - target_compiler: Compiler { host: a, stage: 0 }, - }, - compile::Assemble { - target_compiler: Compiler { host: a, stage: 1 }, - }, - compile::Assemble { - target_compiler: Compiler { host: a, stage: 2 }, - }, - compile::Assemble { - target_compiler: Compiler { host: b, stage: 2 }, - }, + compile::Assemble { target_compiler: Compiler { host: a, stage: 0 } }, + compile::Assemble { target_compiler: Compiler { host: a, stage: 1 } }, + compile::Assemble { target_compiler: Compiler { host: a, stage: 2 } }, + compile::Assemble { target_compiler: Compiler { host: b, stage: 2 } }, ] ); } @@ -401,76 +280,28 @@ fn build_default() { assert_eq!( first(builder.cache.all::<compile::Std>()), &[ - compile::Std { - compiler: Compiler { host: a, stage: 0 }, - target: a, - }, - compile::Std { - compiler: Compiler { host: a, stage: 1 }, - target: a, - }, - compile::Std { - compiler: Compiler { host: a, stage: 2 }, - target: a, - }, - compile::Std { - compiler: Compiler { host: b, stage: 2 }, - target: a, - }, - compile::Std { - compiler: Compiler { host: a, stage: 1 }, - target: b, - }, - compile::Std { - compiler: Compiler { host: a, stage: 2 }, - target: b, - }, - compile::Std { - compiler: Compiler { host: b, stage: 2 }, - target: b, - }, - compile::Std { - compiler: Compiler { host: a, stage: 2 }, - target: c, - }, - compile::Std { - compiler: Compiler { host: b, stage: 2 }, - target: c, - }, + compile::Std { compiler: Compiler { host: a, stage: 0 }, target: a }, + compile::Std { compiler: Compiler { host: a, stage: 1 }, target: a }, + compile::Std { compiler: Compiler { host: a, stage: 2 }, target: a }, + compile::Std { compiler: Compiler { host: b, stage: 2 }, target: a }, + compile::Std { compiler: Compiler { host: a, stage: 1 }, target: b }, + compile::Std { compiler: Compiler { host: a, stage: 2 }, target: b }, + compile::Std { compiler: Compiler { host: b, stage: 2 }, target: b }, + compile::Std { compiler: Compiler { host: a, stage: 2 }, target: c }, + compile::Std { compiler: Compiler { host: b, stage: 2 }, target: c }, ] ); assert!(!builder.cache.all::<compile::Assemble>().is_empty()); assert_eq!( first(builder.cache.all::<compile::Rustc>()), &[ - compile::Rustc { - compiler: Compiler { host: a, stage: 0 }, - target: a, - }, - compile::Rustc { - compiler: Compiler { host: a, stage: 1 }, - target: a, - }, - compile::Rustc { - compiler: Compiler { host: a, stage: 2 }, - target: a, - }, - compile::Rustc { - compiler: Compiler { host: b, stage: 2 }, - target: a, - }, - compile::Rustc { - compiler: Compiler { host: a, stage: 1 }, - target: b, - }, - compile::Rustc { - compiler: Compiler { host: a, stage: 2 }, - target: b, - }, - compile::Rustc { - compiler: Compiler { host: b, stage: 2 }, - target: b, - }, + compile::Rustc { compiler: Compiler { host: a, stage: 0 }, target: a }, + compile::Rustc { compiler: Compiler { host: a, stage: 1 }, target: a }, + compile::Rustc { compiler: Compiler { host: a, stage: 2 }, target: a }, + compile::Rustc { compiler: Compiler { host: b, stage: 2 }, target: a }, + compile::Rustc { compiler: Compiler { host: a, stage: 1 }, target: b }, + compile::Rustc { compiler: Compiler { host: a, stage: 2 }, target: b }, + compile::Rustc { compiler: Compiler { host: b, stage: 2 }, target: b }, ] ); } @@ -490,76 +321,32 @@ fn build_with_target_flag() { assert_eq!( first(builder.cache.all::<compile::Std>()), &[ - compile::Std { - compiler: Compiler { host: a, stage: 0 }, - target: a, - }, - compile::Std { - compiler: Compiler { host: a, stage: 1 }, - target: a, - }, - compile::Std { - compiler: Compiler { host: a, stage: 2 }, - target: a, - }, - compile::Std { - compiler: Compiler { host: b, stage: 2 }, - target: a, - }, - compile::Std { - compiler: Compiler { host: a, stage: 1 }, - target: b, - }, - compile::Std { - compiler: Compiler { host: a, stage: 2 }, - target: b, - }, - compile::Std { - compiler: Compiler { host: b, stage: 2 }, - target: b, - }, - compile::Std { - compiler: Compiler { host: a, stage: 2 }, - target: c, - }, - compile::Std { - compiler: Compiler { host: b, stage: 2 }, - target: c, - }, + compile::Std { compiler: Compiler { host: a, stage: 0 }, target: a }, + compile::Std { compiler: Compiler { host: a, stage: 1 }, target: a }, + compile::Std { compiler: Compiler { host: a, stage: 2 }, target: a }, + compile::Std { compiler: Compiler { host: b, stage: 2 }, target: a }, + compile::Std { compiler: Compiler { host: a, stage: 1 }, target: b }, + compile::Std { compiler: Compiler { host: a, stage: 2 }, target: b }, + compile::Std { compiler: Compiler { host: b, stage: 2 }, target: b }, + compile::Std { compiler: Compiler { host: a, stage: 2 }, target: c }, + compile::Std { compiler: Compiler { host: b, stage: 2 }, target: c }, ] ); assert_eq!( first(builder.cache.all::<compile::Assemble>()), &[ - compile::Assemble { - target_compiler: Compiler { host: a, stage: 0 }, - }, - compile::Assemble { - target_compiler: Compiler { host: a, stage: 1 }, - }, - compile::Assemble { - target_compiler: Compiler { host: a, stage: 2 }, - }, - compile::Assemble { - target_compiler: Compiler { host: b, stage: 2 }, - }, + compile::Assemble { target_compiler: Compiler { host: a, stage: 0 } }, + compile::Assemble { target_compiler: Compiler { host: a, stage: 1 } }, + compile::Assemble { target_compiler: Compiler { host: a, stage: 2 } }, + compile::Assemble { target_compiler: Compiler { host: b, stage: 2 } }, ] ); assert_eq!( first(builder.cache.all::<compile::Rustc>()), &[ - compile::Rustc { - compiler: Compiler { host: a, stage: 0 }, - target: a, - }, - compile::Rustc { - compiler: Compiler { host: a, stage: 1 }, - target: a, - }, - compile::Rustc { - compiler: Compiler { host: a, stage: 1 }, - target: b, - }, + compile::Rustc { compiler: Compiler { host: a, stage: 0 }, target: a }, + compile::Rustc { compiler: Compiler { host: a, stage: 1 }, target: a }, + compile::Rustc { compiler: Compiler { host: a, stage: 1 }, target: b }, ] ); } @@ -585,10 +372,8 @@ fn test_with_no_doc_stage0() { let host = INTERNER.intern_str("A"); - builder.run_step_descriptions( - &[StepDescription::from::<test::Crate>()], - &["src/libstd".into()], - ); + builder + .run_step_descriptions(&[StepDescription::from::<test::Crate>()], &["src/libstd".into()]); // Ensure we don't build any compiler artifacts. assert!(!builder.cache.contains::<compile::Rustc>()); @@ -607,9 +392,7 @@ fn test_with_no_doc_stage0() { #[test] fn test_exclude() { let mut config = configure(&[], &[]); - config.exclude = vec![ - "src/tools/tidy".into(), - ]; + config.exclude = vec!["src/tools/tidy".into()]; config.cmd = Subcommand::Test { paths: Vec::new(), test_args: Vec::new(), diff --git a/src/bootstrap/cache.rs b/src/bootstrap/cache.rs index 4310f2c6fa1..0c16fae01bc 100644 --- a/src/bootstrap/cache.rs +++ b/src/bootstrap/cache.rs @@ -1,6 +1,7 @@ use std::any::{Any, TypeId}; use std::borrow::Borrow; use std::cell::RefCell; +use std::cmp::{Ord, Ordering, PartialOrd}; use std::collections::HashMap; use std::convert::AsRef; use std::ffi::OsStr; @@ -11,7 +12,6 @@ use std::mem; use std::ops::Deref; use std::path::{Path, PathBuf}; use std::sync::Mutex; -use std::cmp::{PartialOrd, Ord, Ordering}; use lazy_static::lazy_static; @@ -47,7 +47,7 @@ impl<T> Eq for Interned<T> {} impl PartialEq<str> for Interned<String> { fn eq(&self, other: &str) -> bool { - *self == other + *self == other } } impl<'a> PartialEq<&'a str> for Interned<String> { @@ -168,24 +168,21 @@ struct TyIntern<T: Clone + Eq> { impl<T: Hash + Clone + Eq> Default for TyIntern<T> { fn default() -> Self { - TyIntern { - items: Vec::new(), - set: Default::default(), - } + TyIntern { items: Vec::new(), set: Default::default() } } } impl<T: Hash + Clone + Eq> TyIntern<T> { fn intern_borrow<B>(&mut self, item: &B) -> Interned<T> where - B: Eq + Hash + ToOwned<Owned=T> + ?Sized, + B: Eq + Hash + ToOwned<Owned = T> + ?Sized, T: Borrow<B>, { if let Some(i) = self.set.get(&item) { return *i; } let item = item.to_owned(); - let interned = Interned(self.items.len(), PhantomData::<*const T>); + let interned = Interned(self.items.len(), PhantomData::<*const T>); self.set.insert(item.clone(), interned); self.items.push(item); interned @@ -195,7 +192,7 @@ impl<T: Hash + Clone + Eq> TyIntern<T> { if let Some(i) = self.set.get(&item) { return *i; } - let interned = Interned(self.items.len(), PhantomData::<*const T>); + let interned = Interned(self.items.len(), PhantomData::<*const T>); self.set.insert(item.clone(), interned); self.items.push(item); interned @@ -235,10 +232,12 @@ lazy_static! { /// `get()` method. #[derive(Debug)] pub struct Cache( - RefCell<HashMap< - TypeId, - Box<dyn Any>, // actually a HashMap<Step, Interned<Step::Output>> - >> + RefCell< + HashMap< + TypeId, + Box<dyn Any>, // actually a HashMap<Step, Interned<Step::Output>> + >, + >, ); impl Cache { @@ -249,10 +248,11 @@ impl Cache { pub fn put<S: Step>(&self, step: S, value: S::Output) { let mut cache = self.0.borrow_mut(); let type_id = TypeId::of::<S>(); - let stepcache = cache.entry(type_id) - .or_insert_with(|| Box::new(HashMap::<S, S::Output>::new())) - .downcast_mut::<HashMap<S, S::Output>>() - .expect("invalid type mapped"); + let stepcache = cache + .entry(type_id) + .or_insert_with(|| Box::new(HashMap::<S, S::Output>::new())) + .downcast_mut::<HashMap<S, S::Output>>() + .expect("invalid type mapped"); assert!(!stepcache.contains_key(&step), "processing {:?} a second time", step); stepcache.insert(step, value); } @@ -260,10 +260,11 @@ impl Cache { pub fn get<S: Step>(&self, step: &S) -> Option<S::Output> { let mut cache = self.0.borrow_mut(); let type_id = TypeId::of::<S>(); - let stepcache = cache.entry(type_id) - .or_insert_with(|| Box::new(HashMap::<S, S::Output>::new())) - .downcast_mut::<HashMap<S, S::Output>>() - .expect("invalid type mapped"); + let stepcache = cache + .entry(type_id) + .or_insert_with(|| Box::new(HashMap::<S, S::Output>::new())) + .downcast_mut::<HashMap<S, S::Output>>() + .expect("invalid type mapped"); stepcache.get(step).cloned() } } @@ -273,7 +274,8 @@ impl Cache { pub fn all<S: Ord + Copy + Step>(&mut self) -> Vec<(S, S::Output)> { let cache = self.0.get_mut(); let type_id = TypeId::of::<S>(); - let mut v = cache.remove(&type_id) + let mut v = cache + .remove(&type_id) .map(|b| b.downcast::<HashMap<S, S::Output>>().expect("correct type")) .map(|m| m.into_iter().collect::<Vec<_>>()) .unwrap_or_default(); diff --git a/src/bootstrap/cc_detect.rs b/src/bootstrap/cc_detect.rs index a4cb81d3d1b..a236edf971f 100644 --- a/src/bootstrap/cc_detect.rs +++ b/src/bootstrap/cc_detect.rs @@ -22,15 +22,15 @@ //! everything. use std::collections::HashSet; -use std::{env, iter}; use std::path::{Path, PathBuf}; use std::process::Command; +use std::{env, iter}; use build_helper::output; -use crate::{Build, GitRepo}; -use crate::config::Target; use crate::cache::Interned; +use crate::config::Target; +use crate::{Build, GitRepo}; // The `cc` crate doesn't provide a way to obtain a path to the detected archiver, // so use some simplified logic here. First we respect the environment variable `AR`, then @@ -64,14 +64,25 @@ fn cc2ar(cc: &Path, target: &str) -> Option<PathBuf> { pub fn find(build: &mut Build) { // For all targets we're going to need a C compiler for building some shims // and such as well as for being a linker for Rust code. - let targets = build.targets.iter().chain(&build.hosts).cloned().chain(iter::once(build.build)) - .collect::<HashSet<_>>(); + let targets = build + .targets + .iter() + .chain(&build.hosts) + .cloned() + .chain(iter::once(build.build)) + .collect::<HashSet<_>>(); for target in targets.into_iter() { let mut cfg = cc::Build::new(); - cfg.cargo_metadata(false).opt_level(2).warnings(false).debug(false) - .target(&target).host(&build.build); + cfg.cargo_metadata(false) + .opt_level(2) + .warnings(false) + .debug(false) + .target(&target) + .host(&build.build); match build.crt_static(target) { - Some(a) => { cfg.static_crt(a); } + Some(a) => { + cfg.static_crt(a); + } None => { if target.contains("msvc") { cfg.static_crt(true); @@ -102,8 +113,13 @@ pub fn find(build: &mut Build) { // If we use llvm-libunwind, we will need a C++ compiler as well for all targets // We'll need one anyways if the target triple is also a host triple let mut cfg = cc::Build::new(); - cfg.cargo_metadata(false).opt_level(2).warnings(false).debug(false).cpp(true) - .target(&target).host(&build.build); + cfg.cargo_metadata(false) + .opt_level(2) + .warnings(false) + .debug(false) + .cpp(true) + .target(&target) + .host(&build.build); let cxx_configured = if let Some(cxx) = config.and_then(|c| c.cxx.as_ref()) { cfg.compiler(cxx); @@ -133,21 +149,24 @@ pub fn find(build: &mut Build) { } } -fn set_compiler(cfg: &mut cc::Build, - compiler: Language, - target: Interned<String>, - config: Option<&Target>, - build: &Build) { +fn set_compiler( + cfg: &mut cc::Build, + compiler: Language, + target: Interned<String>, + config: Option<&Target>, + build: &Build, +) { match &*target { // When compiling for android we may have the NDK configured in the // config.toml in which case we look there. Otherwise the default // compiler already takes into account the triple in question. t if t.contains("android") => { if let Some(ndk) = config.and_then(|c| c.ndk.as_ref()) { - let target = target.replace("armv7neon", "arm") - .replace("armv7", "arm") - .replace("thumbv7neon", "arm") - .replace("thumbv7", "arm"); + let target = target + .replace("armv7neon", "arm") + .replace("armv7", "arm") + .replace("thumbv7neon", "arm") + .replace("thumbv7", "arm"); let compiler = format!("{}-{}", target, compiler.clang()); cfg.compiler(ndk.join("bin").join(compiler)); } @@ -159,7 +178,7 @@ fn set_compiler(cfg: &mut cc::Build, let c = cfg.get_compiler(); let gnu_compiler = compiler.gcc(); if !c.path().ends_with(gnu_compiler) { - return + return; } let output = output(c.to_command().arg("--version")); @@ -168,7 +187,7 @@ fn set_compiler(cfg: &mut cc::Build, None => return, }; match output[i + 3..].chars().next().unwrap() { - '0' ..= '6' => {} + '0'..='6' => {} _ => return, } let alternative = format!("e{}", gnu_compiler); diff --git a/src/bootstrap/channel.rs b/src/bootstrap/channel.rs index ec4bf9a04fa..38810237ef9 100644 --- a/src/bootstrap/channel.rs +++ b/src/bootstrap/channel.rs @@ -29,31 +29,28 @@ impl GitInfo { pub fn new(ignore_git: bool, dir: &Path) -> GitInfo { // See if this even begins to look like a git dir if ignore_git || !dir.join(".git").exists() { - return GitInfo { inner: None } + return GitInfo { inner: None }; } // Make sure git commands work - match Command::new("git") - .arg("rev-parse") - .current_dir(dir) - .output() - { + match Command::new("git").arg("rev-parse").current_dir(dir).output() { Ok(ref out) if out.status.success() => {} _ => return GitInfo { inner: None }, } // Ok, let's scrape some info - let ver_date = output(Command::new("git").current_dir(dir) - .arg("log").arg("-1") - .arg("--date=short") - .arg("--pretty=format:%cd")); - let ver_hash = output(Command::new("git").current_dir(dir) - .arg("rev-parse").arg("HEAD")); - let short_ver_hash = output(Command::new("git") - .current_dir(dir) - .arg("rev-parse") - .arg("--short=9") - .arg("HEAD")); + let ver_date = output( + Command::new("git") + .current_dir(dir) + .arg("log") + .arg("-1") + .arg("--date=short") + .arg("--pretty=format:%cd"), + ); + let ver_hash = output(Command::new("git").current_dir(dir).arg("rev-parse").arg("HEAD")); + let short_ver_hash = output( + Command::new("git").current_dir(dir).arg("rev-parse").arg("--short=9").arg("HEAD"), + ); GitInfo { inner: Some(Info { commit_date: ver_date.trim().to_string(), diff --git a/src/bootstrap/check.rs b/src/bootstrap/check.rs index f5c427d870e..d4016f16fa9 100644 --- a/src/bootstrap/check.rs +++ b/src/bootstrap/check.rs @@ -1,10 +1,10 @@ //! Implementation of compiling the compiler and standard library, in "check"-based modes. -use crate::compile::{run_cargo, std_cargo, rustc_cargo, add_to_sysroot}; -use crate::builder::{RunConfig, Builder, Kind, ShouldRun, Step}; +use crate::builder::{Builder, Kind, RunConfig, ShouldRun, Step}; +use crate::cache::Interned; +use crate::compile::{add_to_sysroot, run_cargo, rustc_cargo, std_cargo}; use crate::tool::{prepare_tool_cargo, SourceType}; use crate::{Compiler, Mode}; -use crate::cache::Interned; use std::path::PathBuf; #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] @@ -15,7 +15,7 @@ pub struct Std { fn args(kind: Kind) -> Vec<String> { match kind { Kind::Clippy => vec!["--".to_owned(), "--cap-lints".to_owned(), "warn".to_owned()], - _ => Vec::new() + _ => Vec::new(), } } @@ -24,7 +24,7 @@ fn cargo_subcommand(kind: Kind) -> &'static str { Kind::Check => "check", Kind::Clippy => "clippy", Kind::Fix => "fix", - _ => unreachable!() + _ => unreachable!(), } } @@ -37,9 +37,7 @@ impl Step for Std { } fn make_run(run: RunConfig<'_>) { - run.builder.ensure(Std { - target: run.target, - }); + run.builder.ensure(Std { target: run.target }); } fn run(self, builder: &Builder<'_>) { @@ -50,12 +48,14 @@ impl Step for Std { std_cargo(builder, &compiler, target, &mut cargo); builder.info(&format!("Checking std artifacts ({} -> {})", &compiler.host, target)); - run_cargo(builder, - cargo, - args(builder.kind), - &libstd_stamp(builder, compiler, target), - vec![], - true); + run_cargo( + builder, + cargo, + args(builder.kind), + &libstd_stamp(builder, compiler, target), + vec![], + true, + ); let libdir = builder.sysroot_libdir(compiler, target); let hostdir = builder.sysroot_libdir(compiler, compiler.host); @@ -78,9 +78,7 @@ impl Step for Rustc { } fn make_run(run: RunConfig<'_>) { - run.builder.ensure(Rustc { - target: run.target, - }); + run.builder.ensure(Rustc { target: run.target }); } /// Builds the compiler. @@ -94,17 +92,19 @@ impl Step for Rustc { builder.ensure(Std { target }); - let mut cargo = builder.cargo(compiler, Mode::Rustc, target, - cargo_subcommand(builder.kind)); + let mut cargo = + builder.cargo(compiler, Mode::Rustc, target, cargo_subcommand(builder.kind)); rustc_cargo(builder, &mut cargo, target); builder.info(&format!("Checking compiler artifacts ({} -> {})", &compiler.host, target)); - run_cargo(builder, - cargo, - args(builder.kind), - &librustc_stamp(builder, compiler, target), - vec![], - true); + run_cargo( + builder, + cargo, + args(builder.kind), + &librustc_stamp(builder, compiler, target), + vec![], + true, + ); let libdir = builder.sysroot_libdir(compiler, target); let hostdir = builder.sysroot_libdir(compiler, compiler.host); @@ -127,9 +127,7 @@ impl Step for Rustdoc { } fn make_run(run: RunConfig<'_>) { - run.builder.ensure(Rustdoc { - target: run.target, - }); + run.builder.ensure(Rustdoc { target: run.target }); } fn run(self, builder: &Builder<'_>) { @@ -138,22 +136,26 @@ impl Step for Rustdoc { builder.ensure(Rustc { target }); - let cargo = prepare_tool_cargo(builder, - compiler, - Mode::ToolRustc, - target, - cargo_subcommand(builder.kind), - "src/tools/rustdoc", - SourceType::InTree, - &[]); + let cargo = prepare_tool_cargo( + builder, + compiler, + Mode::ToolRustc, + target, + cargo_subcommand(builder.kind), + "src/tools/rustdoc", + SourceType::InTree, + &[], + ); println!("Checking rustdoc artifacts ({} -> {})", &compiler.host, target); - run_cargo(builder, - cargo, - args(builder.kind), - &rustdoc_stamp(builder, compiler, target), - vec![], - true); + run_cargo( + builder, + cargo, + args(builder.kind), + &rustdoc_stamp(builder, compiler, target), + vec![], + true, + ); let libdir = builder.sysroot_libdir(compiler, target); let hostdir = builder.sysroot_libdir(compiler, compiler.host); @@ -188,6 +190,5 @@ pub fn rustdoc_stamp( compiler: Compiler, target: Interned<String>, ) -> PathBuf { - builder.cargo_out(compiler, Mode::ToolRustc, target) - .join(".rustdoc-check.stamp") + builder.cargo_out(compiler, Mode::ToolRustc, target).join(".rustdoc-check.stamp") } diff --git a/src/bootstrap/clean.rs b/src/bootstrap/clean.rs index 73be8bfed8e..b4e58c06fde 100644 --- a/src/bootstrap/clean.rs +++ b/src/bootstrap/clean.rs @@ -31,7 +31,7 @@ pub fn clean(build: &Build, all: bool) { for entry in entries { let entry = t!(entry); if entry.file_name().to_str() == Some("llvm") { - continue + continue; } let path = t!(entry.path().canonicalize()); rm_rf(&path); @@ -47,7 +47,7 @@ fn rm_rf(path: &Path) { return; } panic!("failed to get metadata for file {}: {}", path.display(), e); - }, + } Ok(metadata) => { if metadata.file_type().is_file() || metadata.file_type().is_symlink() { do_op(path, "remove file", |p| fs::remove_file(p)); @@ -58,20 +58,20 @@ fn rm_rf(path: &Path) { rm_rf(&t!(file).path()); } do_op(path, "remove dir", |p| fs::remove_dir(p)); - }, + } }; } fn do_op<F>(path: &Path, desc: &str, mut f: F) - where F: FnMut(&Path) -> io::Result<()> +where + F: FnMut(&Path) -> io::Result<()>, { match f(path) { Ok(()) => {} // On windows we can't remove a readonly file, and git will often clone files as readonly. // As a result, we have some special logic to remove readonly files on windows. // This is also the reason that we can't use things like fs::remove_dir_all(). - Err(ref e) if cfg!(windows) && - e.kind() == ErrorKind::PermissionDenied => { + Err(ref e) if cfg!(windows) && e.kind() == ErrorKind::PermissionDenied => { let mut p = t!(path.symlink_metadata()).permissions(); p.set_readonly(false); t!(fs::set_permissions(path, p)); diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 831053bc0f7..2d60024a22a 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -9,10 +9,10 @@ use std::borrow::Cow; use std::env; use std::fs; -use std::io::BufReader; use std::io::prelude::*; +use std::io::BufReader; use std::path::{Path, PathBuf}; -use std::process::{Command, Stdio, exit}; +use std::process::{exit, Command, Stdio}; use std::str; use build_helper::{output, t, up_to_date}; @@ -20,14 +20,14 @@ use filetime::FileTime; use serde::Deserialize; use serde_json; -use crate::dist; use crate::builder::Cargo; -use crate::util::{exe, is_dylib}; -use crate::{Compiler, Mode, GitRepo}; +use crate::dist; use crate::native; +use crate::util::{exe, is_dylib}; +use crate::{Compiler, GitRepo, Mode}; -use crate::cache::{INTERNER, Interned}; -use crate::builder::{Step, RunConfig, ShouldRun, Builder, Kind}; +use crate::builder::{Builder, Kind, RunConfig, ShouldRun, Step}; +use crate::cache::{Interned, INTERNER}; #[derive(Debug, PartialOrd, Ord, Copy, Clone, PartialEq, Eq, Hash)] pub struct Std { @@ -61,11 +61,7 @@ impl Step for Std { if builder.config.keep_stage.contains(&compiler.stage) { builder.info("Warning: Using a potentially old libstd. This may not behave well."); - builder.ensure(StdLink { - compiler, - target_compiler: compiler, - target, - }); + builder.ensure(StdLink { compiler, target_compiler: compiler, target }); return; } @@ -73,10 +69,7 @@ impl Step for Std { let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target); if compiler_to_use != compiler { - builder.ensure(Std { - compiler: compiler_to_use, - target, - }); + builder.ensure(Std { compiler: compiler_to_use, target }); builder.info(&format!("Uplifting stage1 std ({} -> {})", compiler_to_use.host, target)); // Even if we're not building std this stage, the new sysroot must @@ -96,14 +89,18 @@ impl Step for Std { let mut cargo = builder.cargo(compiler, Mode::Std, target, "build"); std_cargo(builder, &compiler, target, &mut cargo); - builder.info(&format!("Building stage{} std artifacts ({} -> {})", compiler.stage, - &compiler.host, target)); - run_cargo(builder, - cargo, - vec![], - &libstd_stamp(builder, compiler, target), - target_deps, - false); + builder.info(&format!( + "Building stage{} std artifacts ({} -> {})", + compiler.stage, &compiler.host, target + )); + run_cargo( + builder, + cargo, + vec![], + &libstd_stamp(builder, compiler, target), + target_deps, + false, + ); builder.ensure(StdLink { compiler: builder.compiler(compiler.stage, builder.config.build), @@ -114,19 +111,18 @@ impl Step for Std { } /// Copies third party objects needed by various targets. -fn copy_third_party_objects(builder: &Builder<'_>, compiler: &Compiler, target: Interned<String>) - -> Vec<PathBuf> -{ +fn copy_third_party_objects( + builder: &Builder<'_>, + compiler: &Compiler, + target: Interned<String>, +) -> Vec<PathBuf> { let libdir = builder.sysroot_libdir(*compiler, target); let mut target_deps = vec![]; let mut copy_and_stamp = |sourcedir: &Path, name: &str| { let target = libdir.join(name); - builder.copy( - &sourcedir.join(name), - &target, - ); + builder.copy(&sourcedir.join(name), &target); target_deps.push(target); }; @@ -162,10 +158,12 @@ fn copy_third_party_objects(builder: &Builder<'_>, compiler: &Compiler, target: /// Configure cargo to compile the standard library, adding appropriate env vars /// and such. -pub fn std_cargo(builder: &Builder<'_>, - compiler: &Compiler, - target: Interned<String>, - cargo: &mut Cargo) { +pub fn std_cargo( + builder: &Builder<'_>, + compiler: &Compiler, + target: Interned<String>, + cargo: &mut Cargo, +) { if let Some(target) = env::var_os("MACOSX_STD_DEPLOYMENT_TARGET") { cargo.env("MACOSX_DEPLOYMENT_TARGET", target); } @@ -216,14 +214,14 @@ pub fn std_cargo(builder: &Builder<'_>, // missing // We also only build the runtimes when --enable-sanitizers (or its // config.toml equivalent) is used - let llvm_config = builder.ensure(native::Llvm { - target: builder.config.build, - }); + let llvm_config = builder.ensure(native::Llvm { target: builder.config.build }); cargo.env("LLVM_CONFIG", llvm_config); cargo.env("RUSTC_BUILD_SANITIZERS", "1"); } - cargo.arg("--features").arg(features) + cargo + .arg("--features") + .arg(features) .arg("--manifest-path") .arg(builder.src.join("src/libtest/Cargo.toml")); @@ -271,12 +269,10 @@ impl Step for StdLink { let compiler = self.compiler; let target_compiler = self.target_compiler; let target = self.target; - builder.info(&format!("Copying stage{} std from stage{} ({} -> {} / {})", - target_compiler.stage, - compiler.stage, - &compiler.host, - target_compiler.host, - target)); + builder.info(&format!( + "Copying stage{} std from stage{} ({} -> {} / {})", + target_compiler.stage, compiler.stage, &compiler.host, target_compiler.host, target + )); let libdir = builder.sysroot_libdir(target_compiler, target); let hostdir = builder.sysroot_libdir(target_compiler, compiler.host); add_to_sysroot(builder, &libdir, &hostdir, &libstd_stamp(builder, compiler, target)); @@ -337,7 +333,7 @@ impl Step for StartupObjects { let for_compiler = self.compiler; let target = self.target; if !target.contains("windows-gnu") { - return vec![] + return vec![]; } let mut target_deps = vec![]; @@ -352,12 +348,17 @@ impl Step for StartupObjects { let dst_file = &dst_dir.join(file.to_string() + ".o"); if !up_to_date(src_file, dst_file) { let mut cmd = Command::new(&builder.initial_rustc); - builder.run(cmd.env("RUSTC_BOOTSTRAP", "1") - .arg("--cfg").arg("bootstrap") - .arg("--target").arg(target) - .arg("--emit=obj") - .arg("-o").arg(dst_file) - .arg(src_file)); + builder.run( + cmd.env("RUSTC_BOOTSTRAP", "1") + .arg("--cfg") + .arg("bootstrap") + .arg("--target") + .arg(target) + .arg("--emit=obj") + .arg("-o") + .arg(dst_file) + .arg(src_file), + ); } let target = sysroot_dir.join(file.to_string() + ".o"); @@ -366,10 +367,7 @@ impl Step for StartupObjects { } for obj in ["crt2.o", "dllcrt2.o"].iter() { - let src = compiler_file(builder, - builder.cc(target), - target, - obj); + let src = compiler_file(builder, builder.cc(target), target, obj); let target = sysroot_dir.join(obj); builder.copy(&src, &target); target_deps.push(target); @@ -414,22 +412,15 @@ impl Step for Rustc { if builder.config.keep_stage.contains(&compiler.stage) { builder.info("Warning: Using a potentially old librustc. This may not behave well."); - builder.ensure(RustcLink { - compiler, - target_compiler: compiler, - target, - }); + builder.ensure(RustcLink { compiler, target_compiler: compiler, target }); return; } let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target); if compiler_to_use != compiler { - builder.ensure(Rustc { - compiler: compiler_to_use, - target, - }); - builder.info(&format!("Uplifting stage1 rustc ({} -> {})", - builder.config.build, target)); + builder.ensure(Rustc { compiler: compiler_to_use, target }); + builder + .info(&format!("Uplifting stage1 rustc ({} -> {})", builder.config.build, target)); builder.ensure(RustcLink { compiler: compiler_to_use, target_compiler: compiler, @@ -447,14 +438,18 @@ impl Step for Rustc { let mut cargo = builder.cargo(compiler, Mode::Rustc, target, "build"); rustc_cargo(builder, &mut cargo, target); - builder.info(&format!("Building stage{} compiler artifacts ({} -> {})", - compiler.stage, &compiler.host, target)); - run_cargo(builder, - cargo, - vec![], - &librustc_stamp(builder, compiler, target), - vec![], - false); + builder.info(&format!( + "Building stage{} compiler artifacts ({} -> {})", + compiler.stage, &compiler.host, target + )); + run_cargo( + builder, + cargo, + vec![], + &librustc_stamp(builder, compiler, target), + vec![], + false, + ); // We used to build librustc_codegen_llvm as a separate step, // which produced a dylib that the compiler would dlopen() at runtime. @@ -503,19 +498,22 @@ impl Step for Rustc { } pub fn rustc_cargo(builder: &Builder<'_>, cargo: &mut Cargo, target: Interned<String>) { - cargo.arg("--features").arg(builder.rustc_features()) - .arg("--manifest-path") - .arg(builder.src.join("src/rustc/Cargo.toml")); + cargo + .arg("--features") + .arg(builder.rustc_features()) + .arg("--manifest-path") + .arg(builder.src.join("src/rustc/Cargo.toml")); rustc_cargo_env(builder, cargo, target); } pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Cargo, target: Interned<String>) { // Set some configuration variables picked up by build scripts and // the compiler alike - cargo.env("CFG_RELEASE", builder.rust_release()) - .env("CFG_RELEASE_CHANNEL", &builder.config.channel) - .env("CFG_VERSION", builder.rust_version()) - .env("CFG_PREFIX", builder.config.prefix.clone().unwrap_or_default()); + cargo + .env("CFG_RELEASE", builder.rust_release()) + .env("CFG_RELEASE_CHANNEL", &builder.config.channel) + .env("CFG_VERSION", builder.rust_version()) + .env("CFG_PREFIX", builder.config.prefix.clone().unwrap_or_default()); let libdir_relative = builder.config.libdir_relative().unwrap_or(Path::new("lib")); cargo.env("CFG_LIBDIR_RELATIVE", libdir_relative); @@ -561,14 +559,12 @@ pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Cargo, target: Interne } // Building with a static libstdc++ is only supported on linux right now, // not for MSVC or macOS - if builder.config.llvm_static_stdcpp && - !target.contains("freebsd") && - !target.contains("msvc") && - !target.contains("apple") { - let file = compiler_file(builder, - builder.cxx(target).unwrap(), - target, - "libstdc++.a"); + if builder.config.llvm_static_stdcpp + && !target.contains("freebsd") + && !target.contains("msvc") + && !target.contains("apple") + { + let file = compiler_file(builder, builder.cxx(target).unwrap(), target, "libstdc++.a"); cargo.env("LLVM_STATIC_STDCPP", file); } if builder.config.llvm_link_shared || builder.config.llvm_thin_lto { @@ -602,17 +598,15 @@ impl Step for RustcLink { let compiler = self.compiler; let target_compiler = self.target_compiler; let target = self.target; - builder.info(&format!("Copying stage{} rustc from stage{} ({} -> {} / {})", - target_compiler.stage, - compiler.stage, - &compiler.host, - target_compiler.host, - target)); + builder.info(&format!( + "Copying stage{} rustc from stage{} ({} -> {} / {})", + target_compiler.stage, compiler.stage, &compiler.host, target_compiler.host, target + )); add_to_sysroot( builder, &builder.sysroot_libdir(target_compiler, target), &builder.sysroot_libdir(target_compiler, compiler.host), - &librustc_stamp(builder, compiler, target) + &librustc_stamp(builder, compiler, target), ); } } @@ -706,8 +700,10 @@ impl Step for Assemble { let target_compiler = self.target_compiler; if target_compiler.stage == 0 { - assert_eq!(builder.config.build, target_compiler.host, - "Cannot obtain compiler for non-native build triple at stage 0"); + assert_eq!( + builder.config.build, target_compiler.host, + "Cannot obtain compiler for non-native build triple at stage 0" + ); // The stage 0 compiler for the build triple is always pre-built. return target_compiler; } @@ -728,23 +724,17 @@ impl Step for Assemble { // // FIXME: It may be faster if we build just a stage 1 compiler and then // use that to bootstrap this compiler forward. - let build_compiler = - builder.compiler(target_compiler.stage - 1, builder.config.build); + let build_compiler = builder.compiler(target_compiler.stage - 1, builder.config.build); // Build the libraries for this compiler to link to (i.e., the libraries // it uses at runtime). NOTE: Crates the target compiler compiles don't // link to these. (FIXME: Is that correct? It seems to be correct most // of the time but I think we do link to these for stage2/bin compilers // when not performing a full bootstrap). - builder.ensure(Rustc { - compiler: build_compiler, - target: target_compiler.host, - }); + builder.ensure(Rustc { compiler: build_compiler, target: target_compiler.host }); let lld_install = if builder.config.lld_enabled { - Some(builder.ensure(native::Lld { - target: target_compiler.host, - })) + Some(builder.ensure(native::Lld { target: target_compiler.host })) } else { None }; @@ -801,7 +791,7 @@ pub fn add_to_sysroot( builder: &Builder<'_>, sysroot_dst: &Path, sysroot_host_dst: &Path, - stamp: &Path + stamp: &Path, ) { t!(fs::create_dir_all(&sysroot_dst)); t!(fs::create_dir_all(&sysroot_host_dst)); @@ -814,14 +804,14 @@ pub fn add_to_sysroot( } } -pub fn run_cargo(builder: &Builder<'_>, - cargo: Cargo, - tail_args: Vec<String>, - stamp: &Path, - additional_target_deps: Vec<PathBuf>, - is_check: bool) - -> Vec<PathBuf> -{ +pub fn run_cargo( + builder: &Builder<'_>, + cargo: Cargo, + tail_args: Vec<String>, + stamp: &Path, + additional_target_deps: Vec<PathBuf>, + is_check: bool, +) -> Vec<PathBuf> { if builder.config.dry_run { return Vec::new(); } @@ -831,9 +821,12 @@ pub fn run_cargo(builder: &Builder<'_>, // `target_deps_dir` looks like $dir/$target/release/deps let target_deps_dir = target_root_dir.join("deps"); // `host_root_dir` looks like $dir/release - let host_root_dir = target_root_dir.parent().unwrap() // chop off `release` - .parent().unwrap() // chop off `$target` - .join(target_root_dir.file_name().unwrap()); + let host_root_dir = target_root_dir + .parent() + .unwrap() // chop off `release` + .parent() + .unwrap() // chop off `$target` + .join(target_root_dir.file_name().unwrap()); // Spawn Cargo slurping up its JSON output. We'll start building up the // `deps` array of all files it generated along with a `toplevel` array of @@ -844,20 +837,19 @@ pub fn run_cargo(builder: &Builder<'_>, let (filenames, crate_types) = match msg { CargoMessage::CompilerArtifact { filenames, - target: CargoTarget { - crate_types, - }, + target: CargoTarget { crate_types }, .. } => (filenames, crate_types), _ => return, }; for filename in filenames { // Skip files like executables - if !filename.ends_with(".rlib") && - !filename.ends_with(".lib") && - !filename.ends_with(".a") && - !is_dylib(&filename) && - !(is_check && filename.ends_with(".rmeta")) { + if !filename.ends_with(".rlib") + && !filename.ends_with(".lib") + && !filename.ends_with(".a") + && !is_dylib(&filename) + && !(is_check && filename.ends_with(".rmeta")) + { continue; } @@ -913,14 +905,13 @@ pub fn run_cargo(builder: &Builder<'_>, .collect::<Vec<_>>(); for (prefix, extension, expected_len) in toplevel { let candidates = contents.iter().filter(|&&(_, ref filename, ref meta)| { - filename.starts_with(&prefix[..]) && - filename[prefix.len()..].starts_with("-") && - filename.ends_with(&extension[..]) && - meta.len() == expected_len - }); - let max = candidates.max_by_key(|&&(_, _, ref metadata)| { - FileTime::from_last_modification_time(metadata) + filename.starts_with(&prefix[..]) + && filename[prefix.len()..].starts_with("-") + && filename.ends_with(&extension[..]) + && meta.len() == expected_len }); + let max = candidates + .max_by_key(|&&(_, _, ref metadata)| FileTime::from_last_modification_time(metadata)); let path_to_add = match max { Some(triple) => triple.0.to_str().unwrap(), None => panic!("no output generated for {:?} {:?}", prefix, extension), @@ -960,7 +951,7 @@ pub fn stream_cargo( // Instruct Cargo to give us json messages on stdout, critically leaving // stderr as piped so we can get those pretty colors. let mut message_format = String::from("json-render-diagnostics"); - if let Some(s) = &builder.config.rustc_error_format { + if let Some(s) = &builder.config.rustc_error_format { message_format.push_str(",json-diagnostic-"); message_format.push_str(s); } @@ -985,17 +976,18 @@ pub fn stream_cargo( match serde_json::from_str::<CargoMessage<'_>>(&line) { Ok(msg) => cb(msg), // If this was informational, just print it out and continue - Err(_) => println!("{}", line) + Err(_) => println!("{}", line), } } // Make sure Cargo actually succeeded after we read all of its stdout. let status = t!(child.wait()); if !status.success() { - eprintln!("command did not execute successfully: {:?}\n\ + eprintln!( + "command did not execute successfully: {:?}\n\ expected success, got: {}", - cargo, - status); + cargo, status + ); } status.success() } diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 3e67734e690..11bfc7a47cc 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -3,20 +3,20 @@ //! This module implements parsing `config.toml` configuration files to tweak //! how the build runs. +use std::cmp; use std::collections::{HashMap, HashSet}; use std::env; use std::ffi::OsString; use std::fs; use std::path::{Path, PathBuf}; use std::process; -use std::cmp; -use build_helper::t; -use toml; -use serde::Deserialize; -use crate::cache::{INTERNER, Interned}; +use crate::cache::{Interned, INTERNER}; use crate::flags::Flags; pub use crate::flags::Subcommand; +use build_helper::t; +use serde::Deserialize; +use toml; /// Global configuration for the entire build and/or bootstrap. /// @@ -420,17 +420,22 @@ impl Config { let has_targets = !flags.target.is_empty(); config.skip_only_host_steps = !has_hosts && has_targets; - let toml = file.map(|file| { - let contents = t!(fs::read_to_string(&file)); - match toml::from_str(&contents) { - Ok(table) => table, - Err(err) => { - println!("failed to parse TOML configuration '{}': {}", - file.display(), err); - process::exit(2); + let toml = file + .map(|file| { + let contents = t!(fs::read_to_string(&file)); + match toml::from_str(&contents) { + Ok(table) => table, + Err(err) => { + println!( + "failed to parse TOML configuration '{}': {}", + file.display(), + err + ); + process::exit(2); + } } - } - }).unwrap_or_else(|| TomlConfig::default()); + }) + .unwrap_or_else(|| TomlConfig::default()); let build = toml.build.clone().unwrap_or_default(); // set by bootstrap.py @@ -441,24 +446,15 @@ impl Config { config.hosts.push(host); } } - for target in config.hosts.iter().cloned() - .chain(build.target.iter().map(|s| INTERNER.intern_str(s))) + for target in + config.hosts.iter().cloned().chain(build.target.iter().map(|s| INTERNER.intern_str(s))) { if !config.targets.contains(&target) { config.targets.push(target); } } - config.hosts = if !flags.host.is_empty() { - flags.host - } else { - config.hosts - }; - config.targets = if !flags.target.is_empty() { - flags.target - } else { - config.targets - }; - + config.hosts = if !flags.host.is_empty() { flags.host } else { config.hosts }; + config.targets = if !flags.target.is_empty() { flags.target } else { config.targets }; config.nodejs = build.nodejs.map(PathBuf::from); config.gdb = build.gdb.map(PathBuf::from); @@ -507,9 +503,7 @@ impl Config { if let Some(ref llvm) = toml.llvm { match llvm.ccache { - Some(StringOrBool::String(ref s)) => { - config.ccache = Some(s.to_string()) - } + Some(StringOrBool::String(ref s)) => config.ccache = Some(s.to_string()), Some(StringOrBool::Bool(true)) => { config.ccache = Some("ccache".to_string()); } @@ -574,9 +568,8 @@ impl Config { set(&mut config.rust_remap_debuginfo, rust.remap_debuginfo); if let Some(ref backends) = rust.codegen_backends { - config.rust_codegen_backends = backends.iter() - .map(|s| INTERNER.intern_str(s)) - .collect(); + config.rust_codegen_backends = + backends.iter().map(|s| INTERNER.intern_str(s)).collect(); } config.rust_codegen_units = rust.codegen_units.map(threads_from_config); @@ -634,9 +627,11 @@ impl Config { config.rust_debug_assertions = debug_assertions.unwrap_or(default); let with_defaults = |debuginfo_level_specific: Option<u32>| { - debuginfo_level_specific - .or(debuginfo_level) - .unwrap_or(if debug == Some(true) { 2 } else { 0 }) + debuginfo_level_specific.or(debuginfo_level).unwrap_or(if debug == Some(true) { + 2 + } else { + 0 + }) }; config.rust_debuginfo_level_rustc = with_defaults(debuginfo_level_rustc); config.rust_debuginfo_level_std = with_defaults(debuginfo_level_std); diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index 02533944fc2..e64d4c8637d 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -11,18 +11,18 @@ use std::env; use std::fs; use std::io::Write; -use std::path::{PathBuf, Path}; +use std::path::{Path, PathBuf}; use std::process::{Command, Stdio}; use build_helper::{output, t}; -use crate::{Compiler, Mode, LLVM_TOOLS}; -use crate::channel; -use crate::util::{is_dylib, exe, timeit}; use crate::builder::{Builder, RunConfig, ShouldRun, Step}; +use crate::cache::{Interned, INTERNER}; +use crate::channel; use crate::compile; use crate::tool::{self, Tool}; -use crate::cache::{INTERNER, Interned}; +use crate::util::{exe, is_dylib, timeit}; +use crate::{Compiler, Mode, LLVM_TOOLS}; use time::{self, Timespec}; pub fn pkgname(builder: &Builder<'_>, component: &str) -> String { @@ -80,9 +80,7 @@ impl Step for Docs { } fn make_run(run: RunConfig<'_>) { - run.builder.ensure(Docs { - host: run.target, - }); + run.builder.ensure(Docs { host: run.target }); } /// Builds the `rust-docs` installer component. @@ -110,16 +108,19 @@ impl Step for Docs { let mut cmd = rust_installer(builder); cmd.arg("generate") - .arg("--product-name=Rust-Documentation") - .arg("--rel-manifest-dir=rustlib") - .arg("--success-message=Rust-documentation-is-installed.") - .arg("--image-dir").arg(&image) - .arg("--work-dir").arg(&tmpdir(builder)) - .arg("--output-dir").arg(&distdir(builder)) - .arg(format!("--package-name={}-{}", name, host)) - .arg("--component-name=rust-docs") - .arg("--legacy-manifest-dirs=rustlib,cargo") - .arg("--bulk-dirs=share/doc/rust/html"); + .arg("--product-name=Rust-Documentation") + .arg("--rel-manifest-dir=rustlib") + .arg("--success-message=Rust-documentation-is-installed.") + .arg("--image-dir") + .arg(&image) + .arg("--work-dir") + .arg(&tmpdir(builder)) + .arg("--output-dir") + .arg(&distdir(builder)) + .arg(format!("--package-name={}-{}", name, host)) + .arg("--component-name=rust-docs") + .arg("--legacy-manifest-dirs=rustlib,cargo") + .arg("--bulk-dirs=share/doc/rust/html"); builder.run(&mut cmd); builder.remove_dir(&image); @@ -141,9 +142,7 @@ impl Step for RustcDocs { } fn make_run(run: RunConfig<'_>) { - run.builder.ensure(RustcDocs { - host: run.target, - }); + run.builder.ensure(RustcDocs { host: run.target }); } /// Builds the `rustc-docs` installer component. @@ -168,16 +167,19 @@ impl Step for RustcDocs { let mut cmd = rust_installer(builder); cmd.arg("generate") - .arg("--product-name=Rustc-Documentation") - .arg("--rel-manifest-dir=rustlib") - .arg("--success-message=Rustc-documentation-is-installed.") - .arg("--image-dir").arg(&image) - .arg("--work-dir").arg(&tmpdir(builder)) - .arg("--output-dir").arg(&distdir(builder)) - .arg(format!("--package-name={}-{}", name, host)) - .arg("--component-name=rustc-docs") - .arg("--legacy-manifest-dirs=rustlib,cargo") - .arg("--bulk-dirs=share/doc/rust/html"); + .arg("--product-name=Rustc-Documentation") + .arg("--rel-manifest-dir=rustlib") + .arg("--success-message=Rustc-documentation-is-installed.") + .arg("--image-dir") + .arg(&image) + .arg("--work-dir") + .arg(&tmpdir(builder)) + .arg("--output-dir") + .arg(&distdir(builder)) + .arg(format!("--package-name={}-{}", name, host)) + .arg("--component-name=rustc-docs") + .arg("--legacy-manifest-dirs=rustlib,cargo") + .arg("--bulk-dirs=share/doc/rust/html"); builder.info(&format!("Dist compiler docs ({})", host)); let _time = timeit(builder); @@ -192,10 +194,7 @@ fn find_files(files: &[&str], path: &[PathBuf]) -> Vec<PathBuf> { let mut found = Vec::with_capacity(files.len()); for file in files { - let file_path = - path.iter() - .map(|dir| dir.join(file)) - .find(|p| p.exists()); + let file_path = path.iter().map(|dir| dir.join(file)).find(|p| p.exists()); if let Some(file_path) = file_path { found.push(file_path); @@ -208,7 +207,10 @@ fn find_files(files: &[&str], path: &[PathBuf]) -> Vec<PathBuf> { } fn make_win_dist( - rust_root: &Path, plat_root: &Path, target_triple: Interned<String>, builder: &Builder<'_> + rust_root: &Path, + plat_root: &Path, + target_triple: Interned<String>, + builder: &Builder<'_>, ) { //Ask gcc where it keeps its stuff let mut cmd = Command::new(builder.cc(target_triple)); @@ -222,11 +224,7 @@ fn make_win_dist( let idx = line.find(':').unwrap(); let key = &line[..idx]; let trim_chars: &[_] = &[' ', '=']; - let value = - line[(idx + 1)..] - .trim_start_matches(trim_chars) - .split(';') - .map(PathBuf::from); + let value = line[(idx + 1)..].trim_start_matches(trim_chars).split(';').map(PathBuf::from); if key == "programs" { bin_path.extend(value); @@ -243,7 +241,8 @@ fn make_win_dist( rustc_dlls.push("libgcc_s_seh-1.dll"); } - let target_libs = [ //MinGW libs + let target_libs = [ + //MinGW libs "libgcc.a", "libgcc_eh.a", "libgcc_s.a", @@ -312,7 +311,7 @@ fn make_win_dist( &target_bin_dir.join("GCC-WARNING.txt"), "gcc.exe contained in this folder cannot be used for compiling C files - it is only\ used as a linker. In order to be able to compile projects containing C code use\ - the GCC provided by MinGW or Cygwin." + the GCC provided by MinGW or Cygwin.", ); //Copy platform libs to platform-specific lib directory @@ -366,15 +365,18 @@ impl Step for Mingw { let mut cmd = rust_installer(builder); cmd.arg("generate") - .arg("--product-name=Rust-MinGW") - .arg("--rel-manifest-dir=rustlib") - .arg("--success-message=Rust-MinGW-is-installed.") - .arg("--image-dir").arg(&image) - .arg("--work-dir").arg(&tmpdir(builder)) - .arg("--output-dir").arg(&distdir(builder)) - .arg(format!("--package-name={}-{}", name, host)) - .arg("--component-name=rust-mingw") - .arg("--legacy-manifest-dirs=rustlib,cargo"); + .arg("--product-name=Rust-MinGW") + .arg("--rel-manifest-dir=rustlib") + .arg("--success-message=Rust-MinGW-is-installed.") + .arg("--image-dir") + .arg(&image) + .arg("--work-dir") + .arg(&tmpdir(builder)) + .arg("--output-dir") + .arg(&distdir(builder)) + .arg(format!("--package-name={}-{}", name, host)) + .arg("--component-name=rust-mingw") + .arg("--legacy-manifest-dirs=rustlib,cargo"); builder.run(&mut cmd); t!(fs::remove_dir_all(&image)); Some(distdir(builder).join(format!("{}-{}.tar.gz", name, host))) @@ -396,9 +398,8 @@ impl Step for Rustc { } fn make_run(run: RunConfig<'_>) { - run.builder.ensure(Rustc { - compiler: run.builder.compiler(run.builder.top_stage, run.target), - }); + run.builder + .ensure(Rustc { compiler: run.builder.compiler(run.builder.top_stage, run.target) }); } /// Creates the `rustc` installer component. @@ -452,16 +453,20 @@ impl Step for Rustc { // Finally, wrap everything up in a nice tarball! let mut cmd = rust_installer(builder); cmd.arg("generate") - .arg("--product-name=Rust") - .arg("--rel-manifest-dir=rustlib") - .arg("--success-message=Rust-is-ready-to-roll.") - .arg("--image-dir").arg(&image) - .arg("--work-dir").arg(&tmpdir(builder)) - .arg("--output-dir").arg(&distdir(builder)) - .arg("--non-installed-overlay").arg(&overlay) - .arg(format!("--package-name={}-{}", name, host)) - .arg("--component-name=rustc") - .arg("--legacy-manifest-dirs=rustlib,cargo"); + .arg("--product-name=Rust") + .arg("--rel-manifest-dir=rustlib") + .arg("--success-message=Rust-is-ready-to-roll.") + .arg("--image-dir") + .arg(&image) + .arg("--work-dir") + .arg(&tmpdir(builder)) + .arg("--output-dir") + .arg(&distdir(builder)) + .arg("--non-installed-overlay") + .arg(&overlay) + .arg(format!("--package-name={}-{}", name, host)) + .arg("--component-name=rustc") + .arg("--legacy-manifest-dirs=rustlib,cargo"); builder.info(&format!("Dist rustc stage{} ({})", compiler.stage, host)); let _time = timeit(builder); @@ -508,16 +513,10 @@ impl Step for Rustc { // Copy over lld if it's there if builder.config.lld_enabled { let exe = exe("rust-lld", &compiler.host); - let src = builder.sysroot_libdir(compiler, host) - .parent() - .unwrap() - .join("bin") - .join(&exe); + let src = + builder.sysroot_libdir(compiler, host).parent().unwrap().join("bin").join(&exe); // for the rationale about this rename check `compile::copy_lld_to_sysroot` - let dst = image.join("lib/rustlib") - .join(&*host) - .join("bin") - .join(&exe); + let dst = image.join("lib/rustlib").join(&*host).join("bin").join(&exe); t!(fs::create_dir_all(&dst.parent().unwrap())); builder.copy(&src, &dst); } @@ -530,9 +529,10 @@ impl Step for Rustc { // Reproducible builds: If SOURCE_DATE_EPOCH is set, use that as the time. let time = env::var("SOURCE_DATE_EPOCH") .map(|timestamp| { - let epoch = timestamp.parse().map_err(|err| { - format!("could not parse SOURCE_DATE_EPOCH: {}", err) - }).unwrap(); + let epoch = timestamp + .parse() + .map_err(|err| format!("could not parse SOURCE_DATE_EPOCH: {}", err)) + .unwrap(); time::at(Timespec::new(epoch, 0)) }) @@ -546,16 +546,18 @@ impl Step for Rustc { let page_dst = man_dst.join(file_entry.file_name()); t!(fs::copy(&page_src, &page_dst)); // template in month/year and version number - builder.replace_in_file(&page_dst, - &[("<INSERT DATE HERE>", &month_year), - ("<INSERT VERSION HERE>", channel::CFG_RELEASE_NUM)]); + builder.replace_in_file( + &page_dst, + &[ + ("<INSERT DATE HERE>", &month_year), + ("<INSERT VERSION HERE>", channel::CFG_RELEASE_NUM), + ], + ); } // Debugger scripts - builder.ensure(DebuggerScripts { - sysroot: INTERNER.intern_path(image.to_owned()), - host, - }); + builder + .ensure(DebuggerScripts { sysroot: INTERNER.intern_path(image.to_owned()), host }); // Misc license info let cp = |file: &str| { @@ -600,8 +602,11 @@ impl Step for DebuggerScripts { }; if host.contains("windows-msvc") { // windbg debugger scripts - builder.install(&builder.src.join("src/etc/rust-windbg.cmd"), &sysroot.join("bin"), - 0o755); + builder.install( + &builder.src.join("src/etc/rust-windbg.cmd"), + &sysroot.join("bin"), + 0o755, + ); cp_debugger_script("natvis/intrinsic.natvis"); cp_debugger_script("natvis/liballoc.natvis"); @@ -611,17 +616,14 @@ impl Step for DebuggerScripts { cp_debugger_script("debugger_pretty_printers_common.py"); // gdb debugger scripts - builder.install(&builder.src.join("src/etc/rust-gdb"), &sysroot.join("bin"), - 0o755); - builder.install(&builder.src.join("src/etc/rust-gdbgui"), &sysroot.join("bin"), - 0o755); + builder.install(&builder.src.join("src/etc/rust-gdb"), &sysroot.join("bin"), 0o755); + builder.install(&builder.src.join("src/etc/rust-gdbgui"), &sysroot.join("bin"), 0o755); cp_debugger_script("gdb_load_rust_pretty_printers.py"); cp_debugger_script("gdb_rust_pretty_printing.py"); // lldb debugger scripts - builder.install(&builder.src.join("src/etc/rust-lldb"), &sysroot.join("bin"), - 0o755); + builder.install(&builder.src.join("src/etc/rust-lldb"), &sysroot.join("bin"), 0o755); cp_debugger_script("lldb_rust_formatters.py"); } @@ -696,18 +698,21 @@ impl Step for Std { let mut cmd = rust_installer(builder); cmd.arg("generate") - .arg("--product-name=Rust") - .arg("--rel-manifest-dir=rustlib") - .arg("--success-message=std-is-standing-at-the-ready.") - .arg("--image-dir").arg(&image) - .arg("--work-dir").arg(&tmpdir(builder)) - .arg("--output-dir").arg(&distdir(builder)) - .arg(format!("--package-name={}-{}", name, target)) - .arg(format!("--component-name=rust-std-{}", target)) - .arg("--legacy-manifest-dirs=rustlib,cargo"); - - builder.info(&format!("Dist std stage{} ({} -> {})", - compiler.stage, &compiler.host, target)); + .arg("--product-name=Rust") + .arg("--rel-manifest-dir=rustlib") + .arg("--success-message=std-is-standing-at-the-ready.") + .arg("--image-dir") + .arg(&image) + .arg("--work-dir") + .arg(&tmpdir(builder)) + .arg("--output-dir") + .arg(&distdir(builder)) + .arg(format!("--package-name={}-{}", name, target)) + .arg(format!("--component-name=rust-std-{}", target)) + .arg("--legacy-manifest-dirs=rustlib,cargo"); + + builder + .info(&format!("Dist std stage{} ({} -> {})", compiler.stage, &compiler.host, target)); let _time = timeit(builder); builder.run(&mut cmd); builder.remove_dir(&image); @@ -762,18 +767,23 @@ impl Step for RustcDev { let mut cmd = rust_installer(builder); cmd.arg("generate") - .arg("--product-name=Rust") - .arg("--rel-manifest-dir=rustlib") - .arg("--success-message=Rust-is-ready-to-develop.") - .arg("--image-dir").arg(&image) - .arg("--work-dir").arg(&tmpdir(builder)) - .arg("--output-dir").arg(&distdir(builder)) - .arg(format!("--package-name={}-{}", name, target)) - .arg(format!("--component-name=rustc-dev-{}", target)) - .arg("--legacy-manifest-dirs=rustlib,cargo"); - - builder.info(&format!("Dist rustc-dev stage{} ({} -> {})", - compiler.stage, &compiler.host, target)); + .arg("--product-name=Rust") + .arg("--rel-manifest-dir=rustlib") + .arg("--success-message=Rust-is-ready-to-develop.") + .arg("--image-dir") + .arg(&image) + .arg("--work-dir") + .arg(&tmpdir(builder)) + .arg("--output-dir") + .arg(&distdir(builder)) + .arg(format!("--package-name={}-{}", name, target)) + .arg(format!("--component-name=rustc-dev-{}", target)) + .arg("--legacy-manifest-dirs=rustlib,cargo"); + + builder.info(&format!( + "Dist rustc-dev stage{} ({} -> {})", + compiler.stage, &compiler.host, target + )); let _time = timeit(builder); builder.run(&mut cmd); builder.remove_dir(&image); @@ -825,8 +835,11 @@ impl Step for Analysis { let image = tmpdir(builder).join(format!("{}-{}-image", name, target)); - let src = builder.stage_out(compiler, Mode::Std) - .join(target).join(builder.cargo_dir()).join("deps"); + let src = builder + .stage_out(compiler, Mode::Std) + .join(target) + .join(builder.cargo_dir()) + .join("deps"); let image_src = src.join("save-analysis"); let dst = image.join("lib/rustlib").join(target).join("analysis"); @@ -836,15 +849,18 @@ impl Step for Analysis { let mut cmd = rust_installer(builder); cmd.arg("generate") - .arg("--product-name=Rust") - .arg("--rel-manifest-dir=rustlib") - .arg("--success-message=save-analysis-saved.") - .arg("--image-dir").arg(&image) - .arg("--work-dir").arg(&tmpdir(builder)) - .arg("--output-dir").arg(&distdir(builder)) - .arg(format!("--package-name={}-{}", name, target)) - .arg(format!("--component-name=rust-analysis-{}", target)) - .arg("--legacy-manifest-dirs=rustlib,cargo"); + .arg("--product-name=Rust") + .arg("--rel-manifest-dir=rustlib") + .arg("--success-message=save-analysis-saved.") + .arg("--image-dir") + .arg(&image) + .arg("--work-dir") + .arg(&tmpdir(builder)) + .arg("--output-dir") + .arg(&distdir(builder)) + .arg(format!("--package-name={}-{}", name, target)) + .arg(format!("--component-name=rust-analysis-{}", target)) + .arg("--legacy-manifest-dirs=rustlib,cargo"); builder.info("Dist analysis"); let _time = timeit(builder); @@ -861,31 +877,35 @@ fn copy_src_dirs(builder: &Builder<'_>, src_dirs: &[&str], exclude_dirs: &[&str] None => return false, }; if spath.ends_with("~") || spath.ends_with(".pyc") { - return false + return false; } const LLVM_PROJECTS: &[&str] = &[ - "llvm-project/clang", "llvm-project\\clang", - "llvm-project/libunwind", "llvm-project\\libunwind", - "llvm-project/lld", "llvm-project\\lld", - "llvm-project/lldb", "llvm-project\\lldb", - "llvm-project/llvm", "llvm-project\\llvm", - "llvm-project/compiler-rt", "llvm-project\\compiler-rt", + "llvm-project/clang", + "llvm-project\\clang", + "llvm-project/libunwind", + "llvm-project\\libunwind", + "llvm-project/lld", + "llvm-project\\lld", + "llvm-project/lldb", + "llvm-project\\lldb", + "llvm-project/llvm", + "llvm-project\\llvm", + "llvm-project/compiler-rt", + "llvm-project\\compiler-rt", ]; - if spath.contains("llvm-project") && !spath.ends_with("llvm-project") + if spath.contains("llvm-project") + && !spath.ends_with("llvm-project") && !LLVM_PROJECTS.iter().any(|path| spath.contains(path)) { return false; } - const LLVM_TEST: &[&str] = &[ - "llvm-project/llvm/test", "llvm-project\\llvm\\test", - ]; - if LLVM_TEST.iter().any(|path| spath.contains(path)) && - (spath.ends_with(".ll") || - spath.ends_with(".td") || - spath.ends_with(".s")) { - return false + const LLVM_TEST: &[&str] = &["llvm-project/llvm/test", "llvm-project\\llvm\\test"]; + if LLVM_TEST.iter().any(|path| spath.contains(path)) + && (spath.ends_with(".ll") || spath.ends_with(".td") || spath.ends_with(".s")) + { + return false; } let full_path = Path::new(dir).join(path); @@ -894,22 +914,37 @@ fn copy_src_dirs(builder: &Builder<'_>, src_dirs: &[&str], exclude_dirs: &[&str] } let excludes = [ - "CVS", "RCS", "SCCS", ".git", ".gitignore", ".gitmodules", - ".gitattributes", ".cvsignore", ".svn", ".arch-ids", "{arch}", - "=RELEASE-ID", "=meta-update", "=update", ".bzr", ".bzrignore", - ".bzrtags", ".hg", ".hgignore", ".hgrags", "_darcs", + "CVS", + "RCS", + "SCCS", + ".git", + ".gitignore", + ".gitmodules", + ".gitattributes", + ".cvsignore", + ".svn", + ".arch-ids", + "{arch}", + "=RELEASE-ID", + "=meta-update", + "=update", + ".bzr", + ".bzrignore", + ".bzrtags", + ".hg", + ".hgignore", + ".hgrags", + "_darcs", ]; - !path.iter() - .map(|s| s.to_str().unwrap()) - .any(|s| excludes.contains(&s)) + !path.iter().map(|s| s.to_str().unwrap()).any(|s| excludes.contains(&s)) } // Copy the directories using our filter for item in src_dirs { let dst = &dst_dir.join(item); t!(fs::create_dir_all(dst)); - builder.cp_filtered( - &builder.src.join(item), dst, &|path| filter_fn(exclude_dirs, item, path)); + builder + .cp_filtered(&builder.src.join(item), dst, &|path| filter_fn(exclude_dirs, item, path)); } } @@ -940,9 +975,7 @@ impl Step for Src { let dst_src = dst.join("rust"); t!(fs::create_dir_all(&dst_src)); - let src_files = [ - "Cargo.lock", - ]; + let src_files = ["Cargo.lock"]; // This is the reduced set of paths which will become the rust-src component // (essentially libstd and all of its path dependencies) let std_src_dirs = [ @@ -977,15 +1010,18 @@ impl Step for Src { // Create source tarball in rust-installer format let mut cmd = rust_installer(builder); cmd.arg("generate") - .arg("--product-name=Rust") - .arg("--rel-manifest-dir=rustlib") - .arg("--success-message=Awesome-Source.") - .arg("--image-dir").arg(&image) - .arg("--work-dir").arg(&tmpdir(builder)) - .arg("--output-dir").arg(&distdir(builder)) - .arg(format!("--package-name={}", name)) - .arg("--component-name=rust-src") - .arg("--legacy-manifest-dirs=rustlib,cargo"); + .arg("--product-name=Rust") + .arg("--rel-manifest-dir=rustlib") + .arg("--success-message=Awesome-Source.") + .arg("--image-dir") + .arg(&image) + .arg("--work-dir") + .arg(&tmpdir(builder)) + .arg("--output-dir") + .arg(&distdir(builder)) + .arg(format!("--package-name={}", name)) + .arg("--component-name=rust-src") + .arg("--legacy-manifest-dirs=rustlib,cargo"); builder.info("Dist src"); let _time = timeit(builder); @@ -1036,9 +1072,7 @@ impl Step for PlainSourceTarball { "Cargo.toml", "Cargo.lock", ]; - let src_dirs = [ - "src", - ]; + let src_dirs = ["src"]; copy_src_dirs(builder, &src_dirs[..], &[], &plain_dst_src); @@ -1057,8 +1091,7 @@ impl Step for PlainSourceTarball { if builder.rust_info.is_git() { // Vendor all Cargo dependencies let mut cmd = Command::new(&builder.initial_cargo); - cmd.arg("vendor") - .current_dir(&plain_dst_src); + cmd.arg("vendor").current_dir(&plain_dst_src); builder.run(&mut cmd); } @@ -1073,10 +1106,12 @@ impl Step for PlainSourceTarball { builder.info("running installer"); let mut cmd = rust_installer(builder); cmd.arg("tarball") - .arg("--input").arg(&plain_name) - .arg("--output").arg(&tarball) - .arg("--work-dir=.") - .current_dir(tmpdir(builder)); + .arg("--input") + .arg(&plain_name) + .arg("--output") + .arg(&tarball) + .arg("--work-dir=.") + .current_dir(tmpdir(builder)); builder.info("Create plain source tarball"); let _time = timeit(builder); @@ -1095,10 +1130,10 @@ pub fn sanitize_sh(path: &Path) -> String { let mut ch = s.chars(); let drive = ch.next().unwrap_or('C'); if ch.next() != Some(':') { - return None + return None; } if ch.next() != Some('/') { - return None + return None; } Some(format!("/{}/{}", drive, &s[drive.len_utf8() + 2..])) } @@ -1154,8 +1189,7 @@ impl Step for Cargo { builder.install(&man.path(), &image.join("share/man/man1"), 0o644); } builder.install(&etc.join("_cargo"), &image.join("share/zsh/site-functions"), 0o644); - builder.copy(&etc.join("cargo.bashcomp.sh"), - &image.join("etc/bash_completion.d/cargo")); + builder.copy(&etc.join("cargo.bashcomp.sh"), &image.join("etc/bash_completion.d/cargo")); let doc = image.join("share/doc/cargo"); builder.install(&src.join("README.md"), &doc, 0o644); builder.install(&src.join("LICENSE-MIT"), &doc, 0o644); @@ -1175,16 +1209,20 @@ impl Step for Cargo { // Generate the installer tarball let mut cmd = rust_installer(builder); cmd.arg("generate") - .arg("--product-name=Rust") - .arg("--rel-manifest-dir=rustlib") - .arg("--success-message=Rust-is-ready-to-roll.") - .arg("--image-dir").arg(&image) - .arg("--work-dir").arg(&tmpdir(builder)) - .arg("--output-dir").arg(&distdir(builder)) - .arg("--non-installed-overlay").arg(&overlay) - .arg(format!("--package-name={}-{}", name, target)) - .arg("--component-name=cargo") - .arg("--legacy-manifest-dirs=rustlib,cargo"); + .arg("--product-name=Rust") + .arg("--rel-manifest-dir=rustlib") + .arg("--success-message=Rust-is-ready-to-roll.") + .arg("--image-dir") + .arg(&image) + .arg("--work-dir") + .arg(&tmpdir(builder)) + .arg("--output-dir") + .arg(&distdir(builder)) + .arg("--non-installed-overlay") + .arg(&overlay) + .arg(format!("--package-name={}-{}", name, target)) + .arg("--component-name=cargo") + .arg("--legacy-manifest-dirs=rustlib,cargo"); builder.info(&format!("Dist cargo stage{} ({})", compiler.stage, target)); let _time = timeit(builder); @@ -1236,11 +1274,12 @@ impl Step for Rls { // Prepare the image directory // We expect RLS to build, because we've exited this step above if tool // state for RLS isn't testing. - let rls = builder.ensure(tool::Rls { - compiler, - target, - extra_features: Vec::new(), - }).or_else(|| { missing_tool("RLS", builder.build.config.missing_tools); None })?; + let rls = builder + .ensure(tool::Rls { compiler, target, extra_features: Vec::new() }) + .or_else(|| { + missing_tool("RLS", builder.build.config.missing_tools); + None + })?; builder.install(&rls, &image.join("bin"), 0o755); let doc = image.join("share/doc/rls"); @@ -1260,16 +1299,20 @@ impl Step for Rls { // Generate the installer tarball let mut cmd = rust_installer(builder); cmd.arg("generate") - .arg("--product-name=Rust") - .arg("--rel-manifest-dir=rustlib") - .arg("--success-message=RLS-ready-to-serve.") - .arg("--image-dir").arg(&image) - .arg("--work-dir").arg(&tmpdir(builder)) - .arg("--output-dir").arg(&distdir(builder)) - .arg("--non-installed-overlay").arg(&overlay) - .arg(format!("--package-name={}-{}", name, target)) - .arg("--legacy-manifest-dirs=rustlib,cargo") - .arg("--component-name=rls-preview"); + .arg("--product-name=Rust") + .arg("--rel-manifest-dir=rustlib") + .arg("--success-message=RLS-ready-to-serve.") + .arg("--image-dir") + .arg(&image) + .arg("--work-dir") + .arg(&tmpdir(builder)) + .arg("--output-dir") + .arg(&distdir(builder)) + .arg("--non-installed-overlay") + .arg(&overlay) + .arg(format!("--package-name={}-{}", name, target)) + .arg("--legacy-manifest-dirs=rustlib,cargo") + .arg("--component-name=rls-preview"); builder.info(&format!("Dist RLS stage{} ({})", compiler.stage, target)); let _time = timeit(builder); @@ -1321,15 +1364,18 @@ impl Step for Clippy { // Prepare the image directory // We expect clippy to build, because we've exited this step above if tool // state for clippy isn't testing. - let clippy = builder.ensure(tool::Clippy { - compiler, - target, - extra_features: Vec::new(), - }).or_else(|| { missing_tool("clippy", builder.build.config.missing_tools); None })?; - let cargoclippy = builder.ensure(tool::CargoClippy { - compiler, - target, extra_features: Vec::new() - }).or_else(|| { missing_tool("cargo clippy", builder.build.config.missing_tools); None })?; + let clippy = builder + .ensure(tool::Clippy { compiler, target, extra_features: Vec::new() }) + .or_else(|| { + missing_tool("clippy", builder.build.config.missing_tools); + None + })?; + let cargoclippy = builder + .ensure(tool::CargoClippy { compiler, target, extra_features: Vec::new() }) + .or_else(|| { + missing_tool("cargo clippy", builder.build.config.missing_tools); + None + })?; builder.install(&clippy, &image.join("bin"), 0o755); builder.install(&cargoclippy, &image.join("bin"), 0o755); @@ -1350,16 +1396,20 @@ impl Step for Clippy { // Generate the installer tarball let mut cmd = rust_installer(builder); cmd.arg("generate") - .arg("--product-name=Rust") - .arg("--rel-manifest-dir=rustlib") - .arg("--success-message=clippy-ready-to-serve.") - .arg("--image-dir").arg(&image) - .arg("--work-dir").arg(&tmpdir(builder)) - .arg("--output-dir").arg(&distdir(builder)) - .arg("--non-installed-overlay").arg(&overlay) - .arg(format!("--package-name={}-{}", name, target)) - .arg("--legacy-manifest-dirs=rustlib,cargo") - .arg("--component-name=clippy-preview"); + .arg("--product-name=Rust") + .arg("--rel-manifest-dir=rustlib") + .arg("--success-message=clippy-ready-to-serve.") + .arg("--image-dir") + .arg(&image) + .arg("--work-dir") + .arg(&tmpdir(builder)) + .arg("--output-dir") + .arg(&distdir(builder)) + .arg("--non-installed-overlay") + .arg(&overlay) + .arg(format!("--package-name={}-{}", name, target)) + .arg("--legacy-manifest-dirs=rustlib,cargo") + .arg("--component-name=clippy-preview"); builder.info(&format!("Dist clippy stage{} ({})", compiler.stage, target)); let _time = timeit(builder); @@ -1411,16 +1461,18 @@ impl Step for Miri { // Prepare the image directory // We expect miri to build, because we've exited this step above if tool // state for miri isn't testing. - let miri = builder.ensure(tool::Miri { - compiler, - target, - extra_features: Vec::new(), - }).or_else(|| { missing_tool("miri", builder.build.config.missing_tools); None })?; - let cargomiri = builder.ensure(tool::CargoMiri { - compiler, - target, - extra_features: Vec::new() - }).or_else(|| { missing_tool("cargo miri", builder.build.config.missing_tools); None })?; + let miri = builder + .ensure(tool::Miri { compiler, target, extra_features: Vec::new() }) + .or_else(|| { + missing_tool("miri", builder.build.config.missing_tools); + None + })?; + let cargomiri = builder + .ensure(tool::CargoMiri { compiler, target, extra_features: Vec::new() }) + .or_else(|| { + missing_tool("cargo miri", builder.build.config.missing_tools); + None + })?; builder.install(&miri, &image.join("bin"), 0o755); builder.install(&cargomiri, &image.join("bin"), 0o755); @@ -1441,16 +1493,20 @@ impl Step for Miri { // Generate the installer tarball let mut cmd = rust_installer(builder); cmd.arg("generate") - .arg("--product-name=Rust") - .arg("--rel-manifest-dir=rustlib") - .arg("--success-message=miri-ready-to-serve.") - .arg("--image-dir").arg(&image) - .arg("--work-dir").arg(&tmpdir(builder)) - .arg("--output-dir").arg(&distdir(builder)) - .arg("--non-installed-overlay").arg(&overlay) - .arg(format!("--package-name={}-{}", name, target)) - .arg("--legacy-manifest-dirs=rustlib,cargo") - .arg("--component-name=miri-preview"); + .arg("--product-name=Rust") + .arg("--rel-manifest-dir=rustlib") + .arg("--success-message=miri-ready-to-serve.") + .arg("--image-dir") + .arg(&image) + .arg("--work-dir") + .arg(&tmpdir(builder)) + .arg("--output-dir") + .arg(&distdir(builder)) + .arg("--non-installed-overlay") + .arg(&overlay) + .arg(format!("--package-name={}-{}", name, target)) + .arg("--legacy-manifest-dirs=rustlib,cargo") + .arg("--component-name=miri-preview"); builder.info(&format!("Dist miri stage{} ({})", compiler.stage, target)); let _time = timeit(builder); @@ -1499,16 +1555,18 @@ impl Step for Rustfmt { builder.create_dir(&image); // Prepare the image directory - let rustfmt = builder.ensure(tool::Rustfmt { - compiler, - target, - extra_features: Vec::new(), - }).or_else(|| { missing_tool("Rustfmt", builder.build.config.missing_tools); None })?; - let cargofmt = builder.ensure(tool::Cargofmt { - compiler, - target, - extra_features: Vec::new(), - }).or_else(|| { missing_tool("Cargofmt", builder.build.config.missing_tools); None })?; + let rustfmt = builder + .ensure(tool::Rustfmt { compiler, target, extra_features: Vec::new() }) + .or_else(|| { + missing_tool("Rustfmt", builder.build.config.missing_tools); + None + })?; + let cargofmt = builder + .ensure(tool::Cargofmt { compiler, target, extra_features: Vec::new() }) + .or_else(|| { + missing_tool("Cargofmt", builder.build.config.missing_tools); + None + })?; builder.install(&rustfmt, &image.join("bin"), 0o755); builder.install(&cargofmt, &image.join("bin"), 0o755); @@ -1529,16 +1587,20 @@ impl Step for Rustfmt { // Generate the installer tarball let mut cmd = rust_installer(builder); cmd.arg("generate") - .arg("--product-name=Rust") - .arg("--rel-manifest-dir=rustlib") - .arg("--success-message=rustfmt-ready-to-fmt.") - .arg("--image-dir").arg(&image) - .arg("--work-dir").arg(&tmpdir(builder)) - .arg("--output-dir").arg(&distdir(builder)) - .arg("--non-installed-overlay").arg(&overlay) - .arg(format!("--package-name={}-{}", name, target)) - .arg("--legacy-manifest-dirs=rustlib,cargo") - .arg("--component-name=rustfmt-preview"); + .arg("--product-name=Rust") + .arg("--rel-manifest-dir=rustlib") + .arg("--success-message=rustfmt-ready-to-fmt.") + .arg("--image-dir") + .arg(&image) + .arg("--work-dir") + .arg(&tmpdir(builder)) + .arg("--output-dir") + .arg(&distdir(builder)) + .arg("--non-installed-overlay") + .arg(&overlay) + .arg(format!("--package-name={}-{}", name, target)) + .arg("--legacy-manifest-dirs=rustlib,cargo") + .arg("--component-name=rustfmt-preview"); builder.info(&format!("Dist Rustfmt stage{} ({})", compiler.stage, target)); let _time = timeit(builder); @@ -1580,9 +1642,7 @@ impl Step for Extended { builder.info(&format!("Dist extended stage{} ({})", compiler.stage, target)); - let rustc_installer = builder.ensure(Rustc { - compiler: builder.compiler(stage, target), - }); + let rustc_installer = builder.ensure(Rustc { compiler: builder.compiler(stage, target) }); let cargo_installer = builder.ensure(Cargo { compiler, target }); let rustfmt_installer = builder.ensure(Rustfmt { compiler, target }); let rls_installer = builder.ensure(Rls { compiler, target }); @@ -1593,11 +1653,9 @@ impl Step for Extended { let mingw_installer = builder.ensure(Mingw { host: target }); let analysis_installer = builder.ensure(Analysis { compiler, target }); - let docs_installer = builder.ensure(Docs { host: target, }); - let std_installer = builder.ensure(Std { - compiler: builder.compiler(stage, target), - target, - }); + let docs_installer = builder.ensure(Docs { host: target }); + let std_installer = + builder.ensure(Std { compiler: builder.compiler(stage, target), target }); let tmp = tmpdir(builder); let overlay = tmp.join("extended-overlay"); @@ -1648,12 +1706,16 @@ impl Step for Extended { .arg("--product-name=Rust") .arg("--rel-manifest-dir=rustlib") .arg("--success-message=Rust-is-ready-to-roll.") - .arg("--work-dir").arg(&work) - .arg("--output-dir").arg(&distdir(builder)) + .arg("--work-dir") + .arg(&work) + .arg("--output-dir") + .arg(&distdir(builder)) .arg(format!("--package-name={}-{}", pkgname(builder, "rust"), target)) .arg("--legacy-manifest-dirs=rustlib,cargo") - .arg("--input-tarballs").arg(input_tarballs) - .arg("--non-installed-overlay").arg(&overlay); + .arg("--input-tarballs") + .arg(input_tarballs) + .arg("--non-installed-overlay") + .arg(&overlay); let time = timeit(&builder); builder.run(&mut cmd); drop(time); @@ -1718,8 +1780,10 @@ impl Step for Extended { let pkgbuild = |component: &str| { let mut cmd = Command::new("pkgbuild"); - cmd.arg("--identifier").arg(format!("org.rust-lang.{}", component)) - .arg("--scripts").arg(pkg.join(component)) + cmd.arg("--identifier") + .arg(format!("org.rust-lang.{}", component)) + .arg("--scripts") + .arg(pkg.join(component)) .arg("--nopayload") .arg(pkg.join(component).with_extension("pkg")); builder.run(&mut cmd); @@ -1727,8 +1791,10 @@ impl Step for Extended { let prepare = |name: &str| { builder.create_dir(&pkg.join(name)); - builder.cp_r(&work.join(&format!("{}-{}", pkgname(builder, name), target)), - &pkg.join(name)); + builder.cp_r( + &work.join(&format!("{}-{}", pkgname(builder, name), target)), + &pkg.join(name), + ); builder.install(&etc.join("pkg/postinstall"), &pkg.join(name), 0o755); pkgbuild(name); }; @@ -1756,12 +1822,13 @@ impl Step for Extended { builder.create(&pkg.join("res/LICENSE.txt"), &license); builder.install(&etc.join("gfx/rust-logo.png"), &pkg.join("res"), 0o644); let mut cmd = Command::new("productbuild"); - cmd.arg("--distribution").arg(xform(&etc.join("pkg/Distribution.xml"))) - .arg("--resources").arg(pkg.join("res")) - .arg(distdir(builder).join(format!("{}-{}.pkg", - pkgname(builder, "rust"), - target))) - .arg("--package-path").arg(&pkg); + cmd.arg("--distribution") + .arg(xform(&etc.join("pkg/Distribution.xml"))) + .arg("--resources") + .arg(pkg.join("res")) + .arg(distdir(builder).join(format!("{}-{}.pkg", pkgname(builder, "rust"), target))) + .arg("--package-path") + .arg(&pkg); let _time = timeit(builder); builder.run(&mut cmd); } @@ -1783,9 +1850,10 @@ impl Step for Extended { } else { name.to_string() }; - builder.cp_r(&work.join(&format!("{}-{}", pkgname(builder, name), target)) - .join(dir), - &exe.join(name)); + builder.cp_r( + &work.join(&format!("{}-{}", pkgname(builder, name), target)).join(dir), + &exe.join(name), + ); builder.remove(&exe.join(name).join("manifest.in")); }; prepare("rustc"); @@ -1815,9 +1883,7 @@ impl Step for Extended { // Generate exe installer builder.info("building `exe` installer with `iscc`"); let mut cmd = Command::new("iscc"); - cmd.arg("rust.iss") - .arg("/Q") - .current_dir(&exe); + cmd.arg("rust.iss").arg("/Q").current_dir(&exe); if target.contains("windows-gnu") { cmd.arg("/dMINGW"); } @@ -1825,9 +1891,11 @@ impl Step for Extended { let time = timeit(builder); builder.run(&mut cmd); drop(time); - builder.install(&exe.join(format!("{}-{}.exe", pkgname(builder, "rust"), target)), - &distdir(builder), - 0o755); + builder.install( + &exe.join(format!("{}-{}.exe", pkgname(builder, "rust"), target)), + &distdir(builder), + 0o755, + ); // Generate msi installer let wix = PathBuf::from(env::var_os("WIX").unwrap()); @@ -1836,106 +1904,165 @@ impl Step for Extended { let light = wix.join("bin/light.exe"); let heat_flags = ["-nologo", "-gg", "-sfrag", "-srd", "-sreg"]; - builder.run(Command::new(&heat) - .current_dir(&exe) - .arg("dir") - .arg("rustc") - .args(&heat_flags) - .arg("-cg").arg("RustcGroup") - .arg("-dr").arg("Rustc") - .arg("-var").arg("var.RustcDir") - .arg("-out").arg(exe.join("RustcGroup.wxs"))); - builder.run(Command::new(&heat) - .current_dir(&exe) - .arg("dir") - .arg("rust-docs") - .args(&heat_flags) - .arg("-cg").arg("DocsGroup") - .arg("-dr").arg("Docs") - .arg("-var").arg("var.DocsDir") - .arg("-out").arg(exe.join("DocsGroup.wxs")) - .arg("-t").arg(etc.join("msi/squash-components.xsl"))); - builder.run(Command::new(&heat) - .current_dir(&exe) - .arg("dir") - .arg("cargo") - .args(&heat_flags) - .arg("-cg").arg("CargoGroup") - .arg("-dr").arg("Cargo") - .arg("-var").arg("var.CargoDir") - .arg("-out").arg(exe.join("CargoGroup.wxs")) - .arg("-t").arg(etc.join("msi/remove-duplicates.xsl"))); - builder.run(Command::new(&heat) - .current_dir(&exe) - .arg("dir") - .arg("rust-std") - .args(&heat_flags) - .arg("-cg").arg("StdGroup") - .arg("-dr").arg("Std") - .arg("-var").arg("var.StdDir") - .arg("-out").arg(exe.join("StdGroup.wxs"))); + builder.run( + Command::new(&heat) + .current_dir(&exe) + .arg("dir") + .arg("rustc") + .args(&heat_flags) + .arg("-cg") + .arg("RustcGroup") + .arg("-dr") + .arg("Rustc") + .arg("-var") + .arg("var.RustcDir") + .arg("-out") + .arg(exe.join("RustcGroup.wxs")), + ); + builder.run( + Command::new(&heat) + .current_dir(&exe) + .arg("dir") + .arg("rust-docs") + .args(&heat_flags) + .arg("-cg") + .arg("DocsGroup") + .arg("-dr") + .arg("Docs") + .arg("-var") + .arg("var.DocsDir") + .arg("-out") + .arg(exe.join("DocsGroup.wxs")) + .arg("-t") + .arg(etc.join("msi/squash-components.xsl")), + ); + builder.run( + Command::new(&heat) + .current_dir(&exe) + .arg("dir") + .arg("cargo") + .args(&heat_flags) + .arg("-cg") + .arg("CargoGroup") + .arg("-dr") + .arg("Cargo") + .arg("-var") + .arg("var.CargoDir") + .arg("-out") + .arg(exe.join("CargoGroup.wxs")) + .arg("-t") + .arg(etc.join("msi/remove-duplicates.xsl")), + ); + builder.run( + Command::new(&heat) + .current_dir(&exe) + .arg("dir") + .arg("rust-std") + .args(&heat_flags) + .arg("-cg") + .arg("StdGroup") + .arg("-dr") + .arg("Std") + .arg("-var") + .arg("var.StdDir") + .arg("-out") + .arg(exe.join("StdGroup.wxs")), + ); if rls_installer.is_some() { - builder.run(Command::new(&heat) - .current_dir(&exe) - .arg("dir") - .arg("rls") - .args(&heat_flags) - .arg("-cg").arg("RlsGroup") - .arg("-dr").arg("Rls") - .arg("-var").arg("var.RlsDir") - .arg("-out").arg(exe.join("RlsGroup.wxs")) - .arg("-t").arg(etc.join("msi/remove-duplicates.xsl"))); + builder.run( + Command::new(&heat) + .current_dir(&exe) + .arg("dir") + .arg("rls") + .args(&heat_flags) + .arg("-cg") + .arg("RlsGroup") + .arg("-dr") + .arg("Rls") + .arg("-var") + .arg("var.RlsDir") + .arg("-out") + .arg(exe.join("RlsGroup.wxs")) + .arg("-t") + .arg(etc.join("msi/remove-duplicates.xsl")), + ); } if clippy_installer.is_some() { - builder.run(Command::new(&heat) - .current_dir(&exe) - .arg("dir") - .arg("clippy") - .args(&heat_flags) - .arg("-cg").arg("ClippyGroup") - .arg("-dr").arg("Clippy") - .arg("-var").arg("var.ClippyDir") - .arg("-out").arg(exe.join("ClippyGroup.wxs")) - .arg("-t").arg(etc.join("msi/remove-duplicates.xsl"))); + builder.run( + Command::new(&heat) + .current_dir(&exe) + .arg("dir") + .arg("clippy") + .args(&heat_flags) + .arg("-cg") + .arg("ClippyGroup") + .arg("-dr") + .arg("Clippy") + .arg("-var") + .arg("var.ClippyDir") + .arg("-out") + .arg(exe.join("ClippyGroup.wxs")) + .arg("-t") + .arg(etc.join("msi/remove-duplicates.xsl")), + ); } if miri_installer.is_some() { - builder.run(Command::new(&heat) - .current_dir(&exe) - .arg("dir") - .arg("miri") - .args(&heat_flags) - .arg("-cg").arg("MiriGroup") - .arg("-dr").arg("Miri") - .arg("-var").arg("var.MiriDir") - .arg("-out").arg(exe.join("MiriGroup.wxs")) - .arg("-t").arg(etc.join("msi/remove-duplicates.xsl"))); + builder.run( + Command::new(&heat) + .current_dir(&exe) + .arg("dir") + .arg("miri") + .args(&heat_flags) + .arg("-cg") + .arg("MiriGroup") + .arg("-dr") + .arg("Miri") + .arg("-var") + .arg("var.MiriDir") + .arg("-out") + .arg(exe.join("MiriGroup.wxs")) + .arg("-t") + .arg(etc.join("msi/remove-duplicates.xsl")), + ); } - builder.run(Command::new(&heat) - .current_dir(&exe) - .arg("dir") - .arg("rust-analysis") - .args(&heat_flags) - .arg("-cg").arg("AnalysisGroup") - .arg("-dr").arg("Analysis") - .arg("-var").arg("var.AnalysisDir") - .arg("-out").arg(exe.join("AnalysisGroup.wxs")) - .arg("-t").arg(etc.join("msi/remove-duplicates.xsl"))); + builder.run( + Command::new(&heat) + .current_dir(&exe) + .arg("dir") + .arg("rust-analysis") + .args(&heat_flags) + .arg("-cg") + .arg("AnalysisGroup") + .arg("-dr") + .arg("Analysis") + .arg("-var") + .arg("var.AnalysisDir") + .arg("-out") + .arg(exe.join("AnalysisGroup.wxs")) + .arg("-t") + .arg(etc.join("msi/remove-duplicates.xsl")), + ); if target.contains("windows-gnu") { - builder.run(Command::new(&heat) - .current_dir(&exe) - .arg("dir") - .arg("rust-mingw") - .args(&heat_flags) - .arg("-cg").arg("GccGroup") - .arg("-dr").arg("Gcc") - .arg("-var").arg("var.GccDir") - .arg("-out").arg(exe.join("GccGroup.wxs"))); + builder.run( + Command::new(&heat) + .current_dir(&exe) + .arg("dir") + .arg("rust-mingw") + .args(&heat_flags) + .arg("-cg") + .arg("GccGroup") + .arg("-dr") + .arg("Gcc") + .arg("-var") + .arg("var.GccDir") + .arg("-out") + .arg(exe.join("GccGroup.wxs")), + ); } let candle = |input: &Path| { - let output = exe.join(input.file_stem().unwrap()) - .with_extension("wixobj"); - let arch = if target.contains("x86_64") {"x64"} else {"x86"}; + let output = exe.join(input.file_stem().unwrap()).with_extension("wixobj"); + let arch = if target.contains("x86_64") { "x64" } else { "x86" }; let mut cmd = Command::new(&candle); cmd.current_dir(&exe) .arg("-nologo") @@ -1944,8 +2071,10 @@ impl Step for Extended { .arg("-dCargoDir=cargo") .arg("-dStdDir=rust-std") .arg("-dAnalysisDir=rust-analysis") - .arg("-arch").arg(&arch) - .arg("-out").arg(&output) + .arg("-arch") + .arg(&arch) + .arg("-out") + .arg(&output) .arg(&input); add_env(builder, &mut cmd, target); @@ -1993,9 +2122,12 @@ impl Step for Extended { let filename = format!("{}-{}.msi", pkgname(builder, "rust"), target); let mut cmd = Command::new(&light); cmd.arg("-nologo") - .arg("-ext").arg("WixUIExtension") - .arg("-ext").arg("WixUtilExtension") - .arg("-out").arg(exe.join(&filename)) + .arg("-ext") + .arg("WixUIExtension") + .arg("-ext") + .arg("WixUtilExtension") + .arg("-out") + .arg(exe.join(&filename)) .arg("rust.wixobj") .arg("ui.wixobj") .arg("rustwelcomedlg.wixobj") @@ -2035,29 +2167,27 @@ impl Step for Extended { fn add_env(builder: &Builder<'_>, cmd: &mut Command, target: Interned<String>) { let mut parts = channel::CFG_RELEASE_NUM.split('.'); cmd.env("CFG_RELEASE_INFO", builder.rust_version()) - .env("CFG_RELEASE_NUM", channel::CFG_RELEASE_NUM) - .env("CFG_RELEASE", builder.rust_release()) - .env("CFG_VER_MAJOR", parts.next().unwrap()) - .env("CFG_VER_MINOR", parts.next().unwrap()) - .env("CFG_VER_PATCH", parts.next().unwrap()) - .env("CFG_VER_BUILD", "0") // just needed to build - .env("CFG_PACKAGE_VERS", builder.rust_package_vers()) - .env("CFG_PACKAGE_NAME", pkgname(builder, "rust")) - .env("CFG_BUILD", target) - .env("CFG_CHANNEL", &builder.config.channel); + .env("CFG_RELEASE_NUM", channel::CFG_RELEASE_NUM) + .env("CFG_RELEASE", builder.rust_release()) + .env("CFG_VER_MAJOR", parts.next().unwrap()) + .env("CFG_VER_MINOR", parts.next().unwrap()) + .env("CFG_VER_PATCH", parts.next().unwrap()) + .env("CFG_VER_BUILD", "0") // just needed to build + .env("CFG_PACKAGE_VERS", builder.rust_package_vers()) + .env("CFG_PACKAGE_NAME", pkgname(builder, "rust")) + .env("CFG_BUILD", target) + .env("CFG_CHANNEL", &builder.config.channel); if target.contains("windows-gnu") { - cmd.env("CFG_MINGW", "1") - .env("CFG_ABI", "GNU"); + cmd.env("CFG_MINGW", "1").env("CFG_ABI", "GNU"); } else { - cmd.env("CFG_MINGW", "0") - .env("CFG_ABI", "MSVC"); + cmd.env("CFG_MINGW", "0").env("CFG_ABI", "MSVC"); } if target.contains("x86_64") { - cmd.env("CFG_PLATFORM", "x64"); + cmd.env("CFG_PLATFORM", "x64"); } else { - cmd.env("CFG_PLATFORM", "x86"); + cmd.env("CFG_PLATFORM", "x86"); } } @@ -2130,17 +2260,11 @@ impl Step for HashSign { // // Note: This function does no yet support Windows but we also don't support // linking LLVM tools dynamically on Windows yet. -pub fn maybe_install_llvm_dylib(builder: &Builder<'_>, - target: Interned<String>, - sysroot: &Path) { - let src_libdir = builder - .llvm_out(target) - .join("lib"); +pub fn maybe_install_llvm_dylib(builder: &Builder<'_>, target: Interned<String>, sysroot: &Path) { + let src_libdir = builder.llvm_out(target).join("lib"); let dst_libdir1 = sysroot.join("lib/rustlib").join(&*target).join("lib"); - let dst_libdir2 = sysroot.join(builder.sysroot_libdir_relative(Compiler { - stage: 1, - host: target, - })); + let dst_libdir2 = + sysroot.join(builder.sysroot_libdir_relative(Compiler { stage: 1, host: target })); t!(fs::create_dir_all(&dst_libdir1)); t!(fs::create_dir_all(&dst_libdir2)); @@ -2150,7 +2274,7 @@ pub fn maybe_install_llvm_dylib(builder: &Builder<'_>, builder.install(&llvm_dylib_path, &dst_libdir1, 0o644); builder.install(&llvm_dylib_path, &dst_libdir2, 0o644); } - return + return; } // Usually libLLVM.so is a symlink to something like libLLVM-6.0.so. @@ -2159,11 +2283,9 @@ pub fn maybe_install_llvm_dylib(builder: &Builder<'_>, let llvm_dylib_path = src_libdir.join("libLLVM.so"); if llvm_dylib_path.exists() { let llvm_dylib_path = llvm_dylib_path.canonicalize().unwrap_or_else(|e| { - panic!("dist: Error calling canonicalize path `{}`: {}", - llvm_dylib_path.display(), e); + panic!("dist: Error calling canonicalize path `{}`: {}", llvm_dylib_path.display(), e); }); - builder.install(&llvm_dylib_path, &dst_libdir1, 0o644); builder.install(&llvm_dylib_path, &dst_libdir2, 0o644); } @@ -2183,9 +2305,7 @@ impl Step for LlvmTools { } fn make_run(run: RunConfig<'_>) { - run.builder.ensure(LlvmTools { - target: run.target, - }); + run.builder.ensure(LlvmTools { target: run.target }); } fn run(self, builder: &Builder<'_>) -> Option<PathBuf> { @@ -2195,8 +2315,7 @@ impl Step for LlvmTools { /* run only if llvm-config isn't used */ if let Some(config) = builder.config.target_config.get(&target) { if let Some(ref _s) = config.llvm_config { - builder.info(&format!("Skipping LlvmTools ({}): external LLVM", - target)); + builder.info(&format!("Skipping LlvmTools ({}): external LLVM", target)); return None; } } @@ -2211,12 +2330,8 @@ impl Step for LlvmTools { drop(fs::remove_dir_all(&image)); // Prepare the image directory - let src_bindir = builder - .llvm_out(target) - .join("bin"); - let dst_bindir = image.join("lib/rustlib") - .join(&*target) - .join("bin"); + let src_bindir = builder.llvm_out(target).join("bin"); + let dst_bindir = image.join("lib/rustlib").join(&*target).join("bin"); t!(fs::create_dir_all(&dst_bindir)); for tool in LLVM_TOOLS { let exe = src_bindir.join(exe(tool, &target)); @@ -2237,15 +2352,18 @@ impl Step for LlvmTools { .arg("--product-name=Rust") .arg("--rel-manifest-dir=rustlib") .arg("--success-message=llvm-tools-installed.") - .arg("--image-dir").arg(&image) - .arg("--work-dir").arg(&tmpdir(builder)) - .arg("--output-dir").arg(&distdir(builder)) - .arg("--non-installed-overlay").arg(&overlay) + .arg("--image-dir") + .arg(&image) + .arg("--work-dir") + .arg(&tmpdir(builder)) + .arg("--output-dir") + .arg(&distdir(builder)) + .arg("--non-installed-overlay") + .arg(&overlay) .arg(format!("--package-name={}-{}", name, target)) .arg("--legacy-manifest-dirs=rustlib,cargo") .arg("--component-name=llvm-tools-preview"); - builder.run(&mut cmd); Some(distdir(builder).join(format!("{}-{}.tar.gz", name, target))) } @@ -2266,9 +2384,7 @@ impl Step for Lldb { } fn make_run(run: RunConfig<'_>) { - run.builder.ensure(Lldb { - target: run.target, - }); + run.builder.ensure(Lldb { target: run.target }); } fn run(self, builder: &Builder<'_>) -> Option<PathBuf> { @@ -2278,9 +2394,7 @@ impl Step for Lldb { return None; } - let bindir = builder - .llvm_out(target) - .join("bin"); + let bindir = builder.llvm_out(target).join("bin"); let lldb_exe = bindir.join(exe("lldb", &target)); if !lldb_exe.exists() { return None; @@ -2314,7 +2428,7 @@ impl Step for Lldb { if t!(entry.file_type()).is_symlink() { builder.copy_to_folder(&entry.path(), &dst); } else { - builder.install(&entry.path(), &dst, 0o755); + builder.install(&entry.path(), &dst, 0o755); } } } @@ -2333,8 +2447,7 @@ impl Step for Lldb { let entry = t!(entry); if let Ok(name) = entry.file_name().into_string() { if name.starts_with("python") { - let dst = root.join(libdir_name) - .join(entry.file_name()); + let dst = root.join(libdir_name).join(entry.file_name()); t!(fs::create_dir_all(&dst)); builder.cp_r(&entry.path(), &dst); break; @@ -2355,15 +2468,18 @@ impl Step for Lldb { .arg("--product-name=Rust") .arg("--rel-manifest-dir=rustlib") .arg("--success-message=lldb-installed.") - .arg("--image-dir").arg(&image) - .arg("--work-dir").arg(&tmpdir(builder)) - .arg("--output-dir").arg(&distdir(builder)) - .arg("--non-installed-overlay").arg(&overlay) + .arg("--image-dir") + .arg(&image) + .arg("--work-dir") + .arg(&tmpdir(builder)) + .arg("--output-dir") + .arg(&distdir(builder)) + .arg("--non-installed-overlay") + .arg(&overlay) .arg(format!("--package-name={}-{}", name, target)) .arg("--legacy-manifest-dirs=rustlib,cargo") .arg("--component-name=lldb-preview"); - builder.run(&mut cmd); Some(distdir(builder).join(format!("{}-{}.tar.gz", name, target))) } diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index 608cee0a80b..8cd7fc2c172 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -10,17 +10,17 @@ use std::collections::HashSet; use std::fs; use std::io; -use std::path::{PathBuf, Path}; +use std::path::{Path, PathBuf}; use crate::Mode; use build_helper::{t, up_to_date}; -use crate::util::symlink_dir; use crate::builder::{Builder, Compiler, RunConfig, ShouldRun, Step}; -use crate::tool::{self, prepare_tool_cargo, Tool, SourceType}; +use crate::cache::{Interned, INTERNER}; use crate::compile; -use crate::cache::{INTERNER, Interned}; use crate::config::Config; +use crate::tool::{self, prepare_tool_cargo, SourceType, Tool}; +use crate::util::symlink_dir; macro_rules! book { ($($name:ident, $path:expr, $book_name:expr;)+) => { @@ -88,15 +88,11 @@ impl Step for UnstableBook { } fn make_run(run: RunConfig<'_>) { - run.builder.ensure(UnstableBook { - target: run.target, - }); + run.builder.ensure(UnstableBook { target: run.target }); } fn run(self, builder: &Builder<'_>) { - builder.ensure(UnstableBookGen { - target: self.target, - }); + builder.ensure(UnstableBookGen { target: self.target }); builder.ensure(RustbookSrc { target: self.target, name: INTERNER.intern_str("unstable-book"), @@ -121,10 +117,7 @@ impl Step for CargoBook { } fn make_run(run: RunConfig<'_>) { - run.builder.ensure(CargoBook { - target: run.target, - name: INTERNER.intern_str("cargo"), - }); + run.builder.ensure(CargoBook { target: run.target, name: INTERNER.intern_str("cargo") }); } fn run(self, builder: &Builder<'_>) { @@ -141,11 +134,7 @@ impl Step for CargoBook { let _ = fs::remove_dir_all(&out); - builder.run(builder.tool_cmd(Tool::Rustbook) - .arg("build") - .arg(&src) - .arg("-d") - .arg(out)); + builder.run(builder.tool_cmd(Tool::Rustbook).arg("build").arg(&src).arg("-d").arg(out)); } } @@ -180,16 +169,12 @@ impl Step for RustbookSrc { let rustbook = builder.tool_exe(Tool::Rustbook); let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook); if up_to_date(&src, &index) && up_to_date(&rustbook, &index) { - return + return; } builder.info(&format!("Rustbook ({}) - {}", target, name)); let _ = fs::remove_dir_all(&out); - builder.run(rustbook_cmd - .arg("build") - .arg(&src) - .arg("-d") - .arg(out)); + builder.run(rustbook_cmd.arg("build").arg(&src).arg("-d").arg(out)); } } @@ -262,10 +247,7 @@ impl Step for TheBook { }); // build the version info page and CSS - builder.ensure(Standalone { - compiler, - target, - }); + builder.ensure(Standalone { compiler, target }); // build the redirect pages builder.info(&format!("Documenting book redirect pages ({})", target)); @@ -297,13 +279,20 @@ fn invoke_rustdoc( let out = out.join("book"); - cmd.arg("--html-after-content").arg(&footer) - .arg("--html-before-content").arg(&version_info) - .arg("--html-in-header").arg(&header) + cmd.arg("--html-after-content") + .arg(&footer) + .arg("--html-before-content") + .arg(&version_info) + .arg("--html-in-header") + .arg(&header) .arg("--markdown-no-toc") - .arg("--markdown-playground-url").arg("https://play.rust-lang.org/") - .arg("-o").arg(&out).arg(&path) - .arg("--markdown-css").arg("../rust.css"); + .arg("--markdown-playground-url") + .arg("https://play.rust-lang.org/") + .arg("-o") + .arg(&out) + .arg(&path) + .arg("--markdown-css") + .arg("../rust.css"); builder.run(&mut cmd); } @@ -366,33 +355,39 @@ impl Step for Standalone { let path = file.path(); let filename = path.file_name().unwrap().to_str().unwrap(); if !filename.ends_with(".md") || filename == "README.md" { - continue + continue; } let html = out.join(filename).with_extension("html"); let rustdoc = builder.rustdoc(compiler); - if up_to_date(&path, &html) && - up_to_date(&footer, &html) && - up_to_date(&favicon, &html) && - up_to_date(&full_toc, &html) && - (builder.config.dry_run || up_to_date(&version_info, &html)) && - (builder.config.dry_run || up_to_date(&rustdoc, &html)) { - continue + if up_to_date(&path, &html) + && up_to_date(&footer, &html) + && up_to_date(&favicon, &html) + && up_to_date(&full_toc, &html) + && (builder.config.dry_run || up_to_date(&version_info, &html)) + && (builder.config.dry_run || up_to_date(&rustdoc, &html)) + { + continue; } let mut cmd = builder.rustdoc_cmd(compiler); - cmd.arg("--html-after-content").arg(&footer) - .arg("--html-before-content").arg(&version_info) - .arg("--html-in-header").arg(&favicon) - .arg("--markdown-no-toc") - .arg("--index-page").arg(&builder.src.join("src/doc/index.md")) - .arg("--markdown-playground-url").arg("https://play.rust-lang.org/") - .arg("-o").arg(&out) - .arg(&path); + cmd.arg("--html-after-content") + .arg(&footer) + .arg("--html-before-content") + .arg(&version_info) + .arg("--html-in-header") + .arg(&favicon) + .arg("--markdown-no-toc") + .arg("--index-page") + .arg(&builder.src.join("src/doc/index.md")) + .arg("--markdown-playground-url") + .arg("https://play.rust-lang.org/") + .arg("-o") + .arg(&out) + .arg(&path); if filename == "not_found.md" { - cmd.arg("--markdown-css") - .arg("https://doc.rust-lang.org/rust.css"); + cmd.arg("--markdown-css").arg("https://doc.rust-lang.org/rust.css"); } else { cmd.arg("--markdown-css").arg("rust.css"); } @@ -417,10 +412,7 @@ impl Step for Std { } fn make_run(run: RunConfig<'_>) { - run.builder.ensure(Std { - stage: run.builder.top_stage, - target: run.target - }); + run.builder.ensure(Std { stage: run.builder.top_stage, target: run.target }); } /// Compile all standard library documentation. @@ -436,8 +428,7 @@ impl Step for Std { let compiler = builder.compiler(stage, builder.config.build); builder.ensure(compile::Std { compiler, target }); - let out_dir = builder.stage_out(compiler, Mode::Std) - .join(target).join("doc"); + let out_dir = builder.stage_out(compiler, Mode::Std).join(target).join("doc"); // Here what we're doing is creating a *symlink* (directory junction on // Windows) to the final output location. This is not done as an @@ -462,18 +453,21 @@ impl Step for Std { // Keep a whitelist so we do not build internal stdlib crates, these will be // build by the rustc step later if enabled. - cargo.arg("-Z").arg("unstable-options") - .arg("-p").arg(package); + cargo.arg("-Z").arg("unstable-options").arg("-p").arg(package); // Create all crate output directories first to make sure rustdoc uses // relative links. // FIXME: Cargo should probably do this itself. t!(fs::create_dir_all(out_dir.join(package))); - cargo.arg("--") - .arg("--markdown-css").arg("rust.css") - .arg("--markdown-no-toc") - .arg("--generate-redirect-pages") - .arg("--resource-suffix").arg(crate::channel::CFG_RELEASE_NUM) - .arg("--index-page").arg(&builder.src.join("src/doc/index.md")); + cargo + .arg("--") + .arg("--markdown-css") + .arg("rust.css") + .arg("--markdown-no-toc") + .arg("--generate-redirect-pages") + .arg("--resource-suffix") + .arg(crate::channel::CFG_RELEASE_NUM) + .arg("--index-page") + .arg(&builder.src.join("src/doc/index.md")); builder.run(&mut cargo.into()); }; @@ -501,10 +495,7 @@ impl Step for Rustc { } fn make_run(run: RunConfig<'_>) { - run.builder.ensure(Rustc { - stage: run.builder.top_stage, - target: run.target, - }); + run.builder.ensure(Rustc { stage: run.builder.top_stage, target: run.target }); } /// Generates compiler documentation. @@ -568,7 +559,7 @@ impl Step for Rustc { fn find_compiler_crates( builder: &Builder<'_>, name: &Interned<String>, - crates: &mut HashSet<Interned<String>> + crates: &mut HashSet<Interned<String>>, ) { // Add current crate. crates.insert(*name); @@ -597,10 +588,7 @@ impl Step for Rustdoc { } fn make_run(run: RunConfig<'_>) { - run.builder.ensure(Rustdoc { - stage: run.builder.top_stage, - target: run.target, - }); + run.builder.ensure(Rustdoc { stage: run.builder.top_stage, target: run.target }); } /// Generates compiler documentation. @@ -633,9 +621,7 @@ impl Step for Rustdoc { builder.ensure(tool::Rustdoc { compiler: compiler }); // Symlink compiler docs to the output directory of rustdoc documentation. - let out_dir = builder.stage_out(compiler, Mode::ToolRustc) - .join(target) - .join("doc"); + let out_dir = builder.stage_out(compiler, Mode::ToolRustc).join(target).join("doc"); t!(fs::create_dir_all(&out_dir)); t!(symlink_dir_force(&builder.config, &out, &out_dir)); @@ -648,7 +634,7 @@ impl Step for Rustdoc { "doc", "src/tools/rustdoc", SourceType::InTree, - &[] + &[], ); // Only include compiler crates, no dependencies of those, such as `libc`. @@ -676,9 +662,7 @@ impl Step for ErrorIndex { } fn make_run(run: RunConfig<'_>) { - run.builder.ensure(ErrorIndex { - target: run.target, - }); + run.builder.ensure(ErrorIndex { target: run.target }); } /// Generates the HTML rendered error-index by running the @@ -690,10 +674,7 @@ impl Step for ErrorIndex { let out = builder.doc_out(target); t!(fs::create_dir_all(&out)); let compiler = builder.compiler(2, builder.config.build); - let mut index = tool::ErrorIndex::command( - builder, - compiler, - ); + let mut index = tool::ErrorIndex::command(builder, compiler); index.arg("html"); index.arg(out.join("error-index.html")); index.arg(crate::channel::CFG_RELEASE_NUM); @@ -721,9 +702,7 @@ impl Step for UnstableBookGen { } fn make_run(run: RunConfig<'_>) { - run.builder.ensure(UnstableBookGen { - target: run.target, - }); + run.builder.ensure(UnstableBookGen { target: run.target }); } fn run(self, builder: &Builder<'_>) { @@ -751,9 +730,7 @@ fn symlink_dir_force(config: &Config, src: &Path, dst: &Path) -> io::Result<()> } else { // handle directory junctions on windows by falling back to // `remove_dir`. - fs::remove_file(dst).or_else(|_| { - fs::remove_dir(dst) - })?; + fs::remove_file(dst).or_else(|_| fs::remove_dir(dst))?; } } diff --git a/src/bootstrap/flags.rs b/src/bootstrap/flags.rs index b98e2c1bf24..ffc24367db6 100644 --- a/src/bootstrap/flags.rs +++ b/src/bootstrap/flags.rs @@ -88,16 +88,15 @@ pub enum Subcommand { impl Default for Subcommand { fn default() -> Subcommand { - Subcommand::Build { - paths: vec![PathBuf::from("nowhere")], - } + Subcommand::Build { paths: vec![PathBuf::from("nowhere")] } } } impl Flags { pub fn parse(args: &[String]) -> Flags { let mut extra_help = String::new(); - let mut subcommand_help = String::from("\ + let mut subcommand_help = String::from( + "\ Usage: x.py <subcommand> [options] [<paths>...] Subcommands: @@ -113,7 +112,7 @@ Subcommands: dist Build distribution artifacts install Install distribution artifacts -To learn more about a subcommand, run `./x.py <subcommand> -h`" +To learn more about a subcommand, run `./x.py <subcommand> -h`", ); let mut opts = Options::new(); @@ -127,12 +126,20 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`" opts.optmulti("", "exclude", "build paths to exclude", "PATH"); opts.optopt("", "on-fail", "command to run on failure", "CMD"); opts.optflag("", "dry-run", "dry run; don't build anything"); - opts.optopt("", "stage", + opts.optopt( + "", + "stage", "stage to build (indicates compiler to use/test, e.g., stage 0 uses the \ bootstrap compiler, stage 1 the stage 0 rustc artifacts, etc.)", - "N"); - opts.optmulti("", "keep-stage", "stage(s) to keep without recompiling \ - (pass multiple times to keep e.g., both stages 0 and 1)", "N"); + "N", + ); + opts.optmulti( + "", + "keep-stage", + "stage(s) to keep without recompiling \ + (pass multiple times to keep e.g., both stages 0 and 1)", + "N", + ); opts.optopt("", "src", "path to the root of the rust checkout", "DIR"); opts.optopt("j", "jobs", "number of jobs to run in parallel", "JOBS"); opts.optflag("h", "help", "print this help message"); @@ -197,11 +204,7 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`" ); opts.optflag("", "no-doc", "do not run doc tests"); opts.optflag("", "doc", "only run doc tests"); - opts.optflag( - "", - "bless", - "update all stderr/stdout files of failing ui tests", - ); + opts.optflag("", "bless", "update all stderr/stdout files of failing ui tests"); opts.optopt( "", "compare-mode", @@ -212,7 +215,7 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`" "", "pass", "force {check,build,run}-pass tests to this mode.", - "check | build | run" + "check | build | run", ); opts.optflag( "", @@ -386,10 +389,7 @@ Arguments: _ => {} }; // Get any optional paths which occur after the subcommand - let paths = matches.free[1..] - .iter() - .map(|p| p.into()) - .collect::<Vec<PathBuf>>(); + let paths = matches.free[1..].iter().map(|p| p.into()).collect::<Vec<PathBuf>>(); let cfg_file = matches.opt_str("config").map(PathBuf::from).or_else(|| { if fs::metadata("config.toml").is_ok() { @@ -409,10 +409,8 @@ Arguments: extra_help.push_str(maybe_rules_help.unwrap_or_default().as_str()); } else if !(subcommand.as_str() == "clean" || subcommand.as_str() == "fmt") { extra_help.push_str( - format!( - "Run `./x.py {} -h -v` to see a list of available paths.", - subcommand - ).as_str(), + format!("Run `./x.py {} -h -v` to see a list of available paths.", subcommand) + .as_str(), ); } @@ -443,10 +441,7 @@ Arguments: DocTests::Yes }, }, - "bench" => Subcommand::Bench { - paths, - test_args: matches.opt_strs("test-args"), - }, + "bench" => Subcommand::Bench { paths, test_args: matches.opt_strs("test-args") }, "doc" => Subcommand::Doc { paths }, "clean" => { if !paths.is_empty() { @@ -454,15 +449,9 @@ Arguments: usage(1, &opts, &subcommand_help, &extra_help); } - Subcommand::Clean { - all: matches.opt_present("all"), - } - } - "fmt" => { - Subcommand::Format { - check: matches.opt_present("check"), - } + Subcommand::Clean { all: matches.opt_present("all") } } + "fmt" => Subcommand::Format { check: matches.opt_present("check") }, "dist" => Subcommand::Dist { paths }, "install" => Subcommand::Install { paths }, _ => { @@ -476,8 +465,10 @@ Arguments: dry_run: matches.opt_present("dry-run"), on_fail: matches.opt_str("on-fail"), rustc_error_format: matches.opt_str("error-format"), - keep_stage: matches.opt_strs("keep-stage") - .into_iter().map(|j| j.parse().expect("`keep-stage` should be a number")) + keep_stage: matches + .opt_strs("keep-stage") + .into_iter() + .map(|j| j.parse().expect("`keep-stage` should be a number")) .collect(), host: split(&matches.opt_strs("host")) .into_iter() @@ -504,10 +495,7 @@ impl Subcommand { pub fn test_args(&self) -> Vec<&str> { match *self { Subcommand::Test { ref test_args, .. } | Subcommand::Bench { ref test_args, .. } => { - test_args - .iter() - .flat_map(|s| s.split_whitespace()) - .collect() + test_args.iter().flat_map(|s| s.split_whitespace()).collect() } _ => Vec::new(), } @@ -515,10 +503,9 @@ impl Subcommand { pub fn rustc_args(&self) -> Vec<&str> { match *self { - Subcommand::Test { ref rustc_args, .. } => rustc_args - .iter() - .flat_map(|s| s.split_whitespace()) - .collect(), + Subcommand::Test { ref rustc_args, .. } => { + rustc_args.iter().flat_map(|s| s.split_whitespace()).collect() + } _ => Vec::new(), } } @@ -553,28 +540,21 @@ impl Subcommand { pub fn compare_mode(&self) -> Option<&str> { match *self { - Subcommand::Test { - ref compare_mode, .. - } => compare_mode.as_ref().map(|s| &s[..]), + Subcommand::Test { ref compare_mode, .. } => compare_mode.as_ref().map(|s| &s[..]), _ => None, } } pub fn pass(&self) -> Option<&str> { match *self { - Subcommand::Test { - ref pass, .. - } => pass.as_ref().map(|s| &s[..]), + Subcommand::Test { ref pass, .. } => pass.as_ref().map(|s| &s[..]), _ => None, } } } fn split(s: &[String]) -> Vec<String> { - s.iter() - .flat_map(|s| s.split(',')) - .map(|s| s.to_string()) - .collect() + s.iter().flat_map(|s| s.split(',')).map(|s| s.to_string()).collect() } fn parse_deny_warnings(matches: &getopts::Matches) -> Option<bool> { @@ -582,12 +562,9 @@ fn parse_deny_warnings(matches: &getopts::Matches) -> Option<bool> { Some("deny") => Some(true), Some("warn") => Some(false), Some(value) => { - eprintln!( - r#"invalid value for --warnings: {:?}, expected "warn" or "deny""#, - value, - ); + eprintln!(r#"invalid value for --warnings: {:?}, expected "warn" or "deny""#, value,); process::exit(1); - }, + } None => None, } } diff --git a/src/bootstrap/job.rs b/src/bootstrap/job.rs index 6867d62a480..57153e2ad39 100644 --- a/src/bootstrap/job.rs +++ b/src/bootstrap/job.rs @@ -29,11 +29,11 @@ #![allow(nonstandard_style, dead_code)] +use crate::Build; use std::env; use std::io; use std::mem; use std::ptr; -use crate::Build; type HANDLE = *mut u8; type BOOL = i32; @@ -61,21 +61,23 @@ extern "system" { fn CreateJobObjectW(lpJobAttributes: *mut u8, lpName: *const u8) -> HANDLE; fn CloseHandle(hObject: HANDLE) -> BOOL; fn GetCurrentProcess() -> HANDLE; - fn OpenProcess(dwDesiredAccess: DWORD, - bInheritHandle: BOOL, - dwProcessId: DWORD) -> HANDLE; - fn DuplicateHandle(hSourceProcessHandle: HANDLE, - hSourceHandle: HANDLE, - hTargetProcessHandle: HANDLE, - lpTargetHandle: LPHANDLE, - dwDesiredAccess: DWORD, - bInheritHandle: BOOL, - dwOptions: DWORD) -> BOOL; + fn OpenProcess(dwDesiredAccess: DWORD, bInheritHandle: BOOL, dwProcessId: DWORD) -> HANDLE; + fn DuplicateHandle( + hSourceProcessHandle: HANDLE, + hSourceHandle: HANDLE, + hTargetProcessHandle: HANDLE, + lpTargetHandle: LPHANDLE, + dwDesiredAccess: DWORD, + bInheritHandle: BOOL, + dwOptions: DWORD, + ) -> BOOL; fn AssignProcessToJobObject(hJob: HANDLE, hProcess: HANDLE) -> BOOL; - fn SetInformationJobObject(hJob: HANDLE, - JobObjectInformationClass: JOBOBJECTINFOCLASS, - lpJobObjectInformation: LPVOID, - cbJobObjectInformationLength: DWORD) -> BOOL; + fn SetInformationJobObject( + hJob: HANDLE, + JobObjectInformationClass: JOBOBJECTINFOCLASS, + lpJobObjectInformation: LPVOID, + cbJobObjectInformationLength: DWORD, + ) -> BOOL; fn SetErrorMode(mode: UINT) -> UINT; } @@ -132,10 +134,12 @@ pub unsafe fn setup(build: &mut Build) { info.BasicLimitInformation.LimitFlags |= JOB_OBJECT_LIMIT_PRIORITY_CLASS; info.BasicLimitInformation.PriorityClass = BELOW_NORMAL_PRIORITY_CLASS; } - let r = SetInformationJobObject(job, - JobObjectExtendedLimitInformation, - &mut info as *mut _ as LPVOID, - mem::size_of_val(&info) as DWORD); + let r = SetInformationJobObject( + job, + JobObjectExtendedLimitInformation, + &mut info as *mut _ as LPVOID, + mem::size_of_val(&info) as DWORD, + ); assert!(r != 0, "{}", io::Error::last_os_error()); // Assign our process to this job object. Note that if this fails, one very @@ -150,7 +154,7 @@ pub unsafe fn setup(build: &mut Build) { let r = AssignProcessToJobObject(job, GetCurrentProcess()); if r == 0 { CloseHandle(job); - return + return; } // If we've got a parent process (e.g., the python script that called us) @@ -169,9 +173,15 @@ pub unsafe fn setup(build: &mut Build) { let parent = OpenProcess(PROCESS_DUP_HANDLE, FALSE, pid.parse().unwrap()); assert!(!parent.is_null(), "{}", io::Error::last_os_error()); let mut parent_handle = ptr::null_mut(); - let r = DuplicateHandle(GetCurrentProcess(), job, - parent, &mut parent_handle, - 0, FALSE, DUPLICATE_SAME_ACCESS); + let r = DuplicateHandle( + GetCurrentProcess(), + job, + parent, + &mut parent_handle, + 0, + FALSE, + DUPLICATE_SAME_ACCESS, + ); // If this failed, well at least we tried! An example of DuplicateHandle // failing in the past has been when the wrong python2 package spawned this diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index ff9a55afa29..1fee3fd9ac1 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -106,12 +106,12 @@ #![feature(core_intrinsics)] #![feature(drain_filter)] -use std::cell::{RefCell, Cell}; -use std::collections::{HashSet, HashMap}; +use std::cell::{Cell, RefCell}; +use std::collections::{HashMap, HashSet}; use std::env; -use std::fs::{self, OpenOptions, File}; -use std::io::{Seek, SeekFrom, Write, Read}; -use std::path::{PathBuf, Path}; +use std::fs::{self, File, OpenOptions}; +use std::io::{Read, Seek, SeekFrom, Write}; +use std::path::{Path, PathBuf}; use std::process::{self, Command}; use std::slice; use std::str; @@ -121,33 +121,31 @@ use std::os::unix::fs::symlink as symlink_file; #[cfg(windows)] use std::os::windows::fs::symlink_file; -use build_helper::{ - mtime, output, run, run_suppressed, t, try_run, try_run_suppressed, -}; +use build_helper::{mtime, output, run, run_suppressed, t, try_run, try_run_suppressed}; use filetime::FileTime; use crate::util::{exe, libdir, CiEnv}; +mod builder; +mod cache; mod cc_detect; mod channel; mod check; -mod test; mod clean; mod compile; -mod metadata; mod config; mod dist; mod doc; mod flags; +mod format; mod install; +mod metadata; mod native; mod sanity; -pub mod util; -mod builder; -mod cache; +mod test; mod tool; mod toolstate; -mod format; +pub mod util; #[cfg(windows)] mod job; @@ -163,13 +161,12 @@ mod job { #[cfg(any(target_os = "haiku", target_os = "hermit", not(any(unix, windows))))] mod job { - pub unsafe fn setup(_build: &mut crate::Build) { - } + pub unsafe fn setup(_build: &mut crate::Build) {} } +use crate::cache::{Interned, INTERNER}; pub use crate::config::Config; use crate::flags::Subcommand; -use crate::cache::{Interned, INTERNER}; const LLVM_TOOLS: &[&str] = &[ "llvm-nm", // used to inspect binaries; it shows symbol names, their sizes and visibility @@ -179,7 +176,7 @@ const LLVM_TOOLS: &[&str] = &[ "llvm-readobj", // used to get information from ELFs/objects that the other tools don't provide "llvm-size", // used to prints the size of the linker sections of a program "llvm-strip", // used to discard symbols from binary files to reduce their size - "llvm-ar" // used for creating and modifying archive files + "llvm-ar", // used for creating and modifying archive files ]; /// A structure representing a Rust compiler. @@ -258,10 +255,8 @@ pub struct Build { ci_env: CiEnv, delayed_failures: RefCell<Vec<String>>, prerelease_version: Cell<Option<u32>>, - tool_artifacts: RefCell<HashMap< - Interned<String>, - HashMap<String, (&'static str, PathBuf, Vec<String>)> - >>, + tool_artifacts: + RefCell<HashMap<Interned<String>, HashMap<String, (&'static str, PathBuf, Vec<String>)>>>, } #[derive(Debug)] @@ -274,8 +269,7 @@ struct Crate { impl Crate { fn is_local(&self, build: &Build) -> bool { - self.path.starts_with(&build.config.src) && - !self.path.to_string_lossy().ends_with("_shim") + self.path.starts_with(&build.config.src) && !self.path.to_string_lossy().ends_with("_shim") } fn local_path(&self, build: &Build) -> PathBuf { @@ -316,7 +310,7 @@ impl Mode { pub fn is_tool(&self) -> bool { match self { Mode::ToolBootstrap | Mode::ToolRustc | Mode::ToolStd => true, - _ => false + _ => false, } } } @@ -331,12 +325,10 @@ impl Build { let out = config.out.clone(); let is_sudo = match env::var_os("SUDO_USER") { - Some(sudo_user) => { - match env::var_os("USER") { - Some(user) => user != sudo_user, - None => false, - } - } + Some(sudo_user) => match env::var_os("USER") { + Some(user) => user != sudo_user, + None => false, + }, None => false, }; @@ -393,11 +385,15 @@ impl Build { // If local-rust is the same major.minor as the current version, then force a // local-rebuild - let local_version_verbose = output( - Command::new(&build.initial_rustc).arg("--version").arg("--verbose")); + let local_version_verbose = + output(Command::new(&build.initial_rustc).arg("--version").arg("--verbose")); let local_release = local_version_verbose - .lines().filter(|x| x.starts_with("release:")) - .next().unwrap().trim_start_matches("release:").trim(); + .lines() + .filter(|x| x.starts_with("release:")) + .next() + .unwrap() + .trim_start_matches("release:") + .trim(); let my_version = channel::CFG_RELEASE_NUM; if local_release.split('.').take(2).eq(my_version.split('.').take(2)) { build.verbose(&format!("auto-detected local-rebuild {}", local_release)); @@ -411,9 +407,7 @@ impl Build { } pub fn build_triple(&self) -> &[Interned<String>] { - unsafe { - slice::from_raw_parts(&self.build, 1) - } + unsafe { slice::from_raw_parts(&self.build, 1) } } /// Executes the entire build, as configured by the flags and configuration. @@ -514,7 +508,7 @@ impl Build { /// Component directory that Cargo will produce output into (e.g. /// release/debug) fn cargo_dir(&self) -> &'static str { - if self.config.rust_optimize {"release"} else {"debug"} + if self.config.rust_optimize { "release" } else { "debug" } } fn tools_dir(&self, compiler: Compiler) -> PathBuf { @@ -535,17 +529,13 @@ impl Build { Mode::ToolBootstrap => "-bootstrap-tools", Mode::ToolStd | Mode::ToolRustc => "-tools", }; - self.out.join(&*compiler.host) - .join(format!("stage{}{}", compiler.stage, suffix)) + self.out.join(&*compiler.host).join(format!("stage{}{}", compiler.stage, suffix)) } /// Returns the root output directory for all Cargo output in a given stage, /// running a particular compiler, whether or not we're building the /// standard library, and targeting the specified architecture. - fn cargo_out(&self, - compiler: Compiler, - mode: Mode, - target: Interned<String>) -> PathBuf { + fn cargo_out(&self, compiler: Compiler, mode: Mode, target: Interned<String>) -> PathBuf { self.stage_out(compiler, mode).join(&*target).join(self.cargo_dir()) } @@ -589,7 +579,7 @@ impl Build { fn is_rust_llvm(&self, target: Interned<String>) -> bool { match self.config.target_config.get(&target) { Some(ref c) => c.llvm_config.is_none(), - None => true + None => true, } } @@ -607,8 +597,8 @@ impl Build { // On Fedora the system LLVM installs FileCheck in the // llvm subdirectory of the libdir. let llvm_libdir = output(Command::new(s).arg("--libdir")); - let lib_filecheck = Path::new(llvm_libdir.trim()) - .join("llvm").join(exe("FileCheck", &*target)); + let lib_filecheck = + Path::new(llvm_libdir.trim()).join("llvm").join(exe("FileCheck", &*target)); if lib_filecheck.exists() { lib_filecheck } else { @@ -667,14 +657,18 @@ impl Build { /// Runs a command, printing out nice contextual information if it fails. fn run(&self, cmd: &mut Command) { - if self.config.dry_run { return; } + if self.config.dry_run { + return; + } self.verbose(&format!("running: {:?}", cmd)); run(cmd) } /// Runs a command, printing out nice contextual information if it fails. fn run_quiet(&self, cmd: &mut Command) { - if self.config.dry_run { return; } + if self.config.dry_run { + return; + } self.verbose(&format!("running: {:?}", cmd)); run_suppressed(cmd) } @@ -683,7 +677,9 @@ impl Build { /// Exits if the command failed to execute at all, otherwise returns its /// `status.success()`. fn try_run(&self, cmd: &mut Command) -> bool { - if self.config.dry_run { return true; } + if self.config.dry_run { + return true; + } self.verbose(&format!("running: {:?}", cmd)); try_run(cmd) } @@ -692,7 +688,9 @@ impl Build { /// Exits if the command failed to execute at all, otherwise returns its /// `status.success()`. fn try_run_quiet(&self, cmd: &mut Command) -> bool { - if self.config.dry_run { return true; } + if self.config.dry_run { + return true; + } self.verbose(&format!("running: {:?}", cmd)); try_run_suppressed(cmd) } @@ -720,7 +718,9 @@ impl Build { } fn info(&self, msg: &str) { - if self.config.dry_run { return; } + if self.config.dry_run { + return; + } println!("{}", msg); } @@ -732,7 +732,7 @@ impl Build { fn debuginfo_map(&self, which: GitRepo) -> Option<String> { if !self.config.rust_remap_debuginfo { - return None + return None; } let path = match which { @@ -755,10 +755,12 @@ impl Build { fn cflags(&self, target: Interned<String>, which: GitRepo) -> Vec<String> { // Filter out -O and /O (the optimization flags) that we picked up from // cc-rs because the build scripts will determine that for themselves. - let mut base = self.cc[&target].args().iter() - .map(|s| s.to_string_lossy().into_owned()) - .filter(|s| !s.starts_with("-O") && !s.starts_with("/O")) - .collect::<Vec<String>>(); + let mut base = self.cc[&target] + .args() + .iter() + .map(|s| s.to_string_lossy().into_owned()) + .filter(|s| !s.starts_with("-O") && !s.starts_with("/O")) + .collect::<Vec<String>>(); // If we're compiling on macOS then we add a few unconditional flags // indicating that we want libc++ (more filled out than libstdc++) and @@ -776,7 +778,7 @@ impl Build { } if let Some(map) = self.debuginfo_map(which) { - let cc = self.cc(target); + let cc = self.cc(target); if cc.ends_with("clang") || cc.ends_with("gcc") { base.push(format!("-fdebug-prefix-map={}", map)); } else if cc.ends_with("clang-cl.exe") { @@ -801,20 +803,21 @@ impl Build { fn cxx(&self, target: Interned<String>) -> Result<&Path, String> { match self.cxx.get(&target) { Some(p) => Ok(p.path()), - None => Err(format!( - "target `{}` is not configured as a host, only as a target", - target)) + None => { + Err(format!("target `{}` is not configured as a host, only as a target", target)) + } } } /// Returns the path to the linker for the given target if it needs to be overridden. fn linker(&self, target: Interned<String>) -> Option<&Path> { - if let Some(linker) = self.config.target_config.get(&target) - .and_then(|c| c.linker.as_ref()) { + if let Some(linker) = self.config.target_config.get(&target).and_then(|c| c.linker.as_ref()) + { Some(linker) - } else if target != self.config.build && - util::use_host_linker(&target) && - !target.contains("msvc") { + } else if target != self.config.build + && util::use_host_linker(&target) + && !target.contains("msvc") + { Some(self.cc(target)) } else { None @@ -826,14 +829,15 @@ impl Build { if target.contains("pc-windows-msvc") { Some(true) } else { - self.config.target_config.get(&target) - .and_then(|t| t.crt_static) + self.config.target_config.get(&target).and_then(|t| t.crt_static) } } /// Returns the "musl root" for this `target`, if defined fn musl_root(&self, target: Interned<String>) -> Option<&Path> { - self.config.target_config.get(&target) + self.config + .target_config + .get(&target) .and_then(|t| t.musl_root.as_ref()) .or(self.config.musl_root.as_ref()) .map(|p| &**p) @@ -841,22 +845,20 @@ impl Build { /// Returns the sysroot for the wasi target, if defined fn wasi_root(&self, target: Interned<String>) -> Option<&Path> { - self.config.target_config.get(&target) - .and_then(|t| t.wasi_root.as_ref()) - .map(|p| &**p) + self.config.target_config.get(&target).and_then(|t| t.wasi_root.as_ref()).map(|p| &**p) } /// Returns `true` if this is a no-std `target`, if defined fn no_std(&self, target: Interned<String>) -> Option<bool> { - self.config.target_config.get(&target) - .map(|t| t.no_std) + self.config.target_config.get(&target).map(|t| t.no_std) } /// Returns `true` if the target will be tested using the `remote-test-client` /// and `remote-test-server` binaries. fn remote_tested(&self, target: Interned<String>) -> bool { - self.qemu_rootfs(target).is_some() || target.contains("android") || - env::var_os("TEST_DEVICE_ADDR").is_some() + self.qemu_rootfs(target).is_some() + || target.contains("android") + || env::var_os("TEST_DEVICE_ADDR").is_some() } /// Returns the root of the "rootfs" image that this target will be using, @@ -865,9 +867,7 @@ impl Build { /// If `Some` is returned then that means that tests for this target are /// emulated with QEMU and binaries will need to be shipped to the emulator. fn qemu_rootfs(&self, target: Interned<String>) -> Option<&Path> { - self.config.target_config.get(&target) - .and_then(|t| t.qemu_rootfs.as_ref()) - .map(|p| &**p) + self.config.target_config.get(&target).and_then(|t| t.qemu_rootfs.as_ref()).map(|p| &**p) } /// Path to the python interpreter to use @@ -899,9 +899,9 @@ impl Build { /// When all of these conditions are met the build will lift artifacts from /// the previous stage forward. fn force_use_stage1(&self, compiler: Compiler, target: Interned<String>) -> bool { - !self.config.full_bootstrap && - compiler.stage >= 2 && - (self.hosts.iter().any(|h| *h == target) || target == self.build) + !self.config.full_bootstrap + && compiler.stage >= 2 + && (self.hosts.iter().any(|h| *h == target) || target == self.build) } /// Given `num` in the form "a.b.c" return a "release string" which @@ -912,11 +912,13 @@ impl Build { fn release(&self, num: &str) -> String { match &self.config.channel[..] { "stable" => num.to_string(), - "beta" => if self.rust_info.is_git() { - format!("{}-beta.{}", num, self.beta_prerelease_version()) - } else { - format!("{}-beta", num) - }, + "beta" => { + if self.rust_info.is_git() { + format!("{}-beta.{}", num, self.beta_prerelease_version()) + } else { + format!("{}-beta", num) + } + } "nightly" => format!("{}-nightly", num), _ => format!("{}-dev", num), } @@ -924,33 +926,21 @@ impl Build { fn beta_prerelease_version(&self) -> u32 { if let Some(s) = self.prerelease_version.get() { - return s + return s; } let beta = output( - Command::new("git") - .arg("ls-remote") - .arg("origin") - .arg("beta") - .current_dir(&self.src) + Command::new("git").arg("ls-remote").arg("origin").arg("beta").current_dir(&self.src), ); let beta = beta.trim().split_whitespace().next().unwrap(); let master = output( - Command::new("git") - .arg("ls-remote") - .arg("origin") - .arg("master") - .current_dir(&self.src) + Command::new("git").arg("ls-remote").arg("origin").arg("master").current_dir(&self.src), ); let master = master.trim().split_whitespace().next().unwrap(); // Figure out where the current beta branch started. let base = output( - Command::new("git") - .arg("merge-base") - .arg(beta) - .arg(master) - .current_dir(&self.src), + Command::new("git").arg("merge-base").arg(beta).arg(master).current_dir(&self.src), ); let base = base.trim(); @@ -1061,7 +1051,7 @@ impl Build { let prefix = "version = \""; let suffix = "\""; if line.starts_with(prefix) && line.ends_with(suffix) { - return line[prefix.len()..line.len() - suffix.len()].to_string() + return line[prefix.len()..line.len() - suffix.len()].to_string(); } } @@ -1106,7 +1096,7 @@ impl Build { // run_cargo for more information (in compile.rs). for part in contents.split(|b| *b == 0) { if part.is_empty() { - continue + continue; } let host = part[0] as char == 'h'; let path = PathBuf::from(t!(str::from_utf8(&part[1..]))); @@ -1117,9 +1107,13 @@ impl Build { /// Copies a file from `src` to `dst` pub fn copy(&self, src: &Path, dst: &Path) { - if self.config.dry_run { return; } + if self.config.dry_run { + return; + } self.verbose_than(1, &format!("Copy {:?} to {:?}", src, dst)); - if src == dst { return; } + if src == dst { + return; + } let _ = fs::remove_file(&dst); let metadata = t!(src.symlink_metadata()); if metadata.file_type().is_symlink() { @@ -1131,8 +1125,7 @@ impl Build { // just fall back to a slow `copy` operation. } else { if let Err(e) = fs::copy(src, dst) { - panic!("failed to copy `{}` to `{}`: {}", src.display(), - dst.display(), e) + panic!("failed to copy `{}` to `{}`: {}", src.display(), dst.display(), e) } t!(fs::set_permissions(dst, metadata.permissions())); let atime = FileTime::from_last_access_time(&metadata); @@ -1144,7 +1137,9 @@ impl Build { /// Search-and-replaces within a file. (Not maximally efficiently: allocates a /// new string for each replacement.) pub fn replace_in_file(&self, path: &Path, replacements: &[(&str, &str)]) { - if self.config.dry_run { return; } + if self.config.dry_run { + return; + } let mut contents = String::new(); let mut file = t!(OpenOptions::new().read(true).write(true).open(path)); t!(file.read_to_string(&mut contents)); @@ -1159,7 +1154,9 @@ impl Build { /// Copies the `src` directory recursively to `dst`. Both are assumed to exist /// when this function is called. pub fn cp_r(&self, src: &Path, dst: &Path) { - if self.config.dry_run { return; } + if self.config.dry_run { + return; + } for f in self.read_dir(src) { let path = f.path(); let name = path.file_name().unwrap(); @@ -1210,7 +1207,9 @@ impl Build { } fn install(&self, src: &Path, dstdir: &Path, perms: u32) { - if self.config.dry_run { return; } + if self.config.dry_run { + return; + } let dst = dstdir.join(src.file_name().unwrap()); self.verbose_than(1, &format!("Install {:?} to {:?}", src, dst)); t!(fs::create_dir_all(dstdir)); @@ -1221,8 +1220,7 @@ impl Build { } let metadata = t!(src.symlink_metadata()); if let Err(e) = fs::copy(&src, &dst) { - panic!("failed to copy `{}` to `{}`: {}", src.display(), - dst.display(), e) + panic!("failed to copy `{}` to `{}`: {}", src.display(), dst.display(), e) } t!(fs::set_permissions(&dst, metadata.permissions())); let atime = FileTime::from_last_access_time(&metadata); @@ -1233,26 +1231,34 @@ impl Build { } fn create(&self, path: &Path, s: &str) { - if self.config.dry_run { return; } + if self.config.dry_run { + return; + } t!(fs::write(path, s)); } fn read(&self, path: &Path) -> String { - if self.config.dry_run { return String::new(); } + if self.config.dry_run { + return String::new(); + } t!(fs::read_to_string(path)) } fn create_dir(&self, dir: &Path) { - if self.config.dry_run { return; } + if self.config.dry_run { + return; + } t!(fs::create_dir_all(dir)) } fn remove_dir(&self, dir: &Path) { - if self.config.dry_run { return; } + if self.config.dry_run { + return; + } t!(fs::remove_dir_all(dir)) } - fn read_dir(&self, dir: &Path) -> impl Iterator<Item=fs::DirEntry> { + fn read_dir(&self, dir: &Path) -> impl Iterator<Item = fs::DirEntry> { let iter = match fs::read_dir(dir) { Ok(v) => v, Err(_) if self.config.dry_run => return vec![].into_iter(), @@ -1262,7 +1268,9 @@ impl Build { } fn remove(&self, f: &Path) { - if self.config.dry_run { return; } + if self.config.dry_run { + return; + } fs::remove_file(f).unwrap_or_else(|_| panic!("failed to remove {:?}", f)); } } @@ -1275,7 +1283,6 @@ fn chmod(path: &Path, perms: u32) { #[cfg(windows)] fn chmod(_path: &Path, _perms: u32) {} - impl Compiler { pub fn with_stage(mut self, stage: u32) -> Compiler { self.stage = stage; diff --git a/src/bootstrap/metadata.rs b/src/bootstrap/metadata.rs index b622b3682a7..8a26adc7ed5 100644 --- a/src/bootstrap/metadata.rs +++ b/src/bootstrap/metadata.rs @@ -1,14 +1,14 @@ use std::collections::HashMap; -use std::process::Command; -use std::path::PathBuf; use std::collections::HashSet; +use std::path::PathBuf; +use std::process::Command; use build_helper::output; use serde::Deserialize; use serde_json; -use crate::{Build, Crate}; use crate::cache::INTERNER; +use crate::{Build, Crate}; #[derive(Deserialize)] struct Output { @@ -71,10 +71,14 @@ fn build_krate(features: &str, build: &mut Build, resolves: &mut Vec<ResolveNode // to know what crates to test. Here we run `cargo metadata` to learn about // the dependency graph and what `-p` arguments there are. let mut cargo = Command::new(&build.initial_cargo); - cargo.arg("metadata") - .arg("--format-version").arg("1") - .arg("--features").arg(features) - .arg("--manifest-path").arg(build.src.join(krate).join("Cargo.toml")); + cargo + .arg("metadata") + .arg("--format-version") + .arg("1") + .arg("--features") + .arg(features) + .arg("--manifest-path") + .arg(build.src.join(krate).join("Cargo.toml")); let output = output(&mut cargo); let output: Output = serde_json::from_str(&output).unwrap(); for package in output.packages { @@ -82,12 +86,7 @@ fn build_krate(features: &str, build: &mut Build, resolves: &mut Vec<ResolveNode let name = INTERNER.intern_string(package.name); let mut path = PathBuf::from(package.manifest_path); path.pop(); - build.crates.insert(name, Crate { - name, - id: package.id, - deps: HashSet::new(), - path, - }); + build.crates.insert(name, Crate { name, id: package.id, deps: HashSet::new(), path }); } } resolves.extend(output.resolve.nodes); diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index be13b9aa2eb..afee154fe71 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -15,15 +15,15 @@ use std::path::{Path, PathBuf}; use std::process::Command; use build_helper::{output, t}; -use cmake; use cc; +use cmake; -use crate::channel; -use crate::util::{self, exe}; -use build_helper::up_to_date; use crate::builder::{Builder, RunConfig, ShouldRun, Step}; use crate::cache::Interned; +use crate::channel; +use crate::util::{self, exe}; use crate::GitRepo; +use build_helper::up_to_date; #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Llvm { @@ -36,15 +36,11 @@ impl Step for Llvm { const ONLY_HOSTS: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.path("src/llvm-project") - .path("src/llvm-project/llvm") - .path("src/llvm") + run.path("src/llvm-project").path("src/llvm-project/llvm").path("src/llvm") } fn make_run(run: RunConfig<'_>) { - run.builder.ensure(Llvm { - target: run.target, - }); + run.builder.ensure(Llvm { target: run.target }); } /// Compile LLVM for `target`. @@ -56,7 +52,7 @@ impl Step for Llvm { if let Some(config) = builder.config.target_config.get(&target) { if let Some(ref s) = config.llvm_config { check_llvm_version(builder, s); - return s.to_path_buf() + return s.to_path_buf(); } } @@ -69,8 +65,8 @@ impl Step for Llvm { } llvm_config_ret_dir.push("bin"); - let build_llvm_config = llvm_config_ret_dir - .join(exe("llvm-config", &*builder.config.build)); + let build_llvm_config = + llvm_config_ret_dir.join(exe("llvm-config", &*builder.config.build)); let done_stamp = out_dir.join("llvm-finished-building"); if done_stamp.exists() { @@ -112,8 +108,10 @@ impl Step for Llvm { // defaults! let llvm_targets = match &builder.config.llvm_targets { Some(s) => s, - None => "AArch64;ARM;Hexagon;MSP430;Mips;NVPTX;PowerPC;RISCV;\ - Sparc;SystemZ;WebAssembly;X86", + None => { + "AArch64;ARM;Hexagon;MSP430;Mips;NVPTX;PowerPC;RISCV;\ + Sparc;SystemZ;WebAssembly;X86" + } }; let llvm_exp_targets = match builder.config.llvm_experimental_targets { @@ -121,31 +119,31 @@ impl Step for Llvm { None => "", }; - let assertions = if builder.config.llvm_assertions {"ON"} else {"OFF"}; + let assertions = if builder.config.llvm_assertions { "ON" } else { "OFF" }; cfg.out_dir(&out_dir) - .profile(profile) - .define("LLVM_ENABLE_ASSERTIONS", assertions) - .define("LLVM_TARGETS_TO_BUILD", llvm_targets) - .define("LLVM_EXPERIMENTAL_TARGETS_TO_BUILD", llvm_exp_targets) - .define("LLVM_INCLUDE_EXAMPLES", "OFF") - .define("LLVM_INCLUDE_TESTS", "OFF") - .define("LLVM_INCLUDE_DOCS", "OFF") - .define("LLVM_INCLUDE_BENCHMARKS", "OFF") - .define("LLVM_ENABLE_ZLIB", "OFF") - .define("WITH_POLLY", "OFF") - .define("LLVM_ENABLE_TERMINFO", "OFF") - .define("LLVM_ENABLE_LIBEDIT", "OFF") - .define("LLVM_ENABLE_BINDINGS", "OFF") - .define("LLVM_ENABLE_Z3_SOLVER", "OFF") - .define("LLVM_PARALLEL_COMPILE_JOBS", builder.jobs().to_string()) - .define("LLVM_TARGET_ARCH", target.split('-').next().unwrap()) - .define("LLVM_DEFAULT_TARGET_TRIPLE", target); + .profile(profile) + .define("LLVM_ENABLE_ASSERTIONS", assertions) + .define("LLVM_TARGETS_TO_BUILD", llvm_targets) + .define("LLVM_EXPERIMENTAL_TARGETS_TO_BUILD", llvm_exp_targets) + .define("LLVM_INCLUDE_EXAMPLES", "OFF") + .define("LLVM_INCLUDE_TESTS", "OFF") + .define("LLVM_INCLUDE_DOCS", "OFF") + .define("LLVM_INCLUDE_BENCHMARKS", "OFF") + .define("LLVM_ENABLE_ZLIB", "OFF") + .define("WITH_POLLY", "OFF") + .define("LLVM_ENABLE_TERMINFO", "OFF") + .define("LLVM_ENABLE_LIBEDIT", "OFF") + .define("LLVM_ENABLE_BINDINGS", "OFF") + .define("LLVM_ENABLE_Z3_SOLVER", "OFF") + .define("LLVM_PARALLEL_COMPILE_JOBS", builder.jobs().to_string()) + .define("LLVM_TARGET_ARCH", target.split('-').next().unwrap()) + .define("LLVM_DEFAULT_TARGET_TRIPLE", target); if builder.config.llvm_thin_lto { cfg.define("LLVM_ENABLE_LTO", "Thin"); if !target.contains("apple") { - cfg.define("LLVM_ENABLE_LLD", "ON"); + cfg.define("LLVM_ENABLE_LLD", "ON"); } } @@ -212,20 +210,17 @@ impl Step for Llvm { // http://llvm.org/docs/HowToCrossCompileLLVM.html if target != builder.config.build { - builder.ensure(Llvm { - target: builder.config.build, - }); + builder.ensure(Llvm { target: builder.config.build }); // FIXME: if the llvm root for the build triple is overridden then we // should use llvm-tblgen from there, also should verify that it // actually exists most of the time in normal installs of LLVM. let host = builder.llvm_out(builder.config.build).join("bin/llvm-tblgen"); - cfg.define("CMAKE_CROSSCOMPILING", "True") - .define("LLVM_TABLEGEN", &host); + cfg.define("CMAKE_CROSSCOMPILING", "True").define("LLVM_TABLEGEN", &host); if target.contains("netbsd") { - cfg.define("CMAKE_SYSTEM_NAME", "NetBSD"); + cfg.define("CMAKE_SYSTEM_NAME", "NetBSD"); } else if target.contains("freebsd") { - cfg.define("CMAKE_SYSTEM_NAME", "FreeBSD"); + cfg.define("CMAKE_SYSTEM_NAME", "FreeBSD"); } cfg.define("LLVM_NATIVE_BUILD", builder.llvm_out(builder.config.build).join("build")); @@ -237,11 +232,8 @@ impl Step for Llvm { cfg.define("LLVM_VERSION_SUFFIX", suffix); } } else { - let mut default_suffix = format!( - "-rust-{}-{}", - channel::CFG_RELEASE_NUM, - builder.config.channel, - ); + let mut default_suffix = + format!("-rust-{}-{}", channel::CFG_RELEASE_NUM, builder.config.channel,); if let Some(sha) = llvm_info.sha_short() { default_suffix.push_str("-"); default_suffix.push_str(sha); @@ -282,7 +274,7 @@ impl Step for Llvm { fn check_llvm_version(builder: &Builder<'_>, llvm_config: &Path) { if !builder.config.llvm_version_check { - return + return; } if builder.config.dry_run { @@ -291,19 +283,16 @@ fn check_llvm_version(builder: &Builder<'_>, llvm_config: &Path) { let mut cmd = Command::new(llvm_config); let version = output(cmd.arg("--version")); - let mut parts = version.split('.').take(2) - .filter_map(|s| s.parse::<u32>().ok()); + let mut parts = version.split('.').take(2).filter_map(|s| s.parse::<u32>().ok()); if let (Some(major), Some(_minor)) = (parts.next(), parts.next()) { if major >= 7 { - return + return; } } panic!("\n\nbad LLVM version: {}, need >=7.0\n\n", version) } -fn configure_cmake(builder: &Builder<'_>, - target: Interned<String>, - cfg: &mut cmake::Config) { +fn configure_cmake(builder: &Builder<'_>, target: Interned<String>, cfg: &mut cmake::Config) { // Do not print installation messages for up-to-date files. // LLVM and LLD builds can produce a lot of those and hit CI limits on log size. cfg.define("CMAKE_INSTALL_MESSAGE", "LAZY"); @@ -311,8 +300,7 @@ fn configure_cmake(builder: &Builder<'_>, if builder.config.ninja { cfg.generator("Ninja"); } - cfg.target(&target) - .host(&builder.config.build); + cfg.target(&target).host(&builder.config.build); let sanitize_cc = |cc: &Path| { if target.contains("msvc") { @@ -326,7 +314,7 @@ fn configure_cmake(builder: &Builder<'_>, // vars that we'd otherwise configure. In that case we just skip this // entirely. if target.contains("msvc") && !builder.config.ninja { - return + return; } let (cc, cxx) = match builder.config.llvm_clang_cl { @@ -335,56 +323,52 @@ fn configure_cmake(builder: &Builder<'_>, }; // Handle msvc + ninja + ccache specially (this is what the bots use) - if target.contains("msvc") && - builder.config.ninja && - builder.config.ccache.is_some() - { - let mut wrap_cc = env::current_exe().expect("failed to get cwd"); - wrap_cc.set_file_name("sccache-plus-cl.exe"); - - cfg.define("CMAKE_C_COMPILER", sanitize_cc(&wrap_cc)) - .define("CMAKE_CXX_COMPILER", sanitize_cc(&wrap_cc)); - cfg.env("SCCACHE_PATH", - builder.config.ccache.as_ref().unwrap()) - .env("SCCACHE_TARGET", target) - .env("SCCACHE_CC", &cc) - .env("SCCACHE_CXX", &cxx); - - // Building LLVM on MSVC can be a little ludicrous at times. We're so far - // off the beaten path here that I'm not really sure this is even half - // supported any more. Here we're trying to: - // - // * Build LLVM on MSVC - // * Build LLVM with `clang-cl` instead of `cl.exe` - // * Build a project with `sccache` - // * Build for 32-bit as well - // * Build with Ninja - // - // For `cl.exe` there are different binaries to compile 32/64 bit which - // we use but for `clang-cl` there's only one which internally - // multiplexes via flags. As a result it appears that CMake's detection - // of a compiler's architecture and such on MSVC **doesn't** pass any - // custom flags we pass in CMAKE_CXX_FLAGS below. This means that if we - // use `clang-cl.exe` it's always diagnosed as a 64-bit compiler which - // definitely causes problems since all the env vars are pointing to - // 32-bit libraries. - // - // To hack around this... again... we pass an argument that's - // unconditionally passed in the sccache shim. This'll get CMake to - // correctly diagnose it's doing a 32-bit compilation and LLVM will - // internally configure itself appropriately. - if builder.config.llvm_clang_cl.is_some() && target.contains("i686") { - cfg.env("SCCACHE_EXTRA_ARGS", "-m32"); - } + if target.contains("msvc") && builder.config.ninja && builder.config.ccache.is_some() { + let mut wrap_cc = env::current_exe().expect("failed to get cwd"); + wrap_cc.set_file_name("sccache-plus-cl.exe"); + + cfg.define("CMAKE_C_COMPILER", sanitize_cc(&wrap_cc)) + .define("CMAKE_CXX_COMPILER", sanitize_cc(&wrap_cc)); + cfg.env("SCCACHE_PATH", builder.config.ccache.as_ref().unwrap()) + .env("SCCACHE_TARGET", target) + .env("SCCACHE_CC", &cc) + .env("SCCACHE_CXX", &cxx); + + // Building LLVM on MSVC can be a little ludicrous at times. We're so far + // off the beaten path here that I'm not really sure this is even half + // supported any more. Here we're trying to: + // + // * Build LLVM on MSVC + // * Build LLVM with `clang-cl` instead of `cl.exe` + // * Build a project with `sccache` + // * Build for 32-bit as well + // * Build with Ninja + // + // For `cl.exe` there are different binaries to compile 32/64 bit which + // we use but for `clang-cl` there's only one which internally + // multiplexes via flags. As a result it appears that CMake's detection + // of a compiler's architecture and such on MSVC **doesn't** pass any + // custom flags we pass in CMAKE_CXX_FLAGS below. This means that if we + // use `clang-cl.exe` it's always diagnosed as a 64-bit compiler which + // definitely causes problems since all the env vars are pointing to + // 32-bit libraries. + // + // To hack around this... again... we pass an argument that's + // unconditionally passed in the sccache shim. This'll get CMake to + // correctly diagnose it's doing a 32-bit compilation and LLVM will + // internally configure itself appropriately. + if builder.config.llvm_clang_cl.is_some() && target.contains("i686") { + cfg.env("SCCACHE_EXTRA_ARGS", "-m32"); + } } else { - // If ccache is configured we inform the build a little differently how - // to invoke ccache while also invoking our compilers. - if let Some(ref ccache) = builder.config.ccache { - cfg.define("CMAKE_C_COMPILER_LAUNCHER", ccache) - .define("CMAKE_CXX_COMPILER_LAUNCHER", ccache); - } - cfg.define("CMAKE_C_COMPILER", sanitize_cc(cc)) - .define("CMAKE_CXX_COMPILER", sanitize_cc(cxx)); + // If ccache is configured we inform the build a little differently how + // to invoke ccache while also invoking our compilers. + if let Some(ref ccache) = builder.config.ccache { + cfg.define("CMAKE_C_COMPILER_LAUNCHER", ccache) + .define("CMAKE_CXX_COMPILER_LAUNCHER", ccache); + } + cfg.define("CMAKE_C_COMPILER", sanitize_cc(cc)) + .define("CMAKE_CXX_COMPILER", sanitize_cc(cxx)); } cfg.build_arg("-j").build_arg(builder.jobs().to_string()); @@ -394,10 +378,7 @@ fn configure_cmake(builder: &Builder<'_>, } cfg.define("CMAKE_C_FLAGS", cflags); let mut cxxflags = builder.cflags(target, GitRepo::Llvm).join(" "); - if builder.config.llvm_static_stdcpp && - !target.contains("msvc") && - !target.contains("netbsd") - { + if builder.config.llvm_static_stdcpp && !target.contains("msvc") && !target.contains("netbsd") { cxxflags.push_str(" -static-libstdc++"); } if let Some(ref s) = builder.config.llvm_cxxflags { @@ -455,14 +436,12 @@ impl Step for Lld { } let target = self.target; - let llvm_config = builder.ensure(Llvm { - target: self.target, - }); + let llvm_config = builder.ensure(Llvm { target: self.target }); let out_dir = builder.lld_out(target); let done_stamp = out_dir.join("lld-finished-building"); if done_stamp.exists() { - return out_dir + return out_dir; } builder.info(&format!("Building LLD for {}", target)); @@ -486,14 +465,12 @@ impl Step for Lld { // ensure we don't hit the same bugs with escaping. It means that you // can't build on a system where your paths require `\` on Windows, but // there's probably a lot of reasons you can't do that other than this. - let llvm_config_shim = env::current_exe() - .unwrap() - .with_file_name("llvm-config-wrapper"); + let llvm_config_shim = env::current_exe().unwrap().with_file_name("llvm-config-wrapper"); cfg.out_dir(&out_dir) - .profile("Release") - .env("LLVM_CONFIG_REAL", llvm_config) - .define("LLVM_CONFIG_PATH", llvm_config_shim) - .define("LLVM_INCLUDE_TESTS", "OFF"); + .profile("Release") + .env("LLVM_CONFIG_REAL", llvm_config) + .define("LLVM_CONFIG_PATH", llvm_config_shim) + .define("LLVM_INCLUDE_TESTS", "OFF"); cfg.build(); @@ -528,7 +505,7 @@ impl Step for TestHelpers { let dst = builder.test_helpers_out(target); let src = builder.src.join("src/test/auxiliary/rust_test_helpers.c"); if up_to_date(&src, &dst.join("librust_test_helpers.a")) { - return + return; } builder.info("Building test helpers"); @@ -550,13 +527,13 @@ impl Step for TestHelpers { } cfg.cargo_metadata(false) - .out_dir(&dst) - .target(&target) - .host(&builder.config.build) - .opt_level(0) - .warnings(false) - .debug(false) - .file(builder.src.join("src/test/auxiliary/rust_test_helpers.c")) - .compile("rust_test_helpers"); + .out_dir(&dst) + .target(&target) + .host(&builder.config.build) + .opt_level(0) + .warnings(false) + .debug(false) + .file(builder.src.join("src/test/auxiliary/rust_test_helpers.c")) + .compile("rust_test_helpers"); } } diff --git a/src/bootstrap/sanity.rs b/src/bootstrap/sanity.rs index bffe748f37c..8ff7056e628 100644 --- a/src/bootstrap/sanity.rs +++ b/src/bootstrap/sanity.rs @@ -10,7 +10,7 @@ use std::collections::HashMap; use std::env; -use std::ffi::{OsString, OsStr}; +use std::ffi::{OsStr, OsString}; use std::fs; use std::path::PathBuf; use std::process::Command; @@ -26,30 +26,31 @@ struct Finder { impl Finder { fn new() -> Self { - Self { - cache: HashMap::new(), - path: env::var_os("PATH").unwrap_or_default() - } + Self { cache: HashMap::new(), path: env::var_os("PATH").unwrap_or_default() } } fn maybe_have<S: AsRef<OsStr>>(&mut self, cmd: S) -> Option<PathBuf> { let cmd: OsString = cmd.as_ref().into(); let path = &self.path; - self.cache.entry(cmd.clone()).or_insert_with(|| { - for path in env::split_paths(path) { - let target = path.join(&cmd); - let mut cmd_exe = cmd.clone(); - cmd_exe.push(".exe"); - - if target.is_file() // some/path/git + self.cache + .entry(cmd.clone()) + .or_insert_with(|| { + for path in env::split_paths(path) { + let target = path.join(&cmd); + 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 - || target.join(&cmd_exe).exists() // some/path/git/git.exe - { - return Some(target); + || target.join(&cmd_exe).exists() + // some/path/git/git.exe + { + return Some(target); + } } - } - None - }).clone() + None + }) + .clone() } fn must_have<S: AsRef<OsStr>>(&mut self, cmd: S) -> PathBuf { @@ -77,11 +78,17 @@ pub fn check(build: &mut Build) { } // We need cmake, but only if we're actually building LLVM or sanitizers. - let building_llvm = build.hosts.iter() - .map(|host| build.config.target_config - .get(host) - .map(|config| config.llvm_config.is_none()) - .unwrap_or(true)) + let building_llvm = build + .hosts + .iter() + .map(|host| { + build + .config + .target_config + .get(host) + .map(|config| config.llvm_config.is_none()) + .unwrap_or(true) + }) .any(|build_llvm_ourselves| build_llvm_ourselves); if building_llvm || build.config.sanitizers { cmd_finder.must_have("cmake"); @@ -119,17 +126,29 @@ pub fn check(build: &mut Build) { } } - build.config.python = build.config.python.take().map(|p| cmd_finder.must_have(p)) + build.config.python = build + .config + .python + .take() + .map(|p| cmd_finder.must_have(p)) .or_else(|| cmd_finder.maybe_have("python2.7")) .or_else(|| cmd_finder.maybe_have("python2")) .or_else(|| env::var_os("BOOTSTRAP_PYTHON").map(PathBuf::from)) // set by bootstrap.py .or_else(|| Some(cmd_finder.must_have("python"))); - build.config.nodejs = build.config.nodejs.take().map(|p| cmd_finder.must_have(p)) + build.config.nodejs = build + .config + .nodejs + .take() + .map(|p| cmd_finder.must_have(p)) .or_else(|| cmd_finder.maybe_have("node")) .or_else(|| cmd_finder.maybe_have("nodejs")); - build.config.gdb = build.config.gdb.take().map(|p| cmd_finder.must_have(p)) + build.config.gdb = build + .config + .gdb + .take() + .map(|p| cmd_finder.must_have(p)) .or_else(|| cmd_finder.maybe_have("gdb")); // We're gonna build some custom C code here and there, host triples @@ -169,15 +188,13 @@ pub fn check(build: &mut Build) { for target in &build.targets { // Can't compile for iOS unless we're on macOS - if target.contains("apple-ios") && - !build.build.contains("apple-darwin") { + if target.contains("apple-ios") && !build.build.contains("apple-darwin") { panic!("the iOS target is only supported on macOS"); } if target.contains("-none-") || target.contains("nvptx") { if build.no_std(*target).is_none() { - let target = build.config.target_config.entry(target.clone()) - .or_default(); + let target = build.config.target_config.entry(target.clone()).or_default(); target.no_std = true; } @@ -192,22 +209,20 @@ pub fn check(build: &mut Build) { // If this is a native target (host is also musl) and no musl-root is given, // fall back to the system toolchain in /usr before giving up if build.musl_root(*target).is_none() && build.config.build == *target { - let target = build.config.target_config.entry(target.clone()) - .or_default(); + let target = build.config.target_config.entry(target.clone()).or_default(); target.musl_root = Some("/usr".into()); } 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 \ + None => panic!( + "when targeting MUSL either the rust.musl-root \ option or the target.$TARGET.musl-root option must \ - be specified in config.toml") - } + be specified in config.toml" + ), } } @@ -217,7 +232,8 @@ pub fn check(build: &mut Build) { // Studio, so detect that here and error. let out = output(Command::new("cmake").arg("--help")); if !out.contains("Visual Studio") { - panic!(" + panic!( + " cmake does not support Visual Studio generators. This is likely due to it being an msys/cygwin build of cmake, @@ -228,7 +244,8 @@ If you are building under msys2 try installing the mingw-w64-x86_64-cmake package instead of cmake: $ pacman -R cmake && pacman -S mingw-w64-x86_64-cmake -"); +" + ); } } } @@ -240,8 +257,10 @@ $ pacman -R cmake && pacman -S mingw-w64-x86_64-cmake if build.config.channel == "stable" { let stage0 = t!(fs::read_to_string(build.src.join("src/stage0.txt"))); if stage0.contains("\ndev:") { - panic!("bootstrapping from a dev compiler in a stable release, but \ - should only be bootstrapping from a released compiler!"); + panic!( + "bootstrapping from a dev compiler in a stable release, but \ + should only be bootstrapping from a released compiler!" + ); } } } diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index 17aea17e69e..58dc8ffc17d 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -19,11 +19,11 @@ use crate::compile; use crate::dist; use crate::flags::Subcommand; use crate::native; -use crate::tool::{self, Tool, SourceType}; +use crate::tool::{self, SourceType, Tool}; use crate::toolstate::ToolState; use crate::util::{self, dylib_path, dylib_path_var}; use crate::Crate as CargoCrate; -use crate::{DocTests, Mode, GitRepo, envify}; +use crate::{envify, DocTests, GitRepo, Mode}; const ADB_TEST_DIR: &str = "/data/tmp/work"; @@ -115,16 +115,13 @@ impl Step for Linkcheck { let _time = util::timeit(&builder); try_run( builder, - builder - .tool_cmd(Tool::Linkchecker) - .arg(builder.out.join(host).join("doc")), + builder.tool_cmd(Tool::Linkchecker).arg(builder.out.join(host).join("doc")), ); } fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { let builder = run.builder; - run.path("src/tools/linkchecker") - .default_condition(builder.config.docs) + run.path("src/tools/linkchecker").default_condition(builder.config.docs) } fn make_run(run: RunConfig<'_>) { @@ -147,10 +144,7 @@ impl Step for Cargotest { } fn make_run(run: RunConfig<'_>) { - run.builder.ensure(Cargotest { - stage: run.builder.top_stage, - host: run.target, - }); + run.builder.ensure(Cargotest { stage: run.builder.top_stage, host: run.target }); } /// Runs the `cargotest` tool as compiled in `stage` by the `host` compiler. @@ -159,10 +153,7 @@ impl Step for Cargotest { /// test` to ensure that we don't regress the test suites there. fn run(self, builder: &Builder<'_>) { let compiler = builder.compiler(self.stage, self.host); - builder.ensure(compile::Rustc { - compiler, - target: compiler.host, - }); + builder.ensure(compile::Rustc { compiler, target: compiler.host }); // Note that this is a short, cryptic, and not scoped directory name. This // is currently to minimize the length of path on Windows where we otherwise @@ -197,28 +188,24 @@ impl Step for Cargo { } fn make_run(run: RunConfig<'_>) { - run.builder.ensure(Cargo { - stage: run.builder.top_stage, - host: run.target, - }); + run.builder.ensure(Cargo { stage: run.builder.top_stage, host: run.target }); } /// Runs `cargo test` for `cargo` packaged with Rust. fn run(self, builder: &Builder<'_>) { let compiler = builder.compiler(self.stage, self.host); - builder.ensure(tool::Cargo { + builder.ensure(tool::Cargo { compiler, target: self.host }); + let mut cargo = tool::prepare_tool_cargo( + builder, compiler, - target: self.host, - }); - let mut cargo = tool::prepare_tool_cargo(builder, - compiler, - Mode::ToolRustc, - self.host, - "test", - "src/tools/cargo", - SourceType::Submodule, - &[]); + Mode::ToolRustc, + self.host, + "test", + "src/tools/cargo", + SourceType::Submodule, + &[], + ); if !builder.fail_fast { cargo.arg("--no-fail-fast"); @@ -254,10 +241,7 @@ impl Step for Rls { } fn make_run(run: RunConfig<'_>) { - run.builder.ensure(Rls { - stage: run.builder.top_stage, - host: run.target, - }); + run.builder.ensure(Rls { stage: run.builder.top_stage, host: run.target }); } /// Runs `cargo test` for the rls. @@ -266,28 +250,26 @@ impl Step for Rls { let host = self.host; let compiler = builder.compiler(stage, host); - let build_result = builder.ensure(tool::Rls { - compiler, - target: self.host, - extra_features: Vec::new(), - }); + let build_result = + builder.ensure(tool::Rls { compiler, target: self.host, extra_features: Vec::new() }); if build_result.is_none() { eprintln!("failed to test rls: could not build"); return; } - let mut cargo = tool::prepare_tool_cargo(builder, - compiler, - Mode::ToolRustc, - host, - "test", - "src/tools/rls", - SourceType::Submodule, - &[]); + let mut cargo = tool::prepare_tool_cargo( + builder, + compiler, + Mode::ToolRustc, + host, + "test", + "src/tools/rls", + SourceType::Submodule, + &[], + ); builder.add_rustc_lib_path(compiler, &mut cargo); - cargo.arg("--") - .args(builder.config.cmd.test_args()); + cargo.arg("--").args(builder.config.cmd.test_args()); if try_run(builder, &mut cargo.into()) { builder.save_toolstate("rls", ToolState::TestPass); @@ -310,10 +292,7 @@ impl Step for Rustfmt { } fn make_run(run: RunConfig<'_>) { - run.builder.ensure(Rustfmt { - stage: run.builder.top_stage, - host: run.target, - }); + run.builder.ensure(Rustfmt { stage: run.builder.top_stage, host: run.target }); } /// Runs `cargo test` for rustfmt. @@ -332,14 +311,16 @@ impl Step for Rustfmt { return; } - let mut cargo = tool::prepare_tool_cargo(builder, - compiler, - Mode::ToolRustc, - host, - "test", - "src/tools/rustfmt", - SourceType::Submodule, - &[]); + let mut cargo = tool::prepare_tool_cargo( + builder, + compiler, + Mode::ToolRustc, + host, + "test", + "src/tools/rustfmt", + SourceType::Submodule, + &[], + ); let dir = testdir(builder, compiler.host); t!(fs::create_dir_all(&dir)); @@ -368,10 +349,7 @@ impl Step for Miri { } fn make_run(run: RunConfig<'_>) { - run.builder.ensure(Miri { - stage: run.builder.top_stage, - host: run.target, - }); + run.builder.ensure(Miri { stage: run.builder.top_stage, host: run.target }); } /// Runs `cargo test` for miri. @@ -380,11 +358,8 @@ impl Step for Miri { let host = self.host; let compiler = builder.compiler(stage, host); - let miri = builder.ensure(tool::Miri { - compiler, - target: self.host, - extra_features: Vec::new(), - }); + let miri = + builder.ensure(tool::Miri { compiler, target: self.host, extra_features: Vec::new() }); if let Some(miri) = miri { let mut cargo = builder.cargo(compiler, Mode::ToolRustc, host, "install"); cargo.arg("xargo"); @@ -407,12 +382,7 @@ impl Step for Miri { SourceType::Submodule, &[], ); - cargo - .arg("--bin") - .arg("cargo-miri") - .arg("--") - .arg("miri") - .arg("setup"); + cargo.arg("--bin").arg("cargo-miri").arg("--").arg("miri").arg("setup"); // Tell `cargo miri` not to worry about the sysroot mismatch (we built with // stage1 but run with stage2). @@ -441,7 +411,8 @@ impl Step for Miri { String::new() } else { builder.verbose(&format!("running: {:?}", cargo)); - let out = cargo.output() + let out = cargo + .output() .expect("We already ran `cargo miri setup` before and that worked"); assert!(out.status.success(), "`cargo miri setup` returned with non-0 exit code"); // Output is "<sysroot>\n". @@ -497,9 +468,7 @@ impl Step for CompiletestTest { } fn make_run(run: RunConfig<'_>) { - run.builder.ensure(CompiletestTest { - host: run.target, - }); + run.builder.ensure(CompiletestTest { host: run.target }); } /// Runs `cargo test` for compiletest. @@ -507,14 +476,16 @@ impl Step for CompiletestTest { let host = self.host; let compiler = builder.compiler(0, host); - let cargo = tool::prepare_tool_cargo(builder, - compiler, - Mode::ToolBootstrap, - host, - "test", - "src/tools/compiletest", - SourceType::InTree, - &[]); + let cargo = tool::prepare_tool_cargo( + builder, + compiler, + Mode::ToolBootstrap, + host, + "test", + "src/tools/compiletest", + SourceType::InTree, + &[], + ); try_run(builder, &mut cargo.into()); } @@ -536,10 +507,7 @@ impl Step for Clippy { } fn make_run(run: RunConfig<'_>) { - run.builder.ensure(Clippy { - stage: run.builder.top_stage, - host: run.target, - }); + run.builder.ensure(Clippy { stage: run.builder.top_stage, host: run.target }); } /// Runs `cargo test` for clippy. @@ -554,22 +522,22 @@ impl Step for Clippy { extra_features: Vec::new(), }); if let Some(clippy) = clippy { - let mut cargo = tool::prepare_tool_cargo(builder, - compiler, - Mode::ToolRustc, - host, - "test", - "src/tools/clippy", - SourceType::Submodule, - &[]); + let mut cargo = tool::prepare_tool_cargo( + builder, + compiler, + Mode::ToolRustc, + host, + "test", + "src/tools/clippy", + SourceType::Submodule, + &[], + ); // clippy tests need to know about the stage sysroot cargo.env("SYSROOT", builder.sysroot(compiler)); cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler)); cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler)); - let host_libs = builder - .stage_out(compiler, Mode::ToolRustc) - .join(builder.cargo_dir()); + let host_libs = builder.stage_out(compiler, Mode::ToolRustc).join(builder.cargo_dir()); let target_libs = builder .stage_out(compiler, Mode::ToolRustc) .join(&self.host) @@ -623,19 +591,10 @@ impl Step for RustdocTheme { let rustdoc = builder.out.join("bootstrap/debug/rustdoc"); let mut cmd = builder.tool_cmd(Tool::RustdocTheme); cmd.arg(rustdoc.to_str().unwrap()) - .arg( - builder - .src - .join("src/librustdoc/html/static/themes") - .to_str() - .unwrap(), - ) + .arg(builder.src.join("src/librustdoc/html/static/themes").to_str().unwrap()) .env("RUSTC_STAGE", self.compiler.stage.to_string()) .env("RUSTC_SYSROOT", builder.sysroot(self.compiler)) - .env( - "RUSTDOC_LIBDIR", - builder.sysroot_libdir(self.compiler, self.compiler.host), - ) + .env("RUSTDOC_LIBDIR", builder.sysroot_libdir(self.compiler, self.compiler.host)) .env("CFG_RELEASE_CHANNEL", &builder.config.channel) .env("RUSTDOC_REAL", builder.rustdoc(self.compiler)) .env("RUSTDOC_CRATE_VERSION", builder.rust_version()) @@ -663,25 +622,17 @@ impl Step for RustdocJSStd { } fn make_run(run: RunConfig<'_>) { - run.builder.ensure(RustdocJSStd { - host: run.host, - target: run.target, - }); + run.builder.ensure(RustdocJSStd { host: run.host, target: run.target }); } fn run(self, builder: &Builder<'_>) { if let Some(ref nodejs) = builder.config.nodejs { let mut command = Command::new(nodejs); command.args(&["src/tools/rustdoc-js-std/tester.js", &*self.host]); - builder.ensure(crate::doc::Std { - target: self.target, - stage: builder.top_stage, - }); + builder.ensure(crate::doc::Std { target: self.target, stage: builder.top_stage }); builder.run(&mut command); } else { - builder.info( - "No nodejs found, skipping \"src/test/rustdoc-js-std\" tests" - ); + builder.info("No nodejs found, skipping \"src/test/rustdoc-js-std\" tests"); } } } @@ -704,11 +655,7 @@ impl Step for RustdocJSNotStd { fn make_run(run: RunConfig<'_>) { let compiler = run.builder.compiler(run.builder.top_stage, run.host); - run.builder.ensure(RustdocJSNotStd { - host: run.host, - target: run.target, - compiler, - }); + run.builder.ensure(RustdocJSNotStd { host: run.host, target: run.target, compiler }); } fn run(self, builder: &Builder<'_>) { @@ -722,9 +669,7 @@ impl Step for RustdocJSNotStd { compare_mode: None, }); } else { - builder.info( - "No nodejs found, skipping \"src/test/rustdoc-js\" tests" - ); + builder.info("No nodejs found, skipping \"src/test/rustdoc-js\" tests"); } } } @@ -747,11 +692,7 @@ impl Step for RustdocUi { fn make_run(run: RunConfig<'_>) { let compiler = run.builder.compiler(run.builder.top_stage, run.host); - run.builder.ensure(RustdocUi { - host: run.host, - target: run.target, - compiler, - }); + run.builder.ensure(RustdocUi { host: run.host, target: run.target, compiler }); } fn run(self, builder: &Builder<'_>) { @@ -818,37 +759,55 @@ fn testdir(builder: &Builder<'_>, host: Interned<String>) -> PathBuf { macro_rules! default_test { ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => { test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: false }); - } + }; } macro_rules! default_test_with_compare_mode { ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, compare_mode: $compare_mode:expr }) => { - test_with_compare_mode!($name { path: $path, mode: $mode, suite: $suite, default: true, - host: false, compare_mode: $compare_mode }); - } + test_with_compare_mode!($name { + path: $path, + mode: $mode, + suite: $suite, + default: true, + host: false, + compare_mode: $compare_mode + }); + }; } macro_rules! host_test { ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => { test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: true }); - } + }; } macro_rules! test { ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr, host: $host:expr }) => { - test_definitions!($name { path: $path, mode: $mode, suite: $suite, default: $default, - host: $host, compare_mode: None }); - } + test_definitions!($name { + path: $path, + mode: $mode, + suite: $suite, + default: $default, + host: $host, + compare_mode: None + }); + }; } macro_rules! test_with_compare_mode { ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr, host: $host:expr, compare_mode: $compare_mode:expr }) => { - test_definitions!($name { path: $path, mode: $mode, suite: $suite, default: $default, - host: $host, compare_mode: Some($compare_mode) }); - } + test_definitions!($name { + path: $path, + mode: $mode, + suite: $suite, + default: $default, + host: $host, + compare_mode: Some($compare_mode) + }); + }; } macro_rules! test_definitions { @@ -878,10 +837,7 @@ macro_rules! test_definitions { fn make_run(run: RunConfig<'_>) { let compiler = run.builder.compiler(run.builder.top_stage, run.host); - run.builder.ensure($name { - compiler, - target: run.target, - }); + run.builder.ensure($name { compiler, target: run.target }); } fn run(self, builder: &Builder<'_>) { @@ -895,7 +851,7 @@ macro_rules! test_definitions { }) } } - } + }; } default_test_with_compare_mode!(Ui { @@ -911,11 +867,7 @@ default_test!(CompileFail { suite: "compile-fail" }); -default_test!(RunFail { - path: "src/test/run-fail", - mode: "run-fail", - suite: "run-fail" -}); +default_test!(RunFail { path: "src/test/run-fail", mode: "run-fail", suite: "run-fail" }); default_test!(RunPassValgrind { path: "src/test/run-pass-valgrind", @@ -923,17 +875,9 @@ default_test!(RunPassValgrind { suite: "run-pass-valgrind" }); -default_test!(MirOpt { - path: "src/test/mir-opt", - mode: "mir-opt", - suite: "mir-opt" -}); +default_test!(MirOpt { path: "src/test/mir-opt", mode: "mir-opt", suite: "mir-opt" }); -default_test!(Codegen { - path: "src/test/codegen", - mode: "codegen", - suite: "codegen" -}); +default_test!(Codegen { path: "src/test/codegen", mode: "codegen", suite: "codegen" }); default_test!(CodegenUnits { path: "src/test/codegen-units", @@ -947,29 +891,13 @@ default_test!(Incremental { suite: "incremental" }); -default_test!(Debuginfo { - path: "src/test/debuginfo", - mode: "debuginfo", - suite: "debuginfo" -}); +default_test!(Debuginfo { path: "src/test/debuginfo", mode: "debuginfo", suite: "debuginfo" }); -host_test!(UiFullDeps { - path: "src/test/ui-fulldeps", - mode: "ui", - suite: "ui-fulldeps" -}); +host_test!(UiFullDeps { path: "src/test/ui-fulldeps", mode: "ui", suite: "ui-fulldeps" }); -host_test!(Rustdoc { - path: "src/test/rustdoc", - mode: "rustdoc", - suite: "rustdoc" -}); +host_test!(Rustdoc { path: "src/test/rustdoc", mode: "rustdoc", suite: "rustdoc" }); -host_test!(Pretty { - path: "src/test/pretty", - mode: "pretty", - suite: "pretty" -}); +host_test!(Pretty { path: "src/test/pretty", mode: "pretty", suite: "pretty" }); test!(RunFailPretty { path: "src/test/run-fail/pretty", mode: "pretty", @@ -985,11 +913,7 @@ test!(RunPassValgrindPretty { host: true }); -default_test!(RunMake { - path: "src/test/run-make", - mode: "run-make", - suite: "run-make" -}); +default_test!(RunMake { path: "src/test/run-make", mode: "run-make", suite: "run-make" }); host_test!(RunMakeFullDeps { path: "src/test/run-make-fulldeps", @@ -997,11 +921,7 @@ host_test!(RunMakeFullDeps { suite: "run-make-fulldeps" }); -default_test!(Assembly { - path: "src/test/assembly", - mode: "assembly", - suite: "assembly" -}); +default_test!(Assembly { path: "src/test/assembly", mode: "assembly", suite: "assembly" }); #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] struct Compiletest { @@ -1048,10 +968,8 @@ impl Step for Compiletest { }); } - builder.ensure(dist::DebuggerScripts { - sysroot: builder.sysroot(compiler), - host: target, - }); + builder + .ensure(dist::DebuggerScripts { sysroot: builder.sysroot(compiler), host: target }); } if suite.ends_with("fulldeps") { @@ -1077,10 +995,8 @@ impl Step for Compiletest { // compiletest currently has... a lot of arguments, so let's just pass all // of them! - cmd.arg("--compile-lib-path") - .arg(builder.rustc_libdir(compiler)); - cmd.arg("--run-lib-path") - .arg(builder.sysroot_libdir(compiler, target)); + cmd.arg("--compile-lib-path").arg(builder.rustc_libdir(compiler)); + cmd.arg("--run-lib-path").arg(builder.sysroot_libdir(compiler, target)); cmd.arg("--rustc-path").arg(builder.rustc(compiler)); let is_rustdoc = suite.ends_with("rustdoc-ui") || suite.ends_with("rustdoc-js"); @@ -1091,33 +1007,25 @@ impl Step for Compiletest { || (mode == "ui" && is_rustdoc) || mode == "js-doc-test" { - cmd.arg("--rustdoc-path") - .arg(builder.rustdoc(compiler)); + cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler)); } - cmd.arg("--src-base") - .arg(builder.src.join("src/test").join(suite)); - cmd.arg("--build-base") - .arg(testdir(builder, compiler.host).join(suite)); - cmd.arg("--stage-id") - .arg(format!("stage{}-{}", compiler.stage, target)); + cmd.arg("--src-base").arg(builder.src.join("src/test").join(suite)); + cmd.arg("--build-base").arg(testdir(builder, compiler.host).join(suite)); + cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target)); cmd.arg("--mode").arg(mode); cmd.arg("--target").arg(target); cmd.arg("--host").arg(&*compiler.host); - cmd.arg("--llvm-filecheck") - .arg(builder.llvm_filecheck(builder.config.build)); + cmd.arg("--llvm-filecheck").arg(builder.llvm_filecheck(builder.config.build)); if builder.config.cmd.bless() { cmd.arg("--bless"); } - let compare_mode = builder.config.cmd.compare_mode().or_else(|| { - if builder.config.test_compare_mode { - self.compare_mode - } else { - None - } - }); + let compare_mode = + builder.config.cmd.compare_mode().or_else(|| { + if builder.config.test_compare_mode { self.compare_mode } else { None } + }); if let Some(ref pass) = builder.config.cmd.pass() { cmd.arg("--pass"); @@ -1128,11 +1036,7 @@ impl Step for Compiletest { cmd.arg("--nodejs").arg(nodejs); } - let mut flags = if is_rustdoc { - Vec::new() - } else { - vec!["-Crpath".to_string()] - }; + let mut flags = if is_rustdoc { Vec::new() } else { vec!["-Crpath".to_string()] }; if !is_rustdoc { if builder.config.rust_optimize_tests { flags.push("-O".to_string()); @@ -1147,17 +1051,11 @@ impl Step for Compiletest { } let mut hostflags = flags.clone(); - hostflags.push(format!( - "-Lnative={}", - builder.test_helpers_out(compiler.host).display() - )); + hostflags.push(format!("-Lnative={}", builder.test_helpers_out(compiler.host).display())); cmd.arg("--host-rustcflags").arg(hostflags.join(" ")); let mut targetflags = flags; - targetflags.push(format!( - "-Lnative={}", - builder.test_helpers_out(target).display() - )); + targetflags.push(format!("-Lnative={}", builder.test_helpers_out(target).display())); cmd.arg("--target-rustcflags").arg(targetflags.join(" ")); cmd.arg("--docck-python").arg(builder.python()); @@ -1178,9 +1076,10 @@ impl Step for Compiletest { let run = |cmd: &mut Command| { cmd.output().map(|output| { String::from_utf8_lossy(&output.stdout) - .lines().next().unwrap_or_else(|| { - panic!("{:?} failed {:?}", cmd, output) - }).to_string() + .lines() + .next() + .unwrap_or_else(|| panic!("{:?} failed {:?}", cmd, output)) + .to_string() }) }; let lldb_exe = if builder.config.lldb_enabled { @@ -1192,7 +1091,7 @@ impl Step for Compiletest { let lldb_version = Command::new(&lldb_exe) .arg("--version") .output() - .map(|output| { String::from_utf8_lossy(&output.stdout).to_string() }) + .map(|output| String::from_utf8_lossy(&output.stdout).to_string()) .ok(); if let Some(ref vers) = lldb_version { cmd.arg("--lldb-version").arg(vers); @@ -1216,11 +1115,9 @@ impl Step for Compiletest { // Get test-args by striping suite path let mut test_args: Vec<&str> = paths .iter() - .map(|p| { - match p.strip_prefix(".") { - Ok(path) => path, - Err(_) => p, - } + .map(|p| match p.strip_prefix(".") { + Ok(path) => path, + Err(_) => p, }) .filter(|p| p.starts_with(suite_path) && (p.is_dir() || p.is_file())) .filter_map(|p| { @@ -1250,9 +1147,7 @@ impl Step for Compiletest { } if builder.config.llvm_enabled() { - let llvm_config = builder.ensure(native::Llvm { - target: builder.config.build, - }); + let llvm_config = builder.ensure(native::Llvm { target: builder.config.build }); if !builder.config.dry_run { let llvm_version = output(Command::new(&llvm_config).arg("--version")); cmd.arg("--llvm-version").arg(llvm_version); @@ -1282,23 +1177,24 @@ impl Step for Compiletest { // The llvm/bin directory contains many useful cross-platform // tools. Pass the path to run-make tests so they can use them. - let llvm_bin_path = llvm_config.parent() + let llvm_bin_path = llvm_config + .parent() .expect("Expected llvm-config to be contained in directory"); assert!(llvm_bin_path.is_dir()); cmd.arg("--llvm-bin-dir").arg(llvm_bin_path); // If LLD is available, add it to the PATH if builder.config.lld_enabled { - let lld_install_root = builder.ensure(native::Lld { - target: builder.config.build, - }); + let lld_install_root = + builder.ensure(native::Lld { target: builder.config.build }); let lld_bin_path = lld_install_root.join("bin"); let old_path = env::var_os("PATH").unwrap_or_default(); - let new_path = env::join_paths(std::iter::once(lld_bin_path) - .chain(env::split_paths(&old_path))) - .expect("Could not add LLD bin path to PATH"); + let new_path = env::join_paths( + std::iter::once(lld_bin_path).chain(env::split_paths(&old_path)), + ) + .expect("Could not add LLD bin path to PATH"); cmd.env("PATH", new_path); } } @@ -1318,8 +1214,7 @@ impl Step for Compiletest { } if builder.remote_tested(target) { - cmd.arg("--remote-test-client") - .arg(builder.tool_exe(Tool::RemoteTestClient)); + cmd.arg("--remote-test-client").arg(builder.tool_exe(Tool::RemoteTestClient)); } // Running a C compiler on MSVC requires a few env vars to be set, to be @@ -1349,7 +1244,6 @@ impl Step for Compiletest { std::fs::create_dir_all(&tmp).unwrap(); cmd.env("RUST_TEST_TMPDIR", tmp); - cmd.arg("--adb-path").arg("adb"); cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR); if target.contains("android") { @@ -1409,10 +1303,7 @@ impl Step for DocTest { fn run(self, builder: &Builder<'_>) { let compiler = self.compiler; - builder.ensure(compile::Std { - compiler, - target: compiler.host, - }); + builder.ensure(compile::Std { compiler, target: compiler.host }); // Do a breadth-first traversal of the `src/doc` directory and just run // tests for all files that end in `*.md` @@ -1516,9 +1407,8 @@ impl Step for ErrorIndex { } fn make_run(run: RunConfig<'_>) { - run.builder.ensure(ErrorIndex { - compiler: run.builder.compiler(run.builder.top_stage, run.host), - }); + run.builder + .ensure(ErrorIndex { compiler: run.builder.compiler(run.builder.top_stage, run.host) }); } /// Runs the error index generator tool to execute the tests located in the error @@ -1530,10 +1420,7 @@ impl Step for ErrorIndex { fn run(self, builder: &Builder<'_>) { let compiler = self.compiler; - builder.ensure(compile::Std { - compiler, - target: compiler.host, - }); + builder.ensure(compile::Std { compiler, target: compiler.host }); let dir = testdir(builder, compiler.host); t!(fs::create_dir_all(&dir)); @@ -1543,9 +1430,7 @@ impl Step for ErrorIndex { builder, builder.compiler(compiler.stage, builder.config.build), ); - tool.arg("markdown") - .arg(&output) - .env("CFG_BUILD", &builder.config.build); + tool.arg("markdown").arg(&output).env("CFG_BUILD", &builder.config.build); builder.info(&format!("Testing error-index stage{}", compiler.stage)); let _time = util::timeit(&builder); @@ -1825,23 +1710,12 @@ impl Step for Crate { if target.contains("emscripten") { cargo.env( format!("CARGO_TARGET_{}_RUNNER", envify(&target)), - builder - .config - .nodejs - .as_ref() - .expect("nodejs not configured"), + builder.config.nodejs.as_ref().expect("nodejs not configured"), ); } else if target.starts_with("wasm32") { - let node = builder - .config - .nodejs - .as_ref() - .expect("nodejs not configured"); - let runner = format!( - "{} {}/src/etc/wasm32-shim.js", - node.display(), - builder.src.display() - ); + let node = builder.config.nodejs.as_ref().expect("nodejs not configured"); + let runner = + format!("{} {}/src/etc/wasm32-shim.js", node.display(), builder.src.display()); cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)), &runner); } else if builder.remote_tested(target) { cargo.env( @@ -1879,10 +1753,7 @@ impl Step for CrateRustdoc { let test_kind = builder.kind.into(); - builder.ensure(CrateRustdoc { - host: run.host, - test_kind, - }); + builder.ensure(CrateRustdoc { host: run.host, test_kind }); } fn run(self, builder: &Builder<'_>) { @@ -1892,14 +1763,16 @@ impl Step for CrateRustdoc { let target = compiler.host; builder.ensure(compile::Rustc { compiler, target }); - let mut cargo = tool::prepare_tool_cargo(builder, - compiler, - Mode::ToolRustc, - target, - test_kind.subcommand(), - "src/tools/rustdoc", - SourceType::InTree, - &[]); + let mut cargo = tool::prepare_tool_cargo( + builder, + compiler, + Mode::ToolRustc, + target, + test_kind.subcommand(), + "src/tools/rustdoc", + SourceType::InTree, + &[], + ); if test_kind.subcommand() == "test" && !builder.fail_fast { cargo.arg("--no-fail-fast"); } @@ -1961,18 +1834,13 @@ impl Step for RemoteCopyLibs { builder.info(&format!("REMOTE copy libs to emulator ({})", target)); t!(fs::create_dir_all(builder.out.join("tmp"))); - let server = builder.ensure(tool::RemoteTestServer { - compiler: compiler.with_stage(0), - target, - }); + let server = + builder.ensure(tool::RemoteTestServer { compiler: compiler.with_stage(0), target }); // Spawn the emulator and wait for it to come online let tool = builder.tool_exe(Tool::RemoteTestClient); let mut cmd = Command::new(&tool); - cmd.arg("spawn-emulator") - .arg(target) - .arg(&server) - .arg(builder.out.join("tmp")); + cmd.arg("spawn-emulator").arg(target).arg(&server).arg(builder.out.join("tmp")); if let Some(rootfs) = builder.qemu_rootfs(target) { cmd.arg(rootfs); } @@ -2027,9 +1895,7 @@ impl Step for Distcheck { .current_dir(&dir), ); builder.run( - Command::new(build_helper::make(&builder.config.build)) - .arg("check") - .current_dir(&dir), + Command::new(build_helper::make(&builder.config.build)).arg("check").current_dir(&dir), ); // Now make sure that rust-src has all of libstd's dependencies diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs index 815498047fd..9fd20386e36 100644 --- a/src/bootstrap/tool.rs +++ b/src/bootstrap/tool.rs @@ -1,20 +1,20 @@ -use std::fs; +use std::collections::HashSet; use std::env; +use std::fs; use std::path::PathBuf; -use std::process::{Command, exit}; -use std::collections::HashSet; +use std::process::{exit, Command}; use build_helper::t; -use crate::Mode; -use crate::Compiler; -use crate::builder::{Step, RunConfig, ShouldRun, Builder, Cargo as CargoCommand}; -use crate::util::{exe, add_lib_path, CiEnv}; -use crate::compile; -use crate::channel::GitInfo; -use crate::channel; +use crate::builder::{Builder, Cargo as CargoCommand, RunConfig, ShouldRun, Step}; use crate::cache::Interned; +use crate::channel; +use crate::channel::GitInfo; +use crate::compile; use crate::toolstate::ToolState; +use crate::util::{add_lib_path, exe, CiEnv}; +use crate::Compiler; +use crate::Mode; #[derive(Debug, Clone, Hash, PartialEq, Eq)] pub enum SourceType { @@ -53,14 +53,10 @@ impl Step for ToolBuild { let is_optional_tool = self.is_optional_tool; match self.mode { - Mode::ToolRustc => { - builder.ensure(compile::Rustc { compiler, target }) - } - Mode::ToolStd => { - builder.ensure(compile::Std { compiler, target }) - } + Mode::ToolRustc => builder.ensure(compile::Rustc { compiler, target }), + Mode::ToolStd => builder.ensure(compile::Std { compiler, target }), Mode::ToolBootstrap => {} // uses downloaded stage0 compiler libs - _ => panic!("unexpected Mode for tool build") + _ => panic!("unexpected Mode for tool build"), } let cargo = prepare_tool_cargo( @@ -79,12 +75,7 @@ impl Step for ToolBuild { let is_expected = compile::stream_cargo(builder, cargo, vec![], &mut |msg| { // Only care about big things like the RLS/Cargo for now match tool { - | "rls" - | "cargo" - | "clippy-driver" - | "miri" - | "rustfmt" - => {} + "rls" | "cargo" | "clippy-driver" | "miri" | "rustfmt" => {} _ => return, } @@ -94,9 +85,7 @@ impl Step for ToolBuild { features, filenames, target: _, - } => { - (package_id, features, filenames) - } + } => (package_id, features, filenames), _ => return, }; let features = features.iter().map(|s| s.to_string()).collect::<Vec<_>>(); @@ -105,7 +94,7 @@ impl Step for ToolBuild { let val = (tool, PathBuf::from(&*path), features.clone()); // we're only interested in deduplicating rlibs for now if val.1.extension().and_then(|s| s.to_str()) != Some("rlib") { - continue + continue; } // Don't worry about compiles that turn out to be host @@ -132,9 +121,7 @@ impl Step for ToolBuild { // already listed then we need to see if we reused the same // artifact or produced a duplicate. let mut artifacts = builder.tool_artifacts.borrow_mut(); - let prev_artifacts = artifacts - .entry(target) - .or_default(); + let prev_artifacts = artifacts.entry(target).or_default(); let prev = match prev_artifacts.get(&*id) { Some(prev) => prev, None => { @@ -160,21 +147,21 @@ impl Step for ToolBuild { // ... and otherwise this looks like we duplicated some sort of // compilation, so record it to generate an error later. - duplicates.push(( - id.to_string(), - val, - prev.clone(), - )); + duplicates.push((id.to_string(), val, prev.clone())); } }); if is_expected && !duplicates.is_empty() { - println!("duplicate artifacts found when compiling a tool, this \ + println!( + "duplicate artifacts found when compiling a tool, this \ typically means that something was recompiled because \ a transitive dependency has different features activated \ - than in a previous build:\n"); - println!("the following dependencies are duplicated although they \ - have the same features enabled:"); + than in a previous build:\n" + ); + println!( + "the following dependencies are duplicated although they \ + have the same features enabled:" + ); for (id, cur, prev) in duplicates.drain_filter(|(_, cur, prev)| cur.2 == prev.2) { println!(" {}", id); // same features @@ -185,24 +172,33 @@ impl Step for ToolBuild { println!(" {}", id); let cur_features: HashSet<_> = cur.2.into_iter().collect(); let prev_features: HashSet<_> = prev.2.into_iter().collect(); - println!(" `{}` additionally enabled features {:?} at {:?}", - cur.0, &cur_features - &prev_features, cur.1); - println!(" `{}` additionally enabled features {:?} at {:?}", - prev.0, &prev_features - &cur_features, prev.1); + println!( + " `{}` additionally enabled features {:?} at {:?}", + cur.0, + &cur_features - &prev_features, + cur.1 + ); + println!( + " `{}` additionally enabled features {:?} at {:?}", + prev.0, + &prev_features - &cur_features, + prev.1 + ); } println!(); - println!("to fix this you will probably want to edit the local \ + println!( + "to fix this you will probably want to edit the local \ src/tools/rustc-workspace-hack/Cargo.toml crate, as \ that will update the dependency graph to ensure that \ - these crates all share the same feature set"); + these crates all share the same feature set" + ); panic!("tools should not compile multiple copies of the same crate"); } - builder.save_toolstate(tool, if is_expected { - ToolState::TestFail - } else { - ToolState::BuildFail - }); + builder.save_toolstate( + tool, + if is_expected { ToolState::TestFail } else { ToolState::BuildFail }, + ); if !is_expected { if !is_optional_tool { @@ -211,8 +207,8 @@ impl Step for ToolBuild { None } } else { - let cargo_out = builder.cargo_out(compiler, self.mode, target) - .join(exe(tool, &compiler.host)); + let cargo_out = + builder.cargo_out(compiler, self.mode, target).join(exe(tool, &compiler.host)); let bin = builder.tools_dir(compiler).join(exe(tool, &compiler.host)); builder.copy(&cargo_out, &bin); Some(bin) @@ -240,12 +236,12 @@ pub fn prepare_tool_cargo( let mut features = extra_features.iter().cloned().collect::<Vec<_>>(); if builder.build.config.cargo_native_static { - if path.ends_with("cargo") || - path.ends_with("rls") || - path.ends_with("clippy") || - path.ends_with("miri") || - path.ends_with("rustbook") || - path.ends_with("rustfmt") + if path.ends_with("cargo") + || path.ends_with("rls") + || path.ends_with("clippy") + || path.ends_with("miri") + || path.ends_with("rustbook") + || path.ends_with("rustfmt") { cargo.env("LIBZ_SYS_STATIC", "1"); features.push("rustc-workspace-hack/all-static".to_string()); @@ -395,9 +391,7 @@ pub struct ErrorIndex { impl ErrorIndex { pub fn command(builder: &Builder<'_>, compiler: Compiler) -> Command { - let mut cmd = Command::new(builder.ensure(ErrorIndex { - compiler - })); + let mut cmd = Command::new(builder.ensure(ErrorIndex { compiler })); add_lib_path( vec![PathBuf::from(&builder.sysroot_libdir(compiler, compiler.host))], &mut cmd, @@ -417,22 +411,23 @@ impl Step for ErrorIndex { // Compile the error-index in the same stage as rustdoc to avoid // recompiling rustdoc twice if we can. let stage = if run.builder.top_stage >= 2 { run.builder.top_stage } else { 0 }; - run.builder.ensure(ErrorIndex { - compiler: run.builder.compiler(stage, run.builder.config.build), - }); + run.builder + .ensure(ErrorIndex { compiler: run.builder.compiler(stage, run.builder.config.build) }); } fn run(self, builder: &Builder<'_>) -> PathBuf { - builder.ensure(ToolBuild { - compiler: self.compiler, - target: self.compiler.host, - tool: "error_index_generator", - mode: Mode::ToolRustc, - path: "src/tools/error_index_generator", - is_optional_tool: false, - source_type: SourceType::InTree, - extra_features: Vec::new(), - }).expect("expected to build -- essential tool") + builder + .ensure(ToolBuild { + compiler: self.compiler, + target: self.compiler.host, + tool: "error_index_generator", + mode: Mode::ToolRustc, + path: "src/tools/error_index_generator", + is_optional_tool: false, + source_type: SourceType::InTree, + extra_features: Vec::new(), + }) + .expect("expected to build -- essential tool") } } @@ -457,16 +452,18 @@ impl Step for RemoteTestServer { } fn run(self, builder: &Builder<'_>) -> PathBuf { - builder.ensure(ToolBuild { - compiler: self.compiler, - target: self.target, - tool: "remote-test-server", - mode: Mode::ToolStd, - path: "src/tools/remote-test-server", - is_optional_tool: false, - source_type: SourceType::InTree, - extra_features: Vec::new(), - }).expect("expected to build -- essential tool") + builder + .ensure(ToolBuild { + compiler: self.compiler, + target: self.target, + tool: "remote-test-server", + mode: Mode::ToolStd, + path: "src/tools/remote-test-server", + is_optional_tool: false, + source_type: SourceType::InTree, + extra_features: Vec::new(), + }) + .expect("expected to build -- essential tool") } } @@ -487,9 +484,8 @@ impl Step for Rustdoc { } fn make_run(run: RunConfig<'_>) { - run.builder.ensure(Rustdoc { - compiler: run.builder.compiler(run.builder.top_stage, run.host), - }); + run.builder + .ensure(Rustdoc { compiler: run.builder.compiler(run.builder.top_stage, run.host) }); } fn run(self, builder: &Builder<'_>) -> PathBuf { @@ -525,14 +521,17 @@ impl Step for Rustdoc { &[], ); - builder.info(&format!("Building rustdoc for stage{} ({})", - target_compiler.stage, target_compiler.host)); + builder.info(&format!( + "Building rustdoc for stage{} ({})", + target_compiler.stage, target_compiler.host + )); builder.run(&mut cargo.into()); // Cargo adds a number of paths to the dylib search path on windows, which results in // the wrong rustdoc being executed. To avoid the conflicting rustdocs, we name the "tool" // rustdoc a different name. - let tool_rustdoc = builder.cargo_out(build_compiler, Mode::ToolRustc, target) + let tool_rustdoc = builder + .cargo_out(build_compiler, Mode::ToolRustc, target) .join(exe("rustdoc_tool_binary", &target_compiler.host)); // don't create a stage0-sysroot/bin directory. @@ -574,16 +573,18 @@ impl Step for Cargo { } fn run(self, builder: &Builder<'_>) -> PathBuf { - builder.ensure(ToolBuild { - compiler: self.compiler, - target: self.target, - tool: "cargo", - mode: Mode::ToolRustc, - path: "src/tools/cargo", - is_optional_tool: false, - source_type: SourceType::Submodule, - extra_features: Vec::new(), - }).expect("expected to build -- essential tool") + builder + .ensure(ToolBuild { + compiler: self.compiler, + target: self.target, + tool: "cargo", + mode: Mode::ToolRustc, + path: "src/tools/cargo", + is_optional_tool: false, + source_type: SourceType::Submodule, + extra_features: Vec::new(), + }) + .expect("expected to build -- essential tool") } } @@ -682,7 +683,7 @@ impl<'a> Builder<'a> { let curpaths = env::split_paths(&curpaths).collect::<Vec<_>>(); for &(ref k, ref v) in self.cc[&compiler.host].env() { if k != "PATH" { - continue + continue; } for path in env::split_paths(v) { if !curpaths.contains(&path) { diff --git a/src/bootstrap/toolstate.rs b/src/bootstrap/toolstate.rs index a90f69d597d..b068c8200ac 100644 --- a/src/bootstrap/toolstate.rs +++ b/src/bootstrap/toolstate.rs @@ -1,14 +1,14 @@ -use serde::{Deserialize, Serialize}; +use crate::builder::{Builder, RunConfig, ShouldRun, Step}; use build_helper::t; -use std::time; -use std::fs; -use std::io::{Seek, SeekFrom}; +use serde::{Deserialize, Serialize}; use std::collections::HashMap; -use crate::builder::{Builder, RunConfig, ShouldRun, Step}; +use std::env; use std::fmt; -use std::process::Command; +use std::fs; +use std::io::{Seek, SeekFrom}; use std::path::PathBuf; -use std::env; +use std::process::Command; +use std::time; // Each cycle is 42 days long (6 weeks); the last week is 35..=42 then. const BETA_WEEK_START: u64 = 35; @@ -38,11 +38,15 @@ pub enum ToolState { impl fmt::Display for ToolState { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", match self { - ToolState::TestFail => "test-fail", - ToolState::TestPass => "test-pass", - ToolState::BuildFail => "build-fail", - }) + write!( + f, + "{}", + match self { + ToolState::TestFail => "test-fail", + ToolState::TestPass => "test-pass", + ToolState::BuildFail => "build-fail", + } + ) } } @@ -120,9 +124,7 @@ fn check_changed_files(toolstates: &HashMap<Box<str>, ToolState>) { let output = t!(String::from_utf8(output.stdout)); for (tool, submodule) in STABLE_TOOLS.iter().chain(NIGHTLY_TOOLS.iter()) { - let changed = output.lines().any(|l| { - l.starts_with("M") && l.ends_with(submodule) - }); + let changed = output.lines().any(|l| l.starts_with("M") && l.ends_with(submodule)); eprintln!("Verifying status of {}...", tool); if !changed { continue; @@ -179,8 +181,10 @@ impl Step for ToolStateCheck { eprintln!("error: Tool `{}` should be test-pass but is {}", tool, state); } else if in_beta_week { did_error = true; - eprintln!("error: Tool `{}` should be test-pass but is {} during beta week.", - tool, state); + eprintln!( + "error: Tool `{}` should be test-pass but is {} during beta week.", + tool, state + ); } } } @@ -210,11 +214,8 @@ impl Builder<'_> { // Ensure the parent directory always exists t!(std::fs::create_dir_all(parent)); } - let mut file = t!(fs::OpenOptions::new() - .create(true) - .write(true) - .read(true) - .open(path)); + let mut file = + t!(fs::OpenOptions::new().create(true).write(true).read(true).open(path)); serde_json::from_reader(&mut file).unwrap_or_default() } else { @@ -233,11 +234,8 @@ impl Builder<'_> { // Ensure the parent directory always exists t!(std::fs::create_dir_all(parent)); } - let mut file = t!(fs::OpenOptions::new() - .create(true) - .read(true) - .write(true) - .open(path)); + let mut file = + t!(fs::OpenOptions::new().create(true).read(true).write(true).open(path)); let mut current_toolstates: HashMap<Box<str>, ToolState> = serde_json::from_reader(&mut file).unwrap_or_default(); @@ -275,10 +273,7 @@ impl Builder<'_> { /// /// * See <https://help.github.com/articles/about-commit-email-addresses/> /// if a private email by GitHub is wanted. -fn commit_toolstate_change( - current_toolstate: &ToolstateData, - in_beta_week: bool, -) { +fn commit_toolstate_change(current_toolstate: &ToolstateData, in_beta_week: bool) { fn git_config(key: &str, value: &str) { let status = Command::new("git").arg("config").arg("--global").arg(key).arg(value).status(); let success = match status { @@ -303,7 +298,8 @@ fn commit_toolstate_change( let git_credential_path = PathBuf::from(t!(env::var("HOME"))).join(".git-credentials"); t!(fs::write(&git_credential_path, credential)); - let status = Command::new("git").arg("clone") + let status = Command::new("git") + .arg("clone") .arg("--depth=1") .arg(t!(env::var("TOOLSTATE_REPO"))) .status(); @@ -402,10 +398,7 @@ fn change_toolstate( std::process::exit(1); } - let commit = t!(std::process::Command::new("git") - .arg("rev-parse") - .arg("HEAD") - .output()); + let commit = t!(std::process::Command::new("git").arg("rev-parse").arg("HEAD").output()); let commit = t!(String::from_utf8(commit.stdout)); let toolstate_serialized = t!(serde_json::to_string(¤t_toolstate)); diff --git a/src/bootstrap/util.rs b/src/bootstrap/util.rs index 085742b011c..5fd25981851 100644 --- a/src/bootstrap/util.rs +++ b/src/bootstrap/util.rs @@ -4,36 +4,28 @@ //! not a lot of interesting happenings here unfortunately. use std::env; -use std::str; use std::fs; use std::io; use std::path::{Path, PathBuf}; use std::process::Command; +use std::str; use std::time::Instant; use build_helper::t; -use crate::config::Config; use crate::builder::Builder; use crate::cache::Interned; +use crate::config::Config; /// Returns the `name` as the filename of a static library for `target`. pub fn staticlib(name: &str, target: &str) -> String { - if target.contains("windows") { - format!("{}.lib", name) - } else { - format!("lib{}.a", name) - } + if target.contains("windows") { format!("{}.lib", name) } else { format!("lib{}.a", name) } } /// Given an executable called `name`, return the filename for the /// executable for a particular target. pub fn exe(name: &str, target: &str) -> String { - if target.contains("windows") { - format!("{}.exe", name) - } else { - name.to_string() - } + if target.contains("windows") { format!("{}.exe", name) } else { name.to_string() } } /// Returns `true` if the file name given looks like a dynamic library. @@ -44,7 +36,7 @@ pub fn is_dylib(name: &str) -> bool { /// Returns the corresponding relative library directory that the compiler's /// dylibs will be found in. pub fn libdir(target: &str) -> &'static str { - if target.contains("windows") {"bin"} else {"lib"} + if target.contains("windows") { "bin" } else { "lib" } } /// Adds a list of lookup paths to `cmd`'s dynamic library lookup path. @@ -106,9 +98,7 @@ impl Drop for TimeIt { fn drop(&mut self) { let time = self.1.elapsed(); if !self.0 { - println!("\tfinished in {}.{:03}", - time.as_secs(), - time.subsec_nanos() / 1_000_000); + println!("\tfinished in {}.{:03}", time.as_secs(), time.subsec_nanos() / 1_000_000); } } } @@ -116,7 +106,9 @@ impl Drop for TimeIt { /// Symlinks two directories, using junctions on Windows and normal symlinks on /// Unix. pub fn symlink_dir(config: &Config, src: &Path, dest: &Path) -> io::Result<()> { - if config.dry_run { return Ok(()); } + if config.dry_run { + return Ok(()); + } let _ = fs::remove_dir(dest); return symlink_dir_inner(src, dest); @@ -136,9 +128,9 @@ pub fn symlink_dir(config: &Config, src: &Path, dest: &Path) -> io::Result<()> { #[cfg(windows)] #[allow(nonstandard_style)] fn symlink_dir_inner(target: &Path, junction: &Path) -> io::Result<()> { - use std::ptr; use std::ffi::OsStr; use std::os::windows::ffi::OsStrExt; + use std::ptr; const MAXIMUM_REPARSE_DATA_BUFFER_SIZE: usize = 16 * 1024; const GENERIC_WRITE: DWORD = 0x40000000; @@ -174,22 +166,25 @@ pub fn symlink_dir(config: &Config, src: &Path, dest: &Path) -> io::Result<()> { } extern "system" { - fn CreateFileW(lpFileName: LPCWSTR, - dwDesiredAccess: DWORD, - dwShareMode: DWORD, - lpSecurityAttributes: LPSECURITY_ATTRIBUTES, - dwCreationDisposition: DWORD, - dwFlagsAndAttributes: DWORD, - hTemplateFile: HANDLE) - -> HANDLE; - fn DeviceIoControl(hDevice: HANDLE, - dwIoControlCode: DWORD, - lpInBuffer: LPVOID, - nInBufferSize: DWORD, - lpOutBuffer: LPVOID, - nOutBufferSize: DWORD, - lpBytesReturned: LPDWORD, - lpOverlapped: LPOVERLAPPED) -> BOOL; + fn CreateFileW( + lpFileName: LPCWSTR, + dwDesiredAccess: DWORD, + dwShareMode: DWORD, + lpSecurityAttributes: LPSECURITY_ATTRIBUTES, + dwCreationDisposition: DWORD, + dwFlagsAndAttributes: DWORD, + hTemplateFile: HANDLE, + ) -> HANDLE; + fn DeviceIoControl( + hDevice: HANDLE, + dwIoControlCode: DWORD, + lpInBuffer: LPVOID, + nInBufferSize: DWORD, + lpOutBuffer: LPVOID, + nOutBufferSize: DWORD, + lpBytesReturned: LPDWORD, + lpOverlapped: LPOVERLAPPED, + ) -> BOOL; fn CloseHandle(hObject: HANDLE) -> BOOL; } @@ -207,17 +202,18 @@ pub fn symlink_dir(config: &Config, src: &Path, dest: &Path) -> io::Result<()> { let path = to_u16s(junction)?; unsafe { - let h = CreateFileW(path.as_ptr(), - GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, - ptr::null_mut(), - OPEN_EXISTING, - FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, - ptr::null_mut()); + let h = CreateFileW( + path.as_ptr(), + GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, + ptr::null_mut(), + OPEN_EXISTING, + FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, + ptr::null_mut(), + ); let mut data = [0u8; MAXIMUM_REPARSE_DATA_BUFFER_SIZE]; - let db = data.as_mut_ptr() - as *mut REPARSE_MOUNTPOINT_DATA_BUFFER; + let db = data.as_mut_ptr() as *mut REPARSE_MOUNTPOINT_DATA_BUFFER; let buf = &mut (*db).ReparseTarget as *mut u16; let mut i = 0; // FIXME: this conversion is very hacky @@ -232,23 +228,21 @@ pub fn symlink_dir(config: &Config, src: &Path, dest: &Path) -> io::Result<()> { (*db).ReparseTag = IO_REPARSE_TAG_MOUNT_POINT; (*db).ReparseTargetMaximumLength = (i * 2) as WORD; (*db).ReparseTargetLength = ((i - 1) * 2) as WORD; - (*db).ReparseDataLength = - (*db).ReparseTargetLength as DWORD + 12; + (*db).ReparseDataLength = (*db).ReparseTargetLength as DWORD + 12; let mut ret = 0; - let res = DeviceIoControl(h as *mut _, - FSCTL_SET_REPARSE_POINT, - data.as_ptr() as *mut _, - (*db).ReparseDataLength + 8, - ptr::null_mut(), 0, - &mut ret, - ptr::null_mut()); - - let out = if res == 0 { - Err(io::Error::last_os_error()) - } else { - Ok(()) - }; + let res = DeviceIoControl( + h as *mut _, + FSCTL_SET_REPARSE_POINT, + data.as_ptr() as *mut _, + (*db).ReparseDataLength + 8, + ptr::null_mut(), + 0, + &mut ret, + ptr::null_mut(), + ); + + let out = if res == 0 { Err(io::Error::last_os_error()) } else { Ok(()) }; CloseHandle(h); out } @@ -299,8 +293,11 @@ pub fn forcing_clang_based_tests() -> bool { "0" | "no" | "off" => false, other => { // Let's make sure typos don't go unnoticed - panic!("Unrecognized option '{}' set in \ - RUSTBUILD_FORCE_CLANG_BASED_TESTS", other) + panic!( + "Unrecognized option '{}' set in \ + RUSTBUILD_FORCE_CLANG_BASED_TESTS", + other + ) } } } else { @@ -311,11 +308,9 @@ pub fn forcing_clang_based_tests() -> bool { pub fn use_host_linker(target: &Interned<String>) -> bool { // FIXME: this information should be gotten by checking the linker flavor // of the rustc target - !( - target.contains("emscripten") || - target.contains("wasm32") || - target.contains("nvptx") || - target.contains("fortanix") || - target.contains("fuchsia") - ) + !(target.contains("emscripten") + || target.contains("wasm32") + || target.contains("nvptx") + || target.contains("fortanix") + || target.contains("fuchsia")) } |
