Skip to content

Commit 92ca0a6

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

File tree

3 files changed

+37
-11
lines changed

3 files changed

+37
-11
lines changed

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

+34-8
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+
/// Override `Builder::kind` on cargo invocations.
24+
///
25+
/// By default, `Builder::kind` is propagated as the subcommand to the cargo invocations.
26+
/// However, there are cases when this is not desirable. For example, when running `x clippy $tool_name`,
27+
/// passing `Builder::kind` to cargo invocations would run clippy on the entire compiler and library,
28+
/// which is not useful if we only want to lint a few crates with specific rules.
29+
override_build_kind: Option<Kind>,
2330
}
2431

2532
impl Std {
2633
pub fn new(target: TargetSelection) -> Self {
27-
Self { target, crates: vec![] }
34+
Self::new_with_build_kind(target, None)
35+
}
36+
37+
pub fn new_with_build_kind(target: TargetSelection, kind: Option<Kind>) -> Self {
38+
Self { target, crates: vec![], override_build_kind: kind }
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, override_build_kind: None });
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+
self.override_build_kind.unwrap_or(builder.kind),
5768
);
5869

5970
std_cargo(builder, target, compiler.stage, &mut cargo);
@@ -107,7 +118,7 @@ impl Step for Std {
107118
Mode::Std,
108119
SourceType::InTree,
109120
target,
110-
builder.kind,
121+
self.override_build_kind.unwrap_or(builder.kind),
111122
);
112123

113124
// If we're not in stage 0, tests and examples will fail to compile
@@ -148,16 +159,31 @@ pub struct Rustc {
148159
///
149160
/// [`compile::Rustc`]: crate::core::build_steps::compile::Rustc
150161
crates: Vec<String>,
162+
/// Override `Builder::kind` on cargo invocations.
163+
///
164+
/// By default, `Builder::kind` is propagated as the subcommand to the cargo invocations.
165+
/// However, there are cases when this is not desirable. For example, when running `x clippy $tool_name`,
166+
/// passing `Builder::kind` to cargo invocations would run clippy on the entire compiler and library,
167+
/// which is not useful if we only want to lint a few crates with specific rules.
168+
override_build_kind: Option<Kind>,
151169
}
152170

153171
impl Rustc {
154172
pub fn new(target: TargetSelection, builder: &Builder<'_>) -> Self {
173+
Self::new_with_build_kind(target, builder, None)
174+
}
175+
176+
pub fn new_with_build_kind(
177+
target: TargetSelection,
178+
builder: &Builder<'_>,
179+
kind: Option<Kind>,
180+
) -> Self {
155181
let crates = builder
156182
.in_tree_crates("rustc-main", Some(target))
157183
.into_iter()
158184
.map(|krate| krate.name.to_string())
159185
.collect();
160-
Self { target, crates }
186+
Self { target, crates, override_build_kind: kind }
161187
}
162188
}
163189

@@ -172,7 +198,7 @@ impl Step for Rustc {
172198

173199
fn make_run(run: RunConfig<'_>) {
174200
let crates = run.make_run_crates(Alias::Compiler);
175-
run.builder.ensure(Rustc { target: run.target, crates });
201+
run.builder.ensure(Rustc { target: run.target, crates, override_build_kind: None });
176202
}
177203

178204
/// Builds the compiler.
@@ -193,7 +219,7 @@ impl Step for Rustc {
193219
builder.ensure(crate::core::build_steps::compile::Std::new(compiler, compiler.host));
194220
builder.ensure(crate::core::build_steps::compile::Std::new(compiler, target));
195221
} else {
196-
builder.ensure(Std::new(target));
222+
builder.ensure(Std::new_with_build_kind(target, self.override_build_kind));
197223
}
198224

199225
let mut cargo = builder::Cargo::new(
@@ -202,7 +228,7 @@ impl Step for Rustc {
202228
Mode::Rustc,
203229
SourceType::InTree,
204230
target,
205-
builder.kind,
231+
self.override_build_kind.unwrap_or(builder.kind),
206232
);
207233

208234
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_build_kind(target, Some(Kind::Check)));
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_build_kind(target, builder, Some(Kind::Check)));
271271

272272
let cargo = prepare_tool_cargo(
273273
builder,

src/bootstrap/src/core/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ impl<'a> ShouldRun<'a> {
689689
}
690690
}
691691

692-
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
692+
#[derive(Debug, Copy, Clone, Eq, Hash, PartialEq, PartialOrd, Ord, ValueEnum)]
693693
pub enum Kind {
694694
#[value(alias = "b")]
695695
Build,

0 commit comments

Comments
 (0)