@@ -32,15 +32,29 @@ struct TomlCrate {
32
32
git_url : Option < String > ,
33
33
git_hash : Option < String > ,
34
34
path : Option < String > ,
35
+ options : Option < Vec < String > > ,
35
36
}
36
37
37
38
/// Represents an archive we download from crates.io, or a git repo, or a local repo/folder
38
39
/// Once processed (downloaded/extracted/cloned/copied...), this will be translated into a `Crate`
39
40
#[ derive( Debug , Serialize , Deserialize , Eq , Hash , PartialEq ) ]
40
41
enum 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
+ } ,
44
58
}
45
59
46
60
/// Represents the actual source code of a crate that we ran "cargo clippy" on
@@ -50,6 +64,7 @@ struct Crate {
50
64
name : String ,
51
65
// path to the extracted sources that clippy can check
52
66
path : PathBuf ,
67
+ options : Option < Vec < String > > ,
53
68
}
54
69
55
70
/// A single warning that clippy issued while checking a `Crate`
@@ -81,7 +96,7 @@ impl CrateSource {
81
96
/// copies a local folder
82
97
fn download_and_extract ( & self ) -> Crate {
83
98
match self {
84
- CrateSource :: CratesIo { name, version } => {
99
+ CrateSource :: CratesIo { name, version, options } => {
85
100
let extract_dir = PathBuf :: from ( "target/lintcheck/crates" ) ;
86
101
let krate_download_dir = PathBuf :: from ( "target/lintcheck/downloads" ) ;
87
102
@@ -113,9 +128,15 @@ impl CrateSource {
113
128
version : version. clone ( ) ,
114
129
name : name. clone ( ) ,
115
130
path : extract_dir. join ( format ! ( "{}-{}/" , name, version) ) ,
131
+ options : options. clone ( ) ,
116
132
}
117
133
} ,
118
- CrateSource :: Git { name, url, commit } => {
134
+ CrateSource :: Git {
135
+ name,
136
+ url,
137
+ commit,
138
+ options,
139
+ } => {
119
140
let repo_path = {
120
141
let mut repo_path = PathBuf :: from ( "target/lintcheck/crates" ) ;
121
142
// add a -git suffix in case we have the same crate from crates.io and a git repo
@@ -152,9 +173,10 @@ impl CrateSource {
152
173
version : commit. clone ( ) ,
153
174
name : name. clone ( ) ,
154
175
path : repo_path,
176
+ options : options. clone ( ) ,
155
177
}
156
178
} ,
157
- CrateSource :: Path { name, path } => {
179
+ CrateSource :: Path { name, path, options } => {
158
180
use fs_extra:: dir;
159
181
160
182
// simply copy the entire directory into our target dir
@@ -183,6 +205,7 @@ impl CrateSource {
183
205
version : String :: from ( "local" ) ,
184
206
name : name. clone ( ) ,
185
207
path : crate_root,
208
+ options : options. clone ( ) ,
186
209
}
187
210
} ,
188
211
}
@@ -198,18 +221,21 @@ impl Crate {
198
221
199
222
let shared_target_dir = clippy_project_root ( ) . join ( "target/lintcheck/shared_target_dir/" ) ;
200
223
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
+
201
234
let all_output = std:: process:: Command :: new ( & cargo_clippy_path)
202
235
. env ( "CARGO_TARGET_DIR" , shared_target_dir)
203
236
// lint warnings will look like this:
204
237
// 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)
213
239
. current_dir ( & self . path )
214
240
. output ( )
215
241
. unwrap_or_else ( |error| {
@@ -257,10 +283,14 @@ fn filter_clippy_warnings(line: &str) -> bool {
257
283
258
284
/// Builds clippy inside the repo to make sure we have a clippy executable we can use.
259
285
fn build_clippy ( ) {
260
- Command :: new ( "cargo" )
286
+ let output = Command :: new ( "cargo" )
261
287
. arg ( "build" )
262
288
. output ( )
263
289
. 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
+ }
264
294
}
265
295
266
296
/// 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>) {
289
319
crate_sources. push ( CrateSource :: Path {
290
320
name : tk. name . clone ( ) ,
291
321
path : PathBuf :: from ( path) ,
322
+ options : tk. options . clone ( ) ,
292
323
} ) ;
293
324
}
294
325
@@ -298,6 +329,7 @@ fn read_crates(toml_path: Option<&str>) -> (String, Vec<CrateSource>) {
298
329
crate_sources. push ( CrateSource :: CratesIo {
299
330
name : tk. name . clone ( ) ,
300
331
version : ver. to_string ( ) ,
332
+ options : tk. options . clone ( ) ,
301
333
} ) ;
302
334
} )
303
335
}
@@ -307,6 +339,7 @@ fn read_crates(toml_path: Option<&str>) -> (String, Vec<CrateSource>) {
307
339
name : tk. name . clone ( ) ,
308
340
url : tk. git_url . clone ( ) . unwrap ( ) ,
309
341
commit : tk. git_hash . clone ( ) . unwrap ( ) ,
342
+ options : tk. options . clone ( ) ,
310
343
} ) ;
311
344
}
312
345
// 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 {
373
406
374
407
/// lintchecks `main()` function
375
408
pub fn run ( clap_config : & ArgMatches ) {
376
- let cargo_clippy_path: PathBuf = PathBuf :: from ( "target/debug/cargo-clippy" ) ;
377
-
378
409
println ! ( "Compiling clippy..." ) ;
379
410
build_clippy ( ) ;
380
411
println ! ( "Done compiling" ) ;
381
412
413
+ let cargo_clippy_path: PathBuf = PathBuf :: from ( "target/debug/cargo-clippy" )
414
+ . canonicalize ( )
415
+ . expect ( "failed to canonicalize path to clippy binary" ) ;
416
+
382
417
// assert that clippy is found
383
418
assert ! (
384
419
cargo_clippy_path. is_file( ) ,
@@ -455,5 +490,6 @@ pub fn run(clap_config: &ArgMatches) {
455
490
. for_each ( |( cratename, msg) | text. push_str ( & format ! ( "{}: '{}'" , cratename, msg) ) ) ;
456
491
457
492
let file = format ! ( "lintcheck-logs/{}_logs.txt" , filename) ;
493
+ println ! ( "Writing logs to {}" , file) ;
458
494
write ( file, text) . unwrap ( ) ;
459
495
}
0 commit comments