Skip to content

Commit 73c2d2a

Browse files
committed
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.
1 parent 073a09f commit 73c2d2a

File tree

6 files changed

+118
-75
lines changed

6 files changed

+118
-75
lines changed

src/bootstrap/build/check.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use std::fs;
12+
1113
use build::{Build, Compiler};
1214

1315
pub fn linkcheck(build: &Build, stage: u32, host: &str) {
@@ -29,9 +31,16 @@ pub fn cargotest(build: &Build, stage: u32, host: &str) {
2931
let sep = if cfg!(windows) { ";" } else {":" };
3032
let ref newpath = format!("{}{}{}", path.display(), sep, old_path);
3133

34+
// Note that this is a short, cryptic, and not scoped directory name. This
35+
// is currently to minimize the length of path on Windows where we otherwise
36+
// quickly run into path name limit constraints.
37+
let out_dir = build.out.join("ct");
38+
t!(fs::create_dir_all(&out_dir));
39+
3240
build.run(build.tool_cmd(compiler, "cargotest")
33-
.env("PATH", newpath)
34-
.arg(&build.cargo));
41+
.env("PATH", newpath)
42+
.arg(&build.cargo)
43+
.arg(&out_dir));
3544
}
3645

3746
pub fn tidy(build: &Build, stage: u32, host: &str) {

src/bootstrap/build/step.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,8 @@ impl<'a> Step<'a> {
318318
vec![self.tool_linkchecker(stage), self.doc(stage)]
319319
}
320320
Source::CheckCargoTest { stage } => {
321-
vec![self.tool_cargotest(stage)]
321+
vec![self.tool_cargotest(stage),
322+
self.librustc(self.compiler(stage))]
322323
}
323324
Source::CheckTidy { stage } => {
324325
vec![self.tool_tidy(stage)]
@@ -333,7 +334,7 @@ impl<'a> Step<'a> {
333334
vec![self.librustc(self.compiler(stage))]
334335
}
335336
Source::ToolCargoTest { stage } => {
336-
vec![self.librustc(self.compiler(stage))]
337+
vec![self.libstd(self.compiler(stage))]
337338
}
338339

339340
Source::DistDocs { stage } => vec![self.doc(stage)],

src/rustc/Cargo.lock

+37-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tools/cargotest/Cargo.lock

-24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tools/cargotest/Cargo.toml

-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ name = "cargotest"
33
version = "0.1.0"
44
authors = ["Brian Anderson <banderson@mozilla.com>"]
55

6-
[dependencies]
7-
tempdir = "0.3.4"
8-
96
[[bin]]
107
name = "cargotest"
118
path = "main.rs"

src/tools/cargotest/main.rs

+67-41
Original file line numberDiff line numberDiff line change
@@ -8,73 +8,90 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
extern crate tempdir;
12-
13-
use tempdir::TempDir;
1411
use std::env;
1512
use std::process::Command;
16-
use std::path::Path;
13+
use std::path::{Path, PathBuf};
1714
use std::fs::File;
1815
use std::io::Write;
1916

20-
const TEST_REPOS: &'static [(&'static str, &'static str, Option<&'static str>)] = &[
21-
("https://github.com/rust-lang/cargo",
22-
"fae9c539388f1b7c70c31fd0a21b5dd9cd071177",
23-
None),
24-
("https://github.com/iron/iron",
25-
"16c858ec2901e2992fe5e529780f59fa8ed12903",
26-
Some(include_str!("lockfiles/iron-Cargo.lock")))
17+
struct Test {
18+
repo: &'static str,
19+
name: &'static str,
20+
sha: &'static str,
21+
lock: Option<&'static str>,
22+
}
23+
24+
const TEST_REPOS: &'static [Test] = &[
25+
Test {
26+
name: "cargo",
27+
repo: "https://github.com/rust-lang/cargo",
28+
sha: "fae9c539388f1b7c70c31fd0a21b5dd9cd071177",
29+
lock: None,
30+
},
31+
Test {
32+
name: "iron",
33+
repo: "https://github.com/iron/iron",
34+
sha: "16c858ec2901e2992fe5e529780f59fa8ed12903",
35+
lock: Some(include_str!("lockfiles/iron-Cargo.lock")),
36+
},
2737
];
2838

2939

3040
fn main() {
31-
let ref cargo = env::args().collect::<Vec<_>>()[1];
41+
let args = env::args().collect::<Vec<_>>();
42+
let ref cargo = args[1];
43+
let out_dir = Path::new(&args[2]);
3244
let ref cargo = Path::new(cargo);
3345

34-
for &(repo, sha, lockfile) in TEST_REPOS.iter().rev() {
35-
test_repo(cargo, repo, sha, lockfile);
46+
for test in TEST_REPOS.iter().rev() {
47+
test_repo(cargo, out_dir, test);
3648
}
3749
}
3850

39-
fn test_repo(cargo: &Path, repo: &str, sha: &str, lockfile: Option<&str>) {
40-
println!("testing {}", repo);
41-
let dir = clone_repo(repo, sha);
42-
if let Some(lockfile) = lockfile {
43-
File::create(&dir.path().join("Cargo.lock")).expect("")
51+
fn test_repo(cargo: &Path, out_dir: &Path, test: &Test) {
52+
println!("testing {}", test.repo);
53+
let dir = clone_repo(test, out_dir);
54+
if let Some(lockfile) = test.lock {
55+
File::create(&dir.join("Cargo.lock")).expect("")
4456
.write_all(lockfile.as_bytes()).expect("");
4557
}
46-
if !run_cargo_test(cargo, dir.path()) {
47-
panic!("tests failed for {}", repo);
58+
if !run_cargo_test(cargo, &dir) {
59+
panic!("tests failed for {}", test.repo);
4860
}
4961
}
5062

51-
fn clone_repo(repo: &str, sha: &str) -> TempDir {
52-
let dir = TempDir::new("cargotest").expect("");
53-
let status = Command::new("git")
54-
.arg("init")
55-
.arg(dir.path())
56-
.status()
57-
.expect("");
58-
assert!(status.success());
63+
fn clone_repo(test: &Test, out_dir: &Path) -> PathBuf {
64+
let out_dir = out_dir.join(test.name);
5965

60-
// Try progressively deeper fetch depths to find the commit
61-
let mut found = false;
62-
for depth in &[1, 10, 100, 1000, 100000] {
66+
if !out_dir.join(".git").is_dir() {
6367
let status = Command::new("git")
64-
.arg("fetch")
65-
.arg(repo)
66-
.arg("master")
67-
.arg(&format!("--depth={}", depth))
68-
.current_dir(dir.path())
68+
.arg("init")
69+
.arg(&out_dir)
6970
.status()
7071
.expect("");
7172
assert!(status.success());
73+
}
74+
75+
// Try progressively deeper fetch depths to find the commit
76+
let mut found = false;
77+
for depth in &[0, 1, 10, 100, 1000, 100000] {
78+
if *depth > 0 {
79+
let status = Command::new("git")
80+
.arg("fetch")
81+
.arg(test.repo)
82+
.arg("master")
83+
.arg(&format!("--depth={}", depth))
84+
.current_dir(&out_dir)
85+
.status()
86+
.expect("");
87+
assert!(status.success());
88+
}
7289

7390
let status = Command::new("git")
7491
.arg("reset")
75-
.arg(sha)
92+
.arg(test.sha)
7693
.arg("--hard")
77-
.current_dir(dir.path())
94+
.current_dir(&out_dir)
7895
.status()
7996
.expect("");
8097

@@ -84,9 +101,18 @@ fn clone_repo(repo: &str, sha: &str) -> TempDir {
84101
}
85102
}
86103

87-
if !found { panic!("unable to find commit {}", sha) }
104+
if !found {
105+
panic!("unable to find commit {}", test.sha)
106+
}
107+
let status = Command::new("git")
108+
.arg("clean")
109+
.arg("-fdx")
110+
.current_dir(&out_dir)
111+
.status()
112+
.unwrap();
113+
assert!(status.success());
88114

89-
dir
115+
out_dir
90116
}
91117

92118
fn run_cargo_test(cargo_path: &Path, crate_path: &Path) -> bool {

0 commit comments

Comments
 (0)