@@ -95,7 +95,7 @@ pub struct RunConfig<'a> {
9595 pub builder : & ' a Builder < ' a > ,
9696 pub host : Interned < String > ,
9797 pub target : Interned < String > ,
98- pub path : Option < & ' a Path > ,
98+ pub path : PathBuf ,
9999}
100100
101101struct StepDescription {
@@ -105,6 +105,32 @@ struct StepDescription {
105105 only_build : bool ,
106106 should_run : fn ( ShouldRun ) -> ShouldRun ,
107107 make_run : fn ( RunConfig ) ,
108+ name : & ' static str ,
109+ }
110+
111+ #[ derive( Debug , Clone , PartialOrd , Ord , PartialEq , Eq ) ]
112+ struct PathSet {
113+ set : BTreeSet < PathBuf > ,
114+ }
115+
116+ impl PathSet {
117+ fn empty ( ) -> PathSet {
118+ PathSet { set : BTreeSet :: new ( ) }
119+ }
120+
121+ fn one < P : Into < PathBuf > > ( path : P ) -> PathSet {
122+ let mut set = BTreeSet :: new ( ) ;
123+ set. insert ( path. into ( ) ) ;
124+ PathSet { set }
125+ }
126+
127+ fn has ( & self , needle : & Path ) -> bool {
128+ self . set . iter ( ) . any ( |p| p. ends_with ( needle) )
129+ }
130+
131+ fn path ( & self , builder : & Builder ) -> PathBuf {
132+ self . set . iter ( ) . next ( ) . unwrap_or ( & builder. build . src ) . to_path_buf ( )
133+ }
108134}
109135
110136impl StepDescription {
@@ -116,10 +142,18 @@ impl StepDescription {
116142 only_build : S :: ONLY_BUILD ,
117143 should_run : S :: should_run,
118144 make_run : S :: make_run,
145+ name : unsafe { :: std:: intrinsics:: type_name :: < S > ( ) } ,
119146 }
120147 }
121148
122- fn maybe_run ( & self , builder : & Builder , path : Option < & Path > ) {
149+ fn maybe_run ( & self , builder : & Builder , pathset : & PathSet ) {
150+ if builder. config . exclude . iter ( ) . any ( |e| pathset. has ( e) ) {
151+ eprintln ! ( "Skipping {:?} because it is excluded" , pathset) ;
152+ return ;
153+ } else if !builder. config . exclude . is_empty ( ) {
154+ eprintln ! ( "{:?} not skipped for {:?} -- not in {:?}" , pathset,
155+ self . name, builder. config. exclude) ;
156+ }
123157 let build = builder. build ;
124158 let hosts = if self . only_build_targets || self . only_build {
125159 build. build_triple ( )
@@ -144,7 +178,7 @@ impl StepDescription {
144178 for target in targets {
145179 let run = RunConfig {
146180 builder,
147- path,
181+ path : pathset . path ( builder ) ,
148182 host : * host,
149183 target : * target,
150184 } ;
@@ -157,19 +191,28 @@ impl StepDescription {
157191 let should_runs = v. iter ( ) . map ( |desc| {
158192 ( desc. should_run ) ( ShouldRun :: new ( builder) )
159193 } ) . collect :: < Vec < _ > > ( ) ;
194+
195+ // sanity checks on rules
196+ for ( desc, should_run) in v. iter ( ) . zip ( & should_runs) {
197+ assert ! ( !should_run. paths. is_empty( ) ,
198+ "{:?} should have at least one pathset" , desc. name) ;
199+ }
200+
160201 if paths. is_empty ( ) {
161202 for ( desc, should_run) in v. iter ( ) . zip ( should_runs) {
162203 if desc. default && should_run. is_really_default {
163- desc. maybe_run ( builder, None ) ;
204+ for pathset in & should_run. paths {
205+ desc. maybe_run ( builder, pathset) ;
206+ }
164207 }
165208 }
166209 } else {
167210 for path in paths {
168211 let mut attempted_run = false ;
169212 for ( desc, should_run) in v. iter ( ) . zip ( & should_runs) {
170- if should_run. run ( path) {
213+ if let Some ( pathset ) = should_run. pathset_for_path ( path) {
171214 attempted_run = true ;
172- desc. maybe_run ( builder, Some ( path ) ) ;
215+ desc. maybe_run ( builder, pathset ) ;
173216 }
174217 }
175218
@@ -185,7 +228,7 @@ impl StepDescription {
185228pub struct ShouldRun < ' a > {
186229 pub builder : & ' a Builder < ' a > ,
187230 // use a BTreeSet to maintain sort order
188- paths : BTreeSet < PathBuf > ,
231+ paths : BTreeSet < PathSet > ,
189232
190233 // If this is a default rule, this is an additional constraint placed on
191234 // it's run. Generally something like compiler docs being enabled.
@@ -206,25 +249,46 @@ impl<'a> ShouldRun<'a> {
206249 self
207250 }
208251
252+ // Unlike `krate` this will create just one pathset. As such, it probably shouldn't actually
253+ // ever be used, but as we transition to having all rules properly handle passing krate(...) by
254+ // actually doing something different for every crate passed.
255+ pub fn all_krates ( mut self , name : & str ) -> Self {
256+ let mut set = BTreeSet :: new ( ) ;
257+ for krate in self . builder . in_tree_crates ( name) {
258+ set. insert ( PathBuf :: from ( & krate. path ) ) ;
259+ }
260+ self . paths . insert ( PathSet { set } ) ;
261+ self
262+ }
263+
209264 pub fn krate ( mut self , name : & str ) -> Self {
210- for ( _ , krate_path ) in self . builder . crates ( name) {
211- self . paths . insert ( PathBuf :: from ( krate_path ) ) ;
265+ for krate in self . builder . in_tree_crates ( name) {
266+ self . paths . insert ( PathSet :: one ( & krate . path ) ) ;
212267 }
213268 self
214269 }
215270
216- pub fn path ( mut self , path : & str ) -> Self {
217- self . paths . insert ( PathBuf :: from ( path) ) ;
271+ // single, non-aliased path
272+ pub fn path ( self , path : & str ) -> Self {
273+ self . paths ( & [ path] )
274+ }
275+
276+ // multiple aliases for the same job
277+ pub fn paths ( mut self , paths : & [ & str ] ) -> Self {
278+ self . paths . insert ( PathSet {
279+ set : paths. iter ( ) . map ( PathBuf :: from) . collect ( ) ,
280+ } ) ;
218281 self
219282 }
220283
221284 // allows being more explicit about why should_run in Step returns the value passed to it
222- pub fn never ( self ) -> ShouldRun < ' a > {
285+ pub fn never ( mut self ) -> ShouldRun < ' a > {
286+ self . paths . insert ( PathSet :: empty ( ) ) ;
223287 self
224288 }
225289
226- fn run ( & self , path : & Path ) -> bool {
227- self . paths . iter ( ) . any ( |p| path . ends_with ( p ) )
290+ fn pathset_for_path ( & self , path : & Path ) -> Option < & PathSet > {
291+ self . paths . iter ( ) . find ( |pathset| pathset . has ( path ) )
228292 }
229293}
230294
@@ -254,19 +318,23 @@ impl<'a> Builder<'a> {
254318 tool:: RustInstaller , tool:: Cargo , tool:: Rls , tool:: Rustdoc , tool:: Clippy ,
255319 native:: Llvm , tool:: Rustfmt , tool:: Miri ) ,
256320 Kind :: Check => describe ! ( check:: Std , check:: Test , check:: Rustc ) ,
257- Kind :: Test => describe ! ( test:: Tidy , test:: Bootstrap , test:: DefaultCompiletest ,
258- test:: HostCompiletest , test:: Crate , test:: CrateLibrustc , test:: Rustdoc ,
259- test:: Linkcheck , test:: Cargotest , test:: Cargo , test:: Rls , test:: Docs ,
260- test:: ErrorIndex , test:: Distcheck , test:: Rustfmt , test:: Miri , test:: Clippy ,
261- test:: RustdocJS , test:: RustdocTheme ) ,
321+ Kind :: Test => describe ! ( test:: Tidy , test:: Bootstrap , test:: Ui , test:: RunPass ,
322+ test:: CompileFail , test:: ParseFail , test:: RunFail , test:: RunPassValgrind ,
323+ test:: MirOpt , test:: Codegen , test:: CodegenUnits , test:: Incremental , test:: Debuginfo ,
324+ test:: UiFullDeps , test:: RunPassFullDeps , test:: RunFailFullDeps ,
325+ test:: CompileFailFullDeps , test:: IncrementalFullDeps , test:: Rustdoc , test:: Pretty ,
326+ test:: RunPassPretty , test:: RunFailPretty , test:: RunPassValgrindPretty ,
327+ test:: RunPassFullDepsPretty , test:: RunFailFullDepsPretty , test:: RunMake ,
328+ test:: Crate , test:: CrateLibrustc , test:: Rustdoc , test:: Linkcheck , test:: Cargotest ,
329+ test:: Cargo , test:: Rls , test:: Docs , test:: ErrorIndex , test:: Distcheck ,
330+ test:: Rustfmt , test:: Miri , test:: Clippy , test:: RustdocJS , test:: RustdocTheme ) ,
262331 Kind :: Bench => describe ! ( test:: Crate , test:: CrateLibrustc ) ,
263332 Kind :: Doc => describe ! ( doc:: UnstableBook , doc:: UnstableBookGen , doc:: TheBook ,
264333 doc:: Standalone , doc:: Std , doc:: Test , doc:: Rustc , doc:: ErrorIndex , doc:: Nomicon ,
265334 doc:: Reference , doc:: Rustdoc , doc:: RustByExample , doc:: CargoBook ) ,
266335 Kind :: Dist => describe ! ( dist:: Docs , dist:: Mingw , dist:: Rustc , dist:: DebuggerScripts ,
267336 dist:: Std , dist:: Analysis , dist:: Src , dist:: PlainSourceTarball , dist:: Cargo ,
268- dist:: Rls , dist:: Rustfmt , dist:: Extended , dist:: HashSign ,
269- dist:: DontDistWithMiriEnabled ) ,
337+ dist:: Rls , dist:: Rustfmt , dist:: Extended , dist:: HashSign ) ,
270338 Kind :: Install => describe ! ( install:: Docs , install:: Std , install:: Cargo , install:: Rls ,
271339 install:: Rustfmt , install:: Analysis , install:: Src , install:: Rustc ) ,
272340 }
@@ -297,8 +365,10 @@ impl<'a> Builder<'a> {
297365 should_run = ( desc. should_run ) ( should_run) ;
298366 }
299367 let mut help = String :: from ( "Available paths:\n " ) ;
300- for path in should_run. paths {
301- help. push_str ( format ! ( " ./x.py {} {}\n " , subcommand, path. display( ) ) . as_str ( ) ) ;
368+ for pathset in should_run. paths {
369+ for path in pathset. set {
370+ help. push_str ( format ! ( " ./x.py {} {}\n " , subcommand, path. display( ) ) . as_str ( ) ) ;
371+ }
302372 }
303373 Some ( help)
304374 }
@@ -323,6 +393,12 @@ impl<'a> Builder<'a> {
323393 stack : RefCell :: new ( Vec :: new ( ) ) ,
324394 } ;
325395
396+ if kind == Kind :: Dist {
397+ assert ! ( !build. config. test_miri, "Do not distribute with miri enabled.\n \
398+ The distributed libraries would include all MIR (increasing binary size).
399+ The distributed MIR would include validation statements." ) ;
400+ }
401+
326402 StepDescription :: run ( & Builder :: get_step_descriptions ( builder. kind ) , & builder, paths) ;
327403 }
328404
0 commit comments