rustbuild: Use Cargo's "target runner"
This commit leverages a relatively new feature in Cargo to execute cross-compiled tests, the `target.$target.runner` configuration. We configure it through environment variables in rustbuild and this avoids the need for us to locate and run tests after-the-fact, instead relying on Cargo to do all that execution for us.
This commit is contained in:
parent
eba9d7f08c
commit
8e7849e766
2 changed files with 26 additions and 69 deletions
|
@ -1050,11 +1050,8 @@ impl Step for Crate {
|
||||||
dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
|
dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
|
||||||
cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
|
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.arg("--");
|
||||||
|
cargo.args(&build.flags.cmd.test_args());
|
||||||
|
|
||||||
if build.config.quiet_tests {
|
if build.config.quiet_tests {
|
||||||
cargo.arg("--quiet");
|
cargo.arg("--quiet");
|
||||||
|
@ -1063,75 +1060,24 @@ impl Step for Crate {
|
||||||
let _time = util::timeit();
|
let _time = util::timeit();
|
||||||
|
|
||||||
if target.contains("emscripten") {
|
if target.contains("emscripten") {
|
||||||
build.run(&mut cargo);
|
cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
|
||||||
krate_emscripten(build, compiler, target, mode);
|
build.config.nodejs.as_ref().expect("nodejs not configured"));
|
||||||
} else if build.remote_tested(target) {
|
} else if build.remote_tested(target) {
|
||||||
build.run(&mut cargo);
|
cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
|
||||||
krate_remote(builder, compiler, target, mode);
|
format!("{} run",
|
||||||
} else {
|
builder.tool_exe(Tool::RemoteTestClient).display()));
|
||||||
cargo.args(&build.flags.cmd.test_args());
|
|
||||||
try_run(build, &mut cargo);
|
|
||||||
}
|
}
|
||||||
|
try_run(build, &mut cargo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn krate_emscripten(build: &Build,
|
fn envify(s: &str) -> String {
|
||||||
compiler: Compiler,
|
s.chars().map(|c| {
|
||||||
target: Interned<String>,
|
match c {
|
||||||
mode: Mode) {
|
'-' => '_',
|
||||||
let out_dir = build.cargo_out(compiler, mode, target);
|
c => c,
|
||||||
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);
|
}).flat_map(|c| c.to_uppercase()).collect()
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
cmd.args(&build.flags.cmd.test_args());
|
|
||||||
try_run(build, &mut cmd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dst
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Some test suites are run inside emulators or on remote devices, and most
|
/// Some test suites are run inside emulators or on remote devices, and most
|
||||||
|
|
|
@ -1417,8 +1417,19 @@ mod tests {
|
||||||
let output = String::from_utf8(result.stdout).unwrap();
|
let output = String::from_utf8(result.stdout).unwrap();
|
||||||
|
|
||||||
for (ref k, ref v) in env::vars() {
|
for (ref k, ref v) in env::vars() {
|
||||||
// don't check android RANDOM variables
|
// Don't check android RANDOM variable which seems to change
|
||||||
if cfg!(target_os = "android") && *k == "RANDOM" {
|
// 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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue