1 #![cfg_attr(feature = "deny-warnings", deny(warnings))]
3 use rustc_tools_util::*;
5 const CARGO_CLIPPY_HELP: &str = r#"Checks a package to catch common mistakes and improve your Rust code.
8 cargo clippy [options] [--] [<opts>...]
11 -h, --help Print this message
12 -V, --version Print version info and exit
14 Other options are the same as `cargo check`.
16 To allow or deny a lint from the command line you can use `cargo clippy --`
19 -W --warn OPT Set lint warnings
20 -A --allow OPT Set lint allowed
21 -D --deny OPT Set lint denied
22 -F --forbid OPT Set lint forbidden
24 You can use tool lints to allow or deny lints from your code, eg.:
26 #[allow(clippy::needless_lifetimes)]
30 println!("{}", CARGO_CLIPPY_HELP);
34 let version_info = rustc_tools_util::get_version_info!();
35 println!("{}", version_info);
39 // Check for version and help flags even when invoked as 'cargo-clippy'
40 if std::env::args().any(|a| a == "--help" || a == "-h") {
45 if std::env::args().any(|a| a == "--version" || a == "-V") {
50 if let Err(code) = process(std::env::args().skip(2)) {
51 std::process::exit(code);
55 fn process<I>(mut old_args: I) -> Result<(), i32>
57 I: Iterator<Item = String>,
59 let mut args = vec!["check".to_owned()];
61 for arg in old_args.by_ref() {
68 let clippy_args: String = old_args.map(|arg| format!("{}__CLIPPY_HACKERY__", arg)).collect();
70 let mut path = std::env::current_exe()
71 .expect("current executable path invalid")
72 .with_file_name("clippy-driver");
74 path.set_extension("exe");
77 let target_dir = std::env::var_os("CLIPPY_DOGFOOD")
79 std::env::var_os("CARGO_MANIFEST_DIR").map_or_else(
80 || std::ffi::OsString::from("clippy_dogfood"),
82 std::path::PathBuf::from(d)
89 .map(|p| ("CARGO_TARGET_DIR", p));
91 // Run the dogfood tests directly on nightly cargo. This is required due
92 // to a bug in rustup.rs when running cargo on custom toolchains. See issue #3118.
93 if std::env::var_os("CLIPPY_DOGFOOD").is_some() && cfg!(windows) {
94 args.insert(0, "+nightly".to_string());
97 let exit_status = std::process::Command::new("cargo")
99 .env("RUSTC_WRAPPER", path)
100 .env("CLIPPY_ARGS", clippy_args)
103 .expect("could not run cargo")
105 .expect("failed to wait for cargo?");
107 if exit_status.success() {
110 Err(exit_status.code().unwrap_or(-1))