@@ -28,16 +28,15 @@ use std::str;
2828
2929use build_helper:: ci:: { gha, CiEnv } ;
3030use build_helper:: exit;
31+ use build_helper:: util:: fail;
3132use channel:: GitInfo ;
3233use config:: { DryRun , Target } ;
3334use filetime:: FileTime ;
3435use once_cell:: sync:: OnceCell ;
3536
3637use crate :: builder:: Kind ;
3738use crate :: config:: { LlvmLibunwind , TargetSelection } ;
38- use crate :: util:: {
39- dir_is_empty, exe, libdir, mtime, output, run, run_suppressed, symlink_dir, try_run_suppressed,
40- } ;
39+ use crate :: util:: { dir_is_empty, exe, libdir, mtime, output, run, symlink_dir} ;
4140
4241mod builder;
4342mod cache;
@@ -91,7 +90,7 @@ mod job {
9190pub use crate :: builder:: PathSet ;
9291use crate :: cache:: { Interned , INTERNER } ;
9392pub use crate :: config:: Config ;
94- use crate :: exec:: BootstrapCommand ;
93+ use crate :: exec:: { BootstrapCommand , OutputOnFailure } ;
9594pub use crate :: flags:: Subcommand ;
9695use termcolor:: { ColorChoice , StandardStream , WriteColor } ;
9796
@@ -976,31 +975,17 @@ impl Build {
976975
977976 /// Runs a command, printing out nice contextual information if it fails.
978977 fn run_quiet ( & self , cmd : & mut Command ) {
979- if self . config . dry_run ( ) {
980- return ;
981- }
982- self . verbose ( & format ! ( "running: {cmd:?}" ) ) ;
983- run_suppressed ( cmd)
978+ let cmd: BootstrapCommand < ' _ > = cmd. into ( ) ;
979+ // TODO: fail bootstrap immediately if this command fails
980+ self . run_cmd ( cmd. output_on_failure ( OutputOnFailure :: Verbose ) ) ;
984981 }
985982
986983 /// Runs a command, printing out nice contextual information if it fails.
987984 /// Exits if the command failed to execute at all, otherwise returns its
988985 /// `status.success()`.
989986 fn run_quiet_delaying_failure ( & self , cmd : & mut Command ) -> bool {
990- if self . config . dry_run ( ) {
991- return true ;
992- }
993- if !self . fail_fast {
994- self . verbose ( & format ! ( "running: {cmd:?}" ) ) ;
995- if !try_run_suppressed ( cmd) {
996- let mut failures = self . delayed_failures . borrow_mut ( ) ;
997- failures. push ( format ! ( "{cmd:?}" ) ) ;
998- return false ;
999- }
1000- } else {
1001- self . run_quiet ( cmd) ;
1002- }
1003- true
987+ let cmd: BootstrapCommand < ' _ > = cmd. into ( ) ;
988+ self . run_cmd ( cmd. output_on_failure ( OutputOnFailure :: Verbose ) . delay_failure ( ) )
1004989 }
1005990
1006991 /// Runs a command, printing out contextual info if it fails, and delaying errors until the build finishes.
@@ -1014,8 +999,43 @@ impl Build {
1014999 let command = cmd. into ( ) ;
10151000 self . verbose ( & format ! ( "running: {command:?}" ) ) ;
10161001
1017- #[ allow( deprecated) ] // can't use Build::try_run, that's us
1018- let result = self . config . try_run ( command. command ) ;
1002+ let output = match command. command . output ( ) {
1003+ Ok ( output) => output,
1004+ Err ( e) => fail ( & format ! ( "failed to execute command: {:?}\n error: {}" , command, e) ) ,
1005+ } ;
1006+ let result = if !output. status . success ( ) {
1007+ let output_on_failure = match command. output_on_failure {
1008+ Some ( output) => Some ( output) ,
1009+ None if self . is_verbose ( ) => Some ( OutputOnFailure :: Succint ) ,
1010+ None => None ,
1011+ } ;
1012+
1013+ if let Some ( output_on_failure) = output_on_failure {
1014+ use std:: fmt:: Write ;
1015+
1016+ let mut message = String :: new ( ) ;
1017+ writeln ! (
1018+ message,
1019+ "\n \n command did not execute successfully: {:?}\n \
1020+ expected success, got: {}\n \n ",
1021+ command. command, output. status
1022+ )
1023+ . unwrap ( ) ;
1024+ if let OutputOnFailure :: Verbose = output_on_failure {
1025+ writeln ! (
1026+ message,
1027+ "stdout ----\n {}\n \
1028+ stderr ----\n {}\n \n ",
1029+ String :: from_utf8_lossy( & output. stdout) ,
1030+ String :: from_utf8_lossy( & output. stderr)
1031+ )
1032+ . unwrap ( ) ;
1033+ }
1034+ }
1035+ Err ( ( ) )
1036+ } else {
1037+ Ok ( ( ) )
1038+ } ;
10191039
10201040 match result {
10211041 Ok ( _) => true ,
0 commit comments