@@ -23,14 +23,13 @@ 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 ;
2929use std:: time:: SystemTime ;
3030
3131use build_helper:: ci:: { gha, CiEnv } ;
3232use build_helper:: exit;
33- use build_helper:: util:: fail;
3433use filetime:: FileTime ;
3534use sha2:: digest:: Digest ;
3635use termcolor:: { ColorChoice , StandardStream , WriteColor } ;
@@ -945,43 +944,61 @@ impl Build {
945944
946945 self . verbose ( || println ! ( "running: {command:?}" ) ) ;
947946
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 ( ) ,
951954 OutputMode :: CaptureStdout => {
952955 command. command . stderr ( Stdio :: inherit ( ) ) ;
953- command. command . output ( ) . map ( |o| o . into ( ) )
956+ command. command . output ( )
954957 }
955958 } ;
956959
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.\
969971 \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 ( ) ;
978982
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+ }
982987 }
988+ output
983989 }
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 ( ) {
9851002 match command. failure_behavior {
9861003 BehaviorOnFailure :: DelayFail => {
9871004 if self . fail_fast {
0 commit comments