@@ -3,7 +3,7 @@ mod cargo;
33use std:: any:: { Any , type_name} ;
44use std:: cell:: { Cell , RefCell } ;
55use std:: collections:: BTreeSet ;
6- use std:: fmt:: { Debug , Write } ;
6+ use std:: fmt:: { self , Debug , Write } ;
77use std:: hash:: Hash ;
88use std:: ops:: Deref ;
99use std:: path:: { Path , PathBuf } ;
@@ -271,16 +271,17 @@ impl PathSet {
271271 /// This is used for `StepDescription::krate`, which passes all matching crates at once to
272272 /// `Step::make_run`, rather than calling it many times with a single crate.
273273 /// See `tests.rs` for examples.
274- fn intersection_removing_matches ( & self , needles : & mut Vec < PathBuf > , module : Kind ) -> PathSet {
274+ fn intersection_removing_matches ( & self , needles : & mut [ CLIStepPath ] , module : Kind ) -> PathSet {
275275 let mut check = |p| {
276- for ( i, n) in needles. iter ( ) . enumerate ( ) {
277- let matched = Self :: check ( p, n, module) ;
276+ let mut result = false ;
277+ for n in needles. iter_mut ( ) {
278+ let matched = Self :: check ( p, & n. path , module) ;
278279 if matched {
279- needles . remove ( i ) ;
280- return true ;
280+ n . will_be_executed = true ;
281+ result = true ;
281282 }
282283 }
283- false
284+ result
284285 } ;
285286 match self {
286287 PathSet :: Set ( set) => PathSet :: Set ( set. iter ( ) . filter ( |& p| check ( p) ) . cloned ( ) . collect ( ) ) ,
@@ -361,6 +362,32 @@ fn remap_paths(paths: &mut Vec<PathBuf>) {
361362 paths. append ( & mut add) ;
362363}
363364
365+ #[ derive( Clone , PartialEq ) ]
366+ struct CLIStepPath {
367+ path : PathBuf ,
368+ will_be_executed : bool ,
369+ }
370+
371+ #[ cfg( test) ]
372+ impl CLIStepPath {
373+ fn will_be_executed ( mut self , will_be_executed : bool ) -> Self {
374+ self . will_be_executed = will_be_executed;
375+ self
376+ }
377+ }
378+
379+ impl Debug for CLIStepPath {
380+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
381+ write ! ( f, "{}" , self . path. display( ) )
382+ }
383+ }
384+
385+ impl From < PathBuf > for CLIStepPath {
386+ fn from ( path : PathBuf ) -> Self {
387+ Self { path, will_be_executed : false }
388+ }
389+ }
390+
364391impl StepDescription {
365392 fn from < S : Step > ( kind : Kind ) -> StepDescription {
366393 StepDescription {
@@ -478,7 +505,8 @@ impl StepDescription {
478505 return ;
479506 }
480507
481- let mut path_lookup: Vec < ( PathBuf , bool ) > =
508+ let mut paths: Vec < CLIStepPath > = paths. into_iter ( ) . map ( |p| p. into ( ) ) . collect ( ) ;
509+ let mut path_lookup: Vec < ( CLIStepPath , bool ) > =
482510 paths. clone ( ) . into_iter ( ) . map ( |p| ( p, false ) ) . collect ( ) ;
483511
484512 // List of `(usize, &StepDescription, Vec<PathSet>)` where `usize` is the closest index of a path
@@ -518,8 +546,10 @@ impl StepDescription {
518546 }
519547 }
520548
549+ paths. retain ( |p| !p. will_be_executed ) ;
550+
521551 if !paths. is_empty ( ) {
522- eprintln ! ( "ERROR: no `{}` rules matched {:?}" , builder. kind. as_str( ) , paths, ) ;
552+ eprintln ! ( "ERROR: no `{}` rules matched {:?}" , builder. kind. as_str( ) , paths) ;
523553 eprintln ! (
524554 "HELP: run `x.py {} --help --verbose` to show a list of available paths" ,
525555 builder. kind. as_str( )
@@ -682,7 +712,7 @@ impl<'a> ShouldRun<'a> {
682712 /// (for now, just `all_krates` and `paths`, but we may want to add an `aliases` function in the future?)
683713 fn pathset_for_paths_removing_matches (
684714 & self ,
685- paths : & mut Vec < PathBuf > ,
715+ paths : & mut [ CLIStepPath ] ,
686716 kind : Kind ,
687717 ) -> Vec < PathSet > {
688718 let mut sets = vec ! [ ] ;
@@ -825,12 +855,8 @@ impl<'a> Builder<'a> {
825855 match kind {
826856 Kind :: Build => describe ! (
827857 compile:: Std ,
828- // FIXME(#135022): `compile::Assemble` **must** come before `compile::Rustc` after
829- // `PathSet` also permits prefix-matching, because `compile::Rustc` can consume the
830- // `"compiler"` path filter first, causing `compile::Assemble` to no longer run when
831- // the user writes `./x build compiler --stage 0`.
832- compile:: Assemble ,
833858 compile:: Rustc ,
859+ compile:: Assemble ,
834860 compile:: CodegenBackend ,
835861 compile:: StartupObjects ,
836862 tool:: BuildManifest ,
@@ -929,14 +955,10 @@ impl<'a> Builder<'a> {
929955 test:: Rustdoc ,
930956 test:: CoverageRunRustdoc ,
931957 test:: Pretty ,
932- test:: Crate ,
933- test:: CrateLibrustc ,
934- // The cranelift and gcc tests need to be listed after the
935- // compiler unit tests (CrateLibrustc) so that they don't
936- // hijack the whole `compiler` directory during path matching.
937- // <https://github.com/rust-lang/rust/pull/134919>
938958 test:: CodegenCranelift ,
939959 test:: CodegenGCC ,
960+ test:: Crate ,
961+ test:: CrateLibrustc ,
940962 test:: CrateRustdoc ,
941963 test:: CrateRustdocJsonTypes ,
942964 test:: CrateBootstrap ,
0 commit comments