Remove cargo_metadata dependency from clippy_dev

This commit is contained in:
Jason Newcomb 2022-03-29 08:32:12 -04:00
parent b3f8415032
commit 7025283f3e
3 changed files with 17 additions and 11 deletions

View File

@ -4,15 +4,12 @@ version = "0.0.1"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
bytecount = "0.6"
clap = "2.33" clap = "2.33"
indoc = "1.0" indoc = "1.0"
itertools = "0.10.1" itertools = "0.10.1"
opener = "0.5" opener = "0.5"
shell-escape = "0.1" shell-escape = "0.1"
walkdir = "2.3" walkdir = "2.3"
cargo_metadata = "0.14"
[features] [features]
deny-warnings = [] deny-warnings = []

View File

@ -1,3 +1,4 @@
#![feature(let_else)]
#![feature(once_cell)] #![feature(once_cell)]
#![feature(rustc_private)] #![feature(rustc_private)]
#![cfg_attr(feature = "deny-warnings", deny(warnings))] #![cfg_attr(feature = "deny-warnings", deny(warnings))]

View File

@ -133,15 +133,23 @@ fn to_camel_case(name: &str) -> String {
} }
fn get_stabilisation_version() -> String { fn get_stabilisation_version() -> String {
let mut command = cargo_metadata::MetadataCommand::new(); fn parse_manifest(contents: &str) -> Option<String> {
command.no_deps(); let version = contents
if let Ok(metadata) = command.exec() { .lines()
if let Some(pkg) = metadata.packages.iter().find(|pkg| pkg.name == "clippy") { .filter_map(|l| l.split_once('='))
return format!("{}.{}.0", pkg.version.minor, pkg.version.patch); .find_map(|(k, v)| (k.trim() == "version").then(|| v.trim()))?;
} let Some(("0", version)) = version.get(1..version.len() - 1)?.split_once('.') else {
return None;
};
let (minor, patch) = version.split_once('.')?;
Some(format!(
"{}.{}.0",
minor.parse::<u32>().ok()?,
patch.parse::<u32>().ok()?
))
} }
let contents = fs::read_to_string("Cargo.toml").expect("Unable to read `Cargo.toml`");
String::from("<TODO set version(see doc/adding_lints.md)>") parse_manifest(&contents).expect("Unable to find package version in `Cargo.toml`")
} }
fn get_test_file_contents(lint_name: &str, header_commands: Option<&str>) -> String { fn get_test_file_contents(lint_name: &str, header_commands: Option<&str>) -> String {