Skip to content

Commit

Permalink
Auto merge of #8605 - Jarcho:remove-deps, r=xFrednet
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Apr 2, 2022
2 parents baaddf2 + ae5af0c commit 85b88be
Show file tree
Hide file tree
Showing 6 changed files with 313 additions and 412 deletions.
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ name = "clippy-driver"
path = "src/driver.rs"

[dependencies]
clippy_lints = { version = "0.1", path = "clippy_lints" }
clippy_lints = { path = "clippy_lints" }
semver = "1.0"
rustc_tools_util = { version = "0.2", path = "rustc_tools_util" }
rustc_tools_util = { path = "rustc_tools_util" }
tempfile = { version = "3.2", optional = true }

[dev-dependencies]
cargo_metadata = "0.14"
compiletest_rs = { version = "0.7.1", features = ["tmp"] }
tester = "0.9"
regex = "1.5"
Expand Down
7 changes: 4 additions & 3 deletions clippy_dev/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ version = "0.0.1"
edition = "2021"

[dependencies]
bytecount = "0.6"
clap = "2.33"
indoc = "1.0"
itertools = "0.10.1"
opener = "0.5"
regex = "1.5"
shell-escape = "0.1"
walkdir = "2.3"
cargo_metadata = "0.14"

[features]
deny-warnings = []

[package.metadata.rust-analyzer]
# This package uses #[feature(rustc_private)]
rustc_private = true
4 changes: 4 additions & 0 deletions clippy_dev/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#![feature(let_else)]
#![feature(once_cell)]
#![feature(rustc_private)]
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
// warn on lints, that are included in `rust-lang/rust`s bootstrap
#![warn(rust_2018_idioms, unused_lifetimes)]

extern crate rustc_lexer;

use std::path::PathBuf;

pub mod bless;
Expand Down
24 changes: 16 additions & 8 deletions clippy_dev/src/new_lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,23 @@ fn to_camel_case(name: &str) -> String {
}

fn get_stabilisation_version() -> String {
let mut command = cargo_metadata::MetadataCommand::new();
command.no_deps();
if let Ok(metadata) = command.exec() {
if let Some(pkg) = metadata.packages.iter().find(|pkg| pkg.name == "clippy") {
return format!("{}.{}.0", pkg.version.minor, pkg.version.patch);
}
fn parse_manifest(contents: &str) -> Option<String> {
let version = contents
.lines()
.filter_map(|l| l.split_once('='))
.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()?
))
}

String::from("<TODO set version(see doc/adding_lints.md)>")
let contents = fs::read_to_string("Cargo.toml").expect("Unable to read `Cargo.toml`");
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 {
Expand Down

0 comments on commit 85b88be

Please sign in to comment.