1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
10 use std::path::PathBuf;
11 use std::process::Command;
13 fn rustc_sysroot_path() -> PathBuf {
14 option_env!("SYSROOT")
16 .or_else(|| std::env::var("SYSROOT").ok())
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)))
28 .and_then(|out| String::from_utf8(out.stdout).ok())
29 .map(|s| s.trim().to_owned())
31 .expect("need to specify SYSROOT env var during clippy compilation, or use rustup or multirust")
37 if option_env!("RUSTC_TEST_SUITE").is_some() || cfg!(windows) {
40 let root_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
41 let clippy_cmd = std::path::Path::new(&root_dir)
43 .join(env!("PROFILE"))
44 .join("cargo-clippy");
46 let output = std::process::Command::new(clippy_cmd)
47 .current_dir(root_dir)
48 .env("CLIPPY_DOGFOOD", "1")
49 .env("RUSTFLAGS", format!("--sysroot {}", rustc_sysroot_path().display()))
52 .arg("--all-features")
54 .args(&["-D", "clippy::all"])
55 .args(&["-D", "clippy::internal"])
56 .args(&["-D", "clippy::pedantic"])
59 println!("status: {}", output.status);
60 println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
61 println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
63 assert!(output.status.success());
68 if option_env!("RUSTC_TEST_SUITE").is_some() || cfg!(windows) {
71 let root_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
72 let clippy_cmd = std::path::Path::new(&root_dir)
74 .join(env!("PROFILE"))
75 .join("cargo-clippy");
78 "clippy_workspace_tests",
79 "clippy_workspace_tests/src",
80 "clippy_workspace_tests/subcrate",
81 "clippy_workspace_tests/subcrate/src",
85 let output = std::process::Command::new(&clippy_cmd)
86 .current_dir(root_dir.join(d))
87 .env("CLIPPY_DOGFOOD", "1")
88 .env("RUSTFLAGS", format!("--sysroot {}", rustc_sysroot_path().display()))
91 .args(&["-D", "clippy::all"])
92 .args(&["-D", "clippy::pedantic"])
95 println!("status: {}", output.status);
96 println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
97 println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
99 assert!(output.status.success());