Skip to content

Commit de0bedd

Browse files
committed
improve check::{Std, Rustc} to handle clippy properly
Signed-off-by: onur-ozkan <[email protected]>
1 parent d94e7ff commit de0bedd

File tree

2 files changed

+40
-9
lines changed

2 files changed

+40
-9
lines changed

src/bootstrap/src/core/build_steps/check.rs

+38-7
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,22 @@ pub struct Std {
2020
///
2121
/// [`compile::Rustc`]: crate::core::build_steps::compile::Rustc
2222
crates: Vec<String>,
23+
/// Whether to force `Kind::Check` on cargo invocations.
24+
///
25+
/// By default, `Builder::kind` is propagated to the cargo invocations. However, there are cases
26+
/// when this is not desirable. For example, when running `x clippy $tool_name`, passing `Builder::kind`
27+
/// to cargo invocations would run clippy on the entire compiler and library, which is not useful if
28+
/// we only want to lint a few crates with specific rules.
29+
force_check: bool,
2330
}
2431

2532
impl Std {
2633
pub fn new(target: TargetSelection) -> Self {
27-
Self { target, crates: vec![] }
34+
Self { target, crates: vec![], force_check: false }
35+
}
36+
37+
pub fn new_with_force_check_flag(target: TargetSelection, force_check: bool) -> Self {
38+
Self { target, crates: vec![], force_check }
2839
}
2940
}
3041

@@ -38,7 +49,7 @@ impl Step for Std {
3849

3950
fn make_run(run: RunConfig<'_>) {
4051
let crates = run.make_run_crates(Alias::Library);
41-
run.builder.ensure(Std { target: run.target, crates });
52+
run.builder.ensure(Std { target: run.target, crates, force_check: false });
4253
}
4354

4455
fn run(self, builder: &Builder<'_>) {
@@ -53,7 +64,7 @@ impl Step for Std {
5364
Mode::Std,
5465
SourceType::InTree,
5566
target,
56-
builder.kind,
67+
if self.force_check { Kind::Check } else { builder.kind },
5768
);
5869

5970
std_cargo(builder, target, compiler.stage, &mut cargo);
@@ -148,6 +159,13 @@ pub struct Rustc {
148159
///
149160
/// [`compile::Rustc`]: crate::core::build_steps::compile::Rustc
150161
crates: Vec<String>,
162+
/// Whether to force `Kind::Check` on cargo invocations.
163+
///
164+
/// By default, `Builder::kind` is propagated to the cargo invocations. However, there are cases
165+
/// when this is not desirable. For example, when running `x clippy $tool_name`, passing `Builder::kind`
166+
/// to cargo invocations would run clippy on the entire compiler and library, which is not useful if
167+
/// we only want to lint a few crates with specific rules.
168+
force_check: bool,
151169
}
152170

153171
impl Rustc {
@@ -157,7 +175,20 @@ impl Rustc {
157175
.into_iter()
158176
.map(|krate| krate.name.to_string())
159177
.collect();
160-
Self { target, crates }
178+
Self { target, crates, force_check: false }
179+
}
180+
181+
pub fn new_with_force_check_flag(
182+
target: TargetSelection,
183+
builder: &Builder<'_>,
184+
force_check: bool,
185+
) -> Self {
186+
let crates = builder
187+
.in_tree_crates("rustc-main", Some(target))
188+
.into_iter()
189+
.map(|krate| krate.name.to_string())
190+
.collect();
191+
Self { target, crates, force_check }
161192
}
162193
}
163194

@@ -172,7 +203,7 @@ impl Step for Rustc {
172203

173204
fn make_run(run: RunConfig<'_>) {
174205
let crates = run.make_run_crates(Alias::Compiler);
175-
run.builder.ensure(Rustc { target: run.target, crates });
206+
run.builder.ensure(Rustc { target: run.target, crates, force_check: false });
176207
}
177208

178209
/// Builds the compiler.
@@ -193,7 +224,7 @@ impl Step for Rustc {
193224
builder.ensure(crate::core::build_steps::compile::Std::new(compiler, compiler.host));
194225
builder.ensure(crate::core::build_steps::compile::Std::new(compiler, target));
195226
} else {
196-
builder.ensure(Std::new(target));
227+
builder.ensure(Std::new_with_force_check_flag(target, self.force_check));
197228
}
198229

199230
let mut cargo = builder::Cargo::new(
@@ -202,7 +233,7 @@ impl Step for Rustc {
202233
Mode::Rustc,
203234
SourceType::InTree,
204235
target,
205-
builder.kind,
236+
if self.force_check { Kind::Check } else { builder.kind },
206237
);
207238

208239
rustc_cargo(builder, &mut cargo, target, &compiler);

src/bootstrap/src/core/build_steps/clippy.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ impl Step for Rustc {
200200
builder.ensure(compile::Std::new(compiler, compiler.host));
201201
builder.ensure(compile::Std::new(compiler, target));
202202
} else {
203-
builder.ensure(check::Std::new(target));
203+
builder.ensure(check::Std::new_with_force_check_flag(target, true));
204204
}
205205

206206
let mut cargo = builder::Cargo::new(
@@ -267,7 +267,7 @@ macro_rules! lint_any {
267267
let compiler = builder.compiler(builder.top_stage, builder.config.build);
268268
let target = self.target;
269269

270-
builder.ensure(check::Rustc::new(target, builder));
270+
builder.ensure(check::Rustc::new_with_force_check_flag(target, builder, true));
271271

272272
let cargo = prepare_tool_cargo(
273273
builder,

0 commit comments

Comments
 (0)