@@ -72,6 +72,18 @@ pub trait Executor: Send + Sync + 'static {
72
72
Ok ( ( ) )
73
73
}
74
74
75
+ fn exec_and_capture_output (
76
+ & self ,
77
+ cmd : ProcessBuilder ,
78
+ id : & PackageId ,
79
+ target : & Target ,
80
+ mode : CompileMode ,
81
+ _state : & job_queue:: JobState < ' _ > ,
82
+ ) -> CargoResult < ( ) > {
83
+ // we forward to exec() to keep RLS working.
84
+ self . exec ( cmd, id, target, mode)
85
+ }
86
+
75
87
fn exec_json (
76
88
& self ,
77
89
cmd : ProcessBuilder ,
@@ -97,7 +109,18 @@ pub trait Executor: Send + Sync + 'static {
97
109
#[ derive( Copy , Clone ) ]
98
110
pub struct DefaultExecutor ;
99
111
100
- impl Executor for DefaultExecutor { }
112
+ impl Executor for DefaultExecutor {
113
+ fn exec_and_capture_output (
114
+ & self ,
115
+ cmd : ProcessBuilder ,
116
+ _id : & PackageId ,
117
+ _target : & Target ,
118
+ _mode : CompileMode ,
119
+ state : & job_queue:: JobState < ' _ > ,
120
+ ) -> CargoResult < ( ) > {
121
+ state. capture_output ( cmd, false ) . map ( drop)
122
+ }
123
+ }
101
124
102
125
fn compile < ' a , ' cfg : ' a > (
103
126
cx : & mut Context < ' a , ' cfg > ,
@@ -216,6 +239,8 @@ fn rustc<'a, 'cfg>(
216
239
. unwrap_or_else ( || cx. bcx . config . cwd ( ) )
217
240
. to_path_buf ( ) ;
218
241
242
+ let should_capture_output = cx. bcx . config . cli_unstable ( ) . compile_progress ;
243
+
219
244
return Ok ( Work :: new ( move |state| {
220
245
// Only at runtime have we discovered what the extra -L and -l
221
246
// arguments are for native libraries, so we process those here. We
@@ -291,7 +316,12 @@ fn rustc<'a, 'cfg>(
291
316
} else if build_plan {
292
317
state. build_plan ( buildkey, rustc. clone ( ) , outputs. clone ( ) ) ;
293
318
} else {
294
- exec. exec ( rustc, & package_id, & target, mode)
319
+ let exec_result = if should_capture_output {
320
+ exec. exec_and_capture_output ( rustc, & package_id, & target, mode, state)
321
+ } else {
322
+ exec. exec ( rustc, & package_id, & target, mode)
323
+ } ;
324
+ exec_result
295
325
. map_err ( Internal :: new)
296
326
. chain_err ( || format ! ( "Could not compile `{}`." , name) ) ?;
297
327
}
@@ -580,6 +610,7 @@ fn rustdoc<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoResult
580
610
rustdoc. arg ( "--crate-name" ) . arg ( & unit. target . crate_name ( ) ) ;
581
611
add_path_args ( bcx, unit, & mut rustdoc) ;
582
612
add_cap_lints ( bcx, unit, & mut rustdoc) ;
613
+ add_color ( bcx, & mut rustdoc) ;
583
614
584
615
if unit. kind != Kind :: Host {
585
616
if let Some ( ref target) = bcx. build_config . requested_target {
@@ -612,6 +643,8 @@ fn rustdoc<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoResult
612
643
let build_state = cx. build_state . clone ( ) ;
613
644
let key = ( unit. pkg . package_id ( ) . clone ( ) , unit. kind ) ;
614
645
646
+ let should_capture_output = cx. bcx . config . cli_unstable ( ) . compile_progress ;
647
+
615
648
Ok ( Work :: new ( move |state| {
616
649
if let Some ( output) = build_state. outputs . lock ( ) . unwrap ( ) . get ( & key) {
617
650
for cfg in output. cfgs . iter ( ) {
@@ -622,9 +655,13 @@ fn rustdoc<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoResult
622
655
}
623
656
}
624
657
state. running ( & rustdoc) ;
625
- rustdoc
626
- . exec ( )
627
- . chain_err ( || format ! ( "Could not document `{}`." , name) ) ?;
658
+
659
+ let exec_result = if should_capture_output {
660
+ state. capture_output ( rustdoc, false ) . map ( drop)
661
+ } else {
662
+ rustdoc. exec ( )
663
+ } ;
664
+ exec_result. chain_err ( || format ! ( "Could not document `{}`." , name) ) ?;
628
665
Ok ( ( ) )
629
666
} ) )
630
667
}
@@ -672,6 +709,15 @@ fn add_cap_lints(bcx: &BuildContext, unit: &Unit, cmd: &mut ProcessBuilder) {
672
709
}
673
710
}
674
711
712
+ fn add_color ( bcx : & BuildContext , cmd : & mut ProcessBuilder ) {
713
+ let capture_output = bcx. config . cli_unstable ( ) . compile_progress ;
714
+ let shell = bcx. config . shell ( ) ;
715
+ if capture_output || shell. color_choice ( ) != ColorChoice :: CargoAuto {
716
+ let color = if shell. supports_color ( ) { "always" } else { "never" } ;
717
+ cmd. args ( & [ "--color" , color] ) ;
718
+ }
719
+ }
720
+
675
721
fn build_base_args < ' a , ' cfg > (
676
722
cx : & mut Context < ' a , ' cfg > ,
677
723
cmd : & mut ProcessBuilder ,
@@ -696,17 +742,8 @@ fn build_base_args<'a, 'cfg>(
696
742
697
743
cmd. arg ( "--crate-name" ) . arg ( & unit. target . crate_name ( ) ) ;
698
744
699
- add_path_args ( & cx. bcx , unit, cmd) ;
700
-
701
- match bcx. config . shell ( ) . color_choice ( ) {
702
- ColorChoice :: Always => {
703
- cmd. arg ( "--color" ) . arg ( "always" ) ;
704
- }
705
- ColorChoice :: Never => {
706
- cmd. arg ( "--color" ) . arg ( "never" ) ;
707
- }
708
- ColorChoice :: CargoAuto => { }
709
- }
745
+ add_path_args ( bcx, unit, cmd) ;
746
+ add_color ( bcx, cmd) ;
710
747
711
748
if bcx. build_config . json_messages ( ) {
712
749
cmd. arg ( "--error-format" ) . arg ( "json" ) ;
0 commit comments