Rollup merge of #129775 - Zalathar:initial-libdir, r=albertlarsan68

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.
This commit is contained in:
Matthias Krüger 2024-09-05 19:43:47 +02:00 committed by GitHub
commit 4a8135c6fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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");