Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x.py check checks tests/examples/benches #76258

Merged
merged 2 commits into from
Sep 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ impl<'a> Builder<'a> {
native::Lld
),
Kind::Check | Kind::Clippy | Kind::Fix | Kind::Format => {
describe!(check::Std, check::Rustc, check::Rustdoc, check::Clippy)
describe!(check::Std, check::Rustc, check::Rustdoc, check::Clippy, check::Bootstrap)
}
Kind::Test => describe!(
crate::toolstate::ToolStateCheck,
Expand Down
65 changes: 62 additions & 3 deletions src/bootstrap/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,43 @@ impl Step for Std {
let libdir = builder.sysroot_libdir(compiler, target);
let hostdir = builder.sysroot_libdir(compiler, compiler.host);
add_to_sysroot(&builder, &libdir, &hostdir, &libstd_stamp(builder, compiler, target));

// Then run cargo again, once we've put the rmeta files for the library
// crates into the sysroot. This is needed because e.g., core's tests
// depend on `libtest` -- Cargo presumes it will exist, but it doesn't
// since we initialize with an empty sysroot.
//
// Currently only the "libtest" tree of crates does this.

let mut cargo = builder.cargo(
compiler,
Mode::Std,
SourceType::InTree,
target,
cargo_subcommand(builder.kind),
);
std_cargo(builder, target, compiler.stage, &mut cargo);
cargo.arg("--all-targets");

// Explicitly pass -p for all dependencies krates -- this will force cargo
// to also check the tests/benches/examples for these crates, rather
// than just the leaf crate.
for krate in builder.in_tree_crates("test") {
cargo.arg("-p").arg(krate.name);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels rather error-prone and annoying to do, but AFAICT there's no better way to get the behavior we want from Cargo. If we don't do this it'll only test the leaf crate (e.g., rustc-main) which is useless for bootstrap.

--workspace is too broad -- we want something like --dependencies-too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, right. Yea, this is probably the best way to do it. Considering in_tree_crates is used elsewhere, I think it should be relatively reliable for now.


builder.info(&format!(
"Checking std test/bench/example targets ({} -> {})",
&compiler.host, target
));
run_cargo(
builder,
cargo,
args(builder.kind),
&libstd_test_stamp(builder, compiler, target),
vec![],
true,
);
}
}

Expand Down Expand Up @@ -106,6 +143,14 @@ impl Step for Rustc {
cargo_subcommand(builder.kind),
);
rustc_cargo(builder, &mut cargo, target);
cargo.arg("--all-targets");

// Explicitly pass -p for all compiler krates -- this will force cargo
// to also check the tests/benches/examples for these crates, rather
// than just the leaf crate.
for krate in builder.in_tree_crates("rustc-main") {
cargo.arg("-p").arg(krate.name);
}

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

builder.ensure(Rustc { target });

let cargo = prepare_tool_cargo(
let mut cargo = prepare_tool_cargo(
builder,
compiler,
Mode::ToolRustc,
Expand All @@ -160,12 +205,14 @@ macro_rules! tool_check_step {
&[],
);

println!(
cargo.arg("--all-targets");

builder.info(&format!(
"Checking {} artifacts ({} -> {})",
stringify!($name).to_lowercase(),
&compiler.host.triple,
target.triple
);
));
run_cargo(
builder,
cargo,
Expand Down Expand Up @@ -202,12 +249,24 @@ tool_check_step!(Rustdoc, "src/tools/rustdoc", SourceType::InTree);
// rejected.
tool_check_step!(Clippy, "src/tools/clippy", SourceType::InTree);

tool_check_step!(Bootstrap, "src/bootstrap", SourceType::InTree);

/// Cargo's output path for the standard library in a given stage, compiled
/// by a particular compiler for the specified target.
fn libstd_stamp(builder: &Builder<'_>, compiler: Compiler, target: TargetSelection) -> PathBuf {
builder.cargo_out(compiler, Mode::Std, target).join(".libstd-check.stamp")
}

/// Cargo's output path for the standard library in a given stage, compiled
/// by a particular compiler for the specified target.
fn libstd_test_stamp(
builder: &Builder<'_>,
compiler: Compiler,
target: TargetSelection,
) -> PathBuf {
builder.cargo_out(compiler, Mode::Std, target).join(".libstd-check-test.stamp")
}

/// Cargo's output path for librustc in a given stage, compiled by a particular
/// compiler for the specified target.
fn librustc_stamp(builder: &Builder<'_>, compiler: Compiler, target: TargetSelection) -> PathBuf {
Expand Down