88# option. This file may not be copied, modified, or distributed
99# except according to those terms.
1010
11+ from __future__ import print_function
1112import argparse
1213import contextlib
1314import datetime
@@ -501,7 +502,7 @@ def build_triple(self):
501502
502503 return "{}-{}" .format (cputype , ostype )
503504
504- def main ():
505+ def bootstrap ():
505506 parser = argparse .ArgumentParser (description = 'Build rust' )
506507 parser .add_argument ('--config' )
507508 parser .add_argument ('--clean' , action = 'store_true' )
@@ -564,8 +565,6 @@ def main():
564565 rb ._rustc_channel , rb ._rustc_date = data ['rustc' ].split ('-' , 1 )
565566 rb ._cargo_rev = data ['cargo' ]
566567
567- start_time = time ()
568-
569568 # Fetch/build the bootstrap
570569 rb .build = rb .build_triple ()
571570 rb .download_stage0 ()
@@ -582,9 +581,19 @@ def main():
582581 env ["BOOTSTRAP_PARENT_ID" ] = str (os .getpid ())
583582 rb .run (args , env )
584583
585- end_time = time ()
586-
587- print ("Build completed in %s" % format_build_time (end_time - start_time ))
584+ def main ():
585+ start_time = time ()
586+ try :
587+ bootstrap ()
588+ print ("Build completed successfully in %s" % format_build_time (time () - start_time ))
589+ except (SystemExit , KeyboardInterrupt ) as e :
590+ if hasattr (e , 'code' ) and isinstance (e .code , int ):
591+ exit_code = e .code
592+ else :
593+ exit_code = 1
594+ print (e )
595+ print ("Build completed unsuccessfully in %s" % format_build_time (time () - start_time ))
596+ sys .exit (exit_code )
588597
589598if __name__ == '__main__' :
590599 main ()
0 commit comments