@@ -166,10 +166,11 @@ pub struct JobState<'a> {
166
166
/// Channel back to the main thread to coordinate messages and such.
167
167
messages : Arc < Queue < Message > > ,
168
168
169
- /// Normally messages are handled in a bounded way. When the job is fresh
170
- /// however we need to immediately return to prevent a deadlock as the messages
171
- /// are processed on the same thread as they are sent from.
172
- messages_bounded : bool ,
169
+ /// Normally output is sent to the job queue with backpressure. When the job is fresh
170
+ /// however we need to immediately display the output to prevent a deadlock as the
171
+ /// output messages are processed on the same thread as they are sent from. `output`
172
+ /// defines where to output in this case.
173
+ output : Option < & ' a Config > ,
173
174
174
175
/// The job id that this state is associated with, used when sending
175
176
/// messages back to the main thread.
@@ -236,20 +237,24 @@ impl<'a> JobState<'a> {
236
237
. push ( Message :: BuildPlanMsg ( module_name, cmd, filenames) ) ;
237
238
}
238
239
239
- pub fn stdout ( & self , stdout : String ) {
240
- if self . messages_bounded {
241
- self . messages . push_bounded ( Message :: Stdout ( stdout) ) ;
240
+ pub fn stdout ( & self , stdout : String ) -> CargoResult < ( ) > {
241
+ if let Some ( config ) = self . output {
242
+ writeln ! ( config . shell ( ) . out ( ) , "{}" , stdout) ? ;
242
243
} else {
243
- self . messages . push ( Message :: Stdout ( stdout) ) ;
244
+ self . messages . push_bounded ( Message :: Stdout ( stdout) ) ;
244
245
}
246
+ Ok ( ( ) )
245
247
}
246
248
247
- pub fn stderr ( & self , stderr : String ) {
248
- if self . messages_bounded {
249
- self . messages . push_bounded ( Message :: Stderr ( stderr) ) ;
249
+ pub fn stderr ( & self , stderr : String ) -> CargoResult < ( ) > {
250
+ if let Some ( config) = self . output {
251
+ let mut shell = config. shell ( ) ;
252
+ shell. print_ansi ( stderr. as_bytes ( ) ) ?;
253
+ shell. err ( ) . write_all ( b"\n " ) ?;
250
254
} else {
251
- self . messages . push ( Message :: Stderr ( stderr) ) ;
255
+ self . messages . push_bounded ( Message :: Stderr ( stderr) ) ;
252
256
}
257
+ Ok ( ( ) )
253
258
}
254
259
255
260
/// A method used to signal to the coordinator thread that the rmeta file
@@ -839,17 +844,9 @@ impl<'cfg> DrainState<'cfg> {
839
844
self . note_working_on ( cx. bcx . config , unit, fresh) ?;
840
845
}
841
846
842
- let doit = move || {
843
- let state = JobState {
844
- id,
845
- messages : messages. clone ( ) ,
846
- messages_bounded : job. freshness ( ) == Freshness :: Dirty ,
847
- rmeta_required : Cell :: new ( rmeta_required) ,
848
- _marker : marker:: PhantomData ,
849
- } ;
850
-
847
+ let doit = move |state : JobState < ' _ > | {
851
848
let mut sender = FinishOnDrop {
852
- messages : & messages,
849
+ messages : & state . messages ,
853
850
id,
854
851
result : None ,
855
852
} ;
@@ -868,7 +865,9 @@ impl<'cfg> DrainState<'cfg> {
868
865
// we need to make sure that the metadata is flagged as produced so
869
866
// send a synthetic message here.
870
867
if state. rmeta_required . get ( ) && sender. result . as_ref ( ) . unwrap ( ) . is_ok ( ) {
871
- messages. push ( Message :: Finish ( id, Artifact :: Metadata , Ok ( ( ) ) ) ) ;
868
+ state
869
+ . messages
870
+ . push ( Message :: Finish ( state. id , Artifact :: Metadata , Ok ( ( ) ) ) ) ;
872
871
}
873
872
874
873
// Use a helper struct with a `Drop` implementation to guarantee
@@ -898,11 +897,25 @@ impl<'cfg> DrainState<'cfg> {
898
897
self . timings . add_fresh ( ) ;
899
898
// Running a fresh job on the same thread is often much faster than spawning a new
900
899
// thread to run the job.
901
- doit ( ) ;
900
+ doit ( JobState {
901
+ id,
902
+ messages : messages. clone ( ) ,
903
+ output : Some ( cx. bcx . config ) ,
904
+ rmeta_required : Cell :: new ( rmeta_required) ,
905
+ _marker : marker:: PhantomData ,
906
+ } ) ;
902
907
}
903
908
Freshness :: Dirty => {
904
909
self . timings . add_dirty ( ) ;
905
- scope. spawn ( move |_| doit ( ) ) ;
910
+ scope. spawn ( move |_| {
911
+ doit ( JobState {
912
+ id,
913
+ messages : messages. clone ( ) ,
914
+ output : None ,
915
+ rmeta_required : Cell :: new ( rmeta_required) ,
916
+ _marker : marker:: PhantomData ,
917
+ } )
918
+ } ) ;
906
919
}
907
920
}
908
921
0 commit comments