From 73c2d2a7419844f763b1ac72b89236bd3183bfaf Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 14 Apr 2016 14:27:51 -0700 Subject: [PATCH] cargotest: Put output in build directory Right now cargotest uses `TempDir` to place output into the system temp directory, but unfortunately this means that if the process is interrupted then it'll leak the directory and that'll never get cleaned up. One of our bots filled up its disk space and there were 20 cargotest directories lying around so seems prudent to clean them up! By putting the output in the build directory it should ensure that we don't leak too many extra builds. --- src/bootstrap/build/check.rs | 13 +++- src/bootstrap/build/step.rs | 5 +- src/rustc/Cargo.lock | 40 +++++++++++- src/tools/cargotest/Cargo.lock | 24 -------- src/tools/cargotest/Cargo.toml | 3 - src/tools/cargotest/main.rs | 108 ++++++++++++++++++++------------- 6 files changed, 118 insertions(+), 75 deletions(-) diff --git a/src/bootstrap/build/check.rs b/src/bootstrap/build/check.rs index d4e344fc48247..6aad49bc9880e 100644 --- a/src/bootstrap/build/check.rs +++ b/src/bootstrap/build/check.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::fs; + use build::{Build, Compiler}; pub fn linkcheck(build: &Build, stage: u32, host: &str) { @@ -29,9 +31,16 @@ pub fn cargotest(build: &Build, stage: u32, host: &str) { 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 + // is currently to minimize the length of path on Windows where we otherwise + // quickly run into path name limit constraints. + let out_dir = build.out.join("ct"); + t!(fs::create_dir_all(&out_dir)); + build.run(build.tool_cmd(compiler, "cargotest") - .env("PATH", newpath) - .arg(&build.cargo)); + .env("PATH", newpath) + .arg(&build.cargo) + .arg(&out_dir)); } pub fn tidy(build: &Build, stage: u32, host: &str) { diff --git a/src/bootstrap/build/step.rs b/src/bootstrap/build/step.rs index 2312f96348c9d..07cfb96c30d57 100644 --- a/src/bootstrap/build/step.rs +++ b/src/bootstrap/build/step.rs @@ -318,7 +318,8 @@ impl<'a> Step<'a> { vec![self.tool_linkchecker(stage), self.doc(stage)] } Source::CheckCargoTest { stage } => { - vec![self.tool_cargotest(stage)] + vec![self.tool_cargotest(stage), + self.librustc(self.compiler(stage))] } Source::CheckTidy { stage } => { vec![self.tool_tidy(stage)] @@ -333,7 +334,7 @@ impl<'a> Step<'a> { vec![self.librustc(self.compiler(stage))] } Source::ToolCargoTest { stage } => { - vec![self.librustc(self.compiler(stage))] + vec![self.libstd(self.compiler(stage))] } Source::DistDocs { stage } => vec![self.doc(stage)], diff --git a/src/rustc/Cargo.lock b/src/rustc/Cargo.lock index 4b5c2850dab08..a3420d75218fb 100644 --- a/src/rustc/Cargo.lock +++ b/src/rustc/Cargo.lock @@ -73,7 +73,7 @@ dependencies = [ "rbml 0.0.0", "rustc_back 0.0.0", "rustc_bitflags 0.0.0", - "rustc_const_eval 0.0.0", + "rustc_const_math 0.0.0", "rustc_data_structures 0.0.0", "serialize 0.0.0", "syntax 0.0.0", @@ -106,6 +106,19 @@ dependencies = [ [[package]] name = "rustc_const_eval" version = "0.0.0" +dependencies = [ + "graphviz 0.0.0", + "log 0.0.0", + "rustc 0.0.0", + "rustc_back 0.0.0", + "rustc_const_math 0.0.0", + "serialize 0.0.0", + "syntax 0.0.0", +] + +[[package]] +name = "rustc_const_math" +version = "0.0.0" dependencies = [ "log 0.0.0", "serialize 0.0.0", @@ -131,6 +144,8 @@ dependencies = [ "rustc 0.0.0", "rustc_back 0.0.0", "rustc_borrowck 0.0.0", + "rustc_const_eval 0.0.0", + "rustc_incremental 0.0.0", "rustc_lint 0.0.0", "rustc_llvm 0.0.0", "rustc_metadata 0.0.0", @@ -147,6 +162,19 @@ dependencies = [ "syntax_ext 0.0.0", ] +[[package]] +name = "rustc_incremental" +version = "0.0.0" +dependencies = [ + "graphviz 0.0.0", + "log 0.0.0", + "rbml 0.0.0", + "rustc 0.0.0", + "rustc_data_structures 0.0.0", + "serialize 0.0.0", + "syntax 0.0.0", +] + [[package]] name = "rustc_lint" version = "0.0.0" @@ -154,6 +182,7 @@ dependencies = [ "log 0.0.0", "rustc 0.0.0", "rustc_back 0.0.0", + "rustc_const_eval 0.0.0", "syntax 0.0.0", ] @@ -176,7 +205,7 @@ dependencies = [ "rustc 0.0.0", "rustc_back 0.0.0", "rustc_bitflags 0.0.0", - "rustc_const_eval 0.0.0", + "rustc_const_math 0.0.0", "rustc_llvm 0.0.0", "serialize 0.0.0", "syntax 0.0.0", @@ -191,6 +220,7 @@ dependencies = [ "rustc 0.0.0", "rustc_back 0.0.0", "rustc_const_eval 0.0.0", + "rustc_const_math 0.0.0", "rustc_data_structures 0.0.0", "syntax 0.0.0", ] @@ -201,6 +231,7 @@ version = "0.0.0" dependencies = [ "log 0.0.0", "rustc 0.0.0", + "rustc_const_eval 0.0.0", "syntax 0.0.0", ] @@ -247,7 +278,6 @@ version = "0.0.0" dependencies = [ "log 0.0.0", "rustc 0.0.0", - "rustc_front 0.0.0", "syntax 0.0.0", ] @@ -262,7 +292,9 @@ dependencies = [ "rustc 0.0.0", "rustc_back 0.0.0", "rustc_const_eval 0.0.0", + "rustc_const_math 0.0.0", "rustc_data_structures 0.0.0", + "rustc_incremental 0.0.0", "rustc_llvm 0.0.0", "rustc_mir 0.0.0", "rustc_platform_intrinsics 0.0.0", @@ -280,6 +312,7 @@ dependencies = [ "rustc 0.0.0", "rustc_back 0.0.0", "rustc_const_eval 0.0.0", + "rustc_const_math 0.0.0", "rustc_platform_intrinsics 0.0.0", "syntax 0.0.0", ] @@ -294,6 +327,7 @@ dependencies = [ "log 0.0.0", "rustc 0.0.0", "rustc_back 0.0.0", + "rustc_const_eval 0.0.0", "rustc_driver 0.0.0", "rustc_lint 0.0.0", "rustc_metadata 0.0.0", diff --git a/src/tools/cargotest/Cargo.lock b/src/tools/cargotest/Cargo.lock index 30b1427733307..bafde903baa44 100644 --- a/src/tools/cargotest/Cargo.lock +++ b/src/tools/cargotest/Cargo.lock @@ -1,28 +1,4 @@ [root] name = "cargotest" version = "0.1.0" -dependencies = [ - "tempdir 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "libc" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "rand" -version = "0.3.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "tempdir" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", -] diff --git a/src/tools/cargotest/Cargo.toml b/src/tools/cargotest/Cargo.toml index 2c7e235e0b506..8108c7f762eeb 100644 --- a/src/tools/cargotest/Cargo.toml +++ b/src/tools/cargotest/Cargo.toml @@ -3,9 +3,6 @@ name = "cargotest" version = "0.1.0" authors = ["Brian Anderson "] -[dependencies] -tempdir = "0.3.4" - [[bin]] name = "cargotest" path = "main.rs" diff --git a/src/tools/cargotest/main.rs b/src/tools/cargotest/main.rs index 87a0103867595..7ad54c5bf6be4 100644 --- a/src/tools/cargotest/main.rs +++ b/src/tools/cargotest/main.rs @@ -8,73 +8,90 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -extern crate tempdir; - -use tempdir::TempDir; use std::env; use std::process::Command; -use std::path::Path; +use std::path::{Path, PathBuf}; use std::fs::File; use std::io::Write; -const TEST_REPOS: &'static [(&'static str, &'static str, Option<&'static str>)] = &[ - ("https://github.com/rust-lang/cargo", - "fae9c539388f1b7c70c31fd0a21b5dd9cd071177", - None), - ("https://github.com/iron/iron", - "16c858ec2901e2992fe5e529780f59fa8ed12903", - Some(include_str!("lockfiles/iron-Cargo.lock"))) +struct Test { + repo: &'static str, + name: &'static str, + sha: &'static str, + lock: Option<&'static str>, +} + +const TEST_REPOS: &'static [Test] = &[ + Test { + name: "cargo", + repo: "https://github.com/rust-lang/cargo", + sha: "fae9c539388f1b7c70c31fd0a21b5dd9cd071177", + lock: None, + }, + Test { + name: "iron", + repo: "https://github.com/iron/iron", + sha: "16c858ec2901e2992fe5e529780f59fa8ed12903", + lock: Some(include_str!("lockfiles/iron-Cargo.lock")), + }, ]; fn main() { - let ref cargo = env::args().collect::>()[1]; + let args = env::args().collect::>(); + let ref cargo = args[1]; + let out_dir = Path::new(&args[2]); let ref cargo = Path::new(cargo); - for &(repo, sha, lockfile) in TEST_REPOS.iter().rev() { - test_repo(cargo, repo, sha, lockfile); + for test in TEST_REPOS.iter().rev() { + test_repo(cargo, out_dir, test); } } -fn test_repo(cargo: &Path, repo: &str, sha: &str, lockfile: Option<&str>) { - println!("testing {}", repo); - let dir = clone_repo(repo, sha); - if let Some(lockfile) = lockfile { - File::create(&dir.path().join("Cargo.lock")).expect("") +fn test_repo(cargo: &Path, out_dir: &Path, test: &Test) { + println!("testing {}", test.repo); + let dir = clone_repo(test, out_dir); + if let Some(lockfile) = test.lock { + File::create(&dir.join("Cargo.lock")).expect("") .write_all(lockfile.as_bytes()).expect(""); } - if !run_cargo_test(cargo, dir.path()) { - panic!("tests failed for {}", repo); + if !run_cargo_test(cargo, &dir) { + panic!("tests failed for {}", test.repo); } } -fn clone_repo(repo: &str, sha: &str) -> TempDir { - let dir = TempDir::new("cargotest").expect(""); - let status = Command::new("git") - .arg("init") - .arg(dir.path()) - .status() - .expect(""); - assert!(status.success()); +fn clone_repo(test: &Test, out_dir: &Path) -> PathBuf { + let out_dir = out_dir.join(test.name); - // Try progressively deeper fetch depths to find the commit - let mut found = false; - for depth in &[1, 10, 100, 1000, 100000] { + if !out_dir.join(".git").is_dir() { let status = Command::new("git") - .arg("fetch") - .arg(repo) - .arg("master") - .arg(&format!("--depth={}", depth)) - .current_dir(dir.path()) + .arg("init") + .arg(&out_dir) .status() .expect(""); assert!(status.success()); + } + + // Try progressively deeper fetch depths to find the commit + let mut found = false; + for depth in &[0, 1, 10, 100, 1000, 100000] { + if *depth > 0 { + let status = Command::new("git") + .arg("fetch") + .arg(test.repo) + .arg("master") + .arg(&format!("--depth={}", depth)) + .current_dir(&out_dir) + .status() + .expect(""); + assert!(status.success()); + } let status = Command::new("git") .arg("reset") - .arg(sha) + .arg(test.sha) .arg("--hard") - .current_dir(dir.path()) + .current_dir(&out_dir) .status() .expect(""); @@ -84,9 +101,18 @@ fn clone_repo(repo: &str, sha: &str) -> TempDir { } } - if !found { panic!("unable to find commit {}", sha) } + if !found { + panic!("unable to find commit {}", test.sha) + } + let status = Command::new("git") + .arg("clean") + .arg("-fdx") + .current_dir(&out_dir) + .status() + .unwrap(); + assert!(status.success()); - dir + out_dir } fn run_cargo_test(cargo_path: &Path, crate_path: &Path) -> bool {