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