-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #960 from oli-obk/libbin
don't require `cargo clippy` to pass a `--lib` or `--bin x` argument
- Loading branch information
Showing
8 changed files
with
127 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
use std::collections::HashMap; | ||
use std::process::Command; | ||
use std::str::{from_utf8, Utf8Error}; | ||
use std::io; | ||
use rustc_serialize::json; | ||
|
||
#[derive(RustcDecodable, Debug)] | ||
pub struct Metadata { | ||
pub packages: Vec<Package>, | ||
resolve: Option<()>, | ||
pub version: usize, | ||
} | ||
|
||
#[derive(RustcDecodable, Debug)] | ||
pub struct Package { | ||
pub name: String, | ||
pub version: String, | ||
id: String, | ||
source: Option<()>, | ||
pub dependencies: Vec<Dependency>, | ||
pub targets: Vec<Target>, | ||
features: HashMap<String, Vec<String>>, | ||
manifest_path: String, | ||
} | ||
|
||
#[derive(RustcDecodable, Debug)] | ||
pub struct Dependency { | ||
pub name: String, | ||
source: Option<String>, | ||
pub req: String, | ||
kind: Option<String>, | ||
optional: bool, | ||
uses_default_features: bool, | ||
features: Vec<HashMap<String, String>>, | ||
target: Option<()>, | ||
} | ||
|
||
#[allow(non_camel_case_types)] | ||
#[derive(RustcDecodable, Debug)] | ||
pub enum Kind { | ||
dylib, | ||
test, | ||
bin, | ||
lib, | ||
} | ||
|
||
#[derive(RustcDecodable, Debug)] | ||
pub struct Target { | ||
pub name: String, | ||
pub kind: Vec<Kind>, | ||
src_path: String, | ||
} | ||
|
||
#[derive(Debug)] | ||
pub enum Error { | ||
Io(io::Error), | ||
Utf8(Utf8Error), | ||
Json(json::DecoderError), | ||
} | ||
|
||
impl From<io::Error> for Error { | ||
fn from(err: io::Error) -> Self { Error::Io(err) } | ||
} | ||
impl From<Utf8Error> for Error { | ||
fn from(err: Utf8Error) -> Self { Error::Utf8(err) } | ||
} | ||
impl From<json::DecoderError> for Error { | ||
fn from(err: json::DecoderError) -> Self { Error::Json(err) } | ||
} | ||
|
||
pub fn metadata() -> Result<Metadata, Error> { | ||
let output = Command::new("cargo").args(&["metadata", "--no-deps"]).output()?; | ||
let stdout = from_utf8(&output.stdout)?; | ||
Ok(json::decode(stdout)?) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
extern crate clippy_lints; | ||
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"); | ||
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"); | ||
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" { | ||
assert_eq!(clippy_lints_meta.packages[0].version, package.req[1..]); | ||
return; | ||
} | ||
} | ||
} |