7
7
// option. This file may not be copied, modified, or distributed
8
8
// except according to those terms.
9
9
10
+ use std:: path:: PathBuf ;
11
+ use std:: process:: Command ;
12
+
13
+ fn rustc_sysroot_path ( ) -> PathBuf {
14
+ option_env ! ( "SYSROOT" )
15
+ . map ( String :: from)
16
+ . or_else ( || std:: env:: var ( "SYSROOT" ) . ok ( ) )
17
+ . or_else ( || {
18
+ let home = option_env ! ( "RUSTUP_HOME" ) . or ( option_env ! ( "MULTIRUST_HOME" ) ) ;
19
+ let toolchain = option_env ! ( "RUSTUP_TOOLCHAIN" ) . or ( option_env ! ( "MULTIRUST_TOOLCHAIN" ) ) ;
20
+ home. and_then ( |home| toolchain. map ( |toolchain| format ! ( "{}/toolchains/{}" , home, toolchain) ) )
21
+ } )
22
+ . or_else ( || {
23
+ Command :: new ( "rustc" )
24
+ . arg ( "--print" )
25
+ . arg ( "sysroot" )
26
+ . output ( )
27
+ . ok ( )
28
+ . and_then ( |out| String :: from_utf8 ( out. stdout ) . ok ( ) )
29
+ . map ( |s| s. trim ( ) . to_owned ( ) )
30
+ } )
31
+ . expect ( "need to specify SYSROOT env var during clippy compilation, or use rustup or multirust" )
32
+ . into ( )
33
+ }
34
+
10
35
#[ test]
11
36
fn dogfood ( ) {
12
37
if option_env ! ( "RUSTC_TEST_SUITE" ) . is_some ( ) || cfg ! ( windows) {
@@ -21,6 +46,7 @@ fn dogfood() {
21
46
let output = std:: process:: Command :: new ( clippy_cmd)
22
47
. current_dir ( root_dir)
23
48
. env ( "CLIPPY_DOGFOOD" , "1" )
49
+ . env ( "RUSTFLAGS" , format ! ( "--sysroot {}" , rustc_sysroot_path( ) . display( ) ) )
24
50
. arg ( "clippy" )
25
51
. arg ( "--all-targets" )
26
52
. arg ( "--all-features" )
@@ -59,6 +85,7 @@ fn dogfood_tests() {
59
85
let output = std:: process:: Command :: new ( & clippy_cmd)
60
86
. current_dir ( root_dir. join ( d) )
61
87
. env ( "CLIPPY_DOGFOOD" , "1" )
88
+ . env ( "RUSTFLAGS" , format ! ( "--sysroot {}" , rustc_sysroot_path( ) . display( ) ) )
62
89
. arg ( "clippy" )
63
90
. arg ( "--" )
64
91
. args ( & [ "-D" , "clippy::all" ] )
0 commit comments