Rollup merge of #127112 - ChrisDenton:lldb, r=Kobzol

Bootstrap: Don't get output if `lldb --version` errors

fixes #126892

`Command` can error in two ways: the OS can fail to run the binary at all or else the binary can return an error exit code. Unfortunately the distinction between the two is not clear cut. The OS may succeed in starting the binary but it may still error before `main` (e.g. if a necessary library fails to load) and this will be reported via the exit code.

Fortunately this case is simpler. We can assume that `lldb --version` will only ever error if there's a startup issue of some kind. so both kinds of errors are caused by the OS. Thus it's safe for us to treat them equally for the sake of this specific check.
This commit is contained in:
Guillaume Gomez 2024-06-29 14:07:22 +02:00 committed by GitHub
commit 38983df5c7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1817,23 +1817,25 @@ fn run(self, builder: &Builder<'_>) {
cmd.arg("--gdb").arg(gdb);
}
let run = |cmd: &mut Command| {
cmd.output().map(|output| {
String::from_utf8_lossy(&output.stdout)
.lines()
.next()
.unwrap_or_else(|| panic!("{:?} failed {:?}", cmd, output))
.to_string()
})
};
let lldb_exe = builder.config.lldb.clone().unwrap_or_else(|| PathBuf::from("lldb"));
let lldb_version = Command::new(&lldb_exe)
.arg("--version")
.output()
.map(|output| String::from_utf8_lossy(&output.stdout).to_string())
.ok();
.map(|output| {
(String::from_utf8_lossy(&output.stdout).to_string(), output.status.success())
})
.ok()
.and_then(|(output, success)| if success { Some(output) } else { None });
if let Some(ref vers) = lldb_version {
let run = |cmd: &mut Command| {
cmd.output().map(|output| {
String::from_utf8_lossy(&output.stdout)
.lines()
.next()
.unwrap_or_else(|| panic!("{:?} failed {:?}", cmd, output))
.to_string()
})
};
cmd.arg("--lldb-version").arg(vers);
let lldb_python_dir = run(Command::new(&lldb_exe).arg("-P")).ok();
if let Some(ref dir) = lldb_python_dir {