@@ -28,16 +28,15 @@ use std::str;
28
28
29
29
use build_helper:: ci:: { gha, CiEnv } ;
30
30
use build_helper:: exit;
31
+ use build_helper:: util:: fail;
31
32
use channel:: GitInfo ;
32
33
use config:: { DryRun , Target } ;
33
34
use filetime:: FileTime ;
34
35
use once_cell:: sync:: OnceCell ;
35
36
36
37
use crate :: builder:: Kind ;
37
38
use 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} ;
41
40
42
41
mod builder;
43
42
mod cache;
@@ -91,7 +90,7 @@ mod job {
91
90
pub use crate :: builder:: PathSet ;
92
91
use crate :: cache:: { Interned , INTERNER } ;
93
92
pub use crate :: config:: Config ;
94
- use crate :: exec:: BootstrapCommand ;
93
+ use crate :: exec:: { BootstrapCommand , OutputOnFailure } ;
95
94
pub use crate :: flags:: Subcommand ;
96
95
use termcolor:: { ColorChoice , StandardStream , WriteColor } ;
97
96
@@ -976,31 +975,17 @@ impl Build {
976
975
977
976
/// Runs a command, printing out nice contextual information if it fails.
978
977
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 ) ) ;
984
981
}
985
982
986
983
/// Runs a command, printing out nice contextual information if it fails.
987
984
/// Exits if the command failed to execute at all, otherwise returns its
988
985
/// `status.success()`.
989
986
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 ( ) )
1004
989
}
1005
990
1006
991
/// Runs a command, printing out contextual info if it fails, and delaying errors until the build finishes.
@@ -1014,8 +999,43 @@ impl Build {
1014
999
let command = cmd. into ( ) ;
1015
1000
self . verbose ( & format ! ( "running: {command:?}" ) ) ;
1016
1001
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
+ } ;
1019
1039
1020
1040
match result {
1021
1041
Ok ( _) => true ,
0 commit comments