@@ -32,15 +32,29 @@ struct TomlCrate {
3232 git_url : Option < String > ,
3333 git_hash : Option < String > ,
3434 path : Option < String > ,
35+ options : Option < Vec < String > > ,
3536}
3637
3738/// Represents an archive we download from crates.io, or a git repo, or a local repo/folder
3839/// Once processed (downloaded/extracted/cloned/copied...), this will be translated into a `Crate`
3940#[ derive( Debug , Serialize , Deserialize , Eq , Hash , PartialEq ) ]
4041enum CrateSource {
41- CratesIo { name : String , version : String } ,
42- Git { name : String , url : String , commit : String } ,
43- Path { name : String , path : PathBuf } ,
42+ CratesIo {
43+ name : String ,
44+ version : String ,
45+ options : Option < Vec < String > > ,
46+ } ,
47+ Git {
48+ name : String ,
49+ url : String ,
50+ commit : String ,
51+ options : Option < Vec < String > > ,
52+ } ,
53+ Path {
54+ name : String ,
55+ path : PathBuf ,
56+ options : Option < Vec < String > > ,
57+ } ,
4458}
4559
4660/// Represents the actual source code of a crate that we ran "cargo clippy" on
@@ -50,6 +64,7 @@ struct Crate {
5064 name : String ,
5165 // path to the extracted sources that clippy can check
5266 path : PathBuf ,
67+ options : Option < Vec < String > > ,
5368}
5469
5570/// A single warning that clippy issued while checking a `Crate`
@@ -81,7 +96,7 @@ impl CrateSource {
8196 /// copies a local folder
8297 fn download_and_extract ( & self ) -> Crate {
8398 match self {
84- CrateSource :: CratesIo { name, version } => {
99+ CrateSource :: CratesIo { name, version, options } => {
85100 let extract_dir = PathBuf :: from ( "target/lintcheck/crates" ) ;
86101 let krate_download_dir = PathBuf :: from ( "target/lintcheck/downloads" ) ;
87102
@@ -113,9 +128,15 @@ impl CrateSource {
113128 version : version. clone ( ) ,
114129 name : name. clone ( ) ,
115130 path : extract_dir. join ( format ! ( "{}-{}/" , name, version) ) ,
131+ options : options. clone ( ) ,
116132 }
117133 } ,
118- CrateSource :: Git { name, url, commit } => {
134+ CrateSource :: Git {
135+ name,
136+ url,
137+ commit,
138+ options,
139+ } => {
119140 let repo_path = {
120141 let mut repo_path = PathBuf :: from ( "target/lintcheck/crates" ) ;
121142 // add a -git suffix in case we have the same crate from crates.io and a git repo
@@ -152,9 +173,10 @@ impl CrateSource {
152173 version : commit. clone ( ) ,
153174 name : name. clone ( ) ,
154175 path : repo_path,
176+ options : options. clone ( ) ,
155177 }
156178 } ,
157- CrateSource :: Path { name, path } => {
179+ CrateSource :: Path { name, path, options } => {
158180 use fs_extra:: dir;
159181
160182 // simply copy the entire directory into our target dir
@@ -183,6 +205,7 @@ impl CrateSource {
183205 version : String :: from ( "local" ) ,
184206 name : name. clone ( ) ,
185207 path : crate_root,
208+ options : options. clone ( ) ,
186209 }
187210 } ,
188211 }
@@ -198,18 +221,21 @@ impl Crate {
198221
199222 let shared_target_dir = clippy_project_root ( ) . join ( "target/lintcheck/shared_target_dir/" ) ;
200223
224+ let mut args = vec ! [ "--" , "--message-format=json" , "--" , "--cap-lints=warn" ] ;
225+
226+ if let Some ( options) = & self . options {
227+ for opt in options {
228+ args. push ( opt) ;
229+ }
230+ } else {
231+ args. extend ( & [ "-Wclippy::pedantic" , "-Wclippy::cargo" ] )
232+ }
233+
201234 let all_output = std:: process:: Command :: new ( & cargo_clippy_path)
202235 . env ( "CARGO_TARGET_DIR" , shared_target_dir)
203236 // lint warnings will look like this:
204237 // src/cargo/ops/cargo_compile.rs:127:35: warning: usage of `FromIterator::from_iter`
205- . args ( & [
206- "--" ,
207- "--message-format=json" ,
208- "--" ,
209- "--cap-lints=warn" ,
210- "-Wclippy::pedantic" ,
211- "-Wclippy::cargo" ,
212- ] )
238+ . args ( & args)
213239 . current_dir ( & self . path )
214240 . output ( )
215241 . unwrap_or_else ( |error| {
@@ -257,10 +283,14 @@ fn filter_clippy_warnings(line: &str) -> bool {
257283
258284/// Builds clippy inside the repo to make sure we have a clippy executable we can use.
259285fn build_clippy ( ) {
260- Command :: new ( "cargo" )
286+ let output = Command :: new ( "cargo" )
261287 . arg ( "build" )
262288 . output ( )
263289 . expect ( "Failed to build clippy!" ) ;
290+ if !output. status . success ( ) {
291+ eprintln ! ( "Failed to compile Clippy" ) ;
292+ eprintln ! ( "stderr: {}" , String :: from_utf8_lossy( & output. stderr) )
293+ }
264294}
265295
266296/// Read a `toml` file and return a list of `CrateSources` that we want to check with clippy
@@ -289,6 +319,7 @@ fn read_crates(toml_path: Option<&str>) -> (String, Vec<CrateSource>) {
289319 crate_sources. push ( CrateSource :: Path {
290320 name : tk. name . clone ( ) ,
291321 path : PathBuf :: from ( path) ,
322+ options : tk. options . clone ( ) ,
292323 } ) ;
293324 }
294325
@@ -298,6 +329,7 @@ fn read_crates(toml_path: Option<&str>) -> (String, Vec<CrateSource>) {
298329 crate_sources. push ( CrateSource :: CratesIo {
299330 name : tk. name . clone ( ) ,
300331 version : ver. to_string ( ) ,
332+ options : tk. options . clone ( ) ,
301333 } ) ;
302334 } )
303335 }
@@ -307,6 +339,7 @@ fn read_crates(toml_path: Option<&str>) -> (String, Vec<CrateSource>) {
307339 name : tk. name . clone ( ) ,
308340 url : tk. git_url . clone ( ) . unwrap ( ) ,
309341 commit : tk. git_hash . clone ( ) . unwrap ( ) ,
342+ options : tk. options . clone ( ) ,
310343 } ) ;
311344 }
312345 // if we have a version as well as a git data OR only one git data, something is funky
@@ -373,12 +406,14 @@ fn gather_stats(clippy_warnings: &[ClippyWarning]) -> String {
373406
374407/// lintchecks `main()` function
375408pub fn run ( clap_config : & ArgMatches ) {
376- let cargo_clippy_path: PathBuf = PathBuf :: from ( "target/debug/cargo-clippy" ) ;
377-
378409 println ! ( "Compiling clippy..." ) ;
379410 build_clippy ( ) ;
380411 println ! ( "Done compiling" ) ;
381412
413+ let cargo_clippy_path: PathBuf = PathBuf :: from ( "target/debug/cargo-clippy" )
414+ . canonicalize ( )
415+ . expect ( "failed to canonicalize path to clippy binary" ) ;
416+
382417 // assert that clippy is found
383418 assert ! (
384419 cargo_clippy_path. is_file( ) ,
@@ -455,5 +490,6 @@ pub fn run(clap_config: &ArgMatches) {
455490 . for_each ( |( cratename, msg) | text. push_str ( & format ! ( "{}: '{}'" , cratename, msg) ) ) ;
456491
457492 let file = format ! ( "lintcheck-logs/{}_logs.txt" , filename) ;
493+ println ! ( "Writing logs to {}" , file) ;
458494 write ( file, text) . unwrap ( ) ;
459495}
0 commit comments