11#![ allow( clippy:: filter_map) ]
22
33use crate :: clippy_project_root;
4- use std:: path:: PathBuf ;
4+ use serde:: { Deserialize , Serialize } ;
5+ use std:: collections:: HashMap ;
56use std:: process:: Command ;
7+ use std:: { fs:: write, path:: PathBuf } ;
68
79// represents an archive we download from crates.io
8- #[ derive( Debug ) ]
10+ #[ derive( Debug , Serialize , Deserialize , Eq , Hash , PartialEq ) ]
911struct KrateSource {
1012 version : String ,
1113 name : String ,
1214}
1315
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+
1422// represents the extracted sourcecode of a crate
1523#[ derive( Debug ) ]
1624struct Krate {
@@ -129,33 +137,25 @@ fn build_clippy() {
129137 . expect ( "Failed to build clippy!" ) ;
130138}
131139
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+
132155// the main fn
133156pub fn run ( ) {
134157 let cargo_clippy_path: PathBuf = PathBuf :: from ( "target/debug/cargo-clippy" ) ;
135158
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-
159159 println ! ( "Compiling clippy..." ) ;
160160 build_clippy ( ) ;
161161 println ! ( "Done compiling" ) ;
@@ -168,15 +168,17 @@ pub fn run() {
168168 ) ;
169169
170170 // 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 ( )
172173 . into_iter ( )
173174 . map ( |krate| krate. download_and_extract ( ) )
174175 . map ( |krate| krate. run_clippy_lints ( & cargo_clippy_path) )
175176 . collect ( ) ;
176177
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 ( ) ;
178180
179181 // save the text into mini-crater/logs.txt
180182 let text = all_warnings. join ( "" ) ;
181- std :: fs :: write ( "mini-crater/logs.txt" , text) . unwrap ( ) ;
183+ write ( "mini-crater/logs.txt" , text) . unwrap ( ) ;
182184}
0 commit comments