From 36c5026c48f1beed77cb4bfacc37d798c1b505a2 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Tue, 21 Jun 2016 12:31:30 +0200 Subject: [PATCH 1/2] fix cargo clippy when using with `--manifest-path` --- clippy_lints/src/utils/cargo.rs | 9 +++++++-- src/main.rs | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/utils/cargo.rs b/clippy_lints/src/utils/cargo.rs index f81fcbc38..48a97f2f1 100644 --- a/clippy_lints/src/utils/cargo.rs +++ b/clippy_lints/src/utils/cargo.rs @@ -65,8 +65,13 @@ impl From for Error { } } -pub fn metadata() -> Result { - let output = Command::new("cargo").args(&["metadata", "--no-deps"]).output()?; +pub fn metadata(manifest_path: Option) -> Result { + let mut cmd = Command::new("cargo"); + cmd.arg("metadata").arg("--no-deps"); + if let Some(ref mani) = manifest_path { + cmd.arg(mani); + } + let output = cmd.output()?; let stdout = from_utf8(&output.stdout)?; Ok(json::decode(stdout)?) } diff --git a/src/main.rs b/src/main.rs index de3361d51..cf5792644 100644 --- a/src/main.rs +++ b/src/main.rs @@ -129,7 +129,8 @@ pub fn main() { }; if let Some("clippy") = std::env::args().nth(1).as_ref().map(AsRef::as_ref) { - let mut metadata = cargo::metadata().expect("could not obtain cargo metadata"); + let manifest_path = std::env::args().skip(2).find(|val| val.starts_with("--manifest-path=")); + let mut metadata = cargo::metadata(manifest_path).expect("could not obtain cargo metadata"); assert_eq!(metadata.version, 1); for target in metadata.packages.remove(0).targets { let args = std::env::args().skip(2); From 44c30ca543642d947116a536223e5f93fb28c35a Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Tue, 21 Jun 2016 12:35:49 +0200 Subject: [PATCH 2/2] fix tests --- tests/versioncheck.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/versioncheck.rs b/tests/versioncheck.rs index b2a2f416a..e216c8015 100644 --- a/tests/versioncheck.rs +++ b/tests/versioncheck.rs @@ -3,9 +3,9 @@ use clippy_lints::utils::cargo; #[test] fn check_that_clippy_lints_has_the_same_version_as_clippy() { - let clippy_meta = cargo::metadata().expect("could not obtain cargo metadata"); + let clippy_meta = cargo::metadata(None).expect("could not obtain cargo metadata"); std::env::set_current_dir(std::env::current_dir().unwrap().join("clippy_lints")).unwrap(); - let clippy_lints_meta = cargo::metadata().expect("could not obtain cargo metadata"); + let clippy_lints_meta = cargo::metadata(None).expect("could not obtain cargo metadata"); assert_eq!(clippy_lints_meta.packages[0].version, clippy_meta.packages[0].version); for package in &clippy_meta.packages[0].dependencies { if package.name == "clippy_lints" {