@@ -12,16 +12,6 @@ use crate::core::builder::{
12
12
use crate :: core:: config:: TargetSelection ;
13
13
use crate :: { Compiler , Mode , Subcommand } ;
14
14
15
- pub fn cargo_subcommand ( kind : Kind ) -> & ' static str {
16
- match kind {
17
- Kind :: Check
18
- // We ensure check steps for both std and rustc from build_steps/clippy, so handle `Kind::Clippy` as well.
19
- | Kind :: Clippy => "check" ,
20
- Kind :: Fix => "fix" ,
21
- _ => unreachable ! ( ) ,
22
- }
23
- }
24
-
25
15
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
26
16
pub struct Std {
27
17
pub target : TargetSelection ,
@@ -31,11 +21,22 @@ pub struct Std {
31
21
///
32
22
/// [`compile::Rustc`]: crate::core::build_steps::compile::Rustc
33
23
crates : Vec < String > ,
24
+ /// Override `Builder::kind` on cargo invocations.
25
+ ///
26
+ /// By default, `Builder::kind` is propagated as the subcommand to the cargo invocations.
27
+ /// However, there are cases when this is not desirable. For example, when running `x clippy $tool_name`,
28
+ /// passing `Builder::kind` to cargo invocations would run clippy on the entire compiler and library,
29
+ /// which is not useful if we only want to lint a few crates with specific rules.
30
+ override_build_kind : Option < Kind > ,
34
31
}
35
32
36
33
impl Std {
37
34
pub fn new ( target : TargetSelection ) -> Self {
38
- Self { target, crates : vec ! [ ] }
35
+ Self :: new_with_build_kind ( target, None )
36
+ }
37
+
38
+ pub fn new_with_build_kind ( target : TargetSelection , kind : Option < Kind > ) -> Self {
39
+ Self { target, crates : vec ! [ ] , override_build_kind : kind }
39
40
}
40
41
}
41
42
@@ -49,7 +50,7 @@ impl Step for Std {
49
50
50
51
fn make_run ( run : RunConfig < ' _ > ) {
51
52
let crates = run. make_run_crates ( Alias :: Library ) ;
52
- run. builder . ensure ( Std { target : run. target , crates } ) ;
53
+ run. builder . ensure ( Std { target : run. target , crates, override_build_kind : None } ) ;
53
54
}
54
55
55
56
fn run ( self , builder : & Builder < ' _ > ) {
@@ -64,7 +65,7 @@ impl Step for Std {
64
65
Mode :: Std ,
65
66
SourceType :: InTree ,
66
67
target,
67
- cargo_subcommand ( builder. kind ) ,
68
+ self . override_build_kind . unwrap_or ( builder. kind ) ,
68
69
) ;
69
70
70
71
std_cargo ( builder, target, compiler. stage , & mut cargo) ;
@@ -118,7 +119,7 @@ impl Step for Std {
118
119
Mode :: Std ,
119
120
SourceType :: InTree ,
120
121
target,
121
- cargo_subcommand ( builder. kind ) ,
122
+ self . override_build_kind . unwrap_or ( builder. kind ) ,
122
123
) ;
123
124
124
125
// If we're not in stage 0, tests and examples will fail to compile
@@ -159,16 +160,31 @@ pub struct Rustc {
159
160
///
160
161
/// [`compile::Rustc`]: crate::core::build_steps::compile::Rustc
161
162
crates : Vec < String > ,
163
+ /// Override `Builder::kind` on cargo invocations.
164
+ ///
165
+ /// By default, `Builder::kind` is propagated as the subcommand to the cargo invocations.
166
+ /// However, there are cases when this is not desirable. For example, when running `x clippy $tool_name`,
167
+ /// passing `Builder::kind` to cargo invocations would run clippy on the entire compiler and library,
168
+ /// which is not useful if we only want to lint a few crates with specific rules.
169
+ override_build_kind : Option < Kind > ,
162
170
}
163
171
164
172
impl Rustc {
165
173
pub fn new ( target : TargetSelection , builder : & Builder < ' _ > ) -> Self {
174
+ Self :: new_with_build_kind ( target, builder, None )
175
+ }
176
+
177
+ pub fn new_with_build_kind (
178
+ target : TargetSelection ,
179
+ builder : & Builder < ' _ > ,
180
+ kind : Option < Kind > ,
181
+ ) -> Self {
166
182
let crates = builder
167
183
. in_tree_crates ( "rustc-main" , Some ( target) )
168
184
. into_iter ( )
169
185
. map ( |krate| krate. name . to_string ( ) )
170
186
. collect ( ) ;
171
- Self { target, crates }
187
+ Self { target, crates, override_build_kind : kind }
172
188
}
173
189
}
174
190
@@ -183,7 +199,7 @@ impl Step for Rustc {
183
199
184
200
fn make_run ( run : RunConfig < ' _ > ) {
185
201
let crates = run. make_run_crates ( Alias :: Compiler ) ;
186
- run. builder . ensure ( Rustc { target : run. target , crates } ) ;
202
+ run. builder . ensure ( Rustc { target : run. target , crates, override_build_kind : None } ) ;
187
203
}
188
204
189
205
/// Builds the compiler.
@@ -204,7 +220,7 @@ impl Step for Rustc {
204
220
builder. ensure ( crate :: core:: build_steps:: compile:: Std :: new ( compiler, compiler. host ) ) ;
205
221
builder. ensure ( crate :: core:: build_steps:: compile:: Std :: new ( compiler, target) ) ;
206
222
} else {
207
- builder. ensure ( Std :: new ( target) ) ;
223
+ builder. ensure ( Std :: new_with_build_kind ( target, self . override_build_kind ) ) ;
208
224
}
209
225
210
226
let mut cargo = builder:: Cargo :: new (
@@ -213,7 +229,7 @@ impl Step for Rustc {
213
229
Mode :: Rustc ,
214
230
SourceType :: InTree ,
215
231
target,
216
- cargo_subcommand ( builder. kind ) ,
232
+ self . override_build_kind . unwrap_or ( builder. kind ) ,
217
233
) ;
218
234
219
235
rustc_cargo ( builder, & mut cargo, target, & compiler) ;
@@ -291,7 +307,7 @@ impl Step for CodegenBackend {
291
307
Mode :: Codegen ,
292
308
SourceType :: InTree ,
293
309
target,
294
- cargo_subcommand ( builder. kind ) ,
310
+ builder. kind ,
295
311
) ;
296
312
297
313
cargo
@@ -349,7 +365,7 @@ impl Step for RustAnalyzer {
349
365
compiler,
350
366
Mode :: ToolRustc ,
351
367
target,
352
- cargo_subcommand ( builder. kind ) ,
368
+ builder. kind ,
353
369
"src/tools/rust-analyzer" ,
354
370
SourceType :: InTree ,
355
371
& [ "in-rust-tree" . to_owned ( ) ] ,
@@ -417,7 +433,7 @@ macro_rules! tool_check_step {
417
433
compiler,
418
434
Mode :: ToolRustc ,
419
435
target,
420
- cargo_subcommand ( builder. kind) ,
436
+ builder. kind,
421
437
$path,
422
438
$source_type,
423
439
& [ ] ,
0 commit comments