@@ -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
2532impl 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
153171impl 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) ;
0 commit comments