Skip to content

rustbuild: Use Cargo's "target runner" #43534

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
Jul 29, 2017
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
80 changes: 13 additions & 67 deletions src/bootstrap/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1050,11 +1050,8 @@ impl Step for Crate {
dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());

if target.contains("emscripten") || build.remote_tested(target) {
cargo.arg("--no-run");
}

cargo.arg("--");
cargo.args(&build.flags.cmd.test_args());

if build.config.quiet_tests {
cargo.arg("--quiet");
Expand All @@ -1063,75 +1060,24 @@ impl Step for Crate {
let _time = util::timeit();

if target.contains("emscripten") {
build.run(&mut cargo);
krate_emscripten(build, compiler, target, mode);
cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
build.config.nodejs.as_ref().expect("nodejs not configured"));
} else if build.remote_tested(target) {
build.run(&mut cargo);
krate_remote(builder, compiler, target, mode);
} else {
cargo.args(&build.flags.cmd.test_args());
try_run(build, &mut cargo);
}
}
}

fn krate_emscripten(build: &Build,
compiler: Compiler,
target: Interned<String>,
mode: Mode) {
let out_dir = build.cargo_out(compiler, mode, target);
let tests = find_tests(&out_dir.join("deps"), target);

let nodejs = build.config.nodejs.as_ref().expect("nodejs not configured");
for test in tests {
println!("running {}", test.display());
let mut cmd = Command::new(nodejs);
cmd.arg(&test);
if build.config.quiet_tests {
cmd.arg("--quiet");
}
try_run(build, &mut cmd);
}
}

fn krate_remote(builder: &Builder,
compiler: Compiler,
target: Interned<String>,
mode: Mode) {
let build = builder.build;
let out_dir = build.cargo_out(compiler, mode, target);
let tests = find_tests(&out_dir.join("deps"), target);

let tool = builder.tool_exe(Tool::RemoteTestClient);
for test in tests {
let mut cmd = Command::new(&tool);
cmd.arg("run")
.arg(&test);
if build.config.quiet_tests {
cmd.arg("--quiet");
cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
format!("{} run",
builder.tool_exe(Tool::RemoteTestClient).display()));
}
cmd.args(&build.flags.cmd.test_args());
try_run(build, &mut cmd);
try_run(build, &mut cargo);
}
}

fn find_tests(dir: &Path, target: Interned<String>) -> Vec<PathBuf> {
let mut dst = Vec::new();
for e in t!(dir.read_dir()).map(|e| t!(e)) {
let file_type = t!(e.file_type());
if !file_type.is_file() {
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.ends_with(".js") &&
!filename.ends_with(".asm.js")) {
dst.push(e.path());
fn envify(s: &str) -> String {
s.chars().map(|c| {
match c {
'-' => '_',
c => c,
}
}
dst
}).flat_map(|c| c.to_uppercase()).collect()
}

/// Some test suites are run inside emulators or on remote devices, and most
Expand Down
15 changes: 13 additions & 2 deletions src/libstd/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1417,8 +1417,19 @@ mod tests {
let output = String::from_utf8(result.stdout).unwrap();

for (ref k, ref v) in env::vars() {
// don't check android RANDOM variables
if cfg!(target_os = "android") && *k == "RANDOM" {
// Don't check android RANDOM variable which seems to change
// whenever the shell runs, and our `env_cmd` is indeed running a
// shell which means it'll get a different RANDOM than we probably
// have.
//
// Also skip env vars with `-` in the name on android because, well,
// I'm not sure. It appears though that the `set` command above does
// not print env vars with `-` in the name, so we just skip them
// here as we won't find them in the output. Note that most env vars
// use `_` instead of `-`, but our build system sets a few env vars
// with `-` in the name.
if cfg!(target_os = "android") &&
(*k == "RANDOM" || k.contains("-")) {
continue
}

Expand Down