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