diff options
| author | Matthias Krüger <476013+matthiaskrgr@users.noreply.github.com> | 2025-09-20 17:55:05 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-20 17:55:05 +0200 |
| commit | f5725f01820720c41b2764dd1c135d99d7f5f257 (patch) | |
| tree | bc6433cc7efa113e8ba9092ef9841b3418ac75e1 /src | |
| parent | 016420a603bca59dde9bc22de9e11aef39329e00 (diff) | |
| parent | 58814bce6cfb8faf62979c7d043347e0526d7e7f (diff) | |
| download | rust-f5725f01820720c41b2764dd1c135d99d7f5f257.tar.gz rust-f5725f01820720c41b2764dd1c135d99d7f5f257.zip | |
Rollup merge of #146774 - Kobzol:bootstrap-relative-path, r=jieyouxu
Allow running `x <cmd> <path>` from a different directory Fixes: https://github.com/rust-lang/rust/issues/146772 r? ``@jieyouxu``
Diffstat (limited to 'src')
| -rw-r--r-- | src/bootstrap/src/core/builder/mod.rs | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/bootstrap/src/core/builder/mod.rs b/src/bootstrap/src/core/builder/mod.rs index 75c8ee36528..8226b4325b6 100644 --- a/src/bootstrap/src/core/builder/mod.rs +++ b/src/bootstrap/src/core/builder/mod.rs @@ -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:?}"); } } }) |
