@@ -15,13 +15,14 @@ use std::{
1515 } ,
1616} ;
1717
18- use crate :: { Error , ErrorKind , Object } ;
18+ use crate :: { Error , ErrorKind , Object , OutputKind } ;
1919
2020#[ derive( Clone , Debug ) ]
2121pub ( crate ) struct CargoOutput {
2222 pub ( crate ) metadata : bool ,
2323 pub ( crate ) warnings : bool ,
2424 pub ( crate ) debug : bool ,
25+ pub ( crate ) output : OutputKind ,
2526 checked_dbg_var : Arc < AtomicBool > ,
2627}
2728
@@ -31,6 +32,7 @@ impl CargoOutput {
3132 Self {
3233 metadata : true ,
3334 warnings : true ,
35+ output : OutputKind :: Forward ,
3436 debug : std:: env:: var_os ( "CC_ENABLE_DEBUG_OUTPUT" ) . is_some ( ) ,
3537 checked_dbg_var : Arc :: new ( AtomicBool :: new ( false ) ) ,
3638 }
@@ -65,6 +67,16 @@ impl CargoOutput {
6567 Stdio :: null ( )
6668 }
6769 }
70+
71+ fn stdio_for_output ( & self ) -> Stdio {
72+ match self . output {
73+ OutputKind :: Capture => Stdio :: piped ( ) ,
74+ OutputKind :: Forward => Stdio :: inherit ( ) ,
75+ OutputKind :: Discard => Stdio :: null ( ) ,
76+ #[ cfg( feature = "stdout_to_stderr" ) ]
77+ OutputKind :: Stderr => std:: io:: stderr ( ) . into ( ) ,
78+ }
79+ }
6880}
6981
7082pub ( crate ) struct StderrForwarder {
@@ -321,9 +333,10 @@ pub(crate) fn run_output(
321333) -> Result < Vec < u8 > , Error > {
322334 let program = program. as_ref ( ) ;
323335
324- cmd. stdout ( Stdio :: piped ( ) ) ;
325-
326- let mut child = spawn ( cmd, program, cargo_output) ?;
336+ // We specifically need the output to be captured, so override default
337+ let mut captured_cargo_output = cargo_output. clone ( ) ;
338+ captured_cargo_output. output = OutputKind :: Capture ;
339+ let mut child = spawn ( cmd, program, & captured_cargo_output) ?;
327340
328341 let mut stdout = vec ! [ ] ;
329342 child
@@ -333,6 +346,7 @@ pub(crate) fn run_output(
333346 . read_to_end ( & mut stdout)
334347 . unwrap ( ) ;
335348
349+ // Don't care about this output, use the normal settings
336350 wait_on_child ( cmd, program, & mut child, cargo_output) ?;
337351
338352 Ok ( stdout)
@@ -356,7 +370,11 @@ pub(crate) fn spawn(
356370 cargo_output. print_debug ( & format_args ! ( "running: {:?}" , cmd) ) ;
357371
358372 let cmd = ResetStderr ( cmd) ;
359- let child = cmd. 0 . stderr ( cargo_output. stdio_for_warnings ( ) ) . spawn ( ) ;
373+ let child = cmd
374+ . 0
375+ . stderr ( cargo_output. stdio_for_warnings ( ) )
376+ . stdout ( cargo_output. stdio_for_output ( ) )
377+ . spawn ( ) ;
360378 match child {
361379 Ok ( child) => Ok ( child) ,
362380 Err ( ref e) if e. kind ( ) == io:: ErrorKind :: NotFound => {
0 commit comments