@@ -34,10 +34,11 @@ fn mk_config(mode: &str) -> compiletest::common::ConfigWithTemp {
3434 config. compile_lib_path = rustc_lib_path ( ) ;
3535 }
3636 config. filter = env:: args ( ) . nth ( 1 ) ;
37+ config. host = get_host ( ) ;
3738 config
3839}
3940
40- fn compile_fail ( sysroot : & Path , path : & str , target : & str , host : & str , opt : bool ) {
41+ fn compile_fail ( path : & str , target : & str , opt : bool ) {
4142 let opt_str = if opt { " with optimizations" } else { "" } ;
4243 eprintln ! ( "{}" , format!(
4344 "## Running compile-fail tests in {} against miri for target {}{}" ,
@@ -47,7 +48,6 @@ fn compile_fail(sysroot: &Path, path: &str, target: &str, host: &str, opt: bool)
4748 ) . green( ) . bold( ) ) ;
4849
4950 let mut flags = Vec :: new ( ) ;
50- flags. push ( format ! ( "--sysroot {}" , sysroot. display( ) ) ) ;
5151 flags. push ( "-Dwarnings -Dunused" . to_owned ( ) ) ; // overwrite the -Aunused in compiletest-rs
5252 flags. push ( "--edition 2018" . to_owned ( ) ) ;
5353 if opt {
@@ -60,12 +60,11 @@ fn compile_fail(sysroot: &Path, path: &str, target: &str, host: &str, opt: bool)
6060 let mut config = mk_config ( "compile-fail" ) ;
6161 config. src_base = PathBuf :: from ( path) ;
6262 config. target = target. to_owned ( ) ;
63- config. host = host. to_owned ( ) ;
6463 config. target_rustcflags = Some ( flags. join ( " " ) ) ;
6564 compiletest:: run_tests ( & config) ;
6665}
6766
68- fn miri_pass ( sysroot : & Path , path : & str , target : & str , host : & str , opt : bool ) {
67+ fn miri_pass ( path : & str , target : & str , opt : bool ) {
6968 let opt_str = if opt { " with optimizations" } else { "" } ;
7069 eprintln ! ( "{}" , format!(
7170 "## Running run-pass tests in {} against miri for target {}{}" ,
@@ -75,7 +74,6 @@ fn miri_pass(sysroot: &Path, path: &str, target: &str, host: &str, opt: bool) {
7574 ) . green( ) . bold( ) ) ;
7675
7776 let mut flags = Vec :: new ( ) ;
78- flags. push ( format ! ( "--sysroot {}" , sysroot. display( ) ) ) ;
7977 flags. push ( "-Dwarnings -Dunused" . to_owned ( ) ) ; // overwrite the -Aunused in compiletest-rs
8078 flags. push ( "--edition 2018" . to_owned ( ) ) ;
8179 if opt {
@@ -87,57 +85,24 @@ fn miri_pass(sysroot: &Path, path: &str, target: &str, host: &str, opt: bool) {
8785 let mut config = mk_config ( "ui" ) ;
8886 config. src_base = PathBuf :: from ( path) ;
8987 config. target = target. to_owned ( ) ;
90- config. host = host. to_owned ( ) ;
9188 config. target_rustcflags = Some ( flags. join ( " " ) ) ;
9289 compiletest:: run_tests ( & config) ;
9390}
9491
95- fn is_target_dir < P : Into < PathBuf > > ( path : P ) -> bool {
96- let mut path = path. into ( ) ;
97- path. push ( "lib" ) ;
98- path. metadata ( ) . map ( |m| m. is_dir ( ) ) . unwrap_or ( false )
99- }
100-
101- fn target_has_std < P : Into < PathBuf > > ( path : P ) -> bool {
102- let mut path = path. into ( ) ;
103- path. push ( "lib" ) ;
104- std:: fs:: read_dir ( path)
105- . expect ( "invalid target" )
106- . map ( |entry| entry. unwrap ( ) )
107- . filter ( |entry| entry. file_type ( ) . unwrap ( ) . is_file ( ) )
108- . filter_map ( |entry| entry. file_name ( ) . into_string ( ) . ok ( ) )
109- . any ( |file_name| file_name == "libstd.rlib" )
110- }
111-
112-
113- fn for_all_targets < F : FnMut ( String ) > ( sysroot : & Path , f : F ) {
114- let target_dir = sysroot. join ( "lib" ) . join ( "rustlib" ) ;
115- let mut targets = std:: fs:: read_dir ( target_dir)
116- . expect ( "invalid sysroot" )
117- . map ( |entry| entry. unwrap ( ) )
118- . filter ( |entry| is_target_dir ( entry. path ( ) ) )
119- . filter ( |entry| target_has_std ( entry. path ( ) ) )
120- . map ( |entry| entry. file_name ( ) . into_string ( ) . unwrap ( ) )
121- . peekable ( ) ;
122-
123- if targets. peek ( ) . is_none ( ) {
124- panic ! ( "No valid targets found" ) ;
92+ /// Make sure the MIRI_SYSROOT env var is set
93+ fn set_sysroot ( ) {
94+ if std:: env:: var ( "MIRI_SYSROOT" ) . is_ok ( ) {
95+ // Nothing to do
96+ return ;
12597 }
126-
127- targets. for_each ( f) ;
128- }
129-
130- fn get_sysroot ( ) -> PathBuf {
131- let sysroot = std:: env:: var ( "MIRI_SYSROOT" ) . unwrap_or_else ( |_| {
132- let sysroot = std:: process:: Command :: new ( "rustc" )
133- . arg ( "--print" )
134- . arg ( "sysroot" )
135- . output ( )
136- . expect ( "rustc not found" )
137- . stdout ;
138- String :: from_utf8 ( sysroot) . expect ( "sysroot is not utf8" )
139- } ) ;
140- PathBuf :: from ( sysroot. trim ( ) )
98+ let sysroot = std:: process:: Command :: new ( "rustc" )
99+ . arg ( "--print" )
100+ . arg ( "sysroot" )
101+ . output ( )
102+ . expect ( "rustc not found" )
103+ . stdout ;
104+ let sysroot = String :: from_utf8 ( sysroot) . expect ( "sysroot is not utf8" ) ;
105+ std:: env:: set_var ( "MIRI_SYSROOT" , sysroot. trim ( ) ) ;
141106}
142107
143108fn get_host ( ) -> String {
@@ -153,28 +118,20 @@ fn get_host() -> String {
153118 version_meta. host
154119}
155120
156- fn run_pass_miri ( opt : bool ) {
157- let sysroot = get_sysroot ( ) ;
158- let host = get_host ( ) ;
121+ fn get_target ( ) -> String {
122+ std :: env :: var ( "MIRI_TARGET" ) . unwrap_or_else ( |_| get_host ( ) )
123+ }
159124
160- for_all_targets ( & sysroot, |target| {
161- miri_pass ( & sysroot, "tests/run-pass" , & target, & host, opt) ;
162- } ) ;
125+ fn run_pass_miri ( opt : bool ) {
126+ miri_pass ( "tests/run-pass" , & get_target ( ) , opt) ;
163127}
164128
165129fn compile_fail_miri ( opt : bool ) {
166- let sysroot = get_sysroot ( ) ;
167- let host = get_host ( ) ;
168-
169- for_all_targets ( & sysroot, |target| {
170- compile_fail ( & sysroot, "tests/compile-fail" , & target, & host, opt) ;
171- } ) ;
130+ compile_fail ( "tests/compile-fail" , & get_target ( ) , opt) ;
172131}
173132
174133fn test_runner ( _tests : & [ & ( ) ] ) {
175- // We put everything into a single test to avoid the parallelism `cargo test`
176- // introduces. We still get parallelism within our tests because `compiletest`
177- // uses `libtest` which runs jobs in parallel.
134+ set_sysroot ( ) ;
178135
179136 run_pass_miri ( false ) ;
180137 run_pass_miri ( true ) ;
0 commit comments