@@ -158,7 +158,13 @@ pub fn test_command(mut config: Config, path: &Path) -> Result<Command> {
158
158
159
159
let comments = Comments :: parse_file ( config. comment_defaults . clone ( ) , path) ?
160
160
. map_err ( |errors| color_eyre:: eyre:: eyre!( "{errors:#?}" ) ) ?;
161
- let mut result = build_command ( path, & config, "" , & comments) . unwrap ( ) ;
161
+ let config = TestConfig {
162
+ config,
163
+ revision : "" ,
164
+ comments : & comments,
165
+ path,
166
+ } ;
167
+ let mut result = build_command ( & config) . unwrap ( ) ;
162
168
result. args ( extra_args) ;
163
169
164
170
Ok ( result)
@@ -425,12 +431,13 @@ fn parse_and_test_file(
425
431
. collect ( ) )
426
432
}
427
433
428
- fn build_command (
429
- path : & Path ,
430
- config : & Config ,
431
- revision : & str ,
432
- comments : & Comments ,
433
- ) -> Result < Command , Errored > {
434
+ fn build_command ( config : & TestConfig ) -> Result < Command , Errored > {
435
+ let TestConfig {
436
+ config,
437
+ revision,
438
+ comments,
439
+ path,
440
+ } = config;
434
441
let mut cmd = config. program . build ( & config. out_dir ) ;
435
442
cmd. arg ( path) ;
436
443
if !revision. is_empty ( ) {
@@ -518,19 +525,22 @@ fn build_aux(
518
525
CrateType :: Test | CrateType :: Bin | CrateType :: Lib => { }
519
526
}
520
527
521
- // Put aux builds into a separate directory per path so that multiple aux files
522
- // from different directories (but with the same file name) don't collide.
523
- let relative = strip_path_prefix ( aux_file. parent ( ) . unwrap ( ) , & config. out_dir ) ;
528
+ let mut config = TestConfig {
529
+ config,
530
+ revision : "" ,
531
+ comments : & comments,
532
+ path : aux_file,
533
+ } ;
524
534
525
- config. out_dir . extend ( relative ) ;
535
+ config. patch_out_dir ( ) ;
526
536
527
- let mut aux_cmd = build_command ( aux_file , & config, "" , & comments ) ?;
537
+ let mut aux_cmd = build_command ( & config) ?;
528
538
529
539
let mut extra_args = build_aux_files (
530
540
aux_file. parent ( ) . unwrap ( ) ,
531
541
& comments,
532
542
"" ,
533
- & config,
543
+ & config. config ,
534
544
build_manager,
535
545
) ?;
536
546
// Make sure we see our dependencies
@@ -560,15 +570,15 @@ fn build_aux(
560
570
for file in output. stdout . lines ( ) {
561
571
let file = std:: str:: from_utf8 ( file) . unwrap ( ) ;
562
572
let crate_name = filename. replace ( '-' , "_" ) ;
563
- let path = config. out_dir . join ( file) ;
573
+ let path = config. config . out_dir . join ( file) ;
564
574
extra_args. push ( "--extern" . into ( ) ) ;
565
575
let mut cname = OsString :: from ( & crate_name) ;
566
576
cname. push ( "=" ) ;
567
577
cname. push ( path) ;
568
578
extra_args. push ( cname) ;
569
579
// Help cargo find the crates added with `--extern`.
570
580
extra_args. push ( "-L" . into ( ) ) ;
571
- extra_args. push ( config. out_dir . as_os_str ( ) . to_os_string ( ) ) ;
581
+ extra_args. push ( config. config . out_dir . as_os_str ( ) . to_os_string ( ) ) ;
572
582
}
573
583
Ok ( extra_args)
574
584
}
@@ -584,12 +594,7 @@ fn run_test(build_manager: &BuildManager<'_>, mut config: TestConfig<'_>) -> Tes
584
594
585
595
config. patch_out_dir ( ) ;
586
596
587
- let mut cmd = build_command (
588
- config. path ,
589
- & config. config ,
590
- config. revision ,
591
- config. comments ,
592
- ) ?;
597
+ let mut cmd = build_command ( & config) ?;
593
598
cmd. args ( & extra_args) ;
594
599
let stdin = config. path . with_extension ( config. extension ( "stdin" ) ) ;
595
600
if stdin. exists ( ) {
@@ -838,6 +843,21 @@ fn run_rustfix(
838
843
"fixed" ,
839
844
& config,
840
845
) ;
846
+ // picking the crate name from the file name is problematic when `.revision_name` is inserted,
847
+ // so we compute it here before replacing the path.
848
+ let crate_name = config
849
+ . path
850
+ . file_stem ( )
851
+ . unwrap ( )
852
+ . to_str ( )
853
+ . unwrap ( )
854
+ . replace ( '-' , "_" ) ;
855
+ let config = TestConfig {
856
+ config : config. config ,
857
+ revision : config. revision ,
858
+ comments : & rustfix_comments,
859
+ path : & rustfix_path,
860
+ } ;
841
861
if !errors. is_empty ( ) {
842
862
return Err ( Errored {
843
863
command : Command :: new ( format ! ( "checking {}" , config. path. display( ) ) ) ,
@@ -851,23 +871,9 @@ fn run_rustfix(
851
871
return Ok ( ( ) ) ;
852
872
}
853
873
854
- let mut cmd = build_command (
855
- & rustfix_path,
856
- & config. config ,
857
- config. revision ,
858
- config. comments ,
859
- ) ?;
874
+ let mut cmd = build_command ( & config) ?;
860
875
cmd. args ( extra_args) ;
861
- // picking the crate name from the file name is problematic when `.revision_name` is inserted
862
- cmd. arg ( "--crate-name" ) . arg (
863
- config
864
- . path
865
- . file_stem ( )
866
- . unwrap ( )
867
- . to_str ( )
868
- . unwrap ( )
869
- . replace ( '-' , "_" ) ,
870
- ) ;
876
+ cmd. arg ( "--crate-name" ) . arg ( crate_name) ;
871
877
let output = cmd. output ( ) . unwrap ( ) ;
872
878
if output. status . success ( ) {
873
879
Ok ( ( ) )
0 commit comments