@@ -20,11 +20,22 @@ pub struct Std {
20
20
///
21
21
/// [`compile::Rustc`]: crate::core::build_steps::compile::Rustc
22
22
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 > ,
23
30
}
24
31
25
32
impl Std {
26
33
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 }
28
39
}
29
40
}
30
41
@@ -38,7 +49,7 @@ impl Step for Std {
38
49
39
50
fn make_run ( run : RunConfig < ' _ > ) {
40
51
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 } ) ;
42
53
}
43
54
44
55
fn run ( self , builder : & Builder < ' _ > ) {
@@ -53,7 +64,7 @@ impl Step for Std {
53
64
Mode :: Std ,
54
65
SourceType :: InTree ,
55
66
target,
56
- builder. kind ,
67
+ self . override_build_kind . unwrap_or ( builder. kind ) ,
57
68
) ;
58
69
59
70
std_cargo ( builder, target, compiler. stage , & mut cargo) ;
@@ -107,7 +118,7 @@ impl Step for Std {
107
118
Mode :: Std ,
108
119
SourceType :: InTree ,
109
120
target,
110
- builder. kind ,
121
+ self . override_build_kind . unwrap_or ( builder. kind ) ,
111
122
) ;
112
123
113
124
// If we're not in stage 0, tests and examples will fail to compile
@@ -148,16 +159,31 @@ pub struct Rustc {
148
159
///
149
160
/// [`compile::Rustc`]: crate::core::build_steps::compile::Rustc
150
161
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 > ,
151
169
}
152
170
153
171
impl Rustc {
154
172
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 {
155
181
let crates = builder
156
182
. in_tree_crates ( "rustc-main" , Some ( target) )
157
183
. into_iter ( )
158
184
. map ( |krate| krate. name . to_string ( ) )
159
185
. collect ( ) ;
160
- Self { target, crates }
186
+ Self { target, crates, override_build_kind : kind }
161
187
}
162
188
}
163
189
@@ -172,7 +198,7 @@ impl Step for Rustc {
172
198
173
199
fn make_run ( run : RunConfig < ' _ > ) {
174
200
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 } ) ;
176
202
}
177
203
178
204
/// Builds the compiler.
@@ -193,7 +219,7 @@ impl Step for Rustc {
193
219
builder. ensure ( crate :: core:: build_steps:: compile:: Std :: new ( compiler, compiler. host ) ) ;
194
220
builder. ensure ( crate :: core:: build_steps:: compile:: Std :: new ( compiler, target) ) ;
195
221
} else {
196
- builder. ensure ( Std :: new ( target) ) ;
222
+ builder. ensure ( Std :: new_with_build_kind ( target, self . override_build_kind ) ) ;
197
223
}
198
224
199
225
let mut cargo = builder:: Cargo :: new (
@@ -202,7 +228,7 @@ impl Step for Rustc {
202
228
Mode :: Rustc ,
203
229
SourceType :: InTree ,
204
230
target,
205
- builder. kind ,
231
+ self . override_build_kind . unwrap_or ( builder. kind ) ,
206
232
) ;
207
233
208
234
rustc_cargo ( builder, & mut cargo, target, & compiler) ;
0 commit comments