@@ -11,7 +11,7 @@ use crate::util::logv;
11
11
use build_helper:: git:: { get_git_modified_files, get_git_untracked_files} ;
12
12
use core:: panic;
13
13
use getopts:: Options ;
14
- use lazycell:: LazyCell ;
14
+ use lazycell:: AtomicLazyCell ;
15
15
use std:: collections:: BTreeSet ;
16
16
use std:: ffi:: OsString ;
17
17
use std:: fs;
@@ -25,6 +25,7 @@ use tracing::*;
25
25
use walkdir:: WalkDir ;
26
26
27
27
use self :: header:: { make_test_description, EarlyProps } ;
28
+ use std:: sync:: Arc ;
28
29
29
30
#[ cfg( test) ]
30
31
mod tests;
@@ -42,7 +43,7 @@ pub mod util;
42
43
fn main ( ) {
43
44
tracing_subscriber:: fmt:: init ( ) ;
44
45
45
- let config = parse_config ( env:: args ( ) . collect ( ) ) ;
46
+ let config = Arc :: new ( parse_config ( env:: args ( ) . collect ( ) ) ) ;
46
47
47
48
if config. valgrind_path . is_none ( ) && config. force_valgrind {
48
49
panic ! ( "Can't find Valgrind to run Valgrind tests" ) ;
@@ -313,7 +314,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
313
314
314
315
force_rerun : matches. opt_present ( "force-rerun" ) ,
315
316
316
- target_cfgs : LazyCell :: new ( ) ,
317
+ target_cfgs : AtomicLazyCell :: new ( ) ,
317
318
318
319
nocapture : matches. opt_present ( "nocapture" ) ,
319
320
}
@@ -369,7 +370,7 @@ pub fn opt_str2(maybestr: Option<String>) -> String {
369
370
}
370
371
}
371
372
372
- pub fn run_tests ( config : Config ) {
373
+ pub fn run_tests ( config : Arc < Config > ) {
373
374
// If we want to collect rustfix coverage information,
374
375
// we first make sure that the coverage file does not exist.
375
376
// It will be created later on.
@@ -411,7 +412,7 @@ pub fn run_tests(config: Config) {
411
412
} ;
412
413
413
414
let mut tests = Vec :: new ( ) ;
414
- for c in & configs {
415
+ for c in configs {
415
416
let mut found_paths = BTreeSet :: new ( ) ;
416
417
make_tests ( c, & mut tests, & mut found_paths) ;
417
418
check_overlapping_tests ( & found_paths) ;
@@ -433,7 +434,11 @@ pub fn run_tests(config: Config) {
433
434
println ! (
434
435
"Some tests failed in compiletest suite={}{} mode={} host={} target={}" ,
435
436
config. suite,
436
- config. compare_mode. map( |c| format!( " compare_mode={:?}" , c) ) . unwrap_or_default( ) ,
437
+ config
438
+ . compare_mode
439
+ . as_ref( )
440
+ . map( |c| format!( " compare_mode={:?}" , c) )
441
+ . unwrap_or_default( ) ,
437
442
config. mode,
438
443
config. host,
439
444
config. target
@@ -453,13 +458,13 @@ pub fn run_tests(config: Config) {
453
458
}
454
459
}
455
460
456
- fn configure_cdb ( config : & Config ) -> Option < Config > {
461
+ fn configure_cdb ( config : & Config ) -> Option < Arc < Config > > {
457
462
config. cdb . as_ref ( ) ?;
458
463
459
- Some ( Config { debugger : Some ( Debugger :: Cdb ) , ..config. clone ( ) } )
464
+ Some ( Arc :: new ( Config { debugger : Some ( Debugger :: Cdb ) , ..config. clone ( ) } ) )
460
465
}
461
466
462
- fn configure_gdb ( config : & Config ) -> Option < Config > {
467
+ fn configure_gdb ( config : & Config ) -> Option < Arc < Config > > {
463
468
config. gdb_version ?;
464
469
465
470
if config. matches_env ( "msvc" ) {
@@ -490,10 +495,10 @@ fn configure_gdb(config: &Config) -> Option<Config> {
490
495
env:: set_var ( "RUST_TEST_THREADS" , "1" ) ;
491
496
}
492
497
493
- Some ( Config { debugger : Some ( Debugger :: Gdb ) , ..config. clone ( ) } )
498
+ Some ( Arc :: new ( Config { debugger : Some ( Debugger :: Gdb ) , ..config. clone ( ) } ) )
494
499
}
495
500
496
- fn configure_lldb ( config : & Config ) -> Option < Config > {
501
+ fn configure_lldb ( config : & Config ) -> Option < Arc < Config > > {
497
502
config. lldb_python_dir . as_ref ( ) ?;
498
503
499
504
if let Some ( 350 ) = config. lldb_version {
@@ -506,7 +511,7 @@ fn configure_lldb(config: &Config) -> Option<Config> {
506
511
return None ;
507
512
}
508
513
509
- Some ( Config { debugger : Some ( Debugger :: Lldb ) , ..config. clone ( ) } )
514
+ Some ( Arc :: new ( Config { debugger : Some ( Debugger :: Lldb ) , ..config. clone ( ) } ) )
510
515
}
511
516
512
517
pub fn test_opts ( config : & Config ) -> test:: TestOpts {
@@ -541,17 +546,17 @@ pub fn test_opts(config: &Config) -> test::TestOpts {
541
546
}
542
547
543
548
pub fn make_tests (
544
- config : & Config ,
549
+ config : Arc < Config > ,
545
550
tests : & mut Vec < test:: TestDescAndFn > ,
546
551
found_paths : & mut BTreeSet < PathBuf > ,
547
552
) {
548
553
debug ! ( "making tests from {:?}" , config. src_base. display( ) ) ;
549
- let inputs = common_inputs_stamp ( config) ;
550
- let modified_tests = modified_tests ( config, & config. src_base ) . unwrap_or_else ( |err| {
554
+ let inputs = common_inputs_stamp ( & config) ;
555
+ let modified_tests = modified_tests ( & config, & config. src_base ) . unwrap_or_else ( |err| {
551
556
panic ! ( "modified_tests got error from dir: {}, error: {}" , config. src_base. display( ) , err)
552
557
} ) ;
553
558
collect_tests_from_dir (
554
- config,
559
+ config. clone ( ) ,
555
560
& config. src_base ,
556
561
& PathBuf :: new ( ) ,
557
562
& inputs,
@@ -622,7 +627,7 @@ fn modified_tests(config: &Config, dir: &Path) -> Result<Vec<PathBuf>, String> {
622
627
}
623
628
624
629
fn collect_tests_from_dir (
625
- config : & Config ,
630
+ config : Arc < Config > ,
626
631
dir : & Path ,
627
632
relative_dir_path : & Path ,
628
633
inputs : & Stamp ,
@@ -650,7 +655,7 @@ fn collect_tests_from_dir(
650
655
// sequential loop because otherwise, if we do it in the
651
656
// tests themselves, they race for the privilege of
652
657
// creating the directories and sometimes fail randomly.
653
- let build_dir = output_relative_path ( config, relative_dir_path) ;
658
+ let build_dir = output_relative_path ( & config, relative_dir_path) ;
654
659
fs:: create_dir_all ( & build_dir) . unwrap ( ) ;
655
660
656
661
// Add each `.rs` file as a test, and recurse further on any
@@ -666,13 +671,13 @@ fn collect_tests_from_dir(
666
671
let paths =
667
672
TestPaths { file : file_path, relative_dir : relative_dir_path. to_path_buf ( ) } ;
668
673
669
- tests. extend ( make_test ( config, & paths, inputs) )
674
+ tests. extend ( make_test ( config. clone ( ) , & paths, inputs) )
670
675
} else if file_path. is_dir ( ) {
671
676
let relative_file_path = relative_dir_path. join ( file. file_name ( ) ) ;
672
677
if & file_name != "auxiliary" {
673
678
debug ! ( "found directory: {:?}" , file_path. display( ) ) ;
674
679
collect_tests_from_dir (
675
- config,
680
+ config. clone ( ) ,
676
681
& file_path,
677
682
& relative_file_path,
678
683
inputs,
@@ -701,14 +706,18 @@ pub fn is_test(file_name: &OsString) -> bool {
701
706
!invalid_prefixes. iter ( ) . any ( |p| file_name. starts_with ( p) )
702
707
}
703
708
704
- fn make_test ( config : & Config , testpaths : & TestPaths , inputs : & Stamp ) -> Vec < test:: TestDescAndFn > {
709
+ fn make_test (
710
+ config : Arc < Config > ,
711
+ testpaths : & TestPaths ,
712
+ inputs : & Stamp ,
713
+ ) -> Vec < test:: TestDescAndFn > {
705
714
let test_path = if config. mode == Mode :: RunMake {
706
715
// Parse directives in the Makefile
707
716
testpaths. file . join ( "Makefile" )
708
717
} else {
709
718
PathBuf :: from ( & testpaths. file )
710
719
} ;
711
- let early_props = EarlyProps :: from_file ( config, & test_path) ;
720
+ let early_props = EarlyProps :: from_file ( & config, & test_path) ;
712
721
713
722
// Incremental tests are special, they inherently cannot be run in parallel.
714
723
// `runtest::run` will be responsible for iterating over revisions.
@@ -723,19 +732,22 @@ fn make_test(config: &Config, testpaths: &TestPaths, inputs: &Stamp) -> Vec<test
723
732
let src_file =
724
733
std:: fs:: File :: open ( & test_path) . expect ( "open test file to parse ignores" ) ;
725
734
let cfg = revision. map ( |v| & * * v) ;
726
- let test_name = crate :: make_test_name ( config, testpaths, revision) ;
727
- let mut desc = make_test_description ( config, test_name, & test_path, src_file, cfg) ;
735
+ let test_name = crate :: make_test_name ( & config, testpaths, revision) ;
736
+ let mut desc = make_test_description ( & config, test_name, & test_path, src_file, cfg) ;
728
737
// Ignore tests that already run and are up to date with respect to inputs.
729
738
if !config. force_rerun {
730
739
desc. ignore |= is_up_to_date (
731
- config,
740
+ & config,
732
741
testpaths,
733
742
& early_props,
734
743
revision. map ( |s| s. as_str ( ) ) ,
735
744
inputs,
736
745
) ;
737
746
}
738
- test:: TestDescAndFn { desc, testfn : make_test_closure ( config, testpaths, revision) }
747
+ test:: TestDescAndFn {
748
+ desc,
749
+ testfn : make_test_closure ( config. clone ( ) , testpaths, revision) ,
750
+ }
739
751
} )
740
752
. collect ( )
741
753
}
@@ -869,7 +881,7 @@ fn make_test_name(
869
881
}
870
882
871
883
fn make_test_closure (
872
- config : & Config ,
884
+ config : Arc < Config > ,
873
885
testpaths : & TestPaths ,
874
886
revision : Option < & String > ,
875
887
) -> test:: TestFn {
0 commit comments