From c689b9db4becb7e171bd82490f66c363d6aa5ab3 Mon Sep 17 00:00:00 2001 From: Srinivas Reddy Thatiparthy Date: Sun, 16 Oct 2016 14:59:52 +0530 Subject: [PATCH] run rustfmt on bootstrap folder --- src/bootstrap/cc.rs | 24 +-- src/bootstrap/channel.rs | 33 ++-- src/bootstrap/check.rs | 213 +++++++++++++------------ src/bootstrap/compile.rs | 102 ++++++------ src/bootstrap/config.rs | 117 +++++++------- src/bootstrap/dist.rs | 194 ++++++++++++----------- src/bootstrap/doc.rs | 70 +++++---- src/bootstrap/install.rs | 84 +++++++--- src/bootstrap/job.rs | 12 +- src/bootstrap/lib.rs | 327 +++++++++++++++++++++++---------------- src/bootstrap/native.rs | 80 +++++----- src/bootstrap/sanity.rs | 18 +-- src/bootstrap/step.rs | 125 ++++++--------- src/bootstrap/util.rs | 21 ++- 14 files changed, 770 insertions(+), 650 deletions(-) diff --git a/src/bootstrap/cc.rs b/src/bootstrap/cc.rs index e2bde4a658611..3b99cec6b0e8e 100644 --- a/src/bootstrap/cc.rs +++ b/src/bootstrap/cc.rs @@ -44,8 +44,11 @@ pub fn find(build: &mut Build) { // and such as well as for being a linker for Rust code. for target in build.config.target.iter() { let mut cfg = gcc::Config::new(); - cfg.cargo_metadata(false).opt_level(0).debug(false) - .target(target).host(&build.config.build); + cfg.cargo_metadata(false) + .opt_level(0) + .debug(false) + .target(target) + .host(&build.config.build); let config = build.config.target_config.get(target); if let Some(cc) = config.and_then(|c| c.cc.as_ref()) { @@ -66,8 +69,12 @@ pub fn find(build: &mut Build) { // For all host triples we need to find a C++ compiler as well for host in build.config.host.iter() { let mut cfg = gcc::Config::new(); - cfg.cargo_metadata(false).opt_level(0).debug(false).cpp(true) - .target(host).host(&build.config.build); + cfg.cargo_metadata(false) + .opt_level(0) + .debug(false) + .cpp(true) + .target(host) + .host(&build.config.build); let config = build.config.target_config.get(host); if let Some(cxx) = config.and_then(|c| c.cxx.as_ref()) { cfg.compiler(cxx); @@ -80,10 +87,7 @@ pub fn find(build: &mut Build) { } } -fn set_compiler(cfg: &mut gcc::Config, - gnu_compiler: &str, - target: &str, - config: Option<&Target>) { +fn set_compiler(cfg: &mut gcc::Config, gnu_compiler: &str, target: &str, config: Option<&Target>) { 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 @@ -101,7 +105,7 @@ fn set_compiler(cfg: &mut gcc::Config, t if t.contains("openbsd") => { let c = cfg.get_compiler(); if !c.path().ends_with(gnu_compiler) { - return + return; } let output = output(c.to_command().arg("--version")); @@ -110,7 +114,7 @@ fn set_compiler(cfg: &mut gcc::Config, 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 879c383404a4c..574da5a84f756 100644 --- a/src/bootstrap/channel.rs +++ b/src/bootstrap/channel.rs @@ -50,8 +50,7 @@ pub fn collect(build: &mut Build) { build.unstable_features = false; } "beta" => { - build.release = format!("{}-beta{}", release_num, - prerelease_version); + build.release = format!("{}-beta{}", release_num, prerelease_version); build.package_vers = "beta".to_string(); build.unstable_features = false; } @@ -71,22 +70,25 @@ pub fn collect(build: &mut Build) { // If we have a git directory, add in some various SHA information of what // commit this compiler was compiled from. if fs::metadata(build.src.join(".git")).is_ok() { - let ver_date = output(Command::new("git").current_dir(&build.src) - .arg("log").arg("-1") - .arg("--date=short") - .arg("--pretty=format:%cd")); - let ver_hash = output(Command::new("git").current_dir(&build.src) - .arg("rev-parse").arg("HEAD")); + let ver_date = output(Command::new("git") + .current_dir(&build.src) + .arg("log") + .arg("-1") + .arg("--date=short") + .arg("--pretty=format:%cd")); + let ver_hash = output(Command::new("git") + .current_dir(&build.src) + .arg("rev-parse") + .arg("HEAD")); let short_ver_hash = output(Command::new("git") - .current_dir(&build.src) - .arg("rev-parse") - .arg("--short=9") - .arg("HEAD")); + .current_dir(&build.src) + .arg("rev-parse") + .arg("--short=9") + .arg("HEAD")); let ver_date = ver_date.trim().to_string(); let ver_hash = ver_hash.trim().to_string(); let short_ver_hash = short_ver_hash.trim().to_string(); - build.version.push_str(&format!(" ({} {})", short_ver_hash, - ver_date)); + build.version.push_str(&format!(" ({} {})", short_ver_hash, ver_date)); build.ver_date = Some(ver_date.to_string()); build.ver_hash = Some(ver_hash); build.short_ver_hash = Some(short_ver_hash); @@ -95,8 +97,7 @@ pub fn collect(build: &mut Build) { // Calculate this compiler's bootstrap key, which is currently defined as // the first 8 characters of the md5 of the release string. let key = md5::compute(build.release.as_bytes()); - build.bootstrap_key = format!("{:02x}{:02x}{:02x}{:02x}", - key[0], key[1], key[2], key[3]); + build.bootstrap_key = format!("{:02x}{:02x}{:02x}{:02x}", key[0], key[1], key[2], key[3]); // Slurp up the stage0 bootstrap key as we're bootstrapping from an // otherwise stable compiler. diff --git a/src/bootstrap/check.rs b/src/bootstrap/check.rs index af76a49fed045..52e81701a0459 100644 --- a/src/bootstrap/check.rs +++ b/src/bootstrap/check.rs @@ -59,7 +59,7 @@ pub fn linkcheck(build: &Build, stage: u32, host: &str) { println!("Linkcheck stage{} ({})", stage, host); let compiler = Compiler::new(stage, host); build.run(build.tool_cmd(&compiler, "linkchecker") - .arg(build.out.join(host).join("doc"))); + .arg(build.out.join(host).join("doc"))); } /// Runs the `cargotest` tool as compiled in `stage` by the `host` compiler. @@ -74,7 +74,7 @@ pub fn cargotest(build: &Build, stage: u32, host: &str) { // fail if rustc is not spelled `rustc`. let path = build.sysroot(compiler).join("bin"); let old_path = ::std::env::var("PATH").expect(""); - let sep = if cfg!(windows) { ";" } else {":" }; + let sep = if cfg!(windows) { ";" } else { ":" }; let ref newpath = format!("{}{}{}", path.display(), sep, old_path); // Note that this is a short, cryptic, and not scoped directory name. This @@ -84,9 +84,9 @@ pub fn cargotest(build: &Build, stage: u32, host: &str) { t!(fs::create_dir_all(&out_dir)); build.run(build.tool_cmd(compiler, "cargotest") - .env("PATH", newpath) - .arg(&build.cargo) - .arg(&out_dir)); + .env("PATH", newpath) + .arg(&build.cargo) + .arg(&out_dir)); } /// Runs the `tidy` tool as compiled in `stage` by the `host` compiler. @@ -98,7 +98,7 @@ pub fn tidy(build: &Build, stage: u32, host: &str) { println!("tidy check stage{} ({})", stage, host); let compiler = Compiler::new(stage, host); build.run(build.tool_cmd(&compiler, "tidy") - .arg(build.src.join("src"))); + .arg(build.src.join("src"))); } fn testdir(build: &Build, host: &str) -> PathBuf { @@ -110,12 +110,11 @@ fn testdir(build: &Build, host: &str) -> PathBuf { /// Compiles all tests with `compiler` for `target` with the specified /// compiletest `mode` and `suite` arguments. For example `mode` can be /// "run-pass" or `suite` can be something like `debuginfo`. -pub fn compiletest(build: &Build, - compiler: &Compiler, - target: &str, - mode: &str, - suite: &str) { - println!("Check compiletest {} ({} -> {})", suite, compiler.host, target); +pub fn compiletest(build: &Build, compiler: &Compiler, target: &str, mode: &str, suite: &str) { + println!("Check compiletest {} ({} -> {})", + suite, + compiler.host, + target); let mut cmd = build.tool_cmd(compiler, "compiletest"); // compiletest currently has... a lot of arguments, so let's just pass all @@ -151,8 +150,7 @@ pub fn compiletest(build: &Build, let mut targetflags = build.rustc_flags(&target); targetflags.extend(flags); - targetflags.push(format!("-Lnative={}", - build.test_helpers_out(target).display())); + targetflags.push(format!("-Lnative={}", build.test_helpers_out(target).display())); cmd.arg("--target-rustcflags").arg(targetflags.join(" ")); // FIXME: CFG_PYTHON should probably be detected more robustly elsewhere @@ -192,17 +190,27 @@ pub fn compiletest(build: &Build, if suite == "run-make" { let llvm_components = output(Command::new(&llvm_config).arg("--components")); let llvm_cxxflags = output(Command::new(&llvm_config).arg("--cxxflags")); - cmd.arg("--cc").arg(build.cc(target)) - .arg("--cxx").arg(build.cxx(target)) - .arg("--cflags").arg(build.cflags(target).join(" ")) - .arg("--llvm-components").arg(llvm_components.trim()) - .arg("--llvm-cxxflags").arg(llvm_cxxflags.trim()); + cmd.arg("--cc") + .arg(build.cc(target)) + .arg("--cxx") + .arg(build.cxx(target)) + .arg("--cflags") + .arg(build.cflags(target).join(" ")) + .arg("--llvm-components") + .arg(llvm_components.trim()) + .arg("--llvm-cxxflags") + .arg(llvm_cxxflags.trim()); } else { - cmd.arg("--cc").arg("") - .arg("--cxx").arg("") - .arg("--cflags").arg("") - .arg("--llvm-components").arg("") - .arg("--llvm-cxxflags").arg(""); + cmd.arg("--cc") + .arg("") + .arg("--cxx") + .arg("") + .arg("--cflags") + .arg("") + .arg("--llvm-components") + .arg("") + .arg("--llvm-cxxflags") + .arg(""); } // Running a C compiler on MSVC requires a few env vars to be set, to be @@ -221,7 +229,7 @@ pub fn compiletest(build: &Build, if target.contains("android") { // Assume that cc for this target comes from the android sysroot cmd.arg("--android-cross-path") - .arg(build.cc(target).parent().unwrap().parent().unwrap()); + .arg(build.cc(target).parent().unwrap().parent().unwrap()); } else { cmd.arg("--android-cross-path").arg(""); } @@ -242,11 +250,11 @@ pub fn docs(build: &Build, compiler: &Compiler) { while let Some(p) = stack.pop() { if p.is_dir() { stack.extend(t!(p.read_dir()).map(|p| t!(p).path())); - continue + continue; } if p.extension().and_then(|s| s.to_str()) != Some("md") { - continue + continue; } println!("doc tests for: {}", p.display()); @@ -265,9 +273,9 @@ pub fn error_index(build: &Build, compiler: &Compiler) { let output = testdir(build, compiler.host).join("error-index.md"); build.run(build.tool_cmd(compiler, "error_index_generator") - .arg("markdown") - .arg(&output) - .env("CFG_BUILD", &build.config.build)); + .arg("markdown") + .arg(&output) + .env("CFG_BUILD", &build.config.build)); markdown_test(build, compiler, &output); } @@ -289,24 +297,18 @@ fn markdown_test(build: &Build, compiler: &Compiler, markdown: &Path) { /// /// Currently this runs all tests for a DAG by passing a bunch of `-p foo` /// arguments, and those arguments are discovered from `cargo metadata`. -pub fn krate(build: &Build, - compiler: &Compiler, - target: &str, - mode: Mode) { +pub fn krate(build: &Build, compiler: &Compiler, target: &str, mode: Mode) { let (name, path, features, root) = match mode { - Mode::Libstd => { - ("libstd", "src/rustc/std_shim", build.std_features(), "std_shim") - } - Mode::Libtest => { - ("libtest", "src/rustc/test_shim", String::new(), "test_shim") - } - Mode::Librustc => { - ("librustc", "src/rustc", build.rustc_features(), "rustc-main") - } + Mode::Libstd => ("libstd", "src/rustc/std_shim", build.std_features(), "std_shim"), + Mode::Libtest => ("libtest", "src/rustc/test_shim", String::new(), "test_shim"), + Mode::Librustc => ("librustc", "src/rustc", build.rustc_features(), "rustc-main"), _ => panic!("can only test libraries"), }; - println!("Testing {} stage{} ({} -> {})", name, compiler.stage, - compiler.host, target); + println!("Testing {} stage{} ({} -> {})", + name, + compiler.stage, + compiler.host, + target); // Run `cargo metadata` to figure out what crates we're testing. // @@ -316,15 +318,19 @@ pub fn krate(build: &Build, // the dependency graph and what `-p` arguments there are. let mut cargo = Command::new(&build.cargo); cargo.arg("metadata") - .arg("--manifest-path").arg(build.src.join(path).join("Cargo.toml")); + .arg("--manifest-path") + .arg(build.src.join(path).join("Cargo.toml")); let output = output(&mut cargo); let output: Output = json::decode(&output).unwrap(); - let id2pkg = output.packages.iter() - .map(|pkg| (&pkg.id, pkg)) - .collect::>(); - let id2deps = output.resolve.nodes.iter() - .map(|node| (&node.id, &node.dependencies)) - .collect::>(); + let id2pkg = output.packages + .iter() + .map(|pkg| (&pkg.id, pkg)) + .collect::>(); + let id2deps = output.resolve + .nodes + .iter() + .map(|node| (&node.id, &node.dependencies)) + .collect::>(); // Build up the base `cargo test` command. // @@ -333,8 +339,9 @@ pub fn krate(build: &Build, // arguments need to get passed. let mut cargo = build.cargo(compiler, mode, target, "test"); cargo.arg("--manifest-path") - .arg(build.src.join(path).join("Cargo.toml")) - .arg("--features").arg(features); + .arg(build.src.join(path).join("Cargo.toml")) + .arg("--features") + .arg(features); let mut visited = HashSet::new(); let root_pkg = output.packages.iter().find(|p| p.name == root).unwrap(); @@ -343,7 +350,7 @@ pub fn krate(build: &Build, // Skip any packages with sources listed, as these come from crates.io // and we shouldn't be testing them. if id2pkg[id].source.is_some() { - continue + continue; } // Right now jemalloc is our only target-specific crate in the sense // that it's not present on all platforms. Custom skip it here for now, @@ -379,10 +386,7 @@ pub fn krate(build: &Build, } } -fn krate_android(build: &Build, - compiler: &Compiler, - target: &str, - mode: Mode) { +fn krate_android(build: &Build, compiler: &Compiler, target: &str, mode: Mode) { let mut tests = Vec::new(); let out_dir = build.cargo_out(compiler, mode, target); find_tests(&out_dir, target, &mut tests); @@ -398,10 +402,8 @@ fn krate_android(build: &Build, target, compiler.host, test_file_name); - let program = format!("(cd {dir}; \ - LD_LIBRARY_PATH=./{target} ./{test} \ - --logfile {log} \ - {args})", + let program = format!("(cd {dir}; LD_LIBRARY_PATH=./{target} ./{test} --logfile {log} \ + {args})", dir = ADB_TEST_DIR, target = target, test = test_file_name, @@ -411,9 +413,9 @@ fn krate_android(build: &Build, let output = output(Command::new("adb").arg("shell").arg(&program)); println!("{}", output); build.run(Command::new("adb") - .arg("pull") - .arg(&log) - .arg(build.out.join("tmp"))); + .arg("pull") + .arg(&log) + .arg(build.out.join("tmp"))); build.run(Command::new("adb").arg("shell").arg("rm").arg(&log)); if !output.contains("result: ok") { panic!("some tests failed"); @@ -421,63 +423,56 @@ fn krate_android(build: &Build, } } -fn krate_emscripten(build: &Build, - compiler: &Compiler, - target: &str, - mode: Mode) { - let mut tests = Vec::new(); - let out_dir = build.cargo_out(compiler, mode, target); - find_tests(&out_dir, target, &mut tests); - find_tests(&out_dir.join("deps"), target, &mut tests); - - for test in tests { - let test_file_name = test.to_string_lossy().into_owned(); - println!("running {}", test_file_name); - let nodejs = build.config.nodejs.as_ref().expect("nodejs not configured"); - let status = Command::new(nodejs) - .arg(&test_file_name) - .stderr(::std::process::Stdio::inherit()) - .status(); - match status { - Ok(status) => { - if !status.success() { - panic!("some tests failed"); - } - } - Err(e) => panic!(format!("failed to execute command: {}", e)), - }; - } - } - - -fn find_tests(dir: &Path, - target: &str, - dst: &mut Vec) { +fn krate_emscripten(build: &Build, compiler: &Compiler, target: &str, mode: Mode) { + let mut tests = Vec::new(); + let out_dir = build.cargo_out(compiler, mode, target); + find_tests(&out_dir, target, &mut tests); + find_tests(&out_dir.join("deps"), target, &mut tests); + + for test in tests { + let test_file_name = test.to_string_lossy().into_owned(); + println!("running {}", test_file_name); + let nodejs = build.config.nodejs.as_ref().expect("nodejs not configured"); + let status = Command::new(nodejs) + .arg(&test_file_name) + .stderr(::std::process::Stdio::inherit()) + .status(); + match status { + Ok(status) => { + if !status.success() { + panic!("some tests failed"); + } + } + Err(e) => panic!(format!("failed to execute command: {}", e)), + }; + } +} + + +fn find_tests(dir: &Path, target: &str, dst: &mut Vec) { for e in t!(dir.read_dir()).map(|e| t!(e)) { let file_type = t!(e.file_type()); if !file_type.is_file() { - continue + continue; } let filename = e.file_name().into_string().unwrap(); if (target.contains("windows") && filename.ends_with(".exe")) || (!target.contains("windows") && !filename.contains(".")) || - (target.contains("emscripten") && filename.contains(".js")){ + (target.contains("emscripten") && filename.contains(".js")) { dst.push(e.path()); } } } -pub fn android_copy_libs(build: &Build, - compiler: &Compiler, - target: &str) { +pub fn android_copy_libs(build: &Build, compiler: &Compiler, target: &str) { println!("Android copy libs to emulator ({})", target); build.run(Command::new("adb").arg("remount")); build.run(Command::new("adb").args(&["shell", "rm", "-r", ADB_TEST_DIR])); build.run(Command::new("adb").args(&["shell", "mkdir", ADB_TEST_DIR])); build.run(Command::new("adb") - .arg("push") - .arg(build.src.join("src/etc/adb_run_wrapper.sh")) - .arg(ADB_TEST_DIR)); + .arg("push") + .arg(build.src.join("src/etc/adb_run_wrapper.sh")) + .arg(ADB_TEST_DIR)); let target_dir = format!("{}/{}", ADB_TEST_DIR, target); build.run(Command::new("adb").args(&["shell", "mkdir", &target_dir[..]])); @@ -487,9 +482,9 @@ pub fn android_copy_libs(build: &Build, let name = f.file_name().into_string().unwrap(); if util::is_dylib(&name) { build.run(Command::new("adb") - .arg("push") - .arg(f.path()) - .arg(&target_dir)); + .arg("push") + .arg(f.path()) + .arg(&target_dir)); } } } diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index ff8e4757bd1f1..6c4c3976c0527 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -34,8 +34,10 @@ use {Build, Compiler, Mode}; /// using the `compiler` targeting the `target` architecture. The artifacts /// created will also be linked into the sysroot directory. pub fn std<'a>(build: &'a Build, target: &str, compiler: &Compiler<'a>) { - println!("Building stage{} std artifacts ({} -> {})", compiler.stage, - compiler.host, target); + println!("Building stage{} std artifacts ({} -> {})", + compiler.stage, + compiler.host, + target); let libdir = build.sysroot_libdir(compiler, target); let _ = fs::remove_dir_all(&libdir); @@ -48,9 +50,10 @@ pub fn std<'a>(build: &'a Build, target: &str, compiler: &Compiler<'a>) { let out_dir = build.cargo_out(compiler, Mode::Libstd, target); build.clear_if_dirty(&out_dir, &build.compiler_path(compiler)); let mut cargo = build.cargo(compiler, Mode::Libstd, target, "build"); - cargo.arg("--features").arg(build.std_features()) - .arg("--manifest-path") - .arg(build.src.join("src/rustc/std_shim/Cargo.toml")); + cargo.arg("--features") + .arg(build.std_features()) + .arg("--manifest-path") + .arg(build.src.join("src/rustc/std_shim/Cargo.toml")); if let Some(target) = build.config.target_config.get(target) { if let Some(ref jemalloc) = target.jemalloc { @@ -72,10 +75,7 @@ pub fn std<'a>(build: &'a Build, target: &str, compiler: &Compiler<'a>) { /// /// Links those artifacts generated in the given `stage` for `target` produced /// by `compiler` into `host`'s sysroot. -pub fn std_link(build: &Build, - target: &str, - compiler: &Compiler, - host: &str) { +pub fn std_link(build: &Build, target: &str, compiler: &Compiler, host: &str) { let target_compiler = Compiler::new(compiler.stage, host); let libdir = build.sysroot_libdir(&target_compiler, target); let out_dir = build.cargo_out(compiler, Mode::Libstd, target); @@ -99,7 +99,8 @@ pub fn std_link(build: &Build, /// Only required for musl targets that statically link to libc fn copy_musl_third_party_objects(build: &Build, target: &str, into: &Path) { for &obj in &["crt1.o", "crti.o", "crtn.o"] { - copy(&build.musl_root(target).unwrap().join("lib").join(obj), &into.join(obj)); + copy(&build.musl_root(target).unwrap().join("lib").join(obj), + &into.join(obj)); } } @@ -111,7 +112,7 @@ fn copy_musl_third_party_objects(build: &Build, target: &str, into: &Path) { /// no other compilers are guaranteed to be available). fn build_startup_objects(build: &Build, target: &str, into: &Path) { if !target.contains("pc-windows-gnu") { - return + return; } let compiler = Compiler::new(0, &build.config.build); let compiler_path = build.compiler_path(&compiler); @@ -120,10 +121,12 @@ fn build_startup_objects(build: &Build, target: &str, into: &Path) { let file = t!(file); let mut cmd = Command::new(&compiler_path); build.add_bootstrap_key(&mut cmd); - build.run(cmd.arg("--target").arg(target) - .arg("--emit=obj") - .arg("--out-dir").arg(into) - .arg(file.path())); + build.run(cmd.arg("--target") + .arg(target) + .arg("--emit=obj") + .arg("--out-dir") + .arg(into) + .arg(file.path())); } for obj in ["crt2.o", "dllcrt2.o"].iter() { @@ -137,13 +140,15 @@ fn build_startup_objects(build: &Build, target: &str, into: &Path) { /// the build using the `compiler` targeting the `target` architecture. The /// artifacts created will also be linked into the sysroot directory. pub fn test<'a>(build: &'a Build, target: &str, compiler: &Compiler<'a>) { - println!("Building stage{} test artifacts ({} -> {})", compiler.stage, - compiler.host, target); + println!("Building stage{} test artifacts ({} -> {})", + compiler.stage, + compiler.host, + target); let out_dir = build.cargo_out(compiler, Mode::Libtest, target); build.clear_if_dirty(&out_dir, &libstd_stamp(build, compiler, target)); let mut cargo = build.cargo(compiler, Mode::Libtest, target, "build"); cargo.arg("--manifest-path") - .arg(build.src.join("src/rustc/test_shim/Cargo.toml")); + .arg(build.src.join("src/rustc/test_shim/Cargo.toml")); build.run(&mut cargo); update_mtime(&libtest_stamp(build, compiler, target)); test_link(build, target, compiler, compiler.host); @@ -153,10 +158,7 @@ pub fn test<'a>(build: &'a Build, target: &str, compiler: &Compiler<'a>) { /// /// Links those artifacts generated in the given `stage` for `target` produced /// by `compiler` into `host`'s sysroot. -pub fn test_link(build: &Build, - target: &str, - compiler: &Compiler, - host: &str) { +pub fn test_link(build: &Build, target: &str, compiler: &Compiler, host: &str) { let target_compiler = Compiler::new(compiler.stage, host); let libdir = build.sysroot_libdir(&target_compiler, target); let out_dir = build.cargo_out(compiler, Mode::Libtest, target); @@ -170,23 +172,27 @@ pub fn test_link(build: &Build, /// created will also be linked into the sysroot directory. pub fn rustc<'a>(build: &'a Build, target: &str, compiler: &Compiler<'a>) { println!("Building stage{} compiler artifacts ({} -> {})", - compiler.stage, compiler.host, target); + compiler.stage, + compiler.host, + target); let out_dir = build.cargo_out(compiler, Mode::Librustc, target); build.clear_if_dirty(&out_dir, &libtest_stamp(build, compiler, target)); let mut cargo = build.cargo(compiler, Mode::Librustc, target, "build"); - cargo.arg("--features").arg(build.rustc_features()) - .arg("--manifest-path") - .arg(build.src.join("src/rustc/Cargo.toml")); + cargo.arg("--features") + .arg(build.rustc_features()) + .arg("--manifest-path") + .arg(build.src.join("src/rustc/Cargo.toml")); // Set some configuration variables picked up by build scripts and // the compiler alike cargo.env("CFG_RELEASE", &build.release) - .env("CFG_RELEASE_CHANNEL", &build.config.channel) - .env("CFG_VERSION", &build.version) - .env("CFG_PREFIX", build.config.prefix.clone().unwrap_or(String::new())) - .env("CFG_LIBDIR_RELATIVE", "lib"); + .env("CFG_RELEASE_CHANNEL", &build.config.channel) + .env("CFG_VERSION", &build.version) + .env("CFG_PREFIX", + build.config.prefix.clone().unwrap_or(String::new())) + .env("CFG_LIBDIR_RELATIVE", "lib"); if let Some(ref ver_date) = build.ver_date { cargo.env("CFG_VER_DATE", ver_date); @@ -225,10 +231,7 @@ pub fn rustc<'a>(build: &'a Build, target: &str, compiler: &Compiler<'a>) { /// /// Links those artifacts generated in the given `stage` for `target` produced /// by `compiler` into `host`'s sysroot. -pub fn rustc_link(build: &Build, - target: &str, - compiler: &Compiler, - host: &str) { +pub fn rustc_link(build: &Build, target: &str, compiler: &Compiler, host: &str) { let target_compiler = Compiler::new(compiler.stage, host); let libdir = build.sysroot_libdir(&target_compiler, target); let out_dir = build.cargo_out(compiler, Mode::Librustc, target); @@ -248,8 +251,7 @@ fn libtest_stamp(build: &Build, compiler: &Compiler, target: &str) -> PathBuf { } fn compiler_file(compiler: &Path, file: &str) -> PathBuf { - let out = output(Command::new(compiler) - .arg(format!("-print-file-name={}", file))); + let out = output(Command::new(compiler).arg(format!("-print-file-name={}", file))); PathBuf::from(out.trim()) } @@ -259,7 +261,8 @@ fn compiler_file(compiler: &Path, file: &str) -> PathBuf { /// must have been previously produced by the `stage - 1` build.config.build /// compiler. pub fn assemble_rustc(build: &Build, stage: u32, host: &str) { - assert!(stage > 0, "the stage0 compiler isn't assembled, it's downloaded"); + assert!(stage > 0, + "the stage0 compiler isn't assembled, it's downloaded"); // The compiler that we're assembling let target_compiler = Compiler::new(stage, host); @@ -318,25 +321,24 @@ fn add_to_sysroot(out_dir: &Path, sysroot_dst: &Path) { // We're only interested in linking rlibs + dylibs, other things like // unit tests don't get linked in - if !filename.ends_with(".rlib") && - !filename.ends_with(".lib") && - !is_dylib(&filename) { - continue + if !filename.ends_with(".rlib") && !filename.ends_with(".lib") && !is_dylib(&filename) { + continue; } let file = file.path(); let dash = filename.find("-").unwrap(); - let key = (filename[..dash].to_string(), - file.extension().unwrap().to_owned()); - map.entry(key).or_insert(Vec::new()) - .push(file.clone()); + let key = (filename[..dash].to_string(), file.extension().unwrap().to_owned()); + map.entry(key) + .or_insert(Vec::new()) + .push(file.clone()); } // For all hash values found, pick the most recent one to move into the // sysroot, that should be the one we just built. for (_, paths) in map { - let (_, path) = paths.iter().map(|path| { - (mtime(&path).seconds(), path) - }).max().unwrap(); + let (_, path) = paths.iter() + .map(|path| (mtime(&path).seconds(), path)) + .max() + .unwrap(); copy(&path, &sysroot_dst.join(path.file_name().unwrap())); } } @@ -361,7 +363,7 @@ pub fn tool(build: &Build, stage: u32, host: &str, tool: &str) { let mut cargo = build.cargo(&compiler, Mode::Tool, host, "build"); cargo.arg("--manifest-path") - .arg(build.src.join(format!("src/tools/{}/Cargo.toml", tool))); + .arg(build.src.join(format!("src/tools/{}/Cargo.toml", tool))); build.run(&mut cargo); } @@ -385,7 +387,7 @@ fn update_mtime(path: &Path) { } if !max.is_none() && max <= Some(mtime(path)) { - return + return; } t!(File::create(path)); } diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 8c0ad1ccf825f..32f009f909050 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -184,32 +184,32 @@ impl Config { config.codegen_tests = true; let toml = file.map(|file| { - let mut f = t!(File::open(&file)); - let mut toml = String::new(); - t!(f.read_to_string(&mut toml)); - let mut p = Parser::new(&toml); - let table = match p.parse() { - Some(table) => table, - None => { - println!("failed to parse TOML configuration:"); - for err in p.errors.iter() { - let (loline, locol) = p.to_linecol(err.lo); - let (hiline, hicol) = p.to_linecol(err.hi); - println!("{}:{}-{}:{}: {}", loline, locol, hiline, - hicol, err.desc); + let mut f = t!(File::open(&file)); + let mut toml = String::new(); + t!(f.read_to_string(&mut toml)); + let mut p = Parser::new(&toml); + let table = match p.parse() { + Some(table) => table, + None => { + println!("failed to parse TOML configuration:"); + for err in p.errors.iter() { + let (loline, locol) = p.to_linecol(err.lo); + let (hiline, hicol) = p.to_linecol(err.hi); + println!("{}:{}-{}:{}: {}", loline, locol, hiline, hicol, err.desc); + } + process::exit(2); + } + }; + let mut d = Decoder::new(Value::Table(table)); + match Decodable::decode(&mut d) { + Ok(cfg) => cfg, + Err(e) => { + println!("failed to decode TOML: {}", e); + process::exit(2); } - process::exit(2); - } - }; - let mut d = Decoder::new(Value::Table(table)); - match Decodable::decode(&mut d) { - Ok(cfg) => cfg, - Err(e) => { - println!("failed to decode TOML: {}", e); - process::exit(2); } - } - }).unwrap_or_else(|| TomlConfig::default()); + }) + .unwrap_or_else(|| TomlConfig::default()); let build = toml.build.clone().unwrap_or(Build::default()); set(&mut config.build, build.build.clone()); @@ -283,7 +283,7 @@ impl Config { } } - return config + return config; } /// "Temporary" routine to parse `config.mk` into this configuration. @@ -300,7 +300,7 @@ impl Config { let value = match parts.next() { Some(n) if n.starts_with('\"') => &n[1..n.len() - 1], Some(n) => n, - None => continue + None => continue, }; macro_rules! check { @@ -346,44 +346,51 @@ impl Config { match key { "CFG_BUILD" => self.build = value.to_string(), "CFG_HOST" => { - self.host = value.split(" ").map(|s| s.to_string()) - .collect(); + self.host = value.split(" ") + .map(|s| s.to_string()) + .collect(); } "CFG_TARGET" => { - self.target = value.split(" ").map(|s| s.to_string()) - .collect(); + self.target = value.split(" ") + .map(|s| s.to_string()) + .collect(); } "CFG_MUSL_ROOT" if value.len() > 0 => { self.musl_root = Some(PathBuf::from(value)); } "CFG_MUSL_ROOT_X86_64" if value.len() > 0 => { let target = "x86_64-unknown-linux-musl".to_string(); - let target = self.target_config.entry(target) - .or_insert(Target::default()); + let target = self.target_config + .entry(target) + .or_insert(Target::default()); target.musl_root = Some(PathBuf::from(value)); } "CFG_MUSL_ROOT_I686" if value.len() > 0 => { let target = "i686-unknown-linux-musl".to_string(); - let target = self.target_config.entry(target) - .or_insert(Target::default()); + let target = self.target_config + .entry(target) + .or_insert(Target::default()); target.musl_root = Some(PathBuf::from(value)); } "CFG_MUSL_ROOT_ARM" if value.len() > 0 => { let target = "arm-unknown-linux-musleabi".to_string(); - let target = self.target_config.entry(target) - .or_insert(Target::default()); + let target = self.target_config + .entry(target) + .or_insert(Target::default()); target.musl_root = Some(PathBuf::from(value)); } "CFG_MUSL_ROOT_ARMHF" if value.len() > 0 => { let target = "arm-unknown-linux-musleabihf".to_string(); - let target = self.target_config.entry(target) - .or_insert(Target::default()); + let target = self.target_config + .entry(target) + .or_insert(Target::default()); target.musl_root = Some(PathBuf::from(value)); } "CFG_MUSL_ROOT_ARMV7" if value.len() > 0 => { let target = "armv7-unknown-linux-musleabihf".to_string(); - let target = self.target_config.entry(target) - .or_insert(Target::default()); + let target = self.target_config + .entry(target) + .or_insert(Target::default()); target.musl_root = Some(PathBuf::from(value)); } "CFG_DEFAULT_AR" if value.len() > 0 => { @@ -408,38 +415,44 @@ impl Config { self.mandir = Some(value.to_string()); } "CFG_LLVM_ROOT" if value.len() > 0 => { - let target = self.target_config.entry(self.build.clone()) - .or_insert(Target::default()); + let target = self.target_config + .entry(self.build.clone()) + .or_insert(Target::default()); let root = PathBuf::from(value); target.llvm_config = Some(root.join("bin/llvm-config")); } "CFG_JEMALLOC_ROOT" if value.len() > 0 => { - let target = self.target_config.entry(self.build.clone()) - .or_insert(Target::default()); + let target = self.target_config + .entry(self.build.clone()) + .or_insert(Target::default()); target.jemalloc = Some(PathBuf::from(value)); } "CFG_ARM_LINUX_ANDROIDEABI_NDK" if value.len() > 0 => { let target = "arm-linux-androideabi".to_string(); - let target = self.target_config.entry(target) - .or_insert(Target::default()); + let target = self.target_config + .entry(target) + .or_insert(Target::default()); target.ndk = Some(PathBuf::from(value)); } "CFG_ARMV7_LINUX_ANDROIDEABI_NDK" if value.len() > 0 => { let target = "armv7-linux-androideabi".to_string(); - let target = self.target_config.entry(target) - .or_insert(Target::default()); + let target = self.target_config + .entry(target) + .or_insert(Target::default()); target.ndk = Some(PathBuf::from(value)); } "CFG_I686_LINUX_ANDROID_NDK" if value.len() > 0 => { let target = "i686-linux-android".to_string(); - let target = self.target_config.entry(target) - .or_insert(Target::default()); + let target = self.target_config + .entry(target) + .or_insert(Target::default()); target.ndk = Some(PathBuf::from(value)); } "CFG_AARCH64_LINUX_ANDROID_NDK" if value.len() > 0 => { let target = "aarch64-linux-android".to_string(); - let target = self.target_config.entry(target) - .or_insert(Target::default()); + let target = self.target_config + .entry(target) + .or_insert(Target::default()); target.ndk = Some(PathBuf::from(value)); } "CFG_LOCAL_RUST_ROOT" if value.len() > 0 => { diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index 8676f5cc4a1ed..17fbeb0033939 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -59,16 +59,16 @@ pub fn docs(build: &Build, stage: u32, host: &str) { let mut cmd = Command::new("sh"); cmd.arg(sanitize_sh(&build.src.join("src/rust-installer/gen-installer.sh"))) - .arg("--product-name=Rust-Documentation") - .arg("--rel-manifest-dir=rustlib") - .arg("--success-message=Rust-documentation-is-installed.") - .arg(format!("--image-dir={}", sanitize_sh(&image))) - .arg(format!("--work-dir={}", sanitize_sh(&tmpdir(build)))) - .arg(format!("--output-dir={}", sanitize_sh(&distdir(build)))) - .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(format!("--image-dir={}", sanitize_sh(&image))) + .arg(format!("--work-dir={}", sanitize_sh(&tmpdir(build)))) + .arg(format!("--output-dir={}", sanitize_sh(&distdir(build)))) + .arg(format!("--package-name={}-{}", name, host)) + .arg("--component-name=rust-docs") + .arg("--legacy-manifest-dirs=rustlib,cargo") + .arg("--bulk-dirs=share/doc/rust/html"); build.run(&mut cmd); t!(fs::remove_dir_all(&image)); @@ -101,22 +101,22 @@ pub fn mingw(build: &Build, host: &str) { // FIXME: this script should be rewritten into Rust let mut cmd = Command::new("python"); cmd.arg(build.src.join("src/etc/make-win-dist.py")) - .arg(tmpdir(build)) - .arg(&image) - .arg(host); + .arg(tmpdir(build)) + .arg(&image) + .arg(host); build.run(&mut cmd); let mut cmd = Command::new("sh"); cmd.arg(sanitize_sh(&build.src.join("src/rust-installer/gen-installer.sh"))) - .arg("--product-name=Rust-MinGW") - .arg("--rel-manifest-dir=rustlib") - .arg("--success-message=Rust-MinGW-is-installed.") - .arg(format!("--image-dir={}", sanitize_sh(&image))) - .arg(format!("--work-dir={}", sanitize_sh(&tmpdir(build)))) - .arg(format!("--output-dir={}", sanitize_sh(&distdir(build)))) - .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(format!("--image-dir={}", sanitize_sh(&image))) + .arg(format!("--work-dir={}", sanitize_sh(&tmpdir(build)))) + .arg(format!("--output-dir={}", sanitize_sh(&distdir(build)))) + .arg(format!("--package-name={}-{}", name, host)) + .arg("--component-name=rust-mingw") + .arg("--legacy-manifest-dirs=rustlib,cargo"); build.run(&mut cmd); t!(fs::remove_dir_all(&image)); } @@ -161,9 +161,9 @@ pub fn rustc(build: &Build, stage: u32, host: &str) { if host.contains("pc-windows-gnu") { let mut cmd = Command::new("python"); cmd.arg(build.src.join("src/etc/make-win-dist.py")) - .arg(&image) - .arg(tmpdir(build)) - .arg(host); + .arg(&image) + .arg(tmpdir(build)) + .arg(host); build.run(&mut cmd); let dst = image.join("share/doc"); @@ -174,16 +174,16 @@ pub fn rustc(build: &Build, stage: u32, host: &str) { // Finally, wrap everything up in a nice tarball! let mut cmd = Command::new("sh"); cmd.arg(sanitize_sh(&build.src.join("src/rust-installer/gen-installer.sh"))) - .arg("--product-name=Rust") - .arg("--rel-manifest-dir=rustlib") - .arg("--success-message=Rust-is-ready-to-roll.") - .arg(format!("--image-dir={}", sanitize_sh(&image))) - .arg(format!("--work-dir={}", sanitize_sh(&tmpdir(build)))) - .arg(format!("--output-dir={}", sanitize_sh(&distdir(build)))) - .arg(format!("--non-installed-overlay={}", sanitize_sh(&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(format!("--image-dir={}", sanitize_sh(&image))) + .arg(format!("--work-dir={}", sanitize_sh(&tmpdir(build)))) + .arg(format!("--output-dir={}", sanitize_sh(&distdir(build)))) + .arg(format!("--non-installed-overlay={}", sanitize_sh(&overlay))) + .arg(format!("--package-name={}-{}", name, host)) + .arg("--component-name=rustc") + .arg("--legacy-manifest-dirs=rustlib,cargo"); build.run(&mut cmd); t!(fs::remove_dir_all(&image)); t!(fs::remove_dir_all(&overlay)); @@ -227,9 +227,7 @@ pub fn rustc(build: &Build, stage: u32, host: &str) { } /// Copies debugger scripts for `host` into the `sysroot` specified. -pub fn debugger_scripts(build: &Build, - sysroot: &Path, - host: &str) { +pub fn debugger_scripts(build: &Build, sysroot: &Path, host: &str) { let cp_debugger_script = |file: &str| { let dst = sysroot.join("lib/rustlib/etc"); t!(fs::create_dir_all(&dst)); @@ -241,14 +239,16 @@ pub fn debugger_scripts(build: &Build, cp_debugger_script("debugger_pretty_printers_common.py"); // gdb debugger scripts - install(&build.src.join("src/etc/rust-gdb"), &sysroot.join("bin"), + install(&build.src.join("src/etc/rust-gdb"), + &sysroot.join("bin"), 0o755); cp_debugger_script("gdb_load_rust_pretty_printers.py"); cp_debugger_script("gdb_rust_pretty_printing.py"); // lldb debugger scripts - install(&build.src.join("src/etc/rust-lldb"), &sysroot.join("bin"), + install(&build.src.join("src/etc/rust-lldb"), + &sysroot.join("bin"), 0o755); cp_debugger_script("lldb_rust_formatters.py"); @@ -258,7 +258,9 @@ pub fn debugger_scripts(build: &Build, /// Creates the `rust-std` installer component as compiled by `compiler` for the /// target `target`. pub fn std(build: &Build, compiler: &Compiler, target: &str) { - println!("Dist std stage{} ({} -> {})", compiler.stage, compiler.host, + println!("Dist std stage{} ({} -> {})", + compiler.stage, + compiler.host, target); let name = format!("rust-std-{}", package_vers(build)); let image = tmpdir(build).join(format!("{}-{}-image", name, target)); @@ -271,15 +273,15 @@ pub fn std(build: &Build, compiler: &Compiler, target: &str) { let mut cmd = Command::new("sh"); cmd.arg(sanitize_sh(&build.src.join("src/rust-installer/gen-installer.sh"))) - .arg("--product-name=Rust") - .arg("--rel-manifest-dir=rustlib") - .arg("--success-message=std-is-standing-at-the-ready.") - .arg(format!("--image-dir={}", sanitize_sh(&image))) - .arg(format!("--work-dir={}", sanitize_sh(&tmpdir(build)))) - .arg(format!("--output-dir={}", sanitize_sh(&distdir(build)))) - .arg(format!("--package-name={}-{}", name, target)) - .arg(format!("--component-name=rust-std-{}", target)) - .arg("--legacy-manifest-dirs=rustlib,cargo"); + .arg("--product-name=Rust") + .arg("--rel-manifest-dir=rustlib") + .arg("--success-message=std-is-standing-at-the-ready.") + .arg(format!("--image-dir={}", sanitize_sh(&image))) + .arg(format!("--work-dir={}", sanitize_sh(&tmpdir(build)))) + .arg(format!("--output-dir={}", sanitize_sh(&distdir(build)))) + .arg(format!("--package-name={}-{}", name, target)) + .arg(format!("--component-name=rust-std-{}", target)) + .arg("--legacy-manifest-dirs=rustlib,cargo"); build.run(&mut cmd); t!(fs::remove_dir_all(&image)); } @@ -298,21 +300,15 @@ pub fn rust_src(build: &Build) { t!(fs::create_dir_all(&dst_src)); // This is the set of root paths which will become part of the source package - let src_files = [ - "COPYRIGHT", - "LICENSE-APACHE", - "LICENSE-MIT", - "CONTRIBUTING.md", - "README.md", - "RELEASES.md", - "configure", - "Makefile.in" - ]; - let src_dirs = [ - "man", - "src", - "mk" - ]; + let src_files = ["COPYRIGHT", + "LICENSE-APACHE", + "LICENSE-MIT", + "CONTRIBUTING.md", + "README.md", + "RELEASES.md", + "configure", + "Makefile.in"]; + let src_dirs = ["man", "src", "mk"]; let filter_fn = move |path: &Path| { let spath = match path.to_str() { @@ -320,25 +316,38 @@ pub fn rust_src(build: &Build) { None => return false, }; if spath.ends_with("~") || spath.ends_with(".pyc") { - return false + return false; } if spath.contains("llvm/test") || spath.contains("llvm\\test") { - if spath.ends_with(".ll") || - spath.ends_with(".td") || - spath.ends_with(".s") { - return false + if spath.ends_with(".ll") || spath.ends_with(".td") || spath.ends_with(".s") { + return false; } } - 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", - ]; + 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"]; !path.iter() - .map(|s| s.to_str().unwrap()) - .any(|s| excludes.contains(&s)) + .map(|s| s.to_str().unwrap()) + .any(|s| excludes.contains(&s)) }; // Copy the directories using our filter @@ -355,15 +364,15 @@ pub fn rust_src(build: &Build) { // Create source tarball in rust-installer format let mut cmd = Command::new("sh"); cmd.arg(sanitize_sh(&build.src.join("src/rust-installer/gen-installer.sh"))) - .arg("--product-name=Rust") - .arg("--rel-manifest-dir=rustlib") - .arg("--success-message=Awesome-Source.") - .arg(format!("--image-dir={}", sanitize_sh(&image))) - .arg(format!("--work-dir={}", sanitize_sh(&tmpdir(build)))) - .arg(format!("--output-dir={}", sanitize_sh(&distdir(build)))) - .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(format!("--image-dir={}", sanitize_sh(&image))) + .arg(format!("--work-dir={}", sanitize_sh(&tmpdir(build)))) + .arg(format!("--output-dir={}", sanitize_sh(&distdir(build)))) + .arg(format!("--package-name={}", name)) + .arg("--component-name=rust-src") + .arg("--legacy-manifest-dirs=rustlib,cargo"); build.run(&mut cmd); // Rename directory, so that root folder of tarball has the correct name @@ -374,9 +383,10 @@ pub fn rust_src(build: &Build) { // Create plain source tarball let mut cmd = Command::new("tar"); - cmd.arg("-czf").arg(sanitize_sh(&distdir(build).join(&format!("{}.tar.gz", plain_name)))) - .arg(&plain_name) - .current_dir(&dst); + cmd.arg("-czf") + .arg(sanitize_sh(&distdir(build).join(&format!("{}.tar.gz", plain_name)))) + .arg(&plain_name) + .current_dir(&dst); build.run(&mut cmd); t!(fs::remove_dir_all(&image)); @@ -407,10 +417,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..])) } diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index c2636384dbb2b..f004950ef06ca 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -39,14 +39,14 @@ pub fn rustbook(build: &Build, stage: u32, target: &str, name: &str, out: &Path) let index = out.join("index.html"); let rustbook = build.tool(&compiler, "rustbook"); if up_to_date(&src, &index) && up_to_date(&rustbook, &index) { - return + return; } println!("Rustbook stage{} ({}) - {}", stage, target, name); let _ = fs::remove_dir_all(&out); build.run(build.tool_cmd(&compiler, "rustbook") - .arg("build") - .arg(&src) - .arg(out)); + .arg("build") + .arg(&src) + .arg(out)); } /// Generates all standalone documentation as compiled by the rustdoc in `stage` @@ -78,8 +78,8 @@ pub fn standalone(build: &Build, stage: u32, target: &str, out: &Path) { let short = build.short_ver_hash.as_ref().unwrap_or(&blank); let hash = build.ver_hash.as_ref().unwrap_or(&blank); let info = info.replace("VERSION", &build.release) - .replace("SHORT_HASH", short) - .replace("STAMP", hash); + .replace("SHORT_HASH", short) + .replace("STAMP", hash); t!(t!(File::create(&version_info)).write_all(info.as_bytes())); } @@ -88,38 +88,39 @@ pub fn standalone(build: &Build, stage: u32, target: &str, out: &Path) { 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 = build.rustdoc(&compiler); - if up_to_date(&path, &html) && - up_to_date(&footer, &html) && - up_to_date(&favicon, &html) && - up_to_date(&full_toc, &html) && - up_to_date(&version_info, &html) && - 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) && + up_to_date(&version_info, &html) && up_to_date(&rustdoc, &html) { + continue; } let mut cmd = Command::new(&rustdoc); build.add_rustc_lib_path(&compiler, &mut cmd); - cmd.arg("--html-after-content").arg(&footer) - .arg("--html-before-content").arg(&version_info) - .arg("--html-in-header").arg(&favicon) - .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-playground-url") + .arg("https://play.rust-lang.org/") + .arg("-o") + .arg(out) + .arg(&path); if filename == "reference.md" { - cmd.arg("--html-in-header").arg(&full_toc); + cmd.arg("--html-in-header").arg(&full_toc); } if filename == "not_found.md" { cmd.arg("--markdown-no-toc") - .arg("--markdown-css") - .arg("https://doc.rust-lang.org/rust.css"); + .arg("--markdown-css") + .arg("https://doc.rust-lang.org/rust.css"); } else { cmd.arg("--markdown-css").arg("rust.css"); } @@ -136,15 +137,17 @@ pub fn std(build: &Build, stage: u32, target: &str, out: &Path) { t!(fs::create_dir_all(out)); let compiler = Compiler::new(stage, &build.config.build); let out_dir = build.stage_out(&compiler, Mode::Libstd) - .join(target).join("doc"); + .join(target) + .join("doc"); let rustdoc = build.rustdoc(&compiler); build.clear_if_dirty(&out_dir, &rustdoc); let mut cargo = build.cargo(&compiler, Mode::Libstd, target, "doc"); cargo.arg("--manifest-path") - .arg(build.src.join("src/rustc/std_shim/Cargo.toml")) - .arg("--features").arg(build.std_features()); + .arg(build.src.join("src/rustc/std_shim/Cargo.toml")) + .arg("--features") + .arg(build.std_features()); build.run(&mut cargo); cp_r(&out_dir, out) } @@ -158,14 +161,15 @@ pub fn test(build: &Build, stage: u32, target: &str, out: &Path) { t!(fs::create_dir_all(out)); let compiler = Compiler::new(stage, &build.config.build); let out_dir = build.stage_out(&compiler, Mode::Libtest) - .join(target).join("doc"); + .join(target) + .join("doc"); let rustdoc = build.rustdoc(&compiler); build.clear_if_dirty(&out_dir, &rustdoc); let mut cargo = build.cargo(&compiler, Mode::Libtest, target, "doc"); cargo.arg("--manifest-path") - .arg(build.src.join("src/rustc/test_shim/Cargo.toml")); + .arg(build.src.join("src/rustc/test_shim/Cargo.toml")); build.run(&mut cargo); cp_r(&out_dir, out) } @@ -179,15 +183,17 @@ pub fn rustc(build: &Build, stage: u32, target: &str, out: &Path) { t!(fs::create_dir_all(out)); let compiler = Compiler::new(stage, &build.config.build); let out_dir = build.stage_out(&compiler, Mode::Librustc) - .join(target).join("doc"); + .join(target) + .join("doc"); let rustdoc = build.rustdoc(&compiler); if !up_to_date(&rustdoc, &out_dir.join("rustc/index.html")) && out_dir.exists() { t!(fs::remove_dir_all(&out_dir)); } let mut cargo = build.cargo(&compiler, Mode::Librustc, target, "doc"); cargo.arg("--manifest-path") - .arg(build.src.join("src/rustc/Cargo.toml")) - .arg("--features").arg(build.rustc_features()); + .arg(build.src.join("src/rustc/Cargo.toml")) + .arg("--features") + .arg(build.rustc_features()); build.run(&mut cargo); cp_r(&out_dir, out) } diff --git a/src/bootstrap/install.rs b/src/bootstrap/install.rs index 9bc5a7c00abaf..ed1cacd9b5474 100644 --- a/src/bootstrap/install.rs +++ b/src/bootstrap/install.rs @@ -23,39 +23,87 @@ use dist::{package_vers, sanitize_sh, tmpdir}; /// Installs everything. pub fn install(build: &Build, stage: u32, host: &str) { - let prefix = build.config.prefix.as_ref().clone().map(|x| Path::new(x)) + let prefix = build.config + .prefix + .as_ref() + .clone() + .map(|x| Path::new(x)) .unwrap_or(Path::new("/usr/local")); - let docdir = build.config.docdir.as_ref().clone().map(|x| Cow::Borrowed(Path::new(x))) + let docdir = build.config + .docdir + .as_ref() + .clone() + .map(|x| Cow::Borrowed(Path::new(x))) .unwrap_or(Cow::Owned(prefix.join("share/doc/rust"))); - let libdir = build.config.libdir.as_ref().clone().map(|x| Cow::Borrowed(Path::new(x))) + let libdir = build.config + .libdir + .as_ref() + .clone() + .map(|x| Cow::Borrowed(Path::new(x))) .unwrap_or(Cow::Owned(prefix.join("lib"))); - let mandir = build.config.mandir.as_ref().clone().map(|x| Cow::Borrowed(Path::new(x))) + let mandir = build.config + .mandir + .as_ref() + .clone() + .map(|x| Cow::Borrowed(Path::new(x))) .unwrap_or(Cow::Owned(prefix.join("share/man"))); let empty_dir = build.out.join("tmp/empty_dir"); t!(fs::create_dir_all(&empty_dir)); if build.config.docs { - install_sh(&build, "docs", "rust-docs", stage, host, prefix, - &docdir, &libdir, &mandir, &empty_dir); + install_sh(&build, + "docs", + "rust-docs", + stage, + host, + prefix, + &docdir, + &libdir, + &mandir, + &empty_dir); } - install_sh(&build, "std", "rust-std", stage, host, prefix, - &docdir, &libdir, &mandir, &empty_dir); - install_sh(&build, "rustc", "rustc", stage, host, prefix, - &docdir, &libdir, &mandir, &empty_dir); + install_sh(&build, + "std", + "rust-std", + stage, + host, + prefix, + &docdir, + &libdir, + &mandir, + &empty_dir); + install_sh(&build, + "rustc", + "rustc", + stage, + host, + prefix, + &docdir, + &libdir, + &mandir, + &empty_dir); t!(fs::remove_dir_all(&empty_dir)); } -fn install_sh(build: &Build, package: &str, name: &str, stage: u32, host: &str, - prefix: &Path, docdir: &Path, libdir: &Path, mandir: &Path, empty_dir: &Path) { +fn install_sh(build: &Build, + package: &str, + name: &str, + stage: u32, + host: &str, + prefix: &Path, + docdir: &Path, + libdir: &Path, + mandir: &Path, + empty_dir: &Path) { println!("Install {} stage{} ({})", package, stage, host); let package_name = format!("{}-{}-{}", name, package_vers(build), host); let mut cmd = Command::new("sh"); cmd.current_dir(empty_dir) - .arg(sanitize_sh(&tmpdir(build).join(&package_name).join("install.sh"))) - .arg(format!("--prefix={}", sanitize_sh(prefix))) - .arg(format!("--docdir={}", sanitize_sh(docdir))) - .arg(format!("--libdir={}", sanitize_sh(libdir))) - .arg(format!("--mandir={}", sanitize_sh(mandir))) - .arg("--disable-ldconfig"); + .arg(sanitize_sh(&tmpdir(build).join(&package_name).join("install.sh"))) + .arg(format!("--prefix={}", sanitize_sh(prefix))) + .arg(format!("--docdir={}", sanitize_sh(docdir))) + .arg(format!("--libdir={}", sanitize_sh(libdir))) + .arg(format!("--mandir={}", sanitize_sh(mandir))) + .arg("--disable-ldconfig"); build.run(&mut cmd); } diff --git a/src/bootstrap/job.rs b/src/bootstrap/job.rs index 4558e6f049432..18ae12e93c146 100644 --- a/src/bootstrap/job.rs +++ b/src/bootstrap/job.rs @@ -76,7 +76,7 @@ pub unsafe fn setup() { 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) @@ -95,9 +95,13 @@ pub unsafe fn setup() { let parent = OpenProcess(PROCESS_DUP_HANDLE, FALSE, pid.parse().unwrap()); assert!(parent != 0 as *mut _, "{}", io::Error::last_os_error()); let mut parent_handle = 0 as *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 spawed this diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 7c5a0c7373f88..d546df801bc05 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -221,11 +221,14 @@ impl Build { self.verbose("collecting channel variables"); channel::collect(self); // If local-rust is the same major.minor as the current version, then force a local-rebuild - let local_version_verbose = output( - Command::new(&self.rustc).arg("--version").arg("--verbose")); - let local_release = local_version_verbose - .lines().filter(|x| x.starts_with("release:")) - .next().unwrap().trim_left_matches("release:").trim(); + let local_version_verbose = + output(Command::new(&self.rustc).arg("--version").arg("--verbose")); + let local_release = local_version_verbose.lines() + .filter(|x| x.starts_with("release:")) + .next() + .unwrap() + .trim_left_matches("release:") + .trim(); if local_release.split('.').take(2).eq(self.release.split('.').take(2)) { self.verbose(&format!("auto-detected local-rebuild {}", local_release)); self.local_rebuild = true; @@ -290,8 +293,7 @@ impl Build { compile::tool(self, stage, target.target, "rustbook"); } ToolErrorIndex { stage } => { - compile::tool(self, stage, target.target, - "error_index_generator"); + compile::tool(self, stage, target.target, "error_index_generator"); } ToolCargoTest { stage } => { compile::tool(self, stage, target.target, "cargotest"); @@ -306,8 +308,7 @@ impl Build { doc::rustbook(self, stage, target.target, "book", &doc_out); } DocNomicon { stage } => { - doc::rustbook(self, stage, target.target, "nomicon", - &doc_out); + doc::rustbook(self, stage, target.target, "nomicon", &doc_out); } DocStandalone { stage } => { doc::standalone(self, stage, target.target, &doc_out); @@ -335,97 +336,123 @@ impl Build { check::tidy(self, stage, target.target); } CheckRPass { compiler } => { - check::compiletest(self, &compiler, target.target, - "run-pass", "run-pass"); + check::compiletest(self, &compiler, target.target, "run-pass", "run-pass"); } CheckRPassFull { compiler } => { - check::compiletest(self, &compiler, target.target, - "run-pass", "run-pass-fulldeps"); + check::compiletest(self, + &compiler, + target.target, + "run-pass", + "run-pass-fulldeps"); } CheckCFail { compiler } => { - check::compiletest(self, &compiler, target.target, - "compile-fail", "compile-fail"); + check::compiletest(self, + &compiler, + target.target, + "compile-fail", + "compile-fail"); } CheckCFailFull { compiler } => { - check::compiletest(self, &compiler, target.target, - "compile-fail", "compile-fail-fulldeps") + check::compiletest(self, + &compiler, + target.target, + "compile-fail", + "compile-fail-fulldeps") } CheckPFail { compiler } => { - check::compiletest(self, &compiler, target.target, - "parse-fail", "parse-fail"); + check::compiletest(self, &compiler, target.target, "parse-fail", "parse-fail"); } CheckRFail { compiler } => { - check::compiletest(self, &compiler, target.target, - "run-fail", "run-fail"); + check::compiletest(self, &compiler, target.target, "run-fail", "run-fail"); } CheckRFailFull { compiler } => { - check::compiletest(self, &compiler, target.target, - "run-fail", "run-fail-fulldeps"); + check::compiletest(self, + &compiler, + target.target, + "run-fail", + "run-fail-fulldeps"); } CheckPretty { compiler } => { - check::compiletest(self, &compiler, target.target, - "pretty", "pretty"); + check::compiletest(self, &compiler, target.target, "pretty", "pretty"); } CheckPrettyRPass { compiler } => { - check::compiletest(self, &compiler, target.target, - "pretty", "run-pass"); + check::compiletest(self, &compiler, target.target, "pretty", "run-pass"); } CheckPrettyRPassFull { compiler } => { - check::compiletest(self, &compiler, target.target, - "pretty", "run-pass-fulldeps"); + check::compiletest(self, + &compiler, + target.target, + "pretty", + "run-pass-fulldeps"); } CheckPrettyRFail { compiler } => { - check::compiletest(self, &compiler, target.target, - "pretty", "run-fail"); + check::compiletest(self, &compiler, target.target, "pretty", "run-fail"); } CheckPrettyRFailFull { compiler } => { - check::compiletest(self, &compiler, target.target, - "pretty", "run-fail-fulldeps"); + check::compiletest(self, + &compiler, + target.target, + "pretty", + "run-fail-fulldeps"); } CheckPrettyRPassValgrind { compiler } => { - check::compiletest(self, &compiler, target.target, - "pretty", "run-pass-valgrind"); + check::compiletest(self, + &compiler, + target.target, + "pretty", + "run-pass-valgrind"); } CheckMirOpt { compiler } => { - check::compiletest(self, &compiler, target.target, - "mir-opt", "mir-opt"); + check::compiletest(self, &compiler, target.target, "mir-opt", "mir-opt"); } CheckCodegen { compiler } => { if self.config.codegen_tests { - check::compiletest(self, &compiler, target.target, - "codegen", "codegen"); + check::compiletest(self, &compiler, target.target, "codegen", "codegen"); } } CheckCodegenUnits { compiler } => { - check::compiletest(self, &compiler, target.target, - "codegen-units", "codegen-units"); + check::compiletest(self, + &compiler, + target.target, + "codegen-units", + "codegen-units"); } CheckIncremental { compiler } => { - check::compiletest(self, &compiler, target.target, - "incremental", "incremental"); + check::compiletest(self, + &compiler, + target.target, + "incremental", + "incremental"); } CheckUi { compiler } => { - check::compiletest(self, &compiler, target.target, - "ui", "ui"); + check::compiletest(self, &compiler, target.target, "ui", "ui"); } CheckDebuginfo { compiler } => { if target.target.contains("msvc") { // nothing to do } else if target.target.contains("apple") { - check::compiletest(self, &compiler, target.target, - "debuginfo-lldb", "debuginfo"); + check::compiletest(self, + &compiler, + target.target, + "debuginfo-lldb", + "debuginfo"); } else { - check::compiletest(self, &compiler, target.target, - "debuginfo-gdb", "debuginfo"); + check::compiletest(self, + &compiler, + target.target, + "debuginfo-gdb", + "debuginfo"); } } CheckRustdoc { compiler } => { - check::compiletest(self, &compiler, target.target, - "rustdoc", "rustdoc"); + check::compiletest(self, &compiler, target.target, "rustdoc", "rustdoc"); } CheckRPassValgrind { compiler } => { - check::compiletest(self, &compiler, target.target, - "run-pass-valgrind", "run-pass-valgrind"); + check::compiletest(self, + &compiler, + target.target, + "run-pass-valgrind", + "run-pass-valgrind"); } CheckDocs { compiler } => { check::docs(self, &compiler); @@ -434,8 +461,7 @@ impl Build { check::error_index(self, &compiler); } CheckRMake { compiler } => { - check::compiletest(self, &compiler, target.target, - "run-make", "run-make") + check::compiletest(self, &compiler, target.target, "run-make", "run-make") } CheckCrateStd { compiler } => { check::krate(self, &compiler, target.target, Mode::Libstd) @@ -457,9 +483,7 @@ impl Build { DebuggerScripts { stage } => { let compiler = Compiler::new(stage, target.target); - dist::debugger_scripts(self, - &self.sysroot(&compiler), - target.target); + dist::debugger_scripts(self, &self.sysroot(&compiler), target.target); } AndroidCopyLibs { compiler } => { @@ -496,20 +520,20 @@ impl Build { } if !self.config.submodules { - return + return; } if fs::metadata(self.src.join(".git")).is_err() { - return + return; } let git = || { let mut cmd = Command::new("git"); cmd.current_dir(&self.src); - return cmd + return cmd; }; let git_submodule = || { let mut cmd = Command::new("git"); cmd.current_dir(&self.src).arg("submodule"); - return cmd + return cmd; }; // FIXME: this takes a seriously long time to execute on Windows and a @@ -539,7 +563,10 @@ impl Build { panic!("unexpected git submodule state: {:?}", line.chars().next()); }; - submodules.push(Submodule { path: path, state: state }) + submodules.push(Submodule { + path: path, + state: state, + }) } self.run(git_submodule().arg("sync")); @@ -547,16 +574,17 @@ impl Build { for submodule in submodules { // If using llvm-root then don't touch the llvm submodule. if submodule.path.components().any(|c| c == Component::Normal("llvm".as_ref())) && - self.config.target_config.get(&self.config.build) - .and_then(|c| c.llvm_config.as_ref()).is_some() - { - continue + self.config + .target_config + .get(&self.config.build) + .and_then(|c| c.llvm_config.as_ref()) + .is_some() { + continue; } if submodule.path.components().any(|c| c == Component::Normal("jemalloc".as_ref())) && - !self.config.use_jemalloc - { - continue + !self.config.use_jemalloc { + continue; } // `submodule.path` is the relative path to a submodule (from the repository root) @@ -571,24 +599,28 @@ impl Build { match submodule.state { State::MaybeDirty => { // drop staged changes - self.run(git().current_dir(&submodule_path) - .args(&["reset", "--hard"])); + self.run(git() + .current_dir(&submodule_path) + .args(&["reset", "--hard"])); // drops unstaged changes - self.run(git().current_dir(&submodule_path) - .args(&["clean", "-fdx"])); - }, + self.run(git() + .current_dir(&submodule_path) + .args(&["clean", "-fdx"])); + } State::NotInitialized => { self.run(git_submodule().arg("init").arg(submodule.path)); self.run(git_submodule().arg("update").arg(submodule.path)); - }, + } State::OutOfSync => { // drops submodule commits that weren't reported to the (outer) git repository self.run(git_submodule().arg("update").arg(submodule.path)); - self.run(git().current_dir(&submodule_path) - .args(&["reset", "--hard"])); - self.run(git().current_dir(&submodule_path) - .args(&["clean", "-fdx"])); - }, + self.run(git() + .current_dir(&submodule_path) + .args(&["reset", "--hard"])); + self.run(git() + .current_dir(&submodule_path) + .args(&["clean", "-fdx"])); + } } } } @@ -602,7 +634,7 @@ impl Build { self.verbose(&format!("Dirty - {}", dir.display())); let _ = fs::remove_dir_all(dir); } else if stamp.exists() { - return + return; } t!(fs::create_dir_all(dir)); t!(File::create(stamp)); @@ -615,17 +647,15 @@ impl Build { /// rustc compiler, its output will be scoped by `mode`'s output directory, /// it will pass the `--target` flag for the specified `target`, and will be /// executing the Cargo command `cmd`. - fn cargo(&self, - compiler: &Compiler, - mode: Mode, - target: &str, - cmd: &str) -> Command { + fn cargo(&self, compiler: &Compiler, mode: Mode, target: &str, cmd: &str) -> Command { let mut cargo = Command::new(&self.cargo); let out_dir = self.stage_out(compiler, mode); cargo.env("CARGO_TARGET_DIR", out_dir) - .arg(cmd) - .arg("-j").arg(self.jobs().to_string()) - .arg("--target").arg(target); + .arg(cmd) + .arg("-j") + .arg(self.jobs().to_string()) + .arg("--target") + .arg(target); // FIXME: Temporary fix for https://github.com/rust-lang/cargo/issues/3005 // Force cargo to output binaries with disambiguating hashes in the name @@ -646,22 +676,23 @@ impl Build { // These variables are primarily all read by // src/bootstrap/{rustc,rustdoc.rs} cargo.env("RUSTC", self.out.join("bootstrap/debug/rustc")) - .env("RUSTC_REAL", self.compiler_path(compiler)) - .env("RUSTC_STAGE", stage.to_string()) - .env("RUSTC_DEBUGINFO", self.config.rust_debuginfo.to_string()) - .env("RUSTC_DEBUGINFO_LINES", self.config.rust_debuginfo_lines.to_string()) - .env("RUSTC_CODEGEN_UNITS", - self.config.rust_codegen_units.to_string()) - .env("RUSTC_DEBUG_ASSERTIONS", - self.config.rust_debug_assertions.to_string()) - .env("RUSTC_SNAPSHOT", &self.rustc) - .env("RUSTC_SYSROOT", self.sysroot(compiler)) - .env("RUSTC_LIBDIR", self.rustc_libdir(compiler)) - .env("RUSTC_SNAPSHOT_LIBDIR", self.rustc_snapshot_libdir()) - .env("RUSTC_RPATH", self.config.rust_rpath.to_string()) - .env("RUSTDOC", self.out.join("bootstrap/debug/rustdoc")) - .env("RUSTDOC_REAL", self.rustdoc(compiler)) - .env("RUSTC_FLAGS", self.rustc_flags(target).join(" ")); + .env("RUSTC_REAL", self.compiler_path(compiler)) + .env("RUSTC_STAGE", stage.to_string()) + .env("RUSTC_DEBUGINFO", self.config.rust_debuginfo.to_string()) + .env("RUSTC_DEBUGINFO_LINES", + self.config.rust_debuginfo_lines.to_string()) + .env("RUSTC_CODEGEN_UNITS", + self.config.rust_codegen_units.to_string()) + .env("RUSTC_DEBUG_ASSERTIONS", + self.config.rust_debug_assertions.to_string()) + .env("RUSTC_SNAPSHOT", &self.rustc) + .env("RUSTC_SYSROOT", self.sysroot(compiler)) + .env("RUSTC_LIBDIR", self.rustc_libdir(compiler)) + .env("RUSTC_SNAPSHOT_LIBDIR", self.rustc_snapshot_libdir()) + .env("RUSTC_RPATH", self.config.rust_rpath.to_string()) + .env("RUSTDOC", self.out.join("bootstrap/debug/rustdoc")) + .env("RUSTDOC_REAL", self.rustdoc(compiler)) + .env("RUSTC_FLAGS", self.rustc_flags(target).join(" ")); self.add_bootstrap_key(&mut cargo); @@ -686,7 +717,7 @@ impl Build { if self.config.rust_optimize { cargo.arg("--release"); } - return cargo + return cargo; } /// Get a path to the compiler specified. @@ -709,7 +740,7 @@ impl Build { let mut rustdoc = self.compiler_path(compiler); rustdoc.pop(); rustdoc.push(exe("rustdoc", compiler.host)); - return rustdoc + return rustdoc; } /// Get a `Command` which is ready to run `tool` in `stage` built for @@ -724,7 +755,7 @@ impl Build { self.cargo_out(compiler, Mode::Tool, host).join("deps"), ]; add_lib_path(paths, &mut cmd); - return cmd + return cmd; } /// Get the space-separated set of activated features for the standard @@ -740,7 +771,7 @@ impl Build { if self.config.backtrace { features.push_str(" backtrace"); } - return features + return features; } /// Get the space-separated set of activated features for the compiler. @@ -749,13 +780,17 @@ impl Build { if self.config.use_jemalloc { features.push_str(" jemalloc"); } - return features + return features; } /// 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" + } } /// Returns the sysroot for the `compiler` specified that *this build system @@ -775,8 +810,11 @@ impl Build { /// Returns the libdir where the standard library and other artifacts are /// found for a compiler's sysroot. fn sysroot_libdir(&self, compiler: &Compiler, target: &str) -> PathBuf { - self.sysroot(compiler).join("lib").join("rustlib") - .join(target).join("lib") + self.sysroot(compiler) + .join("lib") + .join("rustlib") + .join(target) + .join("lib") } /// Returns the root directory for all output generated in a particular @@ -790,17 +828,15 @@ impl Build { Mode::Tool => "-tools", Mode::Librustc => "-rustc", }; - 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 comipler, wehther or not we're building the /// standard library, and targeting the specified architecture. - fn cargo_out(&self, - compiler: &Compiler, - mode: Mode, - target: &str) -> PathBuf { + fn cargo_out(&self, compiler: &Compiler, mode: Mode, target: &str) -> PathBuf { self.stage_out(compiler, mode).join(target).join(self.cargo_dir()) } @@ -818,7 +854,7 @@ impl Build { fn is_rust_llvm(&self, target: &str) -> bool { match self.config.target_config.get(target) { Some(ref c) => c.llvm_config.is_none(), - None => true + None => true, } } @@ -831,7 +867,8 @@ impl Build { if let Some(s) = target_config.and_then(|c| c.llvm_config.as_ref()) { s.clone() } else { - self.llvm_out(&self.config.build).join("bin") + self.llvm_out(&self.config.build) + .join("bin") .join(exe("llvm-config", target)) } } @@ -865,7 +902,7 @@ impl Build { // compiler live next to the compiler and the system will find them // automatically. if cfg!(windows) { - return + return; } add_lib_path(vec![self.rustc_libdir(compiler)], cmd); @@ -894,7 +931,11 @@ impl Build { /// Returns the libdir of the snapshot compiler. fn rustc_snapshot_libdir(&self) -> PathBuf { - self.rustc.parent().unwrap().parent().unwrap() + self.rustc + .parent() + .unwrap() + .parent() + .unwrap() .join(libdir(&self.config.build)) } @@ -927,10 +968,13 @@ impl Build { fn cflags(&self, target: &str) -> Vec { // Filter out -O and /O (the optimization flags) that we picked up from // gcc-rs because the build scripts will determine that for themselves. - let mut base = self.cc[target].0.args().iter() - .map(|s| s.to_string_lossy().into_owned()) - .filter(|s| !s.starts_with("-O") && !s.starts_with("/O")) - .collect::>(); + let mut base = self.cc[target] + .0 + .args() + .iter() + .map(|s| s.to_string_lossy().into_owned()) + .filter(|s| !s.starts_with("-O") && !s.starts_with("/O")) + .collect::>(); // If we're compiling on OSX then we add a few unconditional flags // indicating that we want libc++ (more filled out than libstdc++) and @@ -947,10 +991,10 @@ impl Build { "i686-unknown-linux-musl" | "x86_64-unknown-linux-musl" => { base.push("-Wa,-mrelax-relocations=no".into()); - }, - _ => {}, + } + _ => {} } - return base + return base; } /// Returns the path to the `ar` archive utility for the target specified. @@ -963,8 +1007,12 @@ impl Build { fn cxx(&self, target: &str) -> &Path { match self.cxx.get(target) { Some(p) => p.path(), - None => panic!("\n\ntarget `{}` is not configured as a host, - only as a target\n\n", target), + None => { + panic!("\n\ntarget `{}` is not configured as a host, + \ + only as a target\n\n", + target) + } } } @@ -979,15 +1027,17 @@ impl Build { let mut base = Vec::new(); if target != self.config.build && !target.contains("msvc") && - !target.contains("emscripten") { + !target.contains("emscripten") { base.push(format!("-Clinker={}", self.cc(target).display())); } - return base + return base; } /// Returns the "musl root" for this `target`, if defined fn musl_root(&self, target: &str) -> 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) @@ -997,7 +1047,10 @@ impl Build { impl<'a> Compiler<'a> { /// Creates a new complier for the specified stage/host fn new(stage: u32, host: &'a str) -> Compiler<'a> { - Compiler { stage: stage, host: host } + Compiler { + stage: stage, + host: host, + } } /// Returns whether this is a snapshot compiler for `build`'s configuration diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index 1b4e86fb30f25..fb0de43a5e3f0 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -51,7 +51,7 @@ pub fn llvm(build: &Build, target: &str) { let mut done_contents = String::new(); t!(t!(File::open(&done_stamp)).read_to_string(&mut done_contents)); if done_contents == stamp_contents { - return + return; } } drop(fs::remove_dir_all(&dst)); @@ -60,7 +60,11 @@ pub fn llvm(build: &Build, target: &str) { let _ = fs::remove_dir_all(&dst.join("build")); t!(fs::create_dir_all(&dst.join("build"))); - let assertions = if build.config.llvm_assertions {"ON"} else {"OFF"}; + let assertions = if build.config.llvm_assertions { + "ON" + } else { + "OFF" + }; // http://llvm.org/docs/CMake.html let mut cfg = cmake::Config::new(build.src.join("src/llvm")); @@ -68,21 +72,26 @@ pub fn llvm(build: &Build, target: &str) { cfg.generator("Ninja"); } cfg.target(target) - .host(&build.config.build) - .out_dir(&dst) - .profile(if build.config.llvm_optimize {"Release"} else {"Debug"}) - .define("LLVM_ENABLE_ASSERTIONS", assertions) - .define("LLVM_TARGETS_TO_BUILD", "X86;ARM;AArch64;Mips;PowerPC;SystemZ;JSBackend") - .define("LLVM_INCLUDE_EXAMPLES", "OFF") - .define("LLVM_INCLUDE_TESTS", "OFF") - .define("LLVM_INCLUDE_DOCS", "OFF") - .define("LLVM_ENABLE_ZLIB", "OFF") - .define("WITH_POLLY", "OFF") - .define("LLVM_ENABLE_TERMINFO", "OFF") - .define("LLVM_ENABLE_LIBEDIT", "OFF") - .define("LLVM_PARALLEL_COMPILE_JOBS", build.jobs().to_string()) - .define("LLVM_TARGET_ARCH", target.split('-').next().unwrap()) - .define("LLVM_DEFAULT_TARGET_TRIPLE", target); + .host(&build.config.build) + .out_dir(&dst) + .profile(if build.config.llvm_optimize { + "Release" + } else { + "Debug" + }) + .define("LLVM_ENABLE_ASSERTIONS", assertions) + .define("LLVM_TARGETS_TO_BUILD", + "X86;ARM;AArch64;Mips;PowerPC;SystemZ;JSBackend") + .define("LLVM_INCLUDE_EXAMPLES", "OFF") + .define("LLVM_INCLUDE_TESTS", "OFF") + .define("LLVM_INCLUDE_DOCS", "OFF") + .define("LLVM_ENABLE_ZLIB", "OFF") + .define("WITH_POLLY", "OFF") + .define("LLVM_ENABLE_TERMINFO", "OFF") + .define("LLVM_ENABLE_LIBEDIT", "OFF") + .define("LLVM_PARALLEL_COMPILE_JOBS", build.jobs().to_string()) + .define("LLVM_TARGET_ARCH", target.split('-').next().unwrap()) + .define("LLVM_DEFAULT_TARGET_TRIPLE", target); if target.starts_with("i686") { cfg.define("LLVM_BUILD_32_BITS", "ON"); @@ -95,19 +104,19 @@ pub fn llvm(build: &Build, target: &str) { // actually exists most of the time in normal installs of LLVM. let host = build.llvm_out(&build.config.build).join("bin/llvm-tblgen"); cfg.define("CMAKE_CROSSCOMPILING", "True") - .define("LLVM_TABLEGEN", &host); + .define("LLVM_TABLEGEN", &host); } // MSVC handles compiler business itself if !target.contains("msvc") { if build.config.ccache { - cfg.define("CMAKE_C_COMPILER", "ccache") - .define("CMAKE_C_COMPILER_ARG1", build.cc(target)) - .define("CMAKE_CXX_COMPILER", "ccache") - .define("CMAKE_CXX_COMPILER_ARG1", build.cxx(target)); + cfg.define("CMAKE_C_COMPILER", "ccache") + .define("CMAKE_C_COMPILER_ARG1", build.cc(target)) + .define("CMAKE_CXX_COMPILER", "ccache") + .define("CMAKE_CXX_COMPILER_ARG1", build.cxx(target)); } else { - cfg.define("CMAKE_C_COMPILER", build.cc(target)) - .define("CMAKE_CXX_COMPILER", build.cxx(target)); + cfg.define("CMAKE_C_COMPILER", build.cc(target)) + .define("CMAKE_CXX_COMPILER", build.cxx(target)); } cfg.build_arg("-j").build_arg(build.jobs().to_string()); @@ -126,14 +135,13 @@ pub fn llvm(build: &Build, target: &str) { fn check_llvm_version(build: &Build, llvm_config: &Path) { if !build.config.llvm_version_check { - return + return; } let mut cmd = Command::new(llvm_config); let version = output(cmd.arg("--version")); - if version.starts_with("3.5") || version.starts_with("3.6") || - version.starts_with("3.7") { - return + if version.starts_with("3.5") || version.starts_with("3.6") || version.starts_with("3.7") { + return; } panic!("\n\nbad LLVM version: {}, need >=3.5\n\n", version) } @@ -144,18 +152,18 @@ pub fn test_helpers(build: &Build, target: &str) { let dst = build.test_helpers_out(target); let src = build.src.join("src/rt/rust_test_helpers.c"); if up_to_date(&src, &dst.join("librust_test_helpers.a")) { - return + return; } println!("Building test helpers"); t!(fs::create_dir_all(&dst)); let mut cfg = gcc::Config::new(); cfg.cargo_metadata(false) - .out_dir(&dst) - .target(target) - .host(&build.config.build) - .opt_level(0) - .debug(false) - .file(build.src.join("src/rt/rust_test_helpers.c")) - .compile("librust_test_helpers.a"); + .out_dir(&dst) + .target(target) + .host(&build.config.build) + .opt_level(0) + .debug(false) + .file(build.src.join("src/rt/rust_test_helpers.c")) + .compile("librust_test_helpers.a"); } diff --git a/src/bootstrap/sanity.rs b/src/bootstrap/sanity.rs index 969cd70fd57eb..088fd99f6daef 100644 --- a/src/bootstrap/sanity.rs +++ b/src/bootstrap/sanity.rs @@ -42,8 +42,7 @@ pub fn check(build: &mut Build) { } let have_cmd = |cmd: &OsStr| { for path in env::split_paths(&path).map(|p| p.join(cmd)) { - if fs::metadata(&path).is_ok() || - fs::metadata(path.with_extension("exe")).is_ok() { + if fs::metadata(&path).is_ok() || fs::metadata(path.with_extension("exe")).is_ok() { return Some(path); } } @@ -52,7 +51,7 @@ pub fn check(build: &mut Build) { let mut need_cmd = |cmd: &OsStr| { if !checked.insert(cmd.to_owned()) { - return + return; } if have_cmd(cmd).is_none() { panic!("\n\ncouldn't find required command: {:?}\n\n", cmd); @@ -69,14 +68,14 @@ pub fn check(build: &mut Build) { for host in build.config.host.iter() { if let Some(config) = build.config.target_config.get(host) { if config.llvm_config.is_some() { - continue + continue; } } need_cmd("cmake".as_ref()); if build.config.ninja { need_cmd("ninja".as_ref()) } - break + break; } need_cmd("python".as_ref()); @@ -127,8 +126,7 @@ pub fn check(build: &mut Build) { for target in build.config.target.iter() { // Can't compile for iOS unless we're on OSX - if target.contains("apple-ios") && - !build.config.build.contains("apple-darwin") { + if target.contains("apple-ios") && !build.config.build.contains("apple-darwin") { panic!("the iOS target is only supported on OSX"); } @@ -194,8 +192,10 @@ $ pacman -R cmake && pacman -S mingw-w64-x86_64-cmake let run = |cmd: &mut Command| { cmd.output().map(|output| { String::from_utf8_lossy(&output.stdout) - .lines().next().unwrap() - .to_string() + .lines() + .next() + .unwrap() + .to_string() }) }; build.gdb_version = run(Command::new("gdb").arg("--version")).ok(); diff --git a/src/bootstrap/step.rs b/src/bootstrap/step.rs index 3bf0f21192147..200ce5cfe015f 100644 --- a/src/bootstrap/step.rs +++ b/src/bootstrap/step.rs @@ -205,13 +205,20 @@ fn top_level(build: &Build) -> Vec { let host = Step { src: Source::Llvm { _dummy: () }, - target: build.flags.host.iter().next() - .unwrap_or(&build.config.build), + target: build.flags + .host + .iter() + .next() + .unwrap_or(&build.config.build), }; let target = Step { src: Source::Llvm { _dummy: () }, - target: build.flags.target.iter().next().map(|x| &x[..]) - .unwrap_or(host.target) + target: build.flags + .target + .iter() + .next() + .map(|x| &x[..]) + .unwrap_or(host.target), }; // First, try to find steps on the command line. @@ -224,11 +231,11 @@ fn top_level(build: &Build) -> Vec { target: &build.config.build, }; if build.config.docs { - targets.push(t.doc(stage)); + targets.push(t.doc(stage)); } for host in build.config.host.iter() { if !build.flags.host.contains(host) { - continue + continue; } let host = t.target(host); if host.target == build.config.build { @@ -238,15 +245,15 @@ fn top_level(build: &Build) -> Vec { } for target in build.config.target.iter() { if !build.flags.target.contains(target) { - continue + continue; } if host.target == build.config.build { targets.push(host.target(target) - .libtest(host.compiler(stage))); + .libtest(host.compiler(stage))); } else { targets.push(host.target(target) - .libtest_link(t.compiler(stage), host.target)); + .libtest_link(t.compiler(stage), host.target)); } } } @@ -311,7 +318,10 @@ impl<'a> Step<'a> { } fn target(&self, target: &'a str) -> Step<'a> { - Step { target: target, src: self.src.clone() } + Step { + target: target, + src: self.src.clone(), + } } // Define ergonomic constructors for each step defined above so they can be @@ -324,32 +334,22 @@ impl<'a> Step<'a> { /// then returns a list of all the dependencies of that step. pub fn deps(&self, build: &'a Build) -> Vec> { match self.src { - Source::Rustc { stage: 0 } => { - Vec::new() - } + Source::Rustc { stage: 0 } => Vec::new(), Source::Rustc { stage } => { let compiler = Compiler::new(stage - 1, &build.config.build); vec![self.librustc(compiler)] } - Source::Librustc { compiler } => { - vec![self.libtest(compiler), self.llvm(())] - } - Source::Libtest { compiler } => { - vec![self.libstd(compiler)] - } - Source::Libstd { compiler } => { - vec![self.rustc(compiler.stage).target(compiler.host)] - } + Source::Librustc { compiler } => vec![self.libtest(compiler), self.llvm(())], + Source::Libtest { compiler } => vec![self.libstd(compiler)], + Source::Libstd { compiler } => vec![self.rustc(compiler.stage).target(compiler.host)], Source::LibrustcLink { compiler, host } => { - vec![self.librustc(compiler), - self.libtest_link(compiler, host)] + vec![self.librustc(compiler), self.libtest_link(compiler, host)] } Source::LibtestLink { compiler, host } => { vec![self.libtest(compiler), self.libstd_link(compiler, host)] } Source::LibstdLink { compiler, host } => { - vec![self.libstd(compiler), - self.target(host).rustc(compiler.stage)] + vec![self.libstd(compiler), self.target(host).rustc(compiler.stage)] } Source::Llvm { _dummy } => Vec::new(), Source::TestHelpers { _dummy } => Vec::new(), @@ -373,12 +373,8 @@ impl<'a> Step<'a> { Source::DocErrorIndex { stage } => { vec![self.target(&build.config.build).tool_error_index(stage)] } - Source::DocStandalone { stage } => { - vec![self.target(&build.config.build).rustc(stage)] - } - Source::DocRustc { stage } => { - vec![self.doc_test(stage)] - } + Source::DocStandalone { stage } => vec![self.target(&build.config.build).rustc(stage)], + Source::DocRustc { stage } => vec![self.doc_test(stage)], Source::Doc { stage } => { let mut deps = vec![ self.doc_book(stage), self.doc_nomicon(stage), @@ -395,9 +391,11 @@ impl<'a> Step<'a> { Source::Check { stage, compiler } => { // Check is just a pseudo step which means check all targets, // so just depend on checking all targets. - build.config.target.iter().map(|t| { - self.target(t).check_target(stage, compiler) - }).collect() + build.config + .target + .iter() + .map(|t| self.target(t).check_target(stage, compiler)) + .collect() } Source::CheckTarget { stage, compiler } => { // CheckTarget here means run all possible test suites for this @@ -471,17 +469,12 @@ impl<'a> Step<'a> { } base } - Source::CheckLinkcheck { stage } => { - vec![self.tool_linkchecker(stage), self.doc(stage)] - } + Source::CheckLinkcheck { stage } => vec![self.tool_linkchecker(stage), self.doc(stage)], Source::CheckCargoTest { stage } => { - vec![self.tool_cargotest(stage), - self.librustc(self.compiler(stage))] + vec![self.tool_cargotest(stage), self.librustc(self.compiler(stage))] } - Source::CheckTidy { stage } => { - vec![self.tool_tidy(stage)] - } - Source::CheckMirOpt { compiler} | + Source::CheckTidy { stage } => vec![self.tool_tidy(stage)], + Source::CheckMirOpt { compiler } | Source::CheckPrettyRPass { compiler } | Source::CheckPrettyRFail { compiler } | Source::CheckRFail { compiler } | @@ -523,43 +516,25 @@ impl<'a> Step<'a> { vec![self.librustc(compiler), self.target(compiler.host).tool_compiletest(compiler.stage)] } - Source::CheckDocs { compiler } => { - vec![self.libtest(compiler)] - } + Source::CheckDocs { compiler } => vec![self.libtest(compiler)], Source::CheckErrorIndex { compiler } => { vec![self.libstd(compiler), self.target(compiler.host).tool_error_index(compiler.stage)] } - Source::CheckCrateStd { compiler } => { - vec![self.libtest(compiler)] - } - Source::CheckCrateTest { compiler } => { - vec![self.libtest(compiler)] - } - Source::CheckCrateRustc { compiler } => { - vec![self.libtest(compiler)] - } + Source::CheckCrateStd { compiler } => vec![self.libtest(compiler)], + Source::CheckCrateTest { compiler } => vec![self.libtest(compiler)], + Source::CheckCrateRustc { compiler } => vec![self.libtest(compiler)], Source::ToolLinkchecker { stage } | - Source::ToolTidy { stage } => { - vec![self.libstd(self.compiler(stage))] - } + Source::ToolTidy { stage } => vec![self.libstd(self.compiler(stage))], Source::ToolErrorIndex { stage } | - Source::ToolRustbook { stage } => { - vec![self.librustc(self.compiler(stage))] - } - Source::ToolCargoTest { stage } => { - vec![self.libstd(self.compiler(stage))] - } - Source::ToolCompiletest { stage } => { - vec![self.libtest(self.compiler(stage))] - } + Source::ToolRustbook { stage } => vec![self.librustc(self.compiler(stage))], + Source::ToolCargoTest { stage } => vec![self.libstd(self.compiler(stage))], + Source::ToolCompiletest { stage } => vec![self.libtest(self.compiler(stage))], Source::DistDocs { stage } => vec![self.doc(stage)], Source::DistMingw { _dummy: _ } => Vec::new(), - Source::DistRustc { stage } => { - vec![self.rustc(stage)] - } + Source::DistRustc { stage } => vec![self.rustc(stage)], Source::DistStd { compiler } => { // We want to package up as many target libraries as possible // for the `rust-std` package, so if this is a host target we @@ -595,13 +570,9 @@ impl<'a> Step<'a> { base } - Source::Install { stage } => { - vec![self.dist(stage)] - } + Source::Install { stage } => vec![self.dist(stage)], - Source::AndroidCopyLibs { compiler } => { - vec![self.libtest(compiler)] - } + Source::AndroidCopyLibs { compiler } => vec![self.libtest(compiler)], } } } diff --git a/src/bootstrap/util.rs b/src/bootstrap/util.rs index 6c0a32a54d919..6220412890039 100644 --- a/src/bootstrap/util.rs +++ b/src/bootstrap/util.rs @@ -32,9 +32,9 @@ pub fn staticlib(name: &str, target: &str) -> String { /// Returns the last-modified time for `path`, or zero if it doesn't exist. pub fn mtime(path: &Path) -> FileTime { - fs::metadata(path).map(|f| { - FileTime::from_last_modification_time(&f) - }).unwrap_or(FileTime::zero()) + fs::metadata(path) + .map(|f| FileTime::from_last_modification_time(&f)) + .unwrap_or(FileTime::zero()) } /// Copies a file from `src` to `dst`, attempting to use hard links and then @@ -43,8 +43,10 @@ pub fn copy(src: &Path, dst: &Path) { let res = fs::hard_link(src, dst); let res = res.or_else(|_| fs::copy(src, dst).map(|_| ())); if let Err(e) = res { - panic!("failed to copy `{}` to `{}`: {}", src.display(), - dst.display(), e) + panic!("failed to copy `{}` to `{}`: {}", + src.display(), + dst.display(), + e) } } @@ -114,7 +116,11 @@ 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. @@ -169,6 +175,5 @@ pub fn dylib_path_var() -> &'static str { /// Parses the `dylib_path_var()` environment variable, returning a list of /// paths that are members of this lookup path. pub fn dylib_path() -> Vec { - env::split_paths(&env::var_os(dylib_path_var()).unwrap_or(OsString::new())) - .collect() + env::split_paths(&env::var_os(dylib_path_var()).unwrap_or(OsString::new())).collect() }