Skip to content

Commit bfe9a6b

Browse files
committed
Prevent the use of .canonalize() on Windows
1 parent 3c62d7c commit bfe9a6b

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/bootstrap/src/core/builder.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -438,20 +438,32 @@ impl StepDescription {
438438
}
439439
}
440440

441-
// Resolve paths to be relative to the builder source directory.
441+
// Attempt to resolve paths to be relative to the builder source directory.
442442
let paths: Vec<_> = paths
443443
.iter()
444444
.map(|p| {
445445
// If the path does not exist, it may represent the name of a Step, such as `tidy` in `x test tidy`
446446
if !p.exists() {
447447
return p.clone();
448448
}
449-
// Get the canonical path, strip the prefix, and convert to a PathBuf.
449+
450+
#[cfg(windows)]
451+
{
452+
if p.is_absolute() {
453+
panic!("Absolute paths are not supported on Windows");
454+
}
455+
456+
// Strip current directory prefix if present
457+
return path.strip_prefix(".").unwrap_or(path).to_path_buf();
458+
}
459+
460+
// Make the path absolute, strip the prefix, and convert to a PathBuf.
461+
// FIXME: Replace `path.canonicalize()` with `std::path::absolute(path)` to support absolute paths on Windows.
450462
match p.canonicalize() {
451-
Ok(p) => p.strip_prefix(&builder.src).unwrap_or(&p).to_owned(),
463+
Ok(p) => p.strip_prefix(&builder.src).unwrap_or(&p).to_path_buf(),
452464
Err(e) => {
453465
eprintln!("ERROR: {:?}", e);
454-
panic!("Due to the above error, failed to canonicalize path: {:?}", p);
466+
panic!("Due to the above error, failed to resolve path: {:?}", p);
455467
}
456468
}
457469
})

0 commit comments

Comments
 (0)