Skip to content

Commit 021f2ff

Browse files
committed
Update CargoTest
1 parent 21d7a54 commit 021f2ff

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

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

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ impl Step for HtmlCheck {
228228
/// order to test cargo.
229229
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
230230
pub struct Cargotest {
231-
stage: u32,
231+
build_compiler: Compiler,
232232
host: TargetSelection,
233233
}
234234

@@ -241,17 +241,26 @@ impl Step for Cargotest {
241241
}
242242

243243
fn make_run(run: RunConfig<'_>) {
244-
run.builder.ensure(Cargotest { stage: run.builder.top_stage, host: run.target });
244+
// FIXME: support testing stage 0 cargo?
245+
assert!(run.builder.top_stage > 0);
246+
run.builder.ensure(Cargotest {
247+
build_compiler: run.builder.compiler(run.builder.top_stage - 1, run.target),
248+
host: run.target,
249+
});
245250
}
246251

247252
/// Runs the `cargotest` tool as compiled in `stage` by the `host` compiler.
248253
///
249254
/// This tool in `src/tools` will check out a few Rust projects and run `cargo
250255
/// test` to ensure that we don't regress the test suites there.
251256
fn run(self, builder: &Builder<'_>) {
252-
let compiler = builder.compiler(self.stage, self.host);
253-
builder.ensure(compile::Rustc::new(compiler, compiler.host));
254-
let cargo = builder.ensure(tool::Cargo { compiler, target: compiler.host });
257+
// Here we need to ensure that we run cargo with an in-tree compiler, because we test
258+
// both their behavior together.
259+
// We can build cargo with the earlier stage compiler though.
260+
let cargo =
261+
builder.ensure(tool::Cargo { compiler: self.build_compiler, target: self.host });
262+
let tested_compiler = builder.compiler(self.build_compiler.stage + 1, self.host);
263+
builder.std(tested_compiler, self.host);
255264

256265
// Note that this is a short, cryptic, and not scoped directory name. This
257266
// is currently to minimize the length of path on Windows where we otherwise
@@ -264,17 +273,21 @@ impl Step for Cargotest {
264273
cmd.arg(&cargo.tool_path)
265274
.arg(&out_dir)
266275
.args(builder.config.test_args())
267-
.env("RUSTC", builder.rustc(compiler))
268-
.env("RUSTDOC", builder.rustdoc_for_compiler(compiler));
276+
.env("RUSTC", builder.rustc(tested_compiler))
277+
.env("RUSTDOC", builder.rustdoc_for_compiler(tested_compiler));
269278
add_rustdoc_cargo_linker_args(
270279
&mut cmd,
271280
builder,
272-
compiler.host,
281+
tested_compiler.host,
273282
LldThreads::No,
274-
compiler.stage,
283+
tested_compiler.stage,
275284
);
276285
cmd.delay_failure().run(builder);
277286
}
287+
288+
fn metadata(&self) -> Option<StepMetadata> {
289+
Some(StepMetadata::test("cargotest", self.host).stage(self.build_compiler.stage + 1))
290+
}
278291
}
279292

280293
/// Runs `cargo test` for cargo itself.

src/bootstrap/src/core/builder/tests.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,6 +1599,23 @@ mod snapshot {
15991599
steps.assert_contains_fuzzy(StepMetadata::build("rustc", host));
16001600
}
16011601

1602+
#[test]
1603+
fn test_cargotest() {
1604+
let ctx = TestCtx::new();
1605+
insta::assert_snapshot!(
1606+
ctx.config("test")
1607+
.path("cargotest")
1608+
.render_steps(), @r"
1609+
[build] rustc 0 <host> -> cargo 1 <host>
1610+
[build] llvm <host>
1611+
[build] rustc 0 <host> -> rustc 1 <host>
1612+
[build] rustc 1 <host> -> std 1 <host>
1613+
[build] rustc 0 <host> -> CargoTest 1 <host>
1614+
[build] rustdoc 1 <host>
1615+
[test] cargotest 1 <host>
1616+
");
1617+
}
1618+
16021619
#[test]
16031620
fn doc_library() {
16041621
let ctx = TestCtx::new();

0 commit comments

Comments
 (0)