Skip to content

rustbuild: use Display for exit status instead of Debug, see #74832 for justification #74841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 28, 2020
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
50 changes: 24 additions & 26 deletions src/bootstrap/bin/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
//! never get replaced.

use std::env;
use std::io;
use std::path::PathBuf;
use std::process::Command;
use std::str::FromStr;
Expand Down Expand Up @@ -147,22 +146,15 @@ fn main() {
eprintln!("libdir: {:?}", libdir);
}

if let Some(mut on_fail) = on_fail {
let e = match cmd.status() {
Ok(s) if s.success() => std::process::exit(0),
e => e,
};
println!("\nDid not run successfully: {:?}\n{:?}\n-------------", e, cmd);
status_code(&mut on_fail).expect("could not run the backup command");
std::process::exit(1);
}
let start = Instant::now();
let status = {
let errmsg = format!("\nFailed to run:\n{:?}\n-------------", cmd);
cmd.status().expect(&errmsg)
};

if env::var_os("RUSTC_PRINT_STEP_TIMINGS").is_some() {
if let Some(crate_name) = crate_name {
let start = Instant::now();
let status = cmd.status().unwrap_or_else(|_| panic!("\n\n failed to run {:?}", cmd));
let dur = start.elapsed();

let is_test = args.iter().any(|a| a == "--test");
eprintln!(
"[RUSTC-TIMING] {} test:{} {}.{:03}",
Expand All @@ -171,21 +163,27 @@ fn main() {
dur.as_secs(),
dur.subsec_millis()
);

match status.code() {
Some(i) => std::process::exit(i),
None => {
eprintln!("rustc exited with {}", status);
std::process::exit(0xfe);
}
}
}
}

let code = status_code(&mut cmd).unwrap_or_else(|_| panic!("\n\n failed to run {:?}", cmd));
std::process::exit(code);
}
if status.success() {
std::process::exit(0);
// note: everything below here is unreachable. do not put code that
// should run on success, after this block.
}
println!("\nDid not run successfully: {}\n{:?}\n-------------", status, cmd);

if let Some(mut on_fail) = on_fail {
on_fail.status().expect("Could not run the on_fail command");
}

fn status_code(cmd: &mut Command) -> io::Result<i32> {
cmd.status().map(|status| status.code().unwrap())
// Preserve the exit code. In case of signal, exit with 0xfe since it's
// awkward to preserve this status in a cross-platform way.
match status.code() {
Some(i) => std::process::exit(i),
None => {
eprintln!("rustc exited with {}", status);
std::process::exit(0xfe);
}
}
}