@@ -183,15 +183,14 @@ fn try_main() -> MainResult<i32> {
183
183
return Ok ( 0 ) ;
184
184
}
185
185
186
+ let mut cmd = action. command_to_execute ( & args. script_args , args. wrapper ) ?;
186
187
#[ cfg( unix) ]
187
188
{
188
- let mut cmd = action. cargo ( & args. script_args ) ?;
189
189
let err = cmd. exec ( ) ;
190
190
Err ( MainError :: from ( err) )
191
191
}
192
192
#[ cfg( not( unix) ) ]
193
193
{
194
- let mut cmd = action. cargo ( & args. script_args ) ?;
195
194
let exit_code = cmd. status ( ) . map ( |st| st. code ( ) . unwrap_or ( 1 ) ) ?;
196
195
Ok ( exit_code)
197
196
}
@@ -332,7 +331,11 @@ impl InputAction {
332
331
self . pkg_path . join ( "Cargo.toml" )
333
332
}
334
333
335
- fn cargo ( & self , script_args : & [ String ] ) -> MainResult < Command > {
334
+ fn command_to_execute (
335
+ & self ,
336
+ script_args : & [ String ] ,
337
+ wrapper : Option < String > ,
338
+ ) -> MainResult < Command > {
336
339
let release_mode = !self . debug && !matches ! ( self . build_kind, BuildKind :: Bench ) ;
337
340
338
341
let built_binary_path = platform:: binary_cache_path ( )
@@ -351,9 +354,25 @@ impl InputAction {
351
354
let manifest_path = self . manifest_path ( ) ;
352
355
353
356
let execute_command = || {
354
- let mut cmd = Command :: new ( & built_binary_path) ;
355
- cmd. args ( script_args. iter ( ) ) ;
356
- cmd
357
+ if let Some ( wrapper) = wrapper {
358
+ let wrapper_words = shell_words:: split ( & wrapper) . unwrap ( ) ;
359
+ if wrapper_words. is_empty ( ) {
360
+ return MainResult :: Err ( MainError :: OtherBorrowed (
361
+ "The wrapper cannot be empty" ,
362
+ ) ) ;
363
+ }
364
+ let mut cmd = Command :: new ( & wrapper_words[ 0 ] ) ;
365
+ if wrapper_words. len ( ) > 1 {
366
+ cmd. args ( wrapper_words[ 1 ..] . iter ( ) ) ;
367
+ }
368
+ cmd. arg ( & built_binary_path) ;
369
+ cmd. args ( script_args. iter ( ) ) ;
370
+ Ok ( cmd)
371
+ } else {
372
+ let mut cmd = Command :: new ( & built_binary_path) ;
373
+ cmd. args ( script_args. iter ( ) ) ;
374
+ Ok ( cmd)
375
+ }
357
376
} ;
358
377
359
378
if matches ! ( self . build_kind, BuildKind :: Normal ) && !self . force_compile {
@@ -376,7 +395,7 @@ impl InputAction {
376
395
&& built_binary_time. cmp ( & manifest_mtime) . is_ge ( )
377
396
{
378
397
debug ! ( "Keeping old binary" ) ;
379
- return Ok ( execute_command ( ) ) ;
398
+ return execute_command ( ) ;
380
399
} else {
381
400
debug ! ( "Old binary too old - rebuilding" ) ;
382
401
}
@@ -423,7 +442,7 @@ impl InputAction {
423
442
424
443
if matches ! ( self . build_kind, BuildKind :: Normal ) {
425
444
if cmd. status ( ) ?. code ( ) == Some ( 0 ) {
426
- cmd = execute_command ( ) ;
445
+ cmd = execute_command ( ) ? ;
427
446
} else {
428
447
return Err ( MainError :: OtherOwned ( "Could not execute cargo" . to_string ( ) ) ) ;
429
448
}
0 commit comments