1
1
#![ allow( clippy:: filter_map) ]
2
2
3
3
use crate :: clippy_project_root;
4
- use std:: path:: PathBuf ;
4
+ use serde:: { Deserialize , Serialize } ;
5
+ use std:: collections:: HashMap ;
5
6
use std:: process:: Command ;
7
+ use std:: { fs:: write, path:: PathBuf } ;
6
8
7
9
// represents an archive we download from crates.io
8
- #[ derive( Debug ) ]
10
+ #[ derive( Debug , Serialize , Deserialize , Eq , Hash , PartialEq ) ]
9
11
struct KrateSource {
10
12
version : String ,
11
13
name : String ,
12
14
}
13
15
16
+ // use this to store the crates when interacting with the crates.toml file
17
+ #[ derive( Debug , Serialize , Deserialize ) ]
18
+ struct CrateList {
19
+ crates : HashMap < String , String > ,
20
+ }
21
+
14
22
// represents the extracted sourcecode of a crate
15
23
#[ derive( Debug ) ]
16
24
struct Krate {
@@ -129,33 +137,25 @@ fn build_clippy() {
129
137
. expect ( "Failed to build clippy!" ) ;
130
138
}
131
139
140
+ // get a list of KrateSources we want to check from a "crater_crates.toml" file.
141
+ fn read_crates ( ) -> Vec < KrateSource > {
142
+ let toml_path = PathBuf :: from ( "clippy_dev/crater_crates.toml" ) ;
143
+ let toml_content: String =
144
+ std:: fs:: read_to_string ( & toml_path) . unwrap_or_else ( |_| panic ! ( "Failed to read {}" , toml_path. display( ) ) ) ;
145
+ let crate_list: CrateList =
146
+ toml:: from_str ( & toml_content) . unwrap_or_else ( |e| panic ! ( "Failed to parse {}: \n {}" , toml_path. display( ) , e) ) ;
147
+ // parse the hashmap of the toml file into a list of crates
148
+ crate_list
149
+ . crates
150
+ . iter ( )
151
+ . map ( |( name, version) | KrateSource :: new ( & name, & version) )
152
+ . collect ( )
153
+ }
154
+
132
155
// the main fn
133
156
pub fn run ( ) {
134
157
let cargo_clippy_path: PathBuf = PathBuf :: from ( "target/debug/cargo-clippy" ) ;
135
158
136
- // crates we want to check:
137
- let krates: Vec < KrateSource > = vec ! [
138
- // some of these are form cargotest
139
- KrateSource :: new( "cargo" , "0.49.0" ) ,
140
- KrateSource :: new( "iron" , "0.6.1" ) ,
141
- KrateSource :: new( "ripgrep" , "12.1.1" ) ,
142
- //KrateSource::new("tokei", "12.0.4"),
143
- KrateSource :: new( "xsv" , "0.13.0" ) ,
144
- KrateSource :: new( "serde" , "1.0.118" ) ,
145
- KrateSource :: new( "rayon" , "1.5.0" ) ,
146
- // top 10 crates.io dls
147
- KrateSource :: new( "rand" , "0.7.3" ) ,
148
- KrateSource :: new( "syn" , "1.0.54" ) ,
149
- KrateSource :: new( "libc" , "0.2.81" ) ,
150
- KrateSource :: new( "quote" , "1.0.7" ) ,
151
- KrateSource :: new( "rand_core" , "0.6.0" ) ,
152
- KrateSource :: new( "unicode-xid" , "0.2.1" ) ,
153
- KrateSource :: new( "proc-macro2" , "1.0.24" ) ,
154
- KrateSource :: new( "bitflags" , "1.2.1" ) ,
155
- KrateSource :: new( "log" , "0.4.11" ) ,
156
- KrateSource :: new( "regex" , "1.4.2" ) ,
157
- ] ;
158
-
159
159
println ! ( "Compiling clippy..." ) ;
160
160
build_clippy ( ) ;
161
161
println ! ( "Done compiling" ) ;
@@ -168,15 +168,17 @@ pub fn run() {
168
168
) ;
169
169
170
170
// download and extract the crates, then run clippy on them and collect clippys warnings
171
- let clippy_lint_results: Vec < Vec < String > > = krates
171
+
172
+ let clippy_lint_results: Vec < Vec < String > > = read_crates ( )
172
173
. into_iter ( )
173
174
. map ( |krate| krate. download_and_extract ( ) )
174
175
. map ( |krate| krate. run_clippy_lints ( & cargo_clippy_path) )
175
176
. collect ( ) ;
176
177
177
- let all_warnings: Vec < String > = clippy_lint_results. into_iter ( ) . flatten ( ) . collect ( ) ;
178
+ let mut all_warnings: Vec < String > = clippy_lint_results. into_iter ( ) . flatten ( ) . collect ( ) ;
179
+ all_warnings. sort ( ) ;
178
180
179
181
// save the text into mini-crater/logs.txt
180
182
let text = all_warnings. join ( "" ) ;
181
- std :: fs :: write ( "mini-crater/logs.txt" , text) . unwrap ( ) ;
183
+ write ( "mini-crater/logs.txt" , text) . unwrap ( ) ;
182
184
}
0 commit comments