Skip to content

Commit 85b88be

Browse files
committed
Auto merge of #8605 - Jarcho:remove-deps, r=xFrednet
Remove deps This remove both `regex` and `cargo_metadata` as dependencies making `clippy_dev` compile ~3x faster (~46s -> ~16s locally). `cargo_metadata` was used to extract the `version` field from `Cargo.toml`, which is done trivially without that. `regex` was used to parse `define_clippy_lint` in `update_lints` which is now done using `rustc_lexer`. This isn't any simpler, but it compiles ~15s faster and runs ~3x faster (~2.1s -> ~0.7s locally). The next biggest offenders to compile times are `clap` and `winapi` on windows. `clap` could be removed, but re-implementing enough is probably more work than it's worth. `winapi` is used by `opener` and `walkdir` so it's stuck there. changelog: none
2 parents baaddf2 + ae5af0c commit 85b88be

File tree

6 files changed

+313
-412
lines changed

6 files changed

+313
-412
lines changed

Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@ name = "clippy-driver"
2121
path = "src/driver.rs"
2222

2323
[dependencies]
24-
clippy_lints = { version = "0.1", path = "clippy_lints" }
24+
clippy_lints = { path = "clippy_lints" }
2525
semver = "1.0"
26-
rustc_tools_util = { version = "0.2", path = "rustc_tools_util" }
26+
rustc_tools_util = { path = "rustc_tools_util" }
2727
tempfile = { version = "3.2", optional = true }
2828

2929
[dev-dependencies]
30-
cargo_metadata = "0.14"
3130
compiletest_rs = { version = "0.7.1", features = ["tmp"] }
3231
tester = "0.9"
3332
regex = "1.5"

clippy_dev/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ version = "0.0.1"
44
edition = "2021"
55

66
[dependencies]
7-
bytecount = "0.6"
87
clap = "2.33"
98
indoc = "1.0"
109
itertools = "0.10.1"
1110
opener = "0.5"
12-
regex = "1.5"
1311
shell-escape = "0.1"
1412
walkdir = "2.3"
15-
cargo_metadata = "0.14"
1613

1714
[features]
1815
deny-warnings = []
16+
17+
[package.metadata.rust-analyzer]
18+
# This package uses #[feature(rustc_private)]
19+
rustc_private = true

clippy_dev/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
#![feature(let_else)]
12
#![feature(once_cell)]
3+
#![feature(rustc_private)]
24
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
35
// warn on lints, that are included in `rust-lang/rust`s bootstrap
46
#![warn(rust_2018_idioms, unused_lifetimes)]
57

8+
extern crate rustc_lexer;
9+
610
use std::path::PathBuf;
711

812
pub mod bless;

clippy_dev/src/new_lint.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,23 @@ fn to_camel_case(name: &str) -> String {
133133
}
134134

135135
fn get_stabilisation_version() -> String {
136-
let mut command = cargo_metadata::MetadataCommand::new();
137-
command.no_deps();
138-
if let Ok(metadata) = command.exec() {
139-
if let Some(pkg) = metadata.packages.iter().find(|pkg| pkg.name == "clippy") {
140-
return format!("{}.{}.0", pkg.version.minor, pkg.version.patch);
141-
}
136+
fn parse_manifest(contents: &str) -> Option<String> {
137+
let version = contents
138+
.lines()
139+
.filter_map(|l| l.split_once('='))
140+
.find_map(|(k, v)| (k.trim() == "version").then(|| v.trim()))?;
141+
let Some(("0", version)) = version.get(1..version.len() - 1)?.split_once('.') else {
142+
return None;
143+
};
144+
let (minor, patch) = version.split_once('.')?;
145+
Some(format!(
146+
"{}.{}.0",
147+
minor.parse::<u32>().ok()?,
148+
patch.parse::<u32>().ok()?
149+
))
142150
}
143-
144-
String::from("<TODO set version(see doc/adding_lints.md)>")
151+
let contents = fs::read_to_string("Cargo.toml").expect("Unable to read `Cargo.toml`");
152+
parse_manifest(&contents).expect("Unable to find package version in `Cargo.toml`")
145153
}
146154

147155
fn get_test_file_contents(lint_name: &str, header_commands: Option<&str>) -> String {

0 commit comments

Comments
 (0)