@@ -22,15 +22,28 @@ pub(crate) struct CargoOutput {
22
22
pub ( crate ) metadata : bool ,
23
23
pub ( crate ) warnings : bool ,
24
24
pub ( crate ) debug : bool ,
25
+ pub ( crate ) output : OutputKind ,
25
26
checked_dbg_var : Arc < AtomicBool > ,
26
27
}
27
28
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
+
28
40
impl CargoOutput {
29
41
pub ( crate ) fn new ( ) -> Self {
30
42
#[ allow( clippy:: disallowed_methods) ]
31
43
Self {
32
44
metadata : true ,
33
45
warnings : true ,
46
+ output : OutputKind :: Forward ,
34
47
debug : std:: env:: var_os ( "CC_ENABLE_DEBUG_OUTPUT" ) . is_some ( ) ,
35
48
checked_dbg_var : Arc :: new ( AtomicBool :: new ( false ) ) ,
36
49
}
@@ -65,6 +78,14 @@ impl CargoOutput {
65
78
Stdio :: null ( )
66
79
}
67
80
}
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
+ }
68
89
}
69
90
70
91
pub ( crate ) struct StderrForwarder {
@@ -321,9 +342,10 @@ pub(crate) fn run_output(
321
342
) -> Result < Vec < u8 > , Error > {
322
343
let program = program. as_ref ( ) ;
323
344
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) ?;
327
349
328
350
let mut stdout = vec ! [ ] ;
329
351
child
@@ -333,6 +355,7 @@ pub(crate) fn run_output(
333
355
. read_to_end ( & mut stdout)
334
356
. unwrap ( ) ;
335
357
358
+ // Don't care about this output, use the normal settings
336
359
wait_on_child ( cmd, program, & mut child, cargo_output) ?;
337
360
338
361
Ok ( stdout)
@@ -356,7 +379,11 @@ pub(crate) fn spawn(
356
379
cargo_output. print_debug ( & format_args ! ( "running: {:?}" , cmd) ) ;
357
380
358
381
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 ( ) ;
360
387
match child {
361
388
Ok ( child) => Ok ( child) ,
362
389
Err ( ref e) if e. kind ( ) == io:: ErrorKind :: NotFound => {
0 commit comments