16
16
//! never get replaced.
17
17
18
18
use std:: env;
19
- use std:: io;
20
19
use std:: path:: PathBuf ;
21
20
use std:: process:: Command ;
22
21
use std:: str:: FromStr ;
@@ -147,22 +146,15 @@ fn main() {
147
146
eprintln ! ( "libdir: {:?}" , libdir) ;
148
147
}
149
148
150
- if let Some ( mut on_fail) = on_fail {
151
- let e = match cmd. status ( ) {
152
- Ok ( s) if s. success ( ) => std:: process:: exit ( 0 ) ,
153
- e => e,
154
- } ;
155
- println ! ( "\n Did not run successfully: {:?}\n {:?}\n -------------" , e, cmd) ;
156
- status_code ( & mut on_fail) . expect ( "could not run the backup command" ) ;
157
- std:: process:: exit ( 1 ) ;
158
- }
149
+ let start = Instant :: now ( ) ;
150
+ let status = {
151
+ let errmsg = format ! ( "\n Failed to run:\n {:?}\n -------------" , cmd) ;
152
+ cmd. status ( ) . expect ( & errmsg)
153
+ } ;
159
154
160
155
if env:: var_os ( "RUSTC_PRINT_STEP_TIMINGS" ) . is_some ( ) {
161
156
if let Some ( crate_name) = crate_name {
162
- let start = Instant :: now ( ) ;
163
- let status = cmd. status ( ) . unwrap_or_else ( |_| panic ! ( "\n \n failed to run {:?}" , cmd) ) ;
164
157
let dur = start. elapsed ( ) ;
165
-
166
158
let is_test = args. iter ( ) . any ( |a| a == "--test" ) ;
167
159
eprintln ! (
168
160
"[RUSTC-TIMING] {} test:{} {}.{:03}" ,
@@ -171,21 +163,27 @@ fn main() {
171
163
dur. as_secs( ) ,
172
164
dur. subsec_millis( )
173
165
) ;
174
-
175
- match status. code ( ) {
176
- Some ( i) => std:: process:: exit ( i) ,
177
- None => {
178
- eprintln ! ( "rustc exited with {}" , status) ;
179
- std:: process:: exit ( 0xfe ) ;
180
- }
181
- }
182
166
}
183
167
}
184
168
185
- let code = status_code ( & mut cmd) . unwrap_or_else ( |_| panic ! ( "\n \n failed to run {:?}" , cmd) ) ;
186
- std:: process:: exit ( code) ;
187
- }
169
+ if status. success ( ) {
170
+ std:: process:: exit ( 0 ) ;
171
+ // note: everything below here is unreachable. do not put code that
172
+ // should run on success, after this block.
173
+ }
174
+ println ! ( "\n Did not run successfully: {}\n {:?}\n -------------" , status, cmd) ;
175
+
176
+ if let Some ( mut on_fail) = on_fail {
177
+ on_fail. status ( ) . expect ( "Could not run the on_fail command" ) ;
178
+ }
188
179
189
- fn status_code ( cmd : & mut Command ) -> io:: Result < i32 > {
190
- cmd. status ( ) . map ( |status| status. code ( ) . unwrap ( ) )
180
+ // Preserve the exit code. In case of signal, exit with 0xfe since it's
181
+ // awkward to preserve this status in a cross-platform way.
182
+ match status. code ( ) {
183
+ Some ( i) => std:: process:: exit ( i) ,
184
+ None => {
185
+ eprintln ! ( "rustc exited with {}" , status) ;
186
+ std:: process:: exit ( 0xfe ) ;
187
+ }
188
+ }
191
189
}
0 commit comments