@@ -72,8 +72,19 @@ pub fn main() {
72
72
exit ( 0 ) ;
73
73
}
74
74
75
- let sys_root = option_env ! ( "SYSROOT" )
76
- . map ( String :: from)
75
+ let mut orig_args: Vec < String > = env:: args ( ) . collect ( ) ;
76
+
77
+ // Get the sysroot, looking from most specific to this invocation to the least:
78
+ // - command line
79
+ // - runtime environment
80
+ // - SYSROOT
81
+ // - RUSTUP_HOME, MULTIRUST_HOME, RUSTUP_TOOLCHAIN, MULTIRUST_TOOLCHAIN
82
+ // - sysroot from rustc in the path
83
+ // - compile-time environment
84
+ let sys_root_arg = arg_value ( & orig_args, "--sysroot" , |_| true ) ;
85
+ let have_sys_root_arg = sys_root_arg. is_some ( ) ;
86
+ let sys_root = sys_root_arg
87
+ . map ( |s| s. to_string ( ) )
77
88
. or_else ( || std:: env:: var ( "SYSROOT" ) . ok ( ) )
78
89
. or_else ( || {
79
90
let home = option_env ! ( "RUSTUP_HOME" ) . or ( option_env ! ( "MULTIRUST_HOME" ) ) ;
@@ -89,11 +100,11 @@ pub fn main() {
89
100
. and_then ( |out| String :: from_utf8 ( out. stdout ) . ok ( ) )
90
101
. map ( |s| s. trim ( ) . to_owned ( ) )
91
102
} )
103
+ . or_else ( || option_env ! ( "SYSROOT" ) . map ( String :: from) )
92
104
. expect ( "need to specify SYSROOT env var during clippy compilation, or use rustup or multirust" ) ;
93
105
94
106
// Setting RUSTC_WRAPPER causes Cargo to pass 'rustc' as the first argument.
95
107
// We're invoking the compiler programmatically, so we ignore this/
96
- let mut orig_args: Vec < String > = env:: args ( ) . collect ( ) ;
97
108
if orig_args. len ( ) <= 1 {
98
109
std:: process:: exit ( 1 ) ;
99
110
}
@@ -104,7 +115,7 @@ pub fn main() {
104
115
// this conditional check for the --sysroot flag is there so users can call
105
116
// `clippy_driver` directly
106
117
// without having to pass --sysroot or anything
107
- let mut args: Vec < String > = if orig_args . iter ( ) . any ( |s| s == "--sysroot" ) {
118
+ let mut args: Vec < String > = if have_sys_root_arg {
108
119
orig_args. clone ( )
109
120
} else {
110
121
orig_args
0 commit comments