@@ -31,9 +31,11 @@ extern crate bootstrap;
31
31
32
32
use std:: env;
33
33
use std:: ffi:: OsString ;
34
- use std:: str :: FromStr ;
34
+ use std:: io ;
35
35
use std:: path:: PathBuf ;
36
- use std:: process:: { Command , ExitStatus } ;
36
+ use std:: process:: Command ;
37
+ use std:: str:: FromStr ;
38
+ use std:: time:: Instant ;
37
39
38
40
fn main ( ) {
39
41
let mut args = env:: args_os ( ) . skip ( 1 ) . collect :: < Vec < _ > > ( ) ;
@@ -90,7 +92,7 @@ fn main() {
90
92
} ;
91
93
let stage = env:: var ( "RUSTC_STAGE" ) . expect ( "RUSTC_STAGE was not set" ) ;
92
94
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) ) ;
94
96
95
97
let rustc = env:: var_os ( rustc) . unwrap_or_else ( || panic ! ( "{:?} was not set" , rustc) ) ;
96
98
let libdir = env:: var_os ( libdir) . unwrap_or_else ( || panic ! ( "{:?} was not set" , libdir) ) ;
@@ -103,6 +105,7 @@ fn main() {
103
105
. arg ( format ! ( "stage{}" , stage) )
104
106
. env ( bootstrap:: util:: dylib_path_var ( ) ,
105
107
env:: join_paths ( & dylib_path) . unwrap ( ) ) ;
108
+ let mut maybe_crate = None ;
106
109
107
110
if let Some ( target) = target {
108
111
// The stage0 compiler has a special sysroot distinct from what we
@@ -134,6 +137,7 @@ fn main() {
134
137
. find ( |a| & * a[ 0 ] == "--crate-name" )
135
138
. unwrap ( ) ;
136
139
let crate_name = & * crate_name[ 1 ] ;
140
+ maybe_crate = Some ( crate_name) ;
137
141
138
142
// If we're compiling specifically the `panic_abort` crate then we pass
139
143
// the `-C panic=abort` option. Note that we do not do this for any
@@ -281,31 +285,52 @@ fn main() {
281
285
eprintln ! ( "libdir: {:?}" , libdir) ;
282
286
}
283
287
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
+ }
292
319
}
293
320
}
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) ;
300
325
}
301
326
302
327
#[ cfg( unix) ]
303
- fn exec_cmd ( cmd : & mut Command ) -> :: std :: io:: Result < ExitStatus > {
328
+ fn exec_cmd ( cmd : & mut Command ) -> io:: Result < i32 > {
304
329
use std:: os:: unix:: process:: CommandExt ;
305
330
Err ( cmd. exec ( ) )
306
331
}
307
332
308
333
#[ 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 ( ) )
311
336
}
0 commit comments