Skip to content

Commit 5113de9

Browse files
committed
Add sysroot gettinh code to dogfood tests.
1 parent 571d4cc commit 5113de9

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tests/dogfood.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,31 @@
77
// option. This file may not be copied, modified, or distributed
88
// except according to those terms.
99

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+
1035
#[test]
1136
fn dogfood() {
1237
if option_env!("RUSTC_TEST_SUITE").is_some() || cfg!(windows) {
@@ -21,6 +46,7 @@ fn dogfood() {
2146
let output = std::process::Command::new(clippy_cmd)
2247
.current_dir(root_dir)
2348
.env("CLIPPY_DOGFOOD", "1")
49+
.env("RUSTFLAGS", format!("--sysroot {}", rustc_sysroot_path().display()))
2450
.arg("clippy")
2551
.arg("--all-targets")
2652
.arg("--all-features")
@@ -59,6 +85,7 @@ fn dogfood_tests() {
5985
let output = std::process::Command::new(&clippy_cmd)
6086
.current_dir(root_dir.join(d))
6187
.env("CLIPPY_DOGFOOD", "1")
88+
.env("RUSTFLAGS", format!("--sysroot {}", rustc_sysroot_path().display()))
6289
.arg("clippy")
6390
.arg("--")
6491
.args(&["-D", "clippy::all"])

0 commit comments

Comments
 (0)