44 cargo_metadata:: MetadataCommand ,
55 notify:: { RecommendedWatcher , RecursiveMode , Watcher } ,
66 std:: {
7+ collections:: HashSet ,
78 env,
89 fs,
910 path:: PathBuf ,
@@ -152,10 +153,51 @@ impl Mission {
152153 let mut command = Command :: new (
153154 tokens. next ( ) . unwrap ( ) , // implies a check in the job
154155 ) ;
156+ let mut no_default_features_done = false ;
157+ let mut features_done = false ;
158+ let mut last_is_features = false ;
155159 for arg in tokens {
160+ let mut arg = arg. to_string ( ) ;
161+ if last_is_features {
162+ // arg is expected there to be the list of features
163+ features_done = true ;
164+ match ( & self . settings . features , self . settings . no_default_features ) {
165+ ( Some ( features) , false ) => {
166+ // we take the features of both the job and the args
167+ arg = merge_features ( & arg, & features) ;
168+ }
169+ ( Some ( features) , true ) => {
170+ // arg add features and remove the job ones
171+ arg = features. clone ( ) ;
172+ }
173+ ( None , true ) => {
174+ // arg just remove the job features
175+ arg = "" . to_string ( )
176+ }
177+ ( None , false ) => {
178+ // nothing to change
179+ }
180+ }
181+ last_is_features = false ;
182+ } else if arg == "--no-default-features" {
183+ no_default_features_done = true ;
184+ last_is_features = false ;
185+ } else if arg == "--features" {
186+ last_is_features = true ;
187+ }
156188 command. arg ( arg) ;
157189 }
190+ if self . settings . no_default_features && !no_default_features_done {
191+ command. arg ( "--no-default-features" ) ;
192+ }
193+ if !features_done {
194+ if let Some ( features) = & self . settings . features {
195+ command. arg ( "--features" ) ;
196+ command. arg ( features) ;
197+ }
198+ }
158199 command. current_dir ( & self . cargo_execution_directory ) ;
200+ debug ! ( "command: {:#?}" , & command) ;
159201 command
160202 }
161203
@@ -164,3 +206,14 @@ impl Mission {
164206 self . job . need_stdout
165207 }
166208}
209+
210+ fn merge_features ( a : & str , b : & str ) -> String {
211+ let mut features = HashSet :: new ( ) ;
212+ for feature in a. split ( ',' ) {
213+ features. insert ( feature) ;
214+ }
215+ for feature in b. split ( ',' ) {
216+ features. insert ( feature) ;
217+ }
218+ features. iter ( ) . map ( |& s|s) . collect :: < Vec < & str > > ( ) . join ( "," )
219+ }
0 commit comments