Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix clippy help text, check for clippy-driver
  • Loading branch information
yaahc committed Mar 30, 2019
commit 30da7728e685cfb2c77b63438e42903fcd843f3a
14 changes: 13 additions & 1 deletion src/bin/cargo/commands/clippy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub fn cli() -> App {
subcommand("clippy-preview")
// subcommand aliases are handled in aliased_command()
// .alias("c")
.about("Check a local package and all of its dependencies for errors")
.about("Checks a package to catch common mistakes and improve your Rust code.")
.arg_package_spec(
"Package(s) to check",
"Check all packages in the workspace",
Expand Down Expand Up @@ -49,6 +49,18 @@ the `--release` flag will use the `release` profile instead.

The `--profile test` flag can be used to check unit tests with the
`#[cfg(test)]` attribute.

To allow or deny a lint from the command line you can use `cargo clippy --`
with:

-W --warn OPT Set lint warnings
-A --allow OPT Set lint allowed
-D --deny OPT Set lint denied
-F --forbid OPT Set lint forbidden

You can use tool lints to allow or deny lints from your code, eg.:

#[allow(clippy::needless_lifetimes)]
",
)
}
Expand Down
17 changes: 2 additions & 15 deletions src/bin/cargo/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
use std::collections::BTreeSet;
use std::env;
use std::fs;
use std::path::{Path, PathBuf};
use std::path::PathBuf;

use cargo::core::shell::Shell;
use cargo::util::paths::is_executable;
use cargo::util::{self, command_prelude, lev_distance, CargoResult, CliResult, Config};
use cargo::util::{CliError, ProcessError};

Expand Down Expand Up @@ -164,20 +165,6 @@ fn execute_external_subcommand(config: &Config, cmd: &str, args: &[&str]) -> Cli
Err(CliError::new(err, 101))
}

#[cfg(unix)]
fn is_executable<P: AsRef<Path>>(path: P) -> bool {
use std::os::unix::prelude::*;
fs::metadata(path)
.map(|metadata| metadata.is_file() && metadata.permissions().mode() & 0o111 != 0)
.unwrap_or(false)
}
#[cfg(windows)]
fn is_executable<P: AsRef<Path>>(path: P) -> bool {
fs::metadata(path)
.map(|metadata| metadata.is_file())
.unwrap_or(false)
}

fn search_directories(config: &Config) -> Vec<PathBuf> {
let mut dirs = vec![config.home().clone().into_path_unlocked().join("bin")];
if let Some(val) = env::var_os("PATH") {
Expand Down
20 changes: 13 additions & 7 deletions src/cargo/util/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use serde::Deserialize;
use serde::{de, de::IntoDeserializer};
use url::Url;

use self::ConfigValue as CV;
use crate::core::profiles::ConfigProfiles;
use crate::core::shell::Verbosity;
use crate::core::{CliUnstable, Shell, SourceId, Workspace};
Expand All @@ -30,7 +31,6 @@ use crate::util::Filesystem;
use crate::util::Rustc;
use crate::util::ToUrl;
use crate::util::{paths, validate_package_name};
use self::ConfigValue as CV;

/// Configuration information for cargo. This is not specific to a build, it is information
/// relating to cargo itself.
Expand Down Expand Up @@ -206,7 +206,16 @@ impl Config {
.into_path_unlocked()
});
let wrapper = if self.clippy_override {
Some(self.get_tool("clippy-driver")?)
let tool = self.get_tool("clippy-driver")?;
let tool = paths::resolve_executable(&tool).map_err(|e| {
failure::format_err!("{}: please run `rustup component add clippy`", e)
})?;
if !paths::is_executable(&tool) {
return Err(failure::format_err!(
"found file for `clippy-driver` but its not an executable. what the heck is going on !? please run `rustup component add clippy`"
));
}
Some(tool)
} else {
self.maybe_get_tool("rustc-wrapper")?
};
Expand Down Expand Up @@ -407,6 +416,7 @@ impl Config {
match self.get_env(key)? {
Some(v) => Ok(Some(v)),
None => {
// println!("{:#?}", self);
let config_key = key.to_config();
let o_cv = self.get_cv(&config_key)?;
match o_cv {
Expand Down Expand Up @@ -756,17 +766,14 @@ impl Config {
} else {
PathBuf::from(tool_path)
};
println!("some tool {}", tool);
return Ok(Some(path));
}

let var = format!("build.{}", tool);
if let Some(tool_path) = self.get_path(&var)? {
println!("some tool {}", tool);
return Ok(Some(tool_path.val));
}

println!("NO TOOL {}", tool);
Ok(None)
}

Expand Down Expand Up @@ -940,8 +947,7 @@ impl ConfigError {
}
}

impl std::error::Error for ConfigError {
}
impl std::error::Error for ConfigError {}

// Future note: currently, we cannot override `Fail::cause` (due to
// specialization) so we have no way to return the underlying causes. In the
Expand Down
14 changes: 14 additions & 0 deletions src/cargo/util/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@ pub fn normalize_path(path: &Path) -> PathBuf {
ret
}

#[cfg(unix)]
pub fn is_executable<P: AsRef<Path>>(path: P) -> bool {
use std::os::unix::prelude::*;
fs::metadata(path)
.map(|metadata| metadata.is_file() && metadata.permissions().mode() & 0o111 != 0)
.unwrap_or(false)
}
#[cfg(windows)]
pub fn is_executable<P: AsRef<Path>>(path: P) -> bool {
fs::metadata(path)
.map(|metadata| metadata.is_file())
.unwrap_or(false)
}

pub fn resolve_executable(exec: &Path) -> CargoResult<PathBuf> {
if exec.components().count() == 1 {
let paths = env::var_os("PATH").ok_or_else(|| failure::format_err!("no PATH"))?;
Expand Down