@@ -218,11 +218,13 @@ impl ProcessBuilder {
218
218
}
219
219
220
220
fn _status ( & self ) -> io:: Result < ExitStatus > {
221
- let mut cmd = self . build_command ( ) ;
222
- match cmd. spawn ( ) {
223
- Err ( ref e) if self . should_retry_with_argfile ( e) => { }
224
- Err ( e) => return Err ( e) ,
225
- Ok ( mut child) => return child. wait ( ) ,
221
+ if !debug_force_argfile ( self . retry_with_argfile ) {
222
+ let mut cmd = self . build_command ( ) ;
223
+ match cmd. spawn ( ) {
224
+ Err ( ref e) if self . should_retry_with_argfile ( e) => { }
225
+ Err ( e) => return Err ( e) ,
226
+ Ok ( mut child) => return child. wait ( ) ,
227
+ }
226
228
}
227
229
let ( mut cmd, _argfile) = self . build_command_with_argfile ( ) ?;
228
230
cmd. spawn ( ) ?. wait ( )
@@ -269,11 +271,13 @@ impl ProcessBuilder {
269
271
}
270
272
271
273
fn _output ( & self ) -> io:: Result < Output > {
272
- let mut cmd = self . build_command ( ) ;
273
- match piped ( & mut cmd) . spawn ( ) {
274
- Err ( ref e) if self . should_retry_with_argfile ( e) => { }
275
- Err ( e) => return Err ( e) ,
276
- Ok ( child) => return child. wait_with_output ( ) ,
274
+ if !debug_force_argfile ( self . retry_with_argfile ) {
275
+ let mut cmd = self . build_command ( ) ;
276
+ match piped ( & mut cmd) . spawn ( ) {
277
+ Err ( ref e) if self . should_retry_with_argfile ( e) => { }
278
+ Err ( e) => return Err ( e) ,
279
+ Ok ( child) => return child. wait_with_output ( ) ,
280
+ }
277
281
}
278
282
let ( mut cmd, _argfile) = self . build_command_with_argfile ( ) ?;
279
283
piped ( & mut cmd) . spawn ( ) ?. wait_with_output ( )
@@ -317,11 +321,13 @@ impl ProcessBuilder {
317
321
let mut stderr_pos = 0 ;
318
322
319
323
let spawn = |mut cmd| {
320
- match piped ( & mut cmd) . spawn ( ) {
321
- Err ( ref e) if self . should_retry_with_argfile ( e) => { }
322
- Err ( e) => return Err ( e) ,
323
- Ok ( child) => return Ok ( ( child, None ) ) ,
324
- } ;
324
+ if !debug_force_argfile ( self . retry_with_argfile ) {
325
+ match piped ( & mut cmd) . spawn ( ) {
326
+ Err ( ref e) if self . should_retry_with_argfile ( e) => { }
327
+ Err ( e) => return Err ( e) ,
328
+ Ok ( child) => return Ok ( ( child, None ) ) ,
329
+ }
330
+ }
325
331
let ( mut cmd, argfile) = self . build_command_with_argfile ( ) ?;
326
332
Ok ( ( piped ( & mut cmd) . spawn ( ) ?, Some ( argfile) ) )
327
333
} ;
@@ -506,6 +512,13 @@ impl ProcessBuilder {
506
512
}
507
513
}
508
514
515
+ /// Forces the command to use `@path` argfile.
516
+ ///
517
+ /// You should set `__CARGO_TEST_FORCE_ARGFILE` to enable this.
518
+ fn debug_force_argfile ( retry_enabled : bool ) -> bool {
519
+ cfg ! ( debug_assertions) && env:: var ( "__CARGO_TEST_FORCE_ARGFILE" ) . is_ok ( ) && retry_enabled
520
+ }
521
+
509
522
/// Creates new pipes for stderr and stdout. Ignores stdin.
510
523
fn piped ( cmd : & mut Command ) -> & mut Command {
511
524
cmd. stdout ( Stdio :: piped ( ) )
@@ -515,18 +528,23 @@ fn piped(cmd: &mut Command) -> &mut Command {
515
528
516
529
#[ cfg( unix) ]
517
530
mod imp {
518
- use super :: { ProcessBuilder , ProcessError } ;
531
+ use super :: { debug_force_argfile , ProcessBuilder , ProcessError } ;
519
532
use anyhow:: Result ;
520
533
use std:: io;
521
534
use std:: os:: unix:: process:: CommandExt ;
522
535
523
536
pub fn exec_replace ( process_builder : & ProcessBuilder ) -> Result < ( ) > {
524
- let mut command = process_builder. build_command ( ) ;
525
-
526
- let mut error = command. exec ( ) ;
527
- if process_builder. should_retry_with_argfile ( & error) {
537
+ let mut error;
538
+ if debug_force_argfile ( process_builder. retry_with_argfile ) {
528
539
let ( mut command, _argfile) = process_builder. build_command_with_argfile ( ) ?;
529
540
error = command. exec ( )
541
+ } else {
542
+ let mut command = process_builder. build_command ( ) ;
543
+ error = command. exec ( ) ;
544
+ if process_builder. should_retry_with_argfile ( & error) {
545
+ let ( mut command, _argfile) = process_builder. build_command_with_argfile ( ) ?;
546
+ error = command. exec ( )
547
+ }
530
548
}
531
549
532
550
Err ( anyhow:: Error :: from ( error) . context ( ProcessError :: new (
0 commit comments