diff options
| author | Simonas Kazlauskas <git@kazlauskas.me> | 2017-02-16 20:52:56 +0200 |
|---|---|---|
| committer | Simonas Kazlauskas <git@kazlauskas.me> | 2017-02-16 21:12:38 +0200 |
| commit | 0e45a5ed3f79338656b19a41172d3a7761586ebc (patch) | |
| tree | 14998e1cdb71b36c21fbbdf57b648d19569e2b2e /src/bootstrap/bin | |
| parent | 62eb6056d332be09206dc664f2e949ae64341e64 (diff) | |
| download | rust-0e45a5ed3f79338656b19a41172d3a7761586ebc.tar.gz rust-0e45a5ed3f79338656b19a41172d3a7761586ebc.zip | |
[rustbuild] add a way to run command after failure
This is a simple way to workaround the debugging issues caused by the rustc
wrapper used in the bootstrap process. Namely, it uses some obscure environment
variables and you can’t just copy the failed command and run it in the shell or
debugger to examine the failure more closely.
With `--on-fail` its possible to run an arbitrary command within exactly the
same environment under which rustc failed. Theres’s multiple ways to use this
new flag:
$ python x.py build --stage=1 --on-fail=env
would print a list of environment variables and the failed command, so a
few copy-pastes and you now can run the same rust in your shell outside the
bootstrap system.
$ python x.py build --stage=1 --on-fail=bash
Is a more useful variation of the command above in that it launches a whole
shell with environment already in place! All that’s left to do is copy-paste
the command just above the shell prompt!
Fixes #38686
Fixes #38221
Diffstat (limited to 'src/bootstrap/bin')
| -rw-r--r-- | src/bootstrap/bin/rustc.rs | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index 90fd31ecbdd..bf1da57607d 100644 --- a/src/bootstrap/bin/rustc.rs +++ b/src/bootstrap/bin/rustc.rs @@ -68,6 +68,7 @@ fn main() { }; let stage = env::var("RUSTC_STAGE").expect("RUSTC_STAGE was not set"); let sysroot = env::var_os("RUSTC_SYSROOT").expect("RUSTC_SYSROOT was not set"); + let mut on_fail = env::var_os("RUSTC_ON_FAIL").map(|of| Command::new(of)); let rustc = env::var_os(rustc).unwrap_or_else(|| panic!("{:?} was not set", rustc)); let libdir = env::var_os(libdir).unwrap_or_else(|| panic!("{:?} was not set", libdir)); @@ -212,9 +213,20 @@ fn main() { } // Actually run the compiler! - std::process::exit(match exec_cmd(&mut cmd) { - Ok(s) => s.code().unwrap_or(0xfe), - Err(e) => panic!("\n\nfailed to run {:?}: {}\n\n", cmd, e), + std::process::exit(if let Some(ref mut on_fail) = on_fail { + match cmd.status() { + Ok(s) if s.success() => 0, + _ => { + println!("\nDid not run successfully:\n{:?}\n-------------", cmd); + exec_cmd(on_fail).expect("could not run the backup command"); + 1 + } + } + } else { + std::process::exit(match exec_cmd(&mut cmd) { + Ok(s) => s.code().unwrap_or(0xfe), + Err(e) => panic!("\n\nfailed to run {:?}: {}\n\n", cmd, e), + }) }) } |
