@@ -3,9 +3,9 @@ extern crate compiletest_rs as compiletest;
3
3
use std:: path:: { PathBuf , Path } ;
4
4
use std:: io:: Write ;
5
5
6
- fn compile_fail ( sysroot : & str ) {
7
- let flags = format ! ( "--sysroot {} -Dwarnings" , sysroot) ;
8
- for_all_targets ( sysroot, |target| {
6
+ fn compile_fail ( sysroot : & Path ) {
7
+ let flags = format ! ( "--sysroot {} -Dwarnings" , sysroot. to_str ( ) . expect ( "non utf8 path" ) ) ;
8
+ for_all_targets ( & sysroot, |target| {
9
9
let mut config = compiletest:: default_config ( ) ;
10
10
config. host_rustcflags = Some ( flags. clone ( ) ) ;
11
11
config. mode = "compile-fail" . parse ( ) . expect ( "Invalid mode" ) ;
@@ -27,13 +27,21 @@ fn run_pass() {
27
27
compiletest:: run_tests ( & config) ;
28
28
}
29
29
30
- fn miri_pass ( path : & str , target : & str ) {
30
+ fn miri_pass ( path : & str , target : & str , host : & str ) {
31
31
let mut config = compiletest:: default_config ( ) ;
32
32
config. mode = "mir-opt" . parse ( ) . expect ( "Invalid mode" ) ;
33
33
config. src_base = PathBuf :: from ( path) ;
34
34
config. target = target. to_owned ( ) ;
35
+ config. host = host. to_owned ( ) ;
35
36
config. rustc_path = PathBuf :: from ( "target/debug/miri" ) ;
37
+ // don't actually execute the final binary, it might be for other targets and we only care
38
+ // about running miri, not the binary.
39
+ config. runtool = Some ( "echo \" \" || " . to_owned ( ) ) ;
40
+ if target == host {
41
+ std:: env:: set_var ( "MIRI_HOST_TARGET" , "yes" ) ;
42
+ }
36
43
compiletest:: run_tests ( & config) ;
44
+ std:: env:: set_var ( "MIRI_HOST_TARGET" , "" ) ;
37
45
}
38
46
39
47
fn is_target_dir < P : Into < PathBuf > > ( path : P ) -> bool {
@@ -42,8 +50,10 @@ fn is_target_dir<P: Into<PathBuf>>(path: P) -> bool {
42
50
path. metadata ( ) . map ( |m| m. is_dir ( ) ) . unwrap_or ( false )
43
51
}
44
52
45
- fn for_all_targets < F : FnMut ( String ) > ( sysroot : & str , mut f : F ) {
46
- for entry in std:: fs:: read_dir ( format ! ( "{}/lib/rustlib/" , sysroot) ) . unwrap ( ) {
53
+ fn for_all_targets < F : FnMut ( String ) > ( sysroot : & Path , mut f : F ) {
54
+ let target_dir = sysroot. join ( "lib" ) . join ( "rustlib" ) ;
55
+ println ! ( "target dir: {}" , target_dir. to_str( ) . unwrap( ) ) ;
56
+ for entry in std:: fs:: read_dir ( target_dir) . expect ( "invalid sysroot" ) {
47
57
let entry = entry. unwrap ( ) ;
48
58
if !is_target_dir ( entry. path ( ) ) { continue ; }
49
59
let target = entry. file_name ( ) . into_string ( ) . unwrap ( ) ;
@@ -55,20 +65,27 @@ fn for_all_targets<F: FnMut(String)>(sysroot: &str, mut f: F) {
55
65
56
66
#[ test]
57
67
fn compile_test ( ) {
58
- // Taken from https://github.com/Manishearth/rust-clippy/pull/911.
59
- let home = option_env ! ( "RUSTUP_HOME" ) . or ( option_env ! ( "MULTIRUST_HOME" ) ) ;
60
- let toolchain = option_env ! ( "RUSTUP_TOOLCHAIN" ) . or ( option_env ! ( "MULTIRUST_TOOLCHAIN" ) ) ;
61
- let sysroot = match ( home, toolchain) {
62
- ( Some ( home) , Some ( toolchain) ) => format ! ( "{}/toolchains/{}" , home, toolchain) ,
63
- _ => option_env ! ( "RUST_SYSROOT" )
64
- . expect ( "need to specify RUST_SYSROOT env var or use rustup or multirust" )
65
- . to_owned ( ) ,
66
- } ;
68
+ let sysroot = std:: process:: Command :: new ( "rustc" )
69
+ . arg ( "--print" )
70
+ . arg ( "sysroot" )
71
+ . output ( )
72
+ . expect ( "rustc not found" )
73
+ . stdout ;
74
+ let sysroot = std:: str:: from_utf8 ( & sysroot) . expect ( "sysroot is not utf8" ) . trim ( ) ;
75
+ let sysroot = & Path :: new ( & sysroot) ;
76
+ let host = std:: process:: Command :: new ( "rustc" )
77
+ . arg ( "-vV" )
78
+ . output ( )
79
+ . expect ( "rustc not found for -vV" )
80
+ . stdout ;
81
+ let host = std:: str:: from_utf8 ( & host) . expect ( "sysroot is not utf8" ) ;
82
+ let host = host. split ( "\n host: " ) . skip ( 1 ) . next ( ) . expect ( "no host: part in rustc -vV" ) ;
83
+ let host = host. split ( "\n " ) . next ( ) . expect ( "no \n after host" ) ;
67
84
run_pass ( ) ;
68
85
for_all_targets ( & sysroot, |target| {
69
- miri_pass ( "tests/run-pass" , & target) ;
86
+ miri_pass ( "tests/run-pass" , & target, host ) ;
70
87
if let Ok ( path) = std:: env:: var ( "MIRI_RUSTC_TEST" ) {
71
- miri_pass ( & path, & target) ;
88
+ miri_pass ( & path, & target, host ) ;
72
89
}
73
90
} ) ;
74
91
compile_fail ( & sysroot) ;
0 commit comments