mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-12-18 09:03:18 +00:00
Basic implementation of cargo clippy --all
This implements workspace support for `cargo clippy` by running clippy over all packages in the workspace (in serial). This should probably be parallelised in future (as `cargo build --all`).
This commit is contained in:
parent
7cdaeae1b8
commit
1265b46478
1 changed files with 71 additions and 59 deletions
16
src/main.rs
16
src/main.rs
|
@ -152,6 +152,7 @@ Common options:
|
||||||
-h, --help Print this message
|
-h, --help Print this message
|
||||||
--features Features to compile for the package
|
--features Features to compile for the package
|
||||||
-V, --version Print version info and exit
|
-V, --version Print version info and exit
|
||||||
|
--all @@@ something sensible here (copy from cargo-edit?)
|
||||||
|
|
||||||
Other options are the same as `cargo rustc`.
|
Other options are the same as `cargo rustc`.
|
||||||
|
|
||||||
|
@ -217,6 +218,9 @@ pub fn main() {
|
||||||
.expect("manifest path could not be canonicalized")
|
.expect("manifest path could not be canonicalized")
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let packages = if std::env::args().any(|a| a == "--all" ) {
|
||||||
|
metadata.packages
|
||||||
|
} else {
|
||||||
let package_index = {
|
let package_index = {
|
||||||
if let Some(manifest_path) = manifest_path {
|
if let Some(manifest_path) = manifest_path {
|
||||||
metadata.packages.iter().position(|package| {
|
metadata.packages.iter().position(|package| {
|
||||||
|
@ -265,9 +269,16 @@ pub fn main() {
|
||||||
}
|
}
|
||||||
}.expect("could not find matching package");
|
}.expect("could not find matching package");
|
||||||
|
|
||||||
let package = metadata.packages.remove(package_index);
|
vec![metadata.packages.remove(package_index)]
|
||||||
|
};
|
||||||
|
|
||||||
|
for package in packages {
|
||||||
|
let manifest_path = package.manifest_path;
|
||||||
|
|
||||||
for target in package.targets {
|
for target in package.targets {
|
||||||
let args = std::env::args().skip(2);
|
let args = std::env::args().skip(2).filter(|a| a != "--all" && !a.starts_with("--manifest-path="));
|
||||||
|
|
||||||
|
let args = std::iter::once(format!("--manifest-path={}", manifest_path)).chain(args);
|
||||||
if let Some(first) = target.kind.get(0) {
|
if let Some(first) = target.kind.get(0) {
|
||||||
if target.kind.len() > 1 || first.ends_with("lib") {
|
if target.kind.len() > 1 || first.ends_with("lib") {
|
||||||
if let Err(code) = process(std::iter::once("--lib".to_owned()).chain(args)) {
|
if let Err(code) = process(std::iter::once("--lib".to_owned()).chain(args)) {
|
||||||
|
@ -287,6 +298,7 @@ pub fn main() {
|
||||||
panic!("badly formatted cargo metadata: target::kind is an empty array");
|
panic!("badly formatted cargo metadata: target::kind is an empty array");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// this arm is executed when cargo-clippy runs `cargo rustc` with the `RUSTC`
|
// this arm is executed when cargo-clippy runs `cargo rustc` with the `RUSTC`
|
||||||
// env var set to itself
|
// env var set to itself
|
||||||
|
|
Loading…
Reference in a new issue