Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/bootstrap/src/core/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,18 +590,30 @@ impl StepDescription {
// Attempt to resolve paths to be relative to the builder source directory.
let mut paths: Vec<PathBuf> = paths
.iter()
.map(|p| {
.map(|original_path| {
let mut path = original_path.clone();

// Someone could run `x <cmd> <path>` from a different repository than the source
// directory.
// In that case, we should not try to resolve the paths relative to the working
// directory, but rather relative to the source directory.
// So we forcefully "relocate" the path to the source directory here.
if !path.is_absolute() {
path = builder.src.join(path);
}

// If the path does not exist, it may represent the name of a Step, such as `tidy` in `x test tidy`
if !p.exists() {
return p.clone();
if !path.exists() {
// Use the original path here
return original_path.clone();
}

// Make the path absolute, strip the prefix, and convert to a PathBuf.
match std::path::absolute(p) {
match std::path::absolute(&path) {
Ok(p) => p.strip_prefix(&builder.src).unwrap_or(&p).to_path_buf(),
Err(e) => {
eprintln!("ERROR: {e:?}");
panic!("Due to the above error, failed to resolve path: {p:?}");
panic!("Due to the above error, failed to resolve path: {path:?}");
}
}
})
Expand Down
Loading