remove rustc-serialize dependency and factor util::cargo out into a crate

This commit is contained in:
Oliver Schneider 2017-01-24 11:31:42 +01:00
parent bc497a6262
commit 26e8558d8a
No known key found for this signature in database
GPG key ID: A69F8D225B3AD7D9
9 changed files with 25 additions and 99 deletions

View file

@ -32,14 +32,15 @@ test = false
# begin automatic update
clippy_lints = { version = "0.0.111", path = "clippy_lints" }
# end automatic update
cargo_metadata = "0.1"
[dev-dependencies]
compiletest_rs = "0.2.5"
lazy_static = "0.1.15"
regex = "0.2"
rustc-serialize = "0.3"
serde_derive = "0.9.0-rc3"
clippy-mini-macro-test = { version = "0.1", path = "mini-macro" }
serde = "0.7"
serde = "0.9.0-rc3"
[features]
debugging = []

View file

@ -22,7 +22,6 @@ semver = "0.2.1"
toml = "0.2"
unicode-normalization = "0.1"
quine-mc_cluskey = "0.2.2"
rustc-serialize = "0.3"
[features]
debugging = []

View file

@ -38,8 +38,6 @@ extern crate regex_syntax;
// for finding minimal boolean expressions
extern crate quine_mc_cluskey;
extern crate rustc_serialize;
extern crate rustc_errors;
extern crate rustc_plugin;
extern crate rustc_const_eval;

View file

@ -1,77 +0,0 @@
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<String>,
pub dependencies: Vec<Dependency>,
pub targets: Vec<Target>,
features: HashMap<String, Vec<String>>,
pub 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<String>,
target: Option<String>,
}
#[derive(RustcDecodable, Debug)]
pub struct Target {
pub name: String,
pub kind: Vec<String>,
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(manifest_path_arg: Option<&str>) -> Result<Metadata, Error> {
let mut cmd = Command::new("cargo");
cmd.arg("metadata").arg("--no-deps");
if let Some(mani) = manifest_path_arg {
cmd.arg(mani);
}
let output = cmd.output()?;
let stdout = from_utf8(&output.stdout)?;
Ok(json::decode(stdout)?)
}

View file

@ -21,7 +21,6 @@ use syntax::errors::DiagnosticBuilder;
use syntax::ptr::P;
use syntax::symbol::keywords;
pub mod cargo;
pub mod comparisons;
pub mod conf;
pub mod constants;

View file

@ -21,7 +21,7 @@ use std::process::{self, Command};
use syntax::ast;
use std::io::{self, Write};
use clippy_lints::utils::cargo;
extern crate cargo_metadata;
struct ClippyCompilerCalls {
default: RustcDefaultCalls,
@ -179,15 +179,13 @@ pub fn main() {
let manifest_path_arg = std::env::args().skip(2).find(|val| val.starts_with("--manifest-path="));
let mut metadata = if let Ok(metadata) = cargo::metadata(manifest_path_arg.as_ref().map(AsRef::as_ref)) {
let mut metadata = if let Ok(metadata) = cargo_metadata::metadata(manifest_path_arg.as_ref().map(AsRef::as_ref)) {
metadata
} else {
let _ = io::stderr().write_fmt(format_args!("error: Could not obtain cargo metadata."));
process::exit(101);
};
assert_eq!(metadata.version, 1);
let manifest_path = manifest_path_arg.map(|arg| PathBuf::from(Path::new(&arg["--manifest-path=".len()..])));
let current_dir = std::env::current_dir();

View file

@ -9,14 +9,19 @@ struct A;
impl serde::de::Visitor for A {
type Value = ();
fn visit_str<E>(&mut self, _v: &str) -> Result<Self::Value, E>
where E: serde::Error,
fn expecting(&self, _: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
unimplemented!()
}
fn visit_str<E>(self, _v: &str) -> Result<Self::Value, E>
where E: serde::de::Error,
{
unimplemented!()
}
fn visit_string<E>(&mut self, _v: String) -> Result<Self::Value, E>
where E: serde::Error,
fn visit_string<E>(self, _v: String) -> Result<Self::Value, E>
where E: serde::de::Error,
{
unimplemented!()
}
@ -27,9 +32,13 @@ struct B;
impl serde::de::Visitor for B {
type Value = ();
fn visit_string<E>(&mut self, _v: String) -> Result<Self::Value, E>
fn expecting(&self, _: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
unimplemented!()
}
fn visit_string<E>(self, _v: String) -> Result<Self::Value, E>
//~^ ERROR you should not implement `visit_string` without also implementing `visit_str`
where E: serde::Error,
where E: serde::de::Error,
{
unimplemented!()
}

View file

@ -1,11 +1,11 @@
#![feature(plugin)]
#![plugin(clippy)]
extern crate rustc_serialize;
#[macro_use] extern crate serde_derive;
/// Test that we do not lint for unused underscores in a `MacroAttribute` expansion
#[deny(used_underscore_binding)]
#[derive(RustcEncodable)]
#[derive(Deserialize)]
struct MacroAttributesTest {
_foo: u32,
}

View file

@ -1,11 +1,10 @@
extern crate clippy_lints;
use clippy_lints::utils::cargo;
extern crate cargo_metadata;
#[test]
fn check_that_clippy_lints_has_the_same_version_as_clippy() {
let clippy_meta = cargo::metadata(None).expect("could not obtain cargo metadata");
let clippy_meta = cargo_metadata::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(None).expect("could not obtain cargo metadata");
let clippy_lints_meta = cargo_metadata::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" {