Skip to content

Commit

Permalink
Rollup merge of rust-lang#129775 - Zalathar:initial-libdir, r=albertl…
Browse files Browse the repository at this point in the history
…arsan68

bootstrap: Try to track down why `initial_libdir` sometimes fails

When I try to run `x` commands from the command-line, I occasionally see a mysterious failure that looks something like this:

```text
thread 'main' panicked at src/lib.rs:341:14:
called `Result::unwrap()` on an `Err` value: StripPrefixError(())
```

It happens often enough to be annoying, but rarely enough that I can't reproduce it at will. The error message points to a particular `unwrap` call, but doesn't include enough context to determine *why* the failure occurs.

Re-running the command almost always works, so I suspect some kind of filesystem race condition (possibly involving VSCode invoking bootstrap at the same time), but there's not much I can do with the information I currently have.

So this PR includes some relevant information in the panic message when the failure occurs, in the hope that doing so will make the cause easier to track down when the failure occurs again.
  • Loading branch information
matthiaskrgr authored Sep 5, 2024
2 parents d509cbf + 21edc73 commit 36502ba
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,14 +332,20 @@ impl Build {
.trim()
.to_string();

let initial_libdir = initial_target_dir
.parent()
.unwrap()
.parent()
.unwrap()
.strip_prefix(&initial_sysroot)
.unwrap()
.to_path_buf();
// FIXME(Zalathar): Determining this path occasionally fails locally for
// unknown reasons, so we print some extra context to help track down why.
let find_initial_libdir = || {
let initial_libdir =
initial_target_dir.parent()?.parent()?.strip_prefix(&initial_sysroot).ok()?;
Some(initial_libdir.to_path_buf())
};
let Some(initial_libdir) = find_initial_libdir() else {
panic!(
"couldn't determine `initial_libdir` \
from target dir {initial_target_dir:?} \
and sysroot {initial_sysroot:?}"
)
};

let version = std::fs::read_to_string(src.join("src").join("version"))
.expect("failed to read src/version");
Expand Down

0 comments on commit 36502ba

Please sign in to comment.