@@ -607,7 +607,7 @@ impl Build {
607
607
let output = self
608
608
. run (
609
609
helpers:: git ( Some ( & self . src ) )
610
- . quiet ( )
610
+ . capture ( )
611
611
. args ( [ "config" , "--file" ] )
612
612
. arg ( self . config . src . join ( ".gitmodules" ) )
613
613
. args ( [ "--get-regexp" , "path" ] ) ,
@@ -971,60 +971,62 @@ impl Build {
971
971
972
972
self . verbose ( || println ! ( "running: {command:?}" ) ) ;
973
973
974
- let output_mode = command. output_mode . unwrap_or_else ( || match self . is_verbose ( ) {
975
- true => OutputMode :: All ,
976
- false => OutputMode :: OnlyOutput ,
977
- } ) ;
978
- let ( output, print_error) : ( io:: Result < CommandOutput > , bool ) = match output_mode {
979
- mode @ ( OutputMode :: All | OutputMode :: OnlyOutput ) => (
980
- command. command . status ( ) . map ( |status| status. into ( ) ) ,
981
- matches ! ( mode, OutputMode :: All ) ,
982
- ) ,
983
- mode @ ( OutputMode :: OnlyOnFailure | OutputMode :: Quiet ) => (
984
- command. command . output ( ) . map ( |o| o. into ( ) ) ,
985
- matches ! ( mode, OutputMode :: OnlyOnFailure ) ,
986
- ) ,
974
+ let output: io:: Result < CommandOutput > = match command. output_mode {
975
+ OutputMode :: Print => command. command . status ( ) . map ( |status| status. into ( ) ) ,
976
+ OutputMode :: CaptureAll => command. command . output ( ) . map ( |o| o. into ( ) ) ,
977
+ OutputMode :: CaptureStdout => {
978
+ command. command . stderr ( Stdio :: inherit ( ) ) ;
979
+ command. command . output ( ) . map ( |o| o. into ( ) )
980
+ }
987
981
} ;
988
982
989
983
let output = match output {
990
984
Ok ( output) => output,
991
- Err ( e) => fail ( & format ! ( "failed to execute command: {:?}\n error: {}" , command , e ) ) ,
985
+ Err ( e) => fail ( & format ! ( "failed to execute command: {command :?}\n error: {e}" ) ) ,
992
986
} ;
993
987
if !output. is_success ( ) {
994
- if print_error {
995
- println ! (
996
- "\n \n Command did not execute successfully.\
997
- \n Expected success, got: {}",
998
- output. status( ) ,
999
- ) ;
988
+ use std:: fmt:: Write ;
989
+
990
+ // Here we build an error message, and below we decide if it should be printed or not.
991
+ let mut message = String :: new ( ) ;
992
+ writeln ! (
993
+ message,
994
+ "\n \n Command {command:?} did not execute successfully.\
995
+ \n Expected success, got: {}",
996
+ output. status( ) ,
997
+ )
998
+ . unwrap ( ) ;
1000
999
1001
- if !self . is_verbose ( ) {
1002
- println ! ( "Add `-v` to see more details.\n " ) ;
1003
- }
1000
+ // If the output mode is OutputMode::Print, the output has already been printed to
1001
+ // stdout/stderr, and we thus don't have anything captured to print anyway.
1002
+ if matches ! ( command. output_mode, OutputMode :: CaptureAll | OutputMode :: CaptureStdout ) {
1003
+ writeln ! ( message, "\n STDOUT ----\n {}" , output. stdout( ) . trim( ) ) . unwrap ( ) ;
1004
1004
1005
- self . verbose ( || {
1006
- println ! (
1007
- "\n STDOUT ----\n {}\n \
1008
- STDERR ----\n {}\n ",
1009
- output. stdout( ) ,
1010
- output. stderr( ) ,
1011
- )
1012
- } ) ;
1005
+ // Stderr is added to the message only if it was captured
1006
+ if matches ! ( command. output_mode, OutputMode :: CaptureAll ) {
1007
+ writeln ! ( message, "\n STDERR ----\n {}" , output. stderr( ) . trim( ) ) . unwrap ( ) ;
1008
+ }
1013
1009
}
1014
1010
1015
1011
match command. failure_behavior {
1016
1012
BehaviorOnFailure :: DelayFail => {
1017
1013
if self . fail_fast {
1014
+ println ! ( "{message}" ) ;
1018
1015
exit ! ( 1 ) ;
1019
1016
}
1020
1017
1021
1018
let mut failures = self . delayed_failures . borrow_mut ( ) ;
1022
- failures. push ( format ! ( "{command:?}" ) ) ;
1019
+ failures. push ( message ) ;
1023
1020
}
1024
1021
BehaviorOnFailure :: Exit => {
1022
+ println ! ( "{message}" ) ;
1025
1023
exit ! ( 1 ) ;
1026
1024
}
1027
- BehaviorOnFailure :: Ignore => { }
1025
+ BehaviorOnFailure :: Ignore => {
1026
+ // If failures are allowed, either the error has been printed already
1027
+ // (OutputMode::Print) or the user used a capture output mode and wants to
1028
+ // handle the error output on their own.
1029
+ }
1028
1030
}
1029
1031
}
1030
1032
output
@@ -1515,7 +1517,7 @@ impl Build {
1515
1517
// (Note that we use a `..` range, not the `...` symmetric difference.)
1516
1518
self . run (
1517
1519
helpers:: git ( Some ( & self . src ) )
1518
- . quiet ( )
1520
+ . capture ( )
1519
1521
. arg ( "rev-list" )
1520
1522
. arg ( "--count" )
1521
1523
. arg ( "--merges" )
0 commit comments