@@ -941,133 +941,6 @@ impl Build {
941
941
} )
942
942
}
943
943
944
- /// Execute a command and return its output.
945
- /// Note: Ideally, you should use one of the BootstrapCommand::run* functions to
946
- /// execute commands. They internally call this method.
947
- #[ track_caller]
948
- fn run (
949
- & self ,
950
- command : & mut BootstrapCommand ,
951
- stdout : OutputMode ,
952
- stderr : OutputMode ,
953
- ) -> CommandOutput {
954
- command. mark_as_executed ( ) ;
955
- if self . config . dry_run ( ) && !command. run_always {
956
- return CommandOutput :: default ( ) ;
957
- }
958
-
959
- #[ cfg( feature = "tracing" ) ]
960
- let _run_span = trace_cmd ! ( command) ;
961
-
962
- let created_at = command. get_created_location ( ) ;
963
- let executed_at = std:: panic:: Location :: caller ( ) ;
964
-
965
- self . verbose ( || {
966
- println ! ( "running: {command:?} (created at {created_at}, executed at {executed_at})" )
967
- } ) ;
968
-
969
- let cmd = command. as_command_mut ( ) ;
970
- cmd. stdout ( stdout. stdio ( ) ) ;
971
- cmd. stderr ( stderr. stdio ( ) ) ;
972
-
973
- let output = cmd. output ( ) ;
974
-
975
- use std:: fmt:: Write ;
976
-
977
- let mut message = String :: new ( ) ;
978
- let output: CommandOutput = match output {
979
- // Command has succeeded
980
- Ok ( output) if output. status . success ( ) => {
981
- CommandOutput :: from_output ( output, stdout, stderr)
982
- }
983
- // Command has started, but then it failed
984
- Ok ( output) => {
985
- writeln ! (
986
- message,
987
- r#"
988
- Command {command:?} did not execute successfully.
989
- Expected success, got {}
990
- Created at: {created_at}
991
- Executed at: {executed_at}"# ,
992
- output. status,
993
- )
994
- . unwrap ( ) ;
995
-
996
- let output: CommandOutput = CommandOutput :: from_output ( output, stdout, stderr) ;
997
-
998
- // If the output mode is OutputMode::Capture, we can now print the output.
999
- // If it is OutputMode::Print, then the output has already been printed to
1000
- // stdout/stderr, and we thus don't have anything captured to print anyway.
1001
- if stdout. captures ( ) {
1002
- writeln ! ( message, "\n STDOUT ----\n {}" , output. stdout( ) . trim( ) ) . unwrap ( ) ;
1003
- }
1004
- if stderr. captures ( ) {
1005
- writeln ! ( message, "\n STDERR ----\n {}" , output. stderr( ) . trim( ) ) . unwrap ( ) ;
1006
- }
1007
- output
1008
- }
1009
- // The command did not even start
1010
- Err ( e) => {
1011
- writeln ! (
1012
- message,
1013
- "\n \n Command {command:?} did not execute successfully.\
1014
- \n It was not possible to execute the command: {e:?}"
1015
- )
1016
- . unwrap ( ) ;
1017
- CommandOutput :: did_not_start ( stdout, stderr)
1018
- }
1019
- } ;
1020
-
1021
- let fail = |message : & str , output : CommandOutput | -> ! {
1022
- if self . is_verbose ( ) {
1023
- println ! ( "{message}" ) ;
1024
- } else {
1025
- let ( stdout, stderr) = ( output. stdout_if_present ( ) , output. stderr_if_present ( ) ) ;
1026
- // If the command captures output, the user would not see any indication that
1027
- // it has failed. In this case, print a more verbose error, since to provide more
1028
- // context.
1029
- if stdout. is_some ( ) || stderr. is_some ( ) {
1030
- if let Some ( stdout) =
1031
- output. stdout_if_present ( ) . take_if ( |s| !s. trim ( ) . is_empty ( ) )
1032
- {
1033
- println ! ( "STDOUT:\n {stdout}\n " ) ;
1034
- }
1035
- if let Some ( stderr) =
1036
- output. stderr_if_present ( ) . take_if ( |s| !s. trim ( ) . is_empty ( ) )
1037
- {
1038
- println ! ( "STDERR:\n {stderr}\n " ) ;
1039
- }
1040
- println ! ( "Command {command:?} has failed. Rerun with -v to see more details." ) ;
1041
- } else {
1042
- println ! ( "Command has failed. Rerun with -v to see more details." ) ;
1043
- }
1044
- }
1045
- exit ! ( 1 ) ;
1046
- } ;
1047
-
1048
- if !output. is_success ( ) {
1049
- match command. failure_behavior {
1050
- BehaviorOnFailure :: DelayFail => {
1051
- if self . fail_fast {
1052
- fail ( & message, output) ;
1053
- }
1054
-
1055
- let mut failures = self . delayed_failures . borrow_mut ( ) ;
1056
- failures. push ( message) ;
1057
- }
1058
- BehaviorOnFailure :: Exit => {
1059
- fail ( & message, output) ;
1060
- }
1061
- BehaviorOnFailure :: Ignore => {
1062
- // If failures are allowed, either the error has been printed already
1063
- // (OutputMode::Print) or the user used a capture output mode and wants to
1064
- // handle the error output on their own.
1065
- }
1066
- }
1067
- }
1068
- output
1069
- }
1070
-
1071
944
/// Check if verbosity is greater than the `level`
1072
945
pub fn is_verbose_than ( & self , level : usize ) -> bool {
1073
946
self . verbosity > level
0 commit comments