@@ -274,7 +274,7 @@ impl PathSet {
274274 /// This is used for `StepDescription::krate`, which passes all matching crates at once to
275275 /// `Step::make_run`, rather than calling it many times with a single crate.
276276 /// See `tests.rs` for examples.
277- fn intersection_removing_matches ( & self , needles : & mut Vec < & Path > , module : Kind ) -> PathSet {
277+ fn intersection_removing_matches ( & self , needles : & mut Vec < PathBuf > , module : Kind ) -> PathSet {
278278 let mut check = |p| {
279279 for ( i, n) in needles. iter ( ) . enumerate ( ) {
280280 let matched = Self :: check ( p, n, module) ;
@@ -346,7 +346,7 @@ const PATH_REMAP: &[(&str, &[&str])] = &[
346346 ) ,
347347] ;
348348
349- fn remap_paths ( paths : & mut Vec < & Path > ) {
349+ fn remap_paths ( paths : & mut Vec < PathBuf > ) {
350350 let mut remove = vec ! [ ] ;
351351 let mut add = vec ! [ ] ;
352352 for ( i, path) in paths. iter ( ) . enumerate ( ) . filter_map ( |( i, path) | path. to_str ( ) . map ( |s| ( i, s) ) )
@@ -355,7 +355,7 @@ fn remap_paths(paths: &mut Vec<&Path>) {
355355 // Remove leading and trailing slashes so `tests/` and `tests` are equivalent
356356 if path. trim_matches ( std:: path:: is_separator) == search {
357357 remove. push ( i) ;
358- add. extend ( replace. iter ( ) . map ( Path :: new ) ) ;
358+ add. extend ( replace. iter ( ) . map ( PathBuf :: from ) ) ;
359359 break ;
360360 }
361361 }
@@ -438,8 +438,25 @@ impl StepDescription {
438438 }
439439 }
440440
441- // strip CurDir prefix if present
442- let mut paths: Vec < _ > = paths. iter ( ) . map ( |p| p. strip_prefix ( "." ) . unwrap_or ( p) ) . collect ( ) ;
441+ // Attempt to resolve paths to be relative to the builder source directory.
442+ let mut paths: Vec < PathBuf > = paths
443+ . iter ( )
444+ . map ( |p| {
445+ // If the path does not exist, it may represent the name of a Step, such as `tidy` in `x test tidy`
446+ if !p. exists ( ) {
447+ return p. clone ( ) ;
448+ }
449+
450+ // Make the path absolute, strip the prefix, and convert to a PathBuf.
451+ match std:: path:: absolute ( p) {
452+ Ok ( p) => p. strip_prefix ( & builder. src ) . unwrap_or ( & p) . to_path_buf ( ) ,
453+ Err ( e) => {
454+ eprintln ! ( "ERROR: {:?}" , e) ;
455+ panic ! ( "Due to the above error, failed to resolve path: {:?}" , p) ;
456+ }
457+ }
458+ } )
459+ . collect ( ) ;
443460
444461 remap_paths ( & mut paths) ;
445462
@@ -629,7 +646,7 @@ impl<'a> ShouldRun<'a> {
629646 /// (for now, just `all_krates` and `paths`, but we may want to add an `aliases` function in the future?)
630647 fn pathset_for_paths_removing_matches (
631648 & self ,
632- paths : & mut Vec < & Path > ,
649+ paths : & mut Vec < PathBuf > ,
633650 kind : Kind ,
634651 ) -> Vec < PathSet > {
635652 let mut sets = vec ! [ ] ;
0 commit comments