Skip to content
/ rust Public
forked from rust-lang/rust

Commit 5c448d0

Browse files
authored
Rollup merge of rust-lang#135887 - onur-ozkan:testing-improvements, r=jieyouxu
improvements on `build_steps::test` implementation Reviewing commits one-by-one should make it easier to understand.
2 parents 8edd3ea + e3a5314 commit 5c448d0

File tree

3 files changed

+37
-65
lines changed

3 files changed

+37
-65
lines changed

src/bootstrap/src/core/build_steps/test.rs

+32-64
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl Step for CrateBootstrap {
8787
&[],
8888
);
8989
let crate_name = path.rsplit_once('/').unwrap().1;
90-
run_cargo_test(cargo, &[], &[], crate_name, crate_name, compiler, bootstrap_host, builder);
90+
run_cargo_test(cargo, &[], &[], crate_name, crate_name, bootstrap_host, builder);
9191
}
9292
}
9393

@@ -143,7 +143,6 @@ You can skip linkcheck with --skip src/tools/linkchecker"
143143
&[],
144144
"linkchecker",
145145
"linkchecker self tests",
146-
compiler,
147146
bootstrap_host,
148147
builder,
149148
);
@@ -312,7 +311,7 @@ impl Step for Cargo {
312311
);
313312

314313
// NOTE: can't use `run_cargo_test` because we need to overwrite `PATH`
315-
let mut cargo = prepare_cargo_test(cargo, &[], &[], "cargo", compiler, self.host, builder);
314+
let mut cargo = prepare_cargo_test(cargo, &[], &[], "cargo", self.host, builder);
316315

317316
// Don't run cross-compile tests, we may not have cross-compiled libstd libs
318317
// available.
@@ -397,7 +396,7 @@ impl Step for RustAnalyzer {
397396
cargo.env("SKIP_SLOW_TESTS", "1");
398397

399398
cargo.add_rustc_lib_path(builder);
400-
run_cargo_test(cargo, &[], &[], "rust-analyzer", "rust-analyzer", compiler, host, builder);
399+
run_cargo_test(cargo, &[], &[], "rust-analyzer", "rust-analyzer", host, builder);
401400
}
402401
}
403402

@@ -445,7 +444,7 @@ impl Step for Rustfmt {
445444

446445
cargo.add_rustc_lib_path(builder);
447446

448-
run_cargo_test(cargo, &[], &[], "rustfmt", "rustfmt", compiler, host, builder);
447+
run_cargo_test(cargo, &[], &[], "rustfmt", "rustfmt", host, builder);
449448
}
450449
}
451450

@@ -565,7 +564,7 @@ impl Step for Miri {
565564

566565
// We can NOT use `run_cargo_test` since Miri's integration tests do not use the usual test
567566
// harness and therefore do not understand the flags added by `add_flags_and_try_run_test`.
568-
let mut cargo = prepare_cargo_test(cargo, &[], &[], "miri", host_compiler, host, builder);
567+
let mut cargo = prepare_cargo_test(cargo, &[], &[], "miri", host, builder);
569568

570569
// miri tests need to know about the stage sysroot
571570
cargo.env("MIRI_SYSROOT", &miri_sysroot);
@@ -713,16 +712,7 @@ impl Step for CompiletestTest {
713712
&[],
714713
);
715714
cargo.allow_features("test");
716-
run_cargo_test(
717-
cargo,
718-
&[],
719-
&[],
720-
"compiletest",
721-
"compiletest self test",
722-
compiler,
723-
host,
724-
builder,
725-
);
715+
run_cargo_test(cargo, &[], &[], "compiletest", "compiletest self test", host, builder);
726716
}
727717
}
728718

@@ -769,7 +759,7 @@ impl Step for Clippy {
769759
cargo.env("HOST_LIBS", host_libs);
770760

771761
cargo.add_rustc_lib_path(builder);
772-
let cargo = prepare_cargo_test(cargo, &[], &[], "clippy", compiler, host, builder);
762+
let cargo = prepare_cargo_test(cargo, &[], &[], "clippy", host, builder);
773763

774764
let _guard = builder.msg_sysroot_tool(Kind::Test, compiler.stage, "clippy", host, host);
775765

@@ -1294,7 +1284,6 @@ impl Step for CrateRunMakeSupport {
12941284
&[],
12951285
"run-make-support",
12961286
"run-make-support self test",
1297-
compiler,
12981287
host,
12991288
builder,
13001289
);
@@ -1334,16 +1323,7 @@ impl Step for CrateBuildHelper {
13341323
&[],
13351324
);
13361325
cargo.allow_features("test");
1337-
run_cargo_test(
1338-
cargo,
1339-
&[],
1340-
&[],
1341-
"build_helper",
1342-
"build_helper self test",
1343-
compiler,
1344-
host,
1345-
builder,
1346-
);
1326+
run_cargo_test(cargo, &[], &[], "build_helper", "build_helper self test", host, builder);
13471327
}
13481328
}
13491329

@@ -2540,19 +2520,17 @@ impl Step for CrateLibrustc {
25402520
/// Given a `cargo test` subcommand, add the appropriate flags and run it.
25412521
///
25422522
/// Returns whether the test succeeded.
2543-
#[allow(clippy::too_many_arguments)] // FIXME: reduce the number of args and remove this.
25442523
fn run_cargo_test<'a>(
2545-
cargo: impl Into<BootstrapCommand>,
2524+
cargo: builder::Cargo,
25462525
libtest_args: &[&str],
25472526
crates: &[String],
25482527
primary_crate: &str,
25492528
description: impl Into<Option<&'a str>>,
2550-
compiler: Compiler,
25512529
target: TargetSelection,
25522530
builder: &Builder<'_>,
25532531
) -> bool {
2554-
let mut cargo =
2555-
prepare_cargo_test(cargo, libtest_args, crates, primary_crate, compiler, target, builder);
2532+
let compiler = cargo.compiler();
2533+
let mut cargo = prepare_cargo_test(cargo, libtest_args, crates, primary_crate, target, builder);
25562534
let _time = helpers::timeit(builder);
25572535
let _group = description.into().and_then(|what| {
25582536
builder.msg_sysroot_tool(Kind::Test, compiler.stage, what, compiler.host, target)
@@ -2573,15 +2551,15 @@ fn run_cargo_test<'a>(
25732551

25742552
/// Given a `cargo test` subcommand, pass it the appropriate test flags given a `builder`.
25752553
fn prepare_cargo_test(
2576-
cargo: impl Into<BootstrapCommand>,
2554+
cargo: builder::Cargo,
25772555
libtest_args: &[&str],
25782556
crates: &[String],
25792557
primary_crate: &str,
2580-
compiler: Compiler,
25812558
target: TargetSelection,
25822559
builder: &Builder<'_>,
25832560
) -> BootstrapCommand {
2584-
let mut cargo = cargo.into();
2561+
let compiler = cargo.compiler();
2562+
let mut cargo: BootstrapCommand = cargo.into();
25852563

25862564
// Propagate `--bless` if it has not already been set/unset
25872565
// Any tools that want to use this should bless if `RUSTC_BLESS` is set to
@@ -2793,7 +2771,6 @@ impl Step for Crate {
27932771
&self.crates,
27942772
&self.crates[0],
27952773
&*crate_description(&self.crates),
2796-
compiler,
27972774
target,
27982775
builder,
27992776
);
@@ -2895,7 +2872,6 @@ impl Step for CrateRustdoc {
28952872
&["rustdoc:0.0.0".to_string()],
28962873
"rustdoc",
28972874
"rustdoc",
2898-
compiler,
28992875
target,
29002876
builder,
29012877
);
@@ -2956,7 +2932,6 @@ impl Step for CrateRustdocJsonTypes {
29562932
&["rustdoc-json-types".to_string()],
29572933
"rustdoc-json-types",
29582934
"rustdoc-json-types",
2959-
compiler,
29602935
target,
29612936
builder,
29622937
);
@@ -3113,23 +3088,25 @@ impl Step for Bootstrap {
31133088
// Use `python -m unittest` manually if you want to pass arguments.
31143089
check_bootstrap.delay_failure().run(builder);
31153090

3116-
let mut cmd = command(&builder.initial_cargo);
3117-
cmd.arg("test")
3118-
.current_dir(builder.src.join("src/bootstrap"))
3119-
.env("RUSTFLAGS", "--cfg test -Cdebuginfo=2")
3091+
let mut cargo = tool::prepare_tool_cargo(
3092+
builder,
3093+
compiler,
3094+
Mode::ToolBootstrap,
3095+
host,
3096+
Kind::Test,
3097+
"src/bootstrap",
3098+
SourceType::InTree,
3099+
&[],
3100+
);
3101+
3102+
cargo
3103+
.rustflag("-Cdebuginfo=2")
31203104
.env("CARGO_TARGET_DIR", builder.out.join("bootstrap"))
3121-
.env("RUSTC_BOOTSTRAP", "1")
3122-
.env("RUSTDOC", builder.rustdoc(compiler))
3123-
.env("RUSTC", &builder.initial_rustc);
3124-
if let Some(flags) = option_env!("RUSTFLAGS") {
3125-
// Use the same rustc flags for testing as for "normal" compilation,
3126-
// so that Cargo doesn’t recompile the entire dependency graph every time:
3127-
// https://github.com/rust-lang/rust/issues/49215
3128-
cmd.env("RUSTFLAGS", flags);
3129-
}
3105+
.env("RUSTC_BOOTSTRAP", "1");
3106+
31303107
// bootstrap tests are racy on directory creation so just run them one at a time.
31313108
// Since there's not many this shouldn't be a problem.
3132-
run_cargo_test(cmd, &["--test-threads=1"], &[], "bootstrap", None, compiler, host, builder);
3109+
run_cargo_test(cargo, &["--test-threads=1"], &[], "bootstrap", None, host, builder);
31333110
}
31343111

31353112
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
@@ -3254,7 +3231,7 @@ impl Step for RustInstaller {
32543231
bootstrap_host,
32553232
bootstrap_host,
32563233
);
3257-
run_cargo_test(cargo, &[], &[], "installer", None, compiler, bootstrap_host, builder);
3234+
run_cargo_test(cargo, &[], &[], "installer", None, bootstrap_host, builder);
32583235

32593236
// We currently don't support running the test.sh script outside linux(?) environments.
32603237
// Eventually this should likely migrate to #[test]s in rust-installer proper rather than a
@@ -3639,16 +3616,7 @@ impl Step for TestFloatParse {
36393616
&[],
36403617
);
36413618

3642-
run_cargo_test(
3643-
cargo_test,
3644-
&[],
3645-
&[],
3646-
crate_name,
3647-
crate_name,
3648-
compiler,
3649-
bootstrap_host,
3650-
builder,
3651-
);
3619+
run_cargo_test(cargo_test, &[], &[], crate_name, crate_name, bootstrap_host, builder);
36523620

36533621
// Run the actual parse tests.
36543622
let mut cargo_run = tool::prepare_tool_cargo(

src/bootstrap/src/core/builder/cargo.rs

+4
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ impl Cargo {
121121
cargo
122122
}
123123

124+
pub fn compiler(&self) -> Compiler {
125+
self.compiler
126+
}
127+
124128
pub fn into_cmd(self) -> BootstrapCommand {
125129
self.into()
126130
}

src/bootstrap/src/core/config/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ fn detect_src_and_out() {
9292
// `{build-dir}/bootstrap/debug/deps/bootstrap-c7ee91d5661e2804`
9393
// `{build-dir}` can be anywhere, not just in the rust project directory.
9494
let dep = Path::new(args.first().unwrap());
95-
let expected_out = dep.ancestors().nth(4).unwrap();
95+
let expected_out = dep.ancestors().nth(5).unwrap();
9696

9797
assert_eq!(&cfg.out, expected_out);
9898
}

0 commit comments

Comments
 (0)