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:
Benjamin Gill 2017-08-18 17:57:33 +01:00
parent 7cdaeae1b8
commit 1265b46478

View file

@ -152,6 +152,7 @@ Common options:
-h, --help Print this message
--features Features to compile for the package
-V, --version Print version info and exit
--all @@@ something sensible here (copy from cargo-edit?)
Other options are the same as `cargo rustc`.
@ -217,6 +218,9 @@ pub fn main() {
.expect("manifest path could not be canonicalized")
});
let packages = if std::env::args().any(|a| a == "--all" ) {
metadata.packages
} else {
let package_index = {
if let Some(manifest_path) = manifest_path {
metadata.packages.iter().position(|package| {
@ -265,9 +269,16 @@ pub fn main() {
}
}.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 {
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 target.kind.len() > 1 || first.ends_with("lib") {
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");
}
}
}
} else {
// this arm is executed when cargo-clippy runs `cargo rustc` with the `RUSTC`
// env var set to itself