@@ -23,13 +23,12 @@ use std::fmt::Display;
2323use std:: fs:: { self , File } ;
2424use std:: io;
2525use std:: path:: { Path , PathBuf } ;
26- use std:: process:: { Command , Stdio } ;
26+ use std:: process:: { Command , Output , Stdio } ;
2727use std:: str;
2828use std:: sync:: OnceLock ;
2929
3030use build_helper:: ci:: { gha, CiEnv } ;
3131use build_helper:: exit;
32- use build_helper:: util:: fail;
3332use filetime:: FileTime ;
3433use sha2:: digest:: Digest ;
3534use termcolor:: { ColorChoice , StandardStream , WriteColor } ;
@@ -973,43 +972,61 @@ impl Build {
973972
974973 self . verbose ( || println ! ( "running: {command:?}" ) ) ;
975974
976- let output: io:: Result < CommandOutput > = match command. output_mode {
977- OutputMode :: Print => command. command . status ( ) . map ( |status| status. into ( ) ) ,
978- OutputMode :: CaptureAll => command. command . output ( ) . map ( |o| o. into ( ) ) ,
975+ let output: io:: Result < Output > = match command. output_mode {
976+ OutputMode :: Print => command. command . status ( ) . map ( |status| Output {
977+ status,
978+ stdout : vec ! [ ] ,
979+ stderr : vec ! [ ] ,
980+ } ) ,
981+ OutputMode :: CaptureAll => command. command . output ( ) ,
979982 OutputMode :: CaptureStdout => {
980983 command. command . stderr ( Stdio :: inherit ( ) ) ;
981- command. command . output ( ) . map ( |o| o . into ( ) )
984+ command. command . output ( )
982985 }
983986 } ;
984987
985- let output = match output {
986- Ok ( output) => output,
987- Err ( e) => fail ( & format ! ( "failed to execute command: {command:?}\n error: {e}" ) ) ,
988- } ;
989- if !output. is_success ( ) {
990- use std:: fmt:: Write ;
991-
992- // Here we build an error message, and below we decide if it should be printed or not.
993- let mut message = String :: new ( ) ;
994- writeln ! (
995- message,
996- "\n \n Command {command:?} did not execute successfully.\
988+ use std:: fmt:: Write ;
989+
990+ let mut message = String :: new ( ) ;
991+ let output: CommandOutput = match output {
992+ // Command has succeeded
993+ Ok ( output) if output. status . success ( ) => output. into ( ) ,
994+ // Command has started, but then it failed
995+ Ok ( output) => {
996+ writeln ! (
997+ message,
998+ "\n \n Command {command:?} did not execute successfully.\
997999 \n Expected success, got: {}",
998- output. status( ) ,
999- )
1000- . unwrap ( ) ;
1001-
1002- // If the output mode is OutputMode::Print, the output has already been printed to
1003- // stdout/stderr, and we thus don't have anything captured to print anyway.
1004- if matches ! ( command. output_mode, OutputMode :: CaptureAll | OutputMode :: CaptureStdout ) {
1005- writeln ! ( message, "\n STDOUT ----\n {}" , output. stdout( ) . trim( ) ) . unwrap ( ) ;
1000+ output. status,
1001+ )
1002+ . unwrap ( ) ;
1003+
1004+ let output: CommandOutput = output. into ( ) ;
1005+ // If the output mode is OutputMode::Print, the output has already been printed to
1006+ // stdout/stderr, and we thus don't have anything captured to print anyway.
1007+ if matches ! ( command. output_mode, OutputMode :: CaptureAll | OutputMode :: CaptureStdout )
1008+ {
1009+ writeln ! ( message, "\n STDOUT ----\n {}" , output. stdout( ) . trim( ) ) . unwrap ( ) ;
10061010
1007- // Stderr is added to the message only if it was captured
1008- if matches ! ( command. output_mode, OutputMode :: CaptureAll ) {
1009- writeln ! ( message, "\n STDERR ----\n {}" , output. stderr( ) . trim( ) ) . unwrap ( ) ;
1011+ // Stderr is added to the message only if it was captured
1012+ if matches ! ( command. output_mode, OutputMode :: CaptureAll ) {
1013+ writeln ! ( message, "\n STDERR ----\n {}" , output. stderr( ) . trim( ) ) . unwrap ( ) ;
1014+ }
10101015 }
1016+ output
10111017 }
1012-
1018+ // The command did not even start
1019+ Err ( e) => {
1020+ writeln ! (
1021+ message,
1022+ "\n \n Command {command:?} did not execute successfully.\
1023+ \n It was not possible to execute the command: {e:?}"
1024+ )
1025+ . unwrap ( ) ;
1026+ CommandOutput :: did_not_start ( )
1027+ }
1028+ } ;
1029+ if !output. is_success ( ) {
10131030 match command. failure_behavior {
10141031 BehaviorOnFailure :: DelayFail => {
10151032 if self . fail_fast {
0 commit comments