Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions src/bootstrap/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::fs::{self, OpenOptions, TryLockError};
use std::io::{self, BufRead, BufReader, IsTerminal, Read, Write};
use std::path::Path;
use std::str::FromStr;
use std::sync::Once;
use std::time::Instant;
use std::{env, process};

Expand All @@ -27,16 +28,23 @@ fn main() {

let _start_time = Instant::now();

// Always print backtraces to provide richer errors, to help debug hard-to-reproduce panics
// when the user didn't specify RUST_BACKTRACE
if std::env::var("RUST_BACKTRACE").is_err() {
unsafe {
std::env::set_var("RUST_BACKTRACE", "1");
}
}

let default_panic_hook = std::panic::take_hook();
std::panic::set_hook(Box::new(move |info| {
static BACKTRACE_LOCK: Once = Once::new();

// Always print backtraces to provide richer errors, to help debug hard-to-reproduce panics
// when the user didn't specify RUST_BACKTRACE
// Note that we only override this variable in the panic handler, because bootstrap might
// manually capture backtraces when a command is executed, and in that case we do not want
// to always force backtraces.
BACKTRACE_LOCK.call_once(|| {
if std::env::var("RUST_BACKTRACE").is_err() {
unsafe {
std::env::set_var("RUST_BACKTRACE", "1");
}
}
});

default_panic_hook(info);
StepStack::with_current(|stack| {
eprintln!("\nBootstrap has panicked, currently active steps:");
Expand Down
Loading