@@ -15,29 +15,39 @@ use {
1515/// Channel sizes are designed to avoid useless computations.
1616pub struct Executor {
1717 pub line_receiver : Receiver < CommandExecInfo > ,
18- task_sender : Sender < ( ) > ,
18+ task_sender : Sender < Task > ,
1919 stop_sender : Sender < ( ) > , // signal for stopping the thread
2020 thread : thread:: JoinHandle < ( ) > ,
2121}
2222
23+ #[ derive( Debug , Clone , Copy , PartialEq , Default ) ]
24+ pub struct Task {
25+ pub backtrace : bool ,
26+ }
27+
2328impl Executor {
2429 /// launch the commands, sends the lines of its stderr on the
2530 /// line channel.
2631 /// If `with_stdout` captures and send also its stdout.
2732 pub fn new ( mission : & Mission ) -> Result < Self > {
2833 let mut command = mission. get_command ( ) ;
2934 let with_stdout = mission. need_stdout ( ) ;
30- let ( task_sender, task_receiver) = bounded ( 1 ) ;
35+ let ( task_sender, task_receiver) = bounded :: < Task > ( 1 ) ;
3136 let ( stop_sender, stop_receiver) = bounded ( 0 ) ;
3237 let ( line_sender, line_receiver) = unbounded ( ) ;
38+ command
39+ . stderr ( Stdio :: piped ( ) )
40+ . stdout ( if with_stdout { Stdio :: piped ( ) } else { Stdio :: null ( ) } ) ;
3341 let thread = thread:: spawn ( move || {
3442 loop {
3543 select ! {
36- recv( task_receiver) -> _ => {
37- debug!( "starting task" ) ;
38- command
39- . stderr( Stdio :: piped( ) )
40- . stdout( if with_stdout { Stdio :: piped( ) } else { Stdio :: null( ) } ) ;
44+ recv( task_receiver) -> task => {
45+ let task = task. unwrap( ) ;
46+ debug!( "starting task {:?}" , task) ;
47+ command. env(
48+ "RUST_BACKTRACE" ,
49+ if task. backtrace { "1" } else { "0" } ,
50+ ) ;
4151 let child = command. spawn( ) ;
4252 let mut child = match child {
4353 Ok ( child) => child,
@@ -163,8 +173,8 @@ impl Executor {
163173 } )
164174 }
165175 /// notify the executor a computation is necessary
166- pub fn start ( & self ) -> Result < ( ) > {
167- self . task_sender . try_send ( ( ) ) ?;
176+ pub fn start ( & self , task : Task ) -> Result < ( ) > {
177+ self . task_sender . try_send ( task ) ?;
168178 Ok ( ( ) )
169179 }
170180 pub fn die ( self ) -> Result < ( ) > {
0 commit comments