Skip to content

cargotest: Put output in build directory #32972

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/bootstrap/build/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions src/bootstrap/build/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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)],
Expand Down
40 changes: 37 additions & 3 deletions src/rustc/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 0 additions & 24 deletions src/tools/cargotest/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions src/tools/cargotest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ name = "cargotest"
version = "0.1.0"
authors = ["Brian Anderson <banderson@mozilla.com>"]

[dependencies]
tempdir = "0.3.4"

[[bin]]
name = "cargotest"
path = "main.rs"
108 changes: 67 additions & 41 deletions src/tools/cargotest/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>()[1];
let args = env::args().collect::<Vec<_>>();
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("");

Expand All @@ -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 {
Expand Down