Skip to content

Commit f296163

Browse files
Place all-targets checking behind a flag
This matches Cargo behavior and avoids the (somewhat expensive) double checking, as well as the unfortunate duplicate error messages (#76822, rust-lang/cargo#5128).
1 parent 8876ffc commit f296163

File tree

4 files changed

+50
-33
lines changed

4 files changed

+50
-33
lines changed

src/bootstrap/CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

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

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

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

src/bootstrap/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ impl<'a> Builder<'a> {
532532
pub fn new(build: &Build) -> Builder<'_> {
533533
let (kind, paths) = match build.config.cmd {
534534
Subcommand::Build { ref paths } => (Kind::Build, &paths[..]),
535-
Subcommand::Check { ref paths } => (Kind::Check, &paths[..]),
535+
Subcommand::Check { ref paths, all_targets: _ } => (Kind::Check, &paths[..]),
536536
Subcommand::Clippy { ref paths } => (Kind::Clippy, &paths[..]),
537537
Subcommand::Fix { ref paths } => (Kind::Fix, &paths[..]),
538538
Subcommand::Doc { ref paths, .. } => (Kind::Doc, &paths[..]),

src/bootstrap/check.rs

+39-30
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
//! Implementation of compiling the compiler and standard library, in "check"-based modes.
22
3-
use crate::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
43
use crate::compile::{add_to_sysroot, run_cargo, rustc_cargo, std_cargo};
54
use crate::config::TargetSelection;
65
use crate::tool::{prepare_tool_cargo, SourceType};
6+
use crate::{
7+
builder::{Builder, Kind, RunConfig, ShouldRun, Step},
8+
Subcommand,
9+
};
710
use crate::{Compiler, Mode};
811
use std::path::PathBuf;
912

@@ -74,35 +77,37 @@ impl Step for Std {
7477
//
7578
// Currently only the "libtest" tree of crates does this.
7679

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");
80+
if let Subcommand::Check { all_targets: true, .. } = builder.config.cmd {
81+
let mut cargo = builder.cargo(
82+
compiler,
83+
Mode::Std,
84+
SourceType::InTree,
85+
target,
86+
cargo_subcommand(builder.kind),
87+
);
88+
std_cargo(builder, target, compiler.stage, &mut cargo);
89+
cargo.arg("--all-targets");
90+
91+
// Explicitly pass -p for all dependencies krates -- this will force cargo
92+
// to also check the tests/benches/examples for these crates, rather
93+
// than just the leaf crate.
94+
for krate in builder.in_tree_crates("test") {
95+
cargo.arg("-p").arg(krate.name);
96+
}
8697

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);
98+
builder.info(&format!(
99+
"Checking std test/bench/example targets ({} -> {})",
100+
&compiler.host, target
101+
));
102+
run_cargo(
103+
builder,
104+
cargo,
105+
args(builder.kind),
106+
&libstd_test_stamp(builder, compiler, target),
107+
vec![],
108+
true,
109+
);
92110
}
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-
);
106111
}
107112
}
108113

@@ -143,7 +148,9 @@ impl Step for Rustc {
143148
cargo_subcommand(builder.kind),
144149
);
145150
rustc_cargo(builder, &mut cargo, target);
146-
cargo.arg("--all-targets");
151+
if let Subcommand::Check { all_targets: true, .. } = builder.config.cmd {
152+
cargo.arg("--all-targets");
153+
}
147154

148155
// Explicitly pass -p for all compiler krates -- this will force cargo
149156
// to also check the tests/benches/examples for these crates, rather
@@ -205,7 +212,9 @@ macro_rules! tool_check_step {
205212
&[],
206213
);
207214

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

210219
builder.info(&format!(
211220
"Checking {} artifacts ({} -> {})",

src/bootstrap/flags.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ pub enum Subcommand {
4747
paths: Vec<PathBuf>,
4848
},
4949
Check {
50+
// Whether to run checking over all targets (e.g., unit / integration
51+
// tests).
52+
all_targets: bool,
5053
paths: Vec<PathBuf>,
5154
},
5255
Clippy {
@@ -250,6 +253,9 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
250253
`/<build_base>/rustfix_missing_coverage.txt`",
251254
);
252255
}
256+
"check" => {
257+
opts.optflag("", "all-targets", "Check all targets");
258+
}
253259
"bench" => {
254260
opts.optmulti("", "test-args", "extra arguments", "ARGS");
255261
}
@@ -484,7 +490,9 @@ Arguments:
484490

485491
let cmd = match subcommand.as_str() {
486492
"build" | "b" => Subcommand::Build { paths },
487-
"check" | "c" => Subcommand::Check { paths },
493+
"check" | "c" => {
494+
Subcommand::Check { paths, all_targets: matches.opt_present("all-targets") }
495+
}
488496
"clippy" => Subcommand::Clippy { paths },
489497
"fix" => Subcommand::Fix { paths },
490498
"test" | "t" => Subcommand::Test {

0 commit comments

Comments
 (0)