Skip to content

Commit 81d711d

Browse files
committed
Canonicalize each path before stripping the prefix
1 parent 50a7256 commit 81d711d

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/bootstrap/src/core/builder.rs

+15-4
Original file line numberDiff line numberDiff line change
@@ -438,10 +438,21 @@ impl StepDescription {
438438
}
439439
}
440440

441-
// strip CurDir prefix if present
442-
let curdir_path = PathBuf::from(".").canonicalize().unwrap();
443-
let mut paths: Vec<_> =
444-
paths.iter().map(|p| p.strip_prefix(&curdir_path).unwrap_or(p)).collect();
441+
// Resolve paths to be relative to the builder source directory.
442+
let paths: Vec<_> = paths
443+
.iter()
444+
.map(|p| {
445+
// Get the canonical path, strip the prefix, and convert to a PathBuf.
446+
match p.canonicalize() {
447+
Ok(p) => p.strip_prefix(&builder.src).unwrap_or(&p).to_owned(),
448+
Err(_) => {
449+
panic!("failed to canonicalize path: {:?}", p);
450+
}
451+
}
452+
}).collect();
453+
454+
// Convert Vec<PathBuf> to `Vec<&Path>`
455+
let mut paths:Vec<&Path> = paths.iter().map(|p| p.as_ref()).collect();
445456

446457
remap_paths(&mut paths);
447458

0 commit comments

Comments
 (0)