@@ -22,15 +22,28 @@ pub(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
29+ /// Different strategies for handling compiler output (to stdout)
30+ #[ derive( Clone , Debug ) ]
31+ pub ( crate ) enum OutputKind {
32+ /// Forward the output to this process' stdout (Stdio::inherit)
33+ Forward ,
34+ /// Discard the output (Stdio::null)
35+ Discard ,
36+ /// Capture the result
37+ Capture ,
38+ }
39+
2840impl CargoOutput {
2941 pub ( crate ) fn new ( ) -> Self {
3042 #[ allow( clippy:: disallowed_methods) ]
3143 Self {
3244 metadata : true ,
3345 warnings : true ,
46+ output : OutputKind :: Forward ,
3447 debug : std:: env:: var_os ( "CC_ENABLE_DEBUG_OUTPUT" ) . is_some ( ) ,
3548 checked_dbg_var : Arc :: new ( AtomicBool :: new ( false ) ) ,
3649 }
@@ -65,6 +78,14 @@ impl CargoOutput {
6578 Stdio :: null ( )
6679 }
6780 }
81+
82+ fn stdio_for_output ( & self ) -> Stdio {
83+ match self . output {
84+ OutputKind :: Capture => Stdio :: piped ( ) ,
85+ OutputKind :: Forward => Stdio :: inherit ( ) ,
86+ OutputKind :: Discard => Stdio :: null ( ) ,
87+ }
88+ }
6889}
6990
7091pub ( crate ) struct StderrForwarder {
@@ -321,9 +342,10 @@ pub(crate) fn run_output(
321342) -> Result < Vec < u8 > , Error > {
322343 let program = program. as_ref ( ) ;
323344
324- cmd. stdout ( Stdio :: piped ( ) ) ;
325-
326- let mut child = spawn ( cmd, program, cargo_output) ?;
345+ // We specifically need the output to be captured, so override default
346+ let mut captured_cargo_output = cargo_output. clone ( ) ;
347+ captured_cargo_output. output = OutputKind :: Capture ;
348+ let mut child = spawn ( cmd, program, & captured_cargo_output) ?;
327349
328350 let mut stdout = vec ! [ ] ;
329351 child
@@ -333,6 +355,7 @@ pub(crate) fn run_output(
333355 . read_to_end ( & mut stdout)
334356 . unwrap ( ) ;
335357
358+ // Don't care about this output, use the normal settings
336359 wait_on_child ( cmd, program, & mut child, cargo_output) ?;
337360
338361 Ok ( stdout)
@@ -356,7 +379,11 @@ pub(crate) fn spawn(
356379 cargo_output. print_debug ( & format_args ! ( "running: {:?}" , cmd) ) ;
357380
358381 let cmd = ResetStderr ( cmd) ;
359- let child = cmd. 0 . stderr ( cargo_output. stdio_for_warnings ( ) ) . spawn ( ) ;
382+ let child = cmd
383+ . 0
384+ . stderr ( cargo_output. stdio_for_warnings ( ) )
385+ . stdout ( cargo_output. stdio_for_output ( ) )
386+ . spawn ( ) ;
360387 match child {
361388 Ok ( child) => Ok ( child) ,
362389 Err ( ref e) if e. kind ( ) == io:: ErrorKind :: NotFound => {
0 commit comments