@@ -183,15 +183,14 @@ fn try_main() -> MainResult<i32> {
183183 return Ok ( 0 ) ;
184184 }
185185
186+ let mut cmd = action. command_to_execute ( & args. script_args , args. wrapper ) ?;
186187 #[ cfg( unix) ]
187188 {
188- let mut cmd = action. cargo ( & args. script_args ) ?;
189189 let err = cmd. exec ( ) ;
190190 Err ( MainError :: from ( err) )
191191 }
192192 #[ cfg( not( unix) ) ]
193193 {
194- let mut cmd = action. cargo ( & args. script_args ) ?;
195194 let exit_code = cmd. status ( ) . map ( |st| st. code ( ) . unwrap_or ( 1 ) ) ?;
196195 Ok ( exit_code)
197196 }
@@ -332,7 +331,11 @@ impl InputAction {
332331 self . pkg_path . join ( "Cargo.toml" )
333332 }
334333
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 > {
336339 let release_mode = !self . debug && !matches ! ( self . build_kind, BuildKind :: Bench ) ;
337340
338341 let built_binary_path = platform:: binary_cache_path ( )
@@ -351,9 +354,25 @@ impl InputAction {
351354 let manifest_path = self . manifest_path ( ) ;
352355
353356 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+ }
357376 } ;
358377
359378 if matches ! ( self . build_kind, BuildKind :: Normal ) && !self . force_compile {
@@ -376,7 +395,7 @@ impl InputAction {
376395 && built_binary_time. cmp ( & manifest_mtime) . is_ge ( )
377396 {
378397 debug ! ( "Keeping old binary" ) ;
379- return Ok ( execute_command ( ) ) ;
398+ return execute_command ( ) ;
380399 } else {
381400 debug ! ( "Old binary too old - rebuilding" ) ;
382401 }
@@ -423,7 +442,7 @@ impl InputAction {
423442
424443 if matches ! ( self . build_kind, BuildKind :: Normal ) {
425444 if cmd. status ( ) ?. code ( ) == Some ( 0 ) {
426- cmd = execute_command ( ) ;
445+ cmd = execute_command ( ) ? ;
427446 } else {
428447 return Err ( MainError :: OtherOwned ( "Could not execute cargo" . to_string ( ) ) ) ;
429448 }
0 commit comments