Auto merge of #74841 - infinity0:fix-exec, r=Mark-Simulacrum

rustbuild: use Display for exit status instead of Debug, see #74832 for justification
This commit is contained in:
bors 2020-07-28 03:42:22 +00:00
commit 1454bbd4fd
1 changed files with 24 additions and 26 deletions

View File

@ -16,7 +16,6 @@
//! never get replaced. //! never get replaced.
use std::env; use std::env;
use std::io;
use std::path::PathBuf; use std::path::PathBuf;
use std::process::Command; use std::process::Command;
use std::str::FromStr; use std::str::FromStr;
@ -147,22 +146,15 @@ fn main() {
eprintln!("libdir: {:?}", libdir); eprintln!("libdir: {:?}", libdir);
} }
if let Some(mut on_fail) = on_fail { let start = Instant::now();
let e = match cmd.status() { let status = {
Ok(s) if s.success() => std::process::exit(0), let errmsg = format!("\nFailed to run:\n{:?}\n-------------", cmd);
e => e, cmd.status().expect(&errmsg)
}; };
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);
}
if env::var_os("RUSTC_PRINT_STEP_TIMINGS").is_some() { if env::var_os("RUSTC_PRINT_STEP_TIMINGS").is_some() {
if let Some(crate_name) = crate_name { 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 dur = start.elapsed();
let is_test = args.iter().any(|a| a == "--test"); let is_test = args.iter().any(|a| a == "--test");
eprintln!( eprintln!(
"[RUSTC-TIMING] {} test:{} {}.{:03}", "[RUSTC-TIMING] {} test:{} {}.{:03}",
@ -171,21 +163,27 @@ fn main() {
dur.as_secs(), dur.as_secs(),
dur.subsec_millis() 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)); if status.success() {
std::process::exit(code); 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);
fn status_code(cmd: &mut Command) -> io::Result<i32> { if let Some(mut on_fail) = on_fail {
cmd.status().map(|status| status.code().unwrap()) on_fail.status().expect("Could not run the on_fail command");
}
// 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);
}
}
} }