@@ -34,10 +34,11 @@ fn mk_config(mode: &str) -> compiletest::common::ConfigWithTemp {
34
34
config. compile_lib_path = rustc_lib_path ( ) ;
35
35
}
36
36
config. filter = env:: args ( ) . nth ( 1 ) ;
37
+ config. host = get_host ( ) ;
37
38
config
38
39
}
39
40
40
- fn compile_fail ( sysroot : & Path , path : & str , target : & str , host : & str , opt : bool ) {
41
+ fn compile_fail ( path : & str , target : & str , opt : bool ) {
41
42
let opt_str = if opt { " with optimizations" } else { "" } ;
42
43
eprintln ! ( "{}" , format!(
43
44
"## 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)
47
48
) . green( ) . bold( ) ) ;
48
49
49
50
let mut flags = Vec :: new ( ) ;
50
- flags. push ( format ! ( "--sysroot {}" , sysroot. display( ) ) ) ;
51
51
flags. push ( "-Dwarnings -Dunused" . to_owned ( ) ) ; // overwrite the -Aunused in compiletest-rs
52
52
flags. push ( "--edition 2018" . to_owned ( ) ) ;
53
53
if opt {
@@ -60,12 +60,11 @@ fn compile_fail(sysroot: &Path, path: &str, target: &str, host: &str, opt: bool)
60
60
let mut config = mk_config ( "compile-fail" ) ;
61
61
config. src_base = PathBuf :: from ( path) ;
62
62
config. target = target. to_owned ( ) ;
63
- config. host = host. to_owned ( ) ;
64
63
config. target_rustcflags = Some ( flags. join ( " " ) ) ;
65
64
compiletest:: run_tests ( & config) ;
66
65
}
67
66
68
- fn miri_pass ( sysroot : & Path , path : & str , target : & str , host : & str , opt : bool ) {
67
+ fn miri_pass ( path : & str , target : & str , opt : bool ) {
69
68
let opt_str = if opt { " with optimizations" } else { "" } ;
70
69
eprintln ! ( "{}" , format!(
71
70
"## 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) {
75
74
) . green( ) . bold( ) ) ;
76
75
77
76
let mut flags = Vec :: new ( ) ;
78
- flags. push ( format ! ( "--sysroot {}" , sysroot. display( ) ) ) ;
79
77
flags. push ( "-Dwarnings -Dunused" . to_owned ( ) ) ; // overwrite the -Aunused in compiletest-rs
80
78
flags. push ( "--edition 2018" . to_owned ( ) ) ;
81
79
if opt {
@@ -87,57 +85,24 @@ fn miri_pass(sysroot: &Path, path: &str, target: &str, host: &str, opt: bool) {
87
85
let mut config = mk_config ( "ui" ) ;
88
86
config. src_base = PathBuf :: from ( path) ;
89
87
config. target = target. to_owned ( ) ;
90
- config. host = host. to_owned ( ) ;
91
88
config. target_rustcflags = Some ( flags. join ( " " ) ) ;
92
89
compiletest:: run_tests ( & config) ;
93
90
}
94
91
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 ;
125
97
}
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 ( ) ) ;
141
106
}
142
107
143
108
fn get_host ( ) -> String {
@@ -153,28 +118,20 @@ fn get_host() -> String {
153
118
version_meta. host
154
119
}
155
120
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
+ }
159
124
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) ;
163
127
}
164
128
165
129
fn 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) ;
172
131
}
173
132
174
133
fn 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 ( ) ;
178
135
179
136
run_pass_miri ( false ) ;
180
137
run_pass_miri ( true ) ;
0 commit comments