Skip to content

Commit 9852087

Browse files
committed
fix: remove profile arg, exe check, add rustup check
1 parent 4051b0c commit 9852087

File tree

4 files changed

+26
-45
lines changed

4 files changed

+26
-45
lines changed

src/bin/cargo/commands/clippy.rs

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ use cargo::ops;
44

55
pub fn cli() -> App {
66
subcommand("clippy-preview")
7-
// subcommand aliases are handled in aliased_command()
8-
// .alias("c")
97
.about("Checks a package to catch common mistakes and improve your Rust code.")
108
.arg_package_spec(
119
"Package(s) to check",
@@ -26,7 +24,6 @@ pub fn cli() -> App {
2624
"Check all targets",
2725
)
2826
.arg_release("Check artifacts in release mode, with optimizations")
29-
.arg(opt("profile", "Profile to build the selected target for").value_name("PROFILE"))
3027
.arg_features()
3128
.arg_target_triple("Check for the target triple")
3229
.arg_target_dir()
@@ -43,13 +40,6 @@ All packages in the workspace are checked if the `--all` flag is supplied. The
4340
`--all` flag is automatically assumed for a virtual manifest.
4441
Note that `--exclude` has to be specified in conjunction with the `--all` flag.
4542
46-
Compilation can be configured via the use of profiles which are configured in
47-
the manifest. The default profile for this command is `dev`, but passing
48-
the `--release` flag will use the `release` profile instead.
49-
50-
The `--profile test` flag can be used to check unit tests with the
51-
`#[cfg(test)]` attribute.
52-
5343
To allow or deny a lint from the command line you can use `cargo clippy --`
5444
with:
5545
@@ -68,20 +58,8 @@ You can use tool lints to allow or deny lints from your code, eg.:
6858
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
6959
config.set_clippy_override(true);
7060
let ws = args.workspace(config)?;
71-
let test = match args.value_of("profile") {
72-
Some("test") => true,
73-
None => false,
74-
Some(profile) => {
75-
let err = failure::format_err!(
76-
"unknown profile: `{}`, only `test` is \
77-
currently supported",
78-
profile
79-
);
80-
return Err(CliError::new(err, 101));
81-
}
82-
};
8361

84-
let mode = CompileMode::Check { test };
62+
let mode = CompileMode::Check { test: false };
8563
let compile_opts = args.compile_options(config, mode, Some(&ws))?;
8664

8765
if !config.cli_unstable().unstable_options {

src/bin/cargo/main.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
use std::collections::BTreeSet;
88
use std::env;
99
use std::fs;
10-
use std::path::PathBuf;
10+
use std::path::{Path, PathBuf};
1111

1212
use cargo::core::shell::Shell;
13-
use cargo::util::paths::is_executable;
1413
use cargo::util::{self, command_prelude, lev_distance, CargoResult, CliResult, Config};
1514
use cargo::util::{CliError, ProcessError};
1615

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

167+
#[cfg(unix)]
168+
fn is_executable<P: AsRef<Path>>(path: P) -> bool {
169+
use std::os::unix::prelude::*;
170+
fs::metadata(path)
171+
.map(|metadata| metadata.is_file() && metadata.permissions().mode() & 0o111 != 0)
172+
.unwrap_or(false)
173+
}
174+
#[cfg(windows)]
175+
fn is_executable<P: AsRef<Path>>(path: P) -> bool {
176+
fs::metadata(path)
177+
.map(|metadata| metadata.is_file())
178+
.unwrap_or(false)
179+
}
180+
168181
fn search_directories(config: &Config) -> Vec<PathBuf> {
169182
let mut dirs = vec![config.home().clone().into_path_unlocked().join("bin")];
170183
if let Some(val) = env::var_os("PATH") {

src/cargo/util/config.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,17 @@ impl Config {
208208
let wrapper = if self.clippy_override {
209209
let tool = self.get_tool("clippy-driver")?;
210210
let tool = paths::resolve_executable(&tool).map_err(|e| {
211-
failure::format_err!("{}: please run `rustup component add clippy`", e)
211+
let rustup_in_path = self
212+
.get_tool("rustup")
213+
.and_then(|tool| paths::resolve_executable(&tool))
214+
.is_ok();
215+
let has_rustup_env = std::env::var("RUSTUP_TOOLCHAIN").is_ok();
216+
if dbg!(rustup_in_path) || dbg!(has_rustup_env) {
217+
failure::format_err!("{}: please run `rustup component add clippy`", e)
218+
} else {
219+
failure::format_err!("{}: please install clippy component", e)
220+
}
212221
})?;
213-
if !paths::is_executable(&tool) {
214-
return Err(failure::format_err!(
215-
"found file for `clippy-driver` but its not an executable. what the heck is going on !? please run `rustup component add clippy`"
216-
));
217-
}
218222
Some(tool)
219223
} else {
220224
self.maybe_get_tool("rustc-wrapper")?

src/cargo/util/paths.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,6 @@ pub fn normalize_path(path: &Path) -> PathBuf {
8989
ret
9090
}
9191

92-
#[cfg(unix)]
93-
pub fn is_executable<P: AsRef<Path>>(path: P) -> bool {
94-
use std::os::unix::prelude::*;
95-
fs::metadata(path)
96-
.map(|metadata| metadata.is_file() && metadata.permissions().mode() & 0o111 != 0)
97-
.unwrap_or(false)
98-
}
99-
#[cfg(windows)]
100-
pub fn is_executable<P: AsRef<Path>>(path: P) -> bool {
101-
fs::metadata(path)
102-
.map(|metadata| metadata.is_file())
103-
.unwrap_or(false)
104-
}
105-
10692
pub fn resolve_executable(exec: &Path) -> CargoResult<PathBuf> {
10793
if exec.components().count() == 1 {
10894
let paths = env::var_os("PATH").ok_or_else(|| failure::format_err!("no PATH"))?;

0 commit comments

Comments
 (0)