Skip to content

Commit af13338

Browse files
Check test/example/benchmark on x.py check
Often when modifying compiler code you'll miss that you've changed an API used by unit tests, since x.py check didn't previously catch that. It's also useful to have this for editing with rust-analyzer and similar tooling where editing tests previously didn't notify you of errors in test files.
1 parent 2276991 commit af13338

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

src/bootstrap/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ impl<'a> Builder<'a> {
382382
native::Lld
383383
),
384384
Kind::Check | Kind::Clippy | Kind::Fix | Kind::Format => {
385-
describe!(check::Std, check::Rustc, check::Rustdoc, check::Clippy)
385+
describe!(check::Std, check::Rustc, check::Rustdoc, check::Clippy, check::Bootstrap)
386386
}
387387
Kind::Test => describe!(
388388
crate::toolstate::ToolStateCheck,

src/bootstrap/check.rs

+60-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,43 @@ impl Step for Std {
6666
let libdir = builder.sysroot_libdir(compiler, target);
6767
let hostdir = builder.sysroot_libdir(compiler, compiler.host);
6868
add_to_sysroot(&builder, &libdir, &hostdir, &libstd_stamp(builder, compiler, target));
69+
70+
// Then run cargo again, once we've put the rmeta files for the library
71+
// crates into the sysroot. This is needed because e.g., core's tests
72+
// depend on `libtest` -- Cargo presumes it will exist, but it doesn't
73+
// since we initialize with an empty sysroot.
74+
//
75+
// Currently only the "libtest" tree of crates does this.
76+
77+
let mut cargo = builder.cargo(
78+
compiler,
79+
Mode::Std,
80+
SourceType::InTree,
81+
target,
82+
cargo_subcommand(builder.kind),
83+
);
84+
std_cargo(builder, target, compiler.stage, &mut cargo);
85+
cargo.arg("--all-targets");
86+
87+
// Explicitly pass -p for all dependencies krates -- this will force cargo
88+
// to also check the tests/benches/examples for these crates, rather
89+
// than just the leaf crate.
90+
for krate in builder.in_tree_crates("test") {
91+
cargo.arg("-p").arg(krate.name);
92+
}
93+
94+
builder.info(&format!(
95+
"Checking std test/bench/example targets ({} -> {})",
96+
&compiler.host, target
97+
));
98+
run_cargo(
99+
builder,
100+
cargo,
101+
args(builder.kind),
102+
&libstd_test_stamp(builder, compiler, target),
103+
vec![],
104+
true,
105+
);
69106
}
70107
}
71108

@@ -106,6 +143,14 @@ impl Step for Rustc {
106143
cargo_subcommand(builder.kind),
107144
);
108145
rustc_cargo(builder, &mut cargo, target);
146+
cargo.arg("--all-targets");
147+
148+
// Explicitly pass -p for all compiler krates -- this will force cargo
149+
// to also check the tests/benches/examples for these crates, rather
150+
// than just the leaf crate.
151+
for krate in builder.in_tree_crates("rustc-main") {
152+
cargo.arg("-p").arg(krate.name);
153+
}
109154

110155
builder.info(&format!("Checking compiler artifacts ({} -> {})", &compiler.host, target));
111156
run_cargo(
@@ -149,7 +194,7 @@ macro_rules! tool_check_step {
149194

150195
builder.ensure(Rustc { target });
151196

152-
let cargo = prepare_tool_cargo(
197+
let mut cargo = prepare_tool_cargo(
153198
builder,
154199
compiler,
155200
Mode::ToolRustc,
@@ -160,6 +205,8 @@ macro_rules! tool_check_step {
160205
&[],
161206
);
162207

208+
cargo.arg("--all-targets");
209+
163210
builder.info(&format!(
164211
"Checking {} artifacts ({} -> {})",
165212
stringify!($name).to_lowercase(),
@@ -202,12 +249,24 @@ tool_check_step!(Rustdoc, "src/tools/rustdoc", SourceType::InTree);
202249
// rejected.
203250
tool_check_step!(Clippy, "src/tools/clippy", SourceType::InTree);
204251

252+
tool_check_step!(Bootstrap, "src/bootstrap", SourceType::InTree);
253+
205254
/// Cargo's output path for the standard library in a given stage, compiled
206255
/// by a particular compiler for the specified target.
207256
fn libstd_stamp(builder: &Builder<'_>, compiler: Compiler, target: TargetSelection) -> PathBuf {
208257
builder.cargo_out(compiler, Mode::Std, target).join(".libstd-check.stamp")
209258
}
210259

260+
/// Cargo's output path for the standard library in a given stage, compiled
261+
/// by a particular compiler for the specified target.
262+
fn libstd_test_stamp(
263+
builder: &Builder<'_>,
264+
compiler: Compiler,
265+
target: TargetSelection,
266+
) -> PathBuf {
267+
builder.cargo_out(compiler, Mode::Std, target).join(".libstd-check-test.stamp")
268+
}
269+
211270
/// Cargo's output path for librustc in a given stage, compiled by a particular
212271
/// compiler for the specified target.
213272
fn librustc_stamp(builder: &Builder<'_>, compiler: Compiler, target: TargetSelection) -> PathBuf {

0 commit comments

Comments
 (0)