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