11use config:: Config ;
22use crates:: Crate ;
3+ use dirs;
34use experiments:: Experiment ;
45use failure:: AsFail ;
56use prelude:: * ;
@@ -12,6 +13,7 @@ use utils;
1213
1314pub ( super ) enum TaskStep {
1415 Prepare ,
16+ Cleanup ,
1517 BuildAndTest { tc : Toolchain , quiet : bool } ,
1618 BuildOnly { tc : Toolchain , quiet : bool } ,
1719 CheckOnly { tc : Toolchain , quiet : bool } ,
@@ -23,6 +25,7 @@ impl fmt::Debug for TaskStep {
2325 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
2426 match * self {
2527 TaskStep :: Prepare => write ! ( f, "prepare" ) ?,
28+ TaskStep :: Cleanup => write ! ( f, "cleanup" ) ?,
2629 TaskStep :: BuildAndTest { ref tc, quiet } => {
2730 write ! ( f, "build and test {}" , tc. to_string( ) ) ?;
2831 if quiet {
@@ -71,6 +74,7 @@ impl Task {
7174 // If an error happens while checking if the task should be executed, the error is ignored
7275 // and the function returns true.
7376 match self . step {
77+ TaskStep :: Cleanup => true ,
7478 // The prepare step should always be executed.
7579 // It will not be executed if all the dependent tasks are already executed, since the
7680 // runner will not reach the prepare task in that case.
@@ -94,7 +98,7 @@ impl Task {
9498 result : TestResult ,
9599 ) -> Fallible < ( ) > {
96100 match self . step {
97- TaskStep :: Prepare => { }
101+ TaskStep :: Prepare | TaskStep :: Cleanup => { }
98102 TaskStep :: BuildAndTest { ref tc, .. }
99103 | TaskStep :: BuildOnly { ref tc, .. }
100104 | TaskStep :: CheckOnly { ref tc, .. }
@@ -118,6 +122,13 @@ impl Task {
118122 db : & DB ,
119123 ) -> Fallible < ( ) > {
120124 match self . step {
125+ TaskStep :: Cleanup => {
126+ // Ensure source directories are cleaned up
127+ for tc in & ex. toolchains {
128+ let _ = utils:: fs:: remove_dir_all ( & dirs:: crate_source_dir ( ex, tc, & self . krate ) ) ;
129+ }
130+ Ok ( ( ) )
131+ }
121132 TaskStep :: Prepare => {
122133 let prepare = PrepareCrate :: new ( ex, & self . krate , config, db) ;
123134 prepare. prepare ( )
0 commit comments