@@ -41,7 +41,7 @@ use crate::core::builder::Kind;
4141use crate :: core:: config:: { flags, LldMode } ;
4242use crate :: core:: config:: { DryRun , Target } ;
4343use crate :: core:: config:: { LlvmLibunwind , TargetSelection } ;
44- use crate :: utils:: exec:: { BehaviorOnFailure , BootstrapCommand , OutputMode } ;
44+ use crate :: utils:: exec:: { BehaviorOnFailure , BootstrapCommand , CommandOutput , OutputMode } ;
4545use crate :: utils:: helpers:: { self , dir_is_empty, exe, libdir, mtime, output, symlink_dir} ;
4646
4747mod core;
@@ -958,6 +958,65 @@ impl Build {
958958 } )
959959 }
960960
961+ fn run_tracked ( & self , command : BootstrapCommand ) -> CommandOutput {
962+ if self . config . dry_run ( ) {
963+ return CommandOutput :: default ( ) ;
964+ }
965+
966+ self . verbose ( || println ! ( "running: {command:?}" ) ) ;
967+
968+ let ( output, print_error) : ( io:: Result < CommandOutput > , bool ) = match command. output_mode {
969+ mode @ ( OutputMode :: PrintAll | OutputMode :: PrintOutput ) => (
970+ command. command . status ( ) . map ( |status| status. into ( ) ) ,
971+ matches ! ( mode, OutputMode :: PrintAll ) ,
972+ ) ,
973+ OutputMode :: SuppressOnSuccess => ( command. command . output ( ) . map ( |o| o. into ( ) ) , true ) ,
974+ } ;
975+
976+ let output = match output {
977+ Ok ( output) => output,
978+ Err ( e) => fail ( & format ! ( "failed to execute command: {:?}\n error: {}" , command, e) ) ,
979+ } ;
980+ if !output. is_success ( ) {
981+ if print_error {
982+ println ! (
983+ "\n \n Command did not execute successfully.\
984+ \n Expected success, got: {}",
985+ output. status( ) ,
986+ ) ;
987+
988+ if !self . is_verbose ( ) {
989+ println ! ( "Add `-v` to see more details.\n " ) ;
990+ }
991+
992+ self . verbose ( || {
993+ println ! (
994+ "\n STDOUT ----\n {}\n \
995+ STDERR ----\n {}\n ",
996+ output. stdout( ) ,
997+ output. stderr( ) ,
998+ )
999+ } ) ;
1000+ }
1001+
1002+ match command. failure_behavior {
1003+ BehaviorOnFailure :: DelayFail => {
1004+ if self . fail_fast {
1005+ exit ! ( 1 ) ;
1006+ }
1007+
1008+ let mut failures = self . delayed_failures . borrow_mut ( ) ;
1009+ failures. push ( format ! ( "{command:?}" ) ) ;
1010+ }
1011+ BehaviorOnFailure :: Exit => {
1012+ exit ! ( 1 ) ;
1013+ }
1014+ BehaviorOnFailure :: Ignore => { }
1015+ }
1016+ }
1017+ output
1018+ }
1019+
9611020 /// Runs a command, printing out nice contextual information if it fails.
9621021 fn run ( & self , cmd : & mut Command ) {
9631022 self . run_cmd ( BootstrapCommand :: from ( cmd) . fail_fast ( ) . output_mode (
0 commit comments