@@ -31,9 +31,11 @@ extern crate bootstrap;
3131
3232use std:: env;
3333use std:: ffi:: OsString ;
34- use std:: str :: FromStr ;
34+ use std:: io ;
3535use std:: path:: PathBuf ;
36- use std:: process:: { Command , ExitStatus } ;
36+ use std:: process:: Command ;
37+ use std:: str:: FromStr ;
38+ use std:: time:: Instant ;
3739
3840fn main ( ) {
3941 let mut args = env:: args_os ( ) . skip ( 1 ) . collect :: < Vec < _ > > ( ) ;
@@ -90,7 +92,7 @@ fn main() {
9092 } ;
9193 let stage = env:: var ( "RUSTC_STAGE" ) . expect ( "RUSTC_STAGE was not set" ) ;
9294 let sysroot = env:: var_os ( "RUSTC_SYSROOT" ) . expect ( "RUSTC_SYSROOT was not set" ) ;
93- let mut on_fail = env:: var_os ( "RUSTC_ON_FAIL" ) . map ( |of| Command :: new ( of) ) ;
95+ let on_fail = env:: var_os ( "RUSTC_ON_FAIL" ) . map ( |of| Command :: new ( of) ) ;
9496
9597 let rustc = env:: var_os ( rustc) . unwrap_or_else ( || panic ! ( "{:?} was not set" , rustc) ) ;
9698 let libdir = env:: var_os ( libdir) . unwrap_or_else ( || panic ! ( "{:?} was not set" , libdir) ) ;
@@ -103,6 +105,7 @@ fn main() {
103105 . arg ( format ! ( "stage{}" , stage) )
104106 . env ( bootstrap:: util:: dylib_path_var ( ) ,
105107 env:: join_paths ( & dylib_path) . unwrap ( ) ) ;
108+ let mut maybe_crate = None ;
106109
107110 if let Some ( target) = target {
108111 // The stage0 compiler has a special sysroot distinct from what we
@@ -134,6 +137,7 @@ fn main() {
134137 . find ( |a| & * a[ 0 ] == "--crate-name" )
135138 . unwrap ( ) ;
136139 let crate_name = & * crate_name[ 1 ] ;
140+ maybe_crate = Some ( crate_name) ;
137141
138142 // If we're compiling specifically the `panic_abort` crate then we pass
139143 // the `-C panic=abort` option. Note that we do not do this for any
@@ -281,31 +285,52 @@ fn main() {
281285 eprintln ! ( "libdir: {:?}" , libdir) ;
282286 }
283287
284- // Actually run the compiler!
285- std:: process:: exit ( if let Some ( ref mut on_fail) = on_fail {
286- match cmd. status ( ) {
287- Ok ( s) if s. success ( ) => 0 ,
288- _ => {
289- println ! ( "\n Did not run successfully:\n {:?}\n -------------" , cmd) ;
290- exec_cmd ( on_fail) . expect ( "could not run the backup command" ) ;
291- 1
288+ if let Some ( mut on_fail) = on_fail {
289+ let e = match cmd. status ( ) {
290+ Ok ( s) if s. success ( ) => std:: process:: exit ( 0 ) ,
291+ e => e,
292+ } ;
293+ println ! ( "\n Did not run successfully: {:?}\n {:?}\n -------------" , e, cmd) ;
294+ exec_cmd ( & mut on_fail) . expect ( "could not run the backup command" ) ;
295+ std:: process:: exit ( 1 ) ;
296+ }
297+
298+ if env:: var_os ( "RUSTC_PRINT_STEP_TIMINGS" ) . is_some ( ) {
299+ if let Some ( krate) = maybe_crate {
300+ let start = Instant :: now ( ) ;
301+ let status = cmd
302+ . status ( )
303+ . expect ( & format ! ( "\n \n failed to run {:?}" , cmd) ) ;
304+ let dur = start. elapsed ( ) ;
305+
306+ let is_test = args. iter ( ) . any ( |a| a == "--test" ) ;
307+ eprintln ! ( "[RUSTC-TIMING] {} test:{} {}.{:03}" ,
308+ krate. to_string_lossy( ) ,
309+ is_test,
310+ dur. as_secs( ) ,
311+ dur. subsec_nanos( ) / 1_000_000 ) ;
312+
313+ match status. code ( ) {
314+ Some ( i) => std:: process:: exit ( i) ,
315+ None => {
316+ eprintln ! ( "rustc exited with {}" , status) ;
317+ std:: process:: exit ( 0xfe ) ;
318+ }
292319 }
293320 }
294- } else {
295- std:: process:: exit ( match exec_cmd ( & mut cmd) {
296- Ok ( s) => s. code ( ) . unwrap_or ( 0xfe ) ,
297- Err ( e) => panic ! ( "\n \n failed to run {:?}: {}\n \n " , cmd, e) ,
298- } )
299- } )
321+ }
322+
323+ let code = exec_cmd ( & mut cmd) . expect ( & format ! ( "\n \n failed to run {:?}" , cmd) ) ;
324+ std:: process:: exit ( code) ;
300325}
301326
302327#[ cfg( unix) ]
303- fn exec_cmd ( cmd : & mut Command ) -> :: std :: io:: Result < ExitStatus > {
328+ fn exec_cmd ( cmd : & mut Command ) -> io:: Result < i32 > {
304329 use std:: os:: unix:: process:: CommandExt ;
305330 Err ( cmd. exec ( ) )
306331}
307332
308333#[ cfg( not( unix) ) ]
309- fn exec_cmd ( cmd : & mut Command ) -> :: std :: io:: Result < ExitStatus > {
310- cmd. status ( )
334+ fn exec_cmd ( cmd : & mut Command ) -> io:: Result < i32 > {
335+ cmd. status ( ) . map ( |status| status . code ( ) . unwrap ( ) )
311336}
0 commit comments