@@ -23,14 +23,13 @@ use std::fmt::Display;
23
23
use std:: fs:: { self , File } ;
24
24
use std:: io;
25
25
use std:: path:: { Path , PathBuf } ;
26
- use std:: process:: { Command , Stdio } ;
26
+ use std:: process:: { Command , Output , Stdio } ;
27
27
use std:: str;
28
28
use std:: sync:: OnceLock ;
29
29
use std:: time:: SystemTime ;
30
30
31
31
use build_helper:: ci:: { gha, CiEnv } ;
32
32
use build_helper:: exit;
33
- use build_helper:: util:: fail;
34
33
use filetime:: FileTime ;
35
34
use sha2:: digest:: Digest ;
36
35
use termcolor:: { ColorChoice , StandardStream , WriteColor } ;
@@ -945,43 +944,61 @@ impl Build {
945
944
946
945
self . verbose ( || println ! ( "running: {command:?}" ) ) ;
947
946
948
- let output: io:: Result < CommandOutput > = match command. output_mode {
949
- OutputMode :: Print => command. command . status ( ) . map ( |status| status. into ( ) ) ,
950
- OutputMode :: CaptureAll => command. command . output ( ) . map ( |o| o. into ( ) ) ,
947
+ let output: io:: Result < Output > = match command. output_mode {
948
+ OutputMode :: Print => command. command . status ( ) . map ( |status| Output {
949
+ status,
950
+ stdout : vec ! [ ] ,
951
+ stderr : vec ! [ ] ,
952
+ } ) ,
953
+ OutputMode :: CaptureAll => command. command . output ( ) ,
951
954
OutputMode :: CaptureStdout => {
952
955
command. command . stderr ( Stdio :: inherit ( ) ) ;
953
- command. command . output ( ) . map ( |o| o . into ( ) )
956
+ command. command . output ( )
954
957
}
955
958
} ;
956
959
957
- let output = match output {
958
- Ok ( output) => output,
959
- Err ( e) => fail ( & format ! ( "failed to execute command: {command:?}\n error: {e}" ) ) ,
960
- } ;
961
- if !output. is_success ( ) {
962
- use std:: fmt:: Write ;
963
-
964
- // Here we build an error message, and below we decide if it should be printed or not.
965
- let mut message = String :: new ( ) ;
966
- writeln ! (
967
- message,
968
- "\n \n Command {command:?} did not execute successfully.\
960
+ use std:: fmt:: Write ;
961
+
962
+ let mut message = String :: new ( ) ;
963
+ let output: CommandOutput = match output {
964
+ // Command has succeeded
965
+ Ok ( output) if output. status . success ( ) => output. into ( ) ,
966
+ // Command has started, but then it failed
967
+ Ok ( output) => {
968
+ writeln ! (
969
+ message,
970
+ "\n \n Command {command:?} did not execute successfully.\
969
971
\n Expected success, got: {}",
970
- output. status( ) ,
971
- )
972
- . unwrap ( ) ;
973
-
974
- // If the output mode is OutputMode::Print, the output has already been printed to
975
- // stdout/stderr, and we thus don't have anything captured to print anyway.
976
- if matches ! ( command. output_mode, OutputMode :: CaptureAll | OutputMode :: CaptureStdout ) {
977
- writeln ! ( message, "\n STDOUT ----\n {}" , output. stdout( ) . trim( ) ) . unwrap ( ) ;
972
+ output. status,
973
+ )
974
+ . unwrap ( ) ;
975
+
976
+ let output: CommandOutput = output. into ( ) ;
977
+ // If the output mode is OutputMode::Print, the output has already been printed to
978
+ // stdout/stderr, and we thus don't have anything captured to print anyway.
979
+ if matches ! ( command. output_mode, OutputMode :: CaptureAll | OutputMode :: CaptureStdout )
980
+ {
981
+ writeln ! ( message, "\n STDOUT ----\n {}" , output. stdout( ) . trim( ) ) . unwrap ( ) ;
978
982
979
- // Stderr is added to the message only if it was captured
980
- if matches ! ( command. output_mode, OutputMode :: CaptureAll ) {
981
- writeln ! ( message, "\n STDERR ----\n {}" , output. stderr( ) . trim( ) ) . unwrap ( ) ;
983
+ // Stderr is added to the message only if it was captured
984
+ if matches ! ( command. output_mode, OutputMode :: CaptureAll ) {
985
+ writeln ! ( message, "\n STDERR ----\n {}" , output. stderr( ) . trim( ) ) . unwrap ( ) ;
986
+ }
982
987
}
988
+ output
983
989
}
984
-
990
+ // The command did not even start
991
+ Err ( e) => {
992
+ writeln ! (
993
+ message,
994
+ "\n \n Command {command:?} did not execute successfully.\
995
+ \n It was not possible to execute the command: {e:?}"
996
+ )
997
+ . unwrap ( ) ;
998
+ CommandOutput :: did_not_start ( )
999
+ }
1000
+ } ;
1001
+ if !output. is_success ( ) {
985
1002
match command. failure_behavior {
986
1003
BehaviorOnFailure :: DelayFail => {
987
1004
if self . fail_fast {
0 commit comments