Skip to content

Commit

Permalink
Place all-targets checking behind a flag
Browse files Browse the repository at this point in the history
This matches Cargo behavior and avoids the (somewhat expensive) double checking,
as well as the unfortunate duplicate error messages (#76822,
rust-lang/cargo#5128).
  • Loading branch information
Mark-Simulacrum committed Oct 3, 2020
1 parent 8876ffc commit f296163
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/bootstrap/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Non-breaking changes since the last major version]

None.
- x.py check needs opt-in to check tests (--all-targets) [#77473](https://github.com/rust-lang/rust/pull/77473)

## [Version 2] - 2020-09-25

Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ impl<'a> Builder<'a> {
pub fn new(build: &Build) -> Builder<'_> {
let (kind, paths) = match build.config.cmd {
Subcommand::Build { ref paths } => (Kind::Build, &paths[..]),
Subcommand::Check { ref paths } => (Kind::Check, &paths[..]),
Subcommand::Check { ref paths, all_targets: _ } => (Kind::Check, &paths[..]),
Subcommand::Clippy { ref paths } => (Kind::Clippy, &paths[..]),
Subcommand::Fix { ref paths } => (Kind::Fix, &paths[..]),
Subcommand::Doc { ref paths, .. } => (Kind::Doc, &paths[..]),
Expand Down
69 changes: 39 additions & 30 deletions src/bootstrap/check.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
//! Implementation of compiling the compiler and standard library, in "check"-based modes.

use crate::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
use crate::compile::{add_to_sysroot, run_cargo, rustc_cargo, std_cargo};
use crate::config::TargetSelection;
use crate::tool::{prepare_tool_cargo, SourceType};
use crate::{
builder::{Builder, Kind, RunConfig, ShouldRun, Step},
Subcommand,
};
use crate::{Compiler, Mode};
use std::path::PathBuf;

Expand Down Expand Up @@ -74,35 +77,37 @@ impl Step for Std {
//
// 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");
if let Subcommand::Check { all_targets: true, .. } = builder.config.cmd {
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);
}

// 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);
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,
);
}

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 @@ -143,7 +148,9 @@ impl Step for Rustc {
cargo_subcommand(builder.kind),
);
rustc_cargo(builder, &mut cargo, target);
cargo.arg("--all-targets");
if let Subcommand::Check { all_targets: true, .. } = builder.config.cmd {
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
Expand Down Expand Up @@ -205,7 +212,9 @@ macro_rules! tool_check_step {
&[],
);

cargo.arg("--all-targets");
if let Subcommand::Check { all_targets: true, .. } = builder.config.cmd {
cargo.arg("--all-targets");
}

builder.info(&format!(
"Checking {} artifacts ({} -> {})",
Expand Down
10 changes: 9 additions & 1 deletion src/bootstrap/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ pub enum Subcommand {
paths: Vec<PathBuf>,
},
Check {
// Whether to run checking over all targets (e.g., unit / integration
// tests).
all_targets: bool,
paths: Vec<PathBuf>,
},
Clippy {
Expand Down Expand Up @@ -250,6 +253,9 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
`/<build_base>/rustfix_missing_coverage.txt`",
);
}
"check" => {
opts.optflag("", "all-targets", "Check all targets");
}
"bench" => {
opts.optmulti("", "test-args", "extra arguments", "ARGS");
}
Expand Down Expand Up @@ -484,7 +490,9 @@ Arguments:

let cmd = match subcommand.as_str() {
"build" | "b" => Subcommand::Build { paths },
"check" | "c" => Subcommand::Check { paths },
"check" | "c" => {
Subcommand::Check { paths, all_targets: matches.opt_present("all-targets") }
}
"clippy" => Subcommand::Clippy { paths },
"fix" => Subcommand::Fix { paths },
"test" | "t" => Subcommand::Test {
Expand Down

0 comments on commit f296163

Please sign in to comment.