Skip to content

Commit 6348fac

Browse files
committed
switch Crate to run_cargo_test
1 parent d49c7d6 commit 6348fac

File tree

1 file changed

+43
-61
lines changed

1 file changed

+43
-61
lines changed

src/bootstrap/test.rs

+43-61
Original file line numberDiff line numberDiff line change
@@ -2102,8 +2102,13 @@ impl Step for CrateLibrustc {
21022102
}
21032103

21042104
// Given a `cargo test` subcommand, pass it the appropriate test flags given a `builder`.
2105-
fn cargo_test_args(cargo: &mut Command, libtest_args: &[&str], _crates: &[&str], builder: &Builder<'_>) {
2106-
if !builder.fail_fast {
2105+
fn run_cargo_test(cargo: impl Into<Command>, libtest_args: &[&str], crates: &[Interned<String>], compiler: Compiler, target: TargetSelection, builder: &Builder<'_>) {
2106+
let mut cargo = cargo.into();
2107+
2108+
// Pass in some standard flags then iterate over the graph we've discovered
2109+
// in `cargo metadata` with the maps above and figure out what `-p`
2110+
// arguments need to get passed.
2111+
if builder.kind == Kind::Test && !builder.fail_fast {
21072112
cargo.arg("--no-fail-fast");
21082113
}
21092114
match builder.doc_tests {
@@ -2116,8 +2121,38 @@ fn cargo_test_args(cargo: &mut Command, libtest_args: &[&str], _crates: &[&str],
21162121
DocTests::Yes => {}
21172122
}
21182123

2124+
for &krate in crates {
2125+
cargo.arg("-p").arg(krate);
2126+
}
2127+
2128+
// The tests are going to run with the *target* libraries, so we need to
2129+
// ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
2130+
//
2131+
// Note that to run the compiler we need to run with the *host* libraries,
2132+
// but our wrapper scripts arrange for that to be the case anyway.
2133+
let mut dylib_path = dylib_path();
2134+
dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
2135+
cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
2136+
2137+
if target.contains("emscripten") {
2138+
cargo.env(
2139+
format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)),
2140+
builder.config.nodejs.as_ref().expect("nodejs not configured"),
2141+
);
2142+
} else if target.starts_with("wasm32") {
2143+
let node = builder.config.nodejs.as_ref().expect("nodejs not configured");
2144+
let runner = format!("{} {}/src/etc/wasm32-shim.js", node.display(), builder.src.display());
2145+
cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)), &runner);
2146+
} else if builder.remote_tested(target) {
2147+
cargo.env(
2148+
format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)),
2149+
format!("{} run 0", builder.tool_exe(Tool::RemoteTestClient).display()),
2150+
);
2151+
}
2152+
21192153
cargo.arg("--").args(&builder.config.cmd.test_args()).args(libtest_args);
2120-
add_flags_and_try_run_tests(builder, cargo);
2154+
let _time = util::timeit(&builder);
2155+
add_flags_and_try_run_tests(builder, &mut cargo);
21212156
}
21222157

21232158
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
@@ -2183,60 +2218,6 @@ impl Step for Crate {
21832218
_ => panic!("can only test libraries"),
21842219
};
21852220

2186-
// Build up the base `cargo test` command.
2187-
//
2188-
// Pass in some standard flags then iterate over the graph we've discovered
2189-
// in `cargo metadata` with the maps above and figure out what `-p`
2190-
// arguments need to get passed.
2191-
if builder.kind == Kind::Test && !builder.fail_fast {
2192-
cargo.arg("--no-fail-fast");
2193-
}
2194-
match builder.doc_tests {
2195-
DocTests::Only => {
2196-
cargo.arg("--doc");
2197-
}
2198-
DocTests::No => {
2199-
cargo.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
2200-
}
2201-
DocTests::Yes => {}
2202-
}
2203-
2204-
for krate in &self.crates {
2205-
cargo.arg("-p").arg(krate);
2206-
}
2207-
2208-
// The tests are going to run with the *target* libraries, so we need to
2209-
// ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
2210-
//
2211-
// Note that to run the compiler we need to run with the *host* libraries,
2212-
// but our wrapper scripts arrange for that to be the case anyway.
2213-
let mut dylib_path = dylib_path();
2214-
dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
2215-
cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
2216-
2217-
cargo.arg("--");
2218-
cargo.args(&builder.config.cmd.test_args());
2219-
2220-
cargo.arg("-Z").arg("unstable-options");
2221-
cargo.arg("--format").arg("json");
2222-
2223-
if target.contains("emscripten") {
2224-
cargo.env(
2225-
format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)),
2226-
builder.config.nodejs.as_ref().expect("nodejs not configured"),
2227-
);
2228-
} else if target.starts_with("wasm32") {
2229-
let node = builder.config.nodejs.as_ref().expect("nodejs not configured");
2230-
let runner =
2231-
format!("{} {}/src/etc/wasm32-shim.js", node.display(), builder.src.display());
2232-
cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)), &runner);
2233-
} else if builder.remote_tested(target) {
2234-
cargo.env(
2235-
format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)),
2236-
format!("{} run 0", builder.tool_exe(Tool::RemoteTestClient).display()),
2237-
);
2238-
}
2239-
22402221
builder.info(&format!(
22412222
"{}{} stage{} ({} -> {})",
22422223
builder.kind.test_description(),
@@ -2245,8 +2226,7 @@ impl Step for Crate {
22452226
&compiler.host,
22462227
target
22472228
));
2248-
let _time = util::timeit(&builder);
2249-
crate::render_tests::try_run_tests(builder, &mut cargo.into());
2229+
run_cargo_test(cargo, &[], &self.crates, compiler, target, builder);
22502230
}
22512231
}
22522232

@@ -2569,13 +2549,15 @@ impl Step for Bootstrap {
25692549
check_bootstrap.arg("bootstrap_test.py").current_dir(builder.src.join("src/bootstrap/"));
25702550
try_run(builder, &mut check_bootstrap);
25712551

2552+
let host = builder.config.build;
2553+
let compiler = builder.compiler(0, host);
25722554
let mut cmd = Command::new(&builder.initial_cargo);
25732555
cmd.arg("test")
25742556
.current_dir(builder.src.join("src/bootstrap"))
25752557
.env("RUSTFLAGS", "-Cdebuginfo=2")
25762558
.env("CARGO_TARGET_DIR", builder.out.join("bootstrap"))
25772559
.env("RUSTC_BOOTSTRAP", "1")
2578-
.env("RUSTDOC", builder.rustdoc(builder.compiler(0, builder.build.build)))
2560+
.env("RUSTDOC", builder.rustdoc(compiler))
25792561
.env("RUSTC", &builder.initial_rustc);
25802562
if let Some(flags) = option_env!("RUSTFLAGS") {
25812563
// Use the same rustc flags for testing as for "normal" compilation,
@@ -2585,7 +2567,7 @@ impl Step for Bootstrap {
25852567
}
25862568
// rustbuild tests are racy on directory creation so just run them one at a time.
25872569
// Since there's not many this shouldn't be a problem.
2588-
cargo_test_args(&mut cmd, &["--test-threads=1"], &[], builder);
2570+
run_cargo_test(cmd, &["--test-threads=1"], &[], compiler, host, builder);
25892571
}
25902572

25912573
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {

0 commit comments

Comments
 (0)