1
1
// error-pattern:yummy
2
2
#![ feature( box_syntax) ]
3
3
#![ feature( rustc_private) ]
4
-
5
4
#![ allow( unknown_lints, missing_docs_in_private_items) ]
6
5
7
6
extern crate clippy_lints;
@@ -12,9 +11,9 @@ extern crate rustc_errors;
12
11
extern crate rustc_plugin;
13
12
extern crate syntax;
14
13
15
- use rustc_driver:: { driver, CompilerCalls , RustcDefaultCalls , Compilation } ;
16
- use rustc:: session:: { config, Session , CompileIncomplete } ;
17
- use rustc:: session:: config:: { Input , ErrorOutputType } ;
14
+ use rustc_driver:: { driver, Compilation , CompilerCalls , RustcDefaultCalls } ;
15
+ use rustc:: session:: { config, CompileIncomplete , Session } ;
16
+ use rustc:: session:: config:: { ErrorOutputType , Input } ;
18
17
use std:: collections:: HashMap ;
19
18
use std:: path:: PathBuf ;
20
19
use std:: process:: { self , Command } ;
@@ -152,6 +151,7 @@ Common options:
152
151
-h, --help Print this message
153
152
--features Features to compile for the package
154
153
-V, --version Print version info and exit
154
+ --all Run over all packages in the current workspace
155
155
156
156
Other options are the same as `cargo rustc`.
157
157
@@ -199,9 +199,9 @@ pub fn main() {
199
199
if let Some ( "clippy" ) = std:: env:: args ( ) . nth ( 1 ) . as_ref ( ) . map ( AsRef :: as_ref) {
200
200
// this arm is executed on the initial call to `cargo clippy`
201
201
202
- let manifest_path_arg = std:: env:: args ( ) . skip ( 2 ) . find ( |val| {
203
- val . starts_with ( "--manifest-path=" )
204
- } ) ;
202
+ let manifest_path_arg = std:: env:: args ( )
203
+ . skip ( 2 )
204
+ . find ( |val| val . starts_with ( "--manifest-path=" ) ) ;
205
205
206
206
let mut metadata =
207
207
if let Ok ( metadata) = cargo_metadata:: metadata ( manifest_path_arg. as_ref ( ) . map ( AsRef :: as_ref) ) {
@@ -217,74 +217,86 @@ pub fn main() {
217
217
. expect ( "manifest path could not be canonicalized" )
218
218
} ) ;
219
219
220
- let package_index = {
221
- if let Some ( manifest_path) = manifest_path {
222
- metadata. packages . iter ( ) . position ( |package| {
223
- let package_manifest_path = Path :: new ( & package. manifest_path ) . canonicalize ( ) . expect (
224
- "package manifest path could not be canonicalized" ,
225
- ) ;
226
- package_manifest_path == manifest_path
227
- } )
228
- } else {
229
- let package_manifest_paths: HashMap < _ , _ > = metadata
230
- . packages
231
- . iter ( )
232
- . enumerate ( )
233
- . map ( |( i, package) | {
220
+ let packages = if std:: env:: args ( ) . any ( |a| a == "--all" ) {
221
+ metadata. packages
222
+ } else {
223
+ let package_index = {
224
+ if let Some ( manifest_path) = manifest_path {
225
+ metadata. packages . iter ( ) . position ( |package| {
234
226
let package_manifest_path = Path :: new ( & package. manifest_path )
235
- . parent ( )
236
- . expect ( "could not find parent directory of package manifest" )
237
227
. canonicalize ( )
238
- . expect ( "package directory cannot be canonicalized" ) ;
239
- ( package_manifest_path, i )
228
+ . expect ( "package manifest path could not be canonicalized" ) ;
229
+ package_manifest_path == manifest_path
240
230
} )
241
- . collect ( ) ;
242
-
243
- let current_dir = std:: env:: current_dir ( )
244
- . expect ( "could not read current directory" )
245
- . canonicalize ( )
246
- . expect ( "current directory cannot be canonicalized" ) ;
247
-
248
- let mut current_path: & Path = & current_dir;
249
-
250
- // This gets the most-recent parent (the one that takes the fewest `cd ..`s to
251
- // reach).
252
- loop {
253
- if let Some ( & package_index) = package_manifest_paths. get ( current_path) {
254
- break Some ( package_index) ;
255
- } else {
256
- // We'll never reach the filesystem root, because to get to this point in the
257
- // code
258
- // the call to `cargo_metadata::metadata` must have succeeded. So it's okay to
259
- // unwrap the current path's parent.
260
- current_path = current_path. parent ( ) . unwrap_or_else ( || {
261
- panic ! ( "could not find parent of path {}" , current_path. display( ) )
262
- } ) ;
231
+ } else {
232
+ let package_manifest_paths: HashMap < _ , _ > = metadata
233
+ . packages
234
+ . iter ( )
235
+ . enumerate ( )
236
+ . map ( |( i, package) | {
237
+ let package_manifest_path = Path :: new ( & package. manifest_path )
238
+ . parent ( )
239
+ . expect ( "could not find parent directory of package manifest" )
240
+ . canonicalize ( )
241
+ . expect ( "package directory cannot be canonicalized" ) ;
242
+ ( package_manifest_path, i)
243
+ } )
244
+ . collect ( ) ;
245
+
246
+ let current_dir = std:: env:: current_dir ( )
247
+ . expect ( "could not read current directory" )
248
+ . canonicalize ( )
249
+ . expect ( "current directory cannot be canonicalized" ) ;
250
+
251
+ let mut current_path: & Path = & current_dir;
252
+
253
+ // This gets the most-recent parent (the one that takes the fewest `cd ..`s to
254
+ // reach).
255
+ loop {
256
+ if let Some ( & package_index) = package_manifest_paths. get ( current_path) {
257
+ break Some ( package_index) ;
258
+ } else {
259
+ // We'll never reach the filesystem root, because to get to this point in the
260
+ // code
261
+ // the call to `cargo_metadata::metadata` must have succeeded. So it's okay to
262
+ // unwrap the current path's parent.
263
+ current_path = current_path
264
+ . parent ( )
265
+ . unwrap_or_else ( || panic ! ( "could not find parent of path {}" , current_path. display( ) ) ) ;
266
+ }
263
267
}
264
268
}
265
- }
266
- } . expect ( "could not find matching package" ) ;
267
-
268
- let package = metadata. packages . remove ( package_index) ;
269
- for target in package. targets {
270
- let args = std:: env:: args ( ) . skip ( 2 ) ;
271
- if let Some ( first) = target. kind . get ( 0 ) {
272
- if target. kind . len ( ) > 1 || first. ends_with ( "lib" ) {
273
- if let Err ( code) = process ( std:: iter:: once ( "--lib" . to_owned ( ) ) . chain ( args) ) {
274
- std:: process:: exit ( code) ;
275
- }
276
- } else if [ "bin" , "example" , "test" , "bench" ] . contains ( & & * * first) {
277
- if let Err ( code) = process (
278
- vec ! [ format!( "--{}" , first) , target. name]
279
- . into_iter ( )
280
- . chain ( args) ,
281
- )
282
- {
283
- std:: process:: exit ( code) ;
269
+ } . expect ( "could not find matching package" ) ;
270
+
271
+ vec ! [ metadata. packages. remove( package_index) ]
272
+ } ;
273
+
274
+ for package in packages {
275
+ let manifest_path = package. manifest_path ;
276
+
277
+ for target in package. targets {
278
+ let args = std:: env:: args ( )
279
+ . skip ( 2 )
280
+ . filter ( |a| a != "--all" && !a. starts_with ( "--manifest-path=" ) ) ;
281
+
282
+ let args = std:: iter:: once ( format ! ( "--manifest-path={}" , manifest_path) ) . chain ( args) ;
283
+ if let Some ( first) = target. kind . get ( 0 ) {
284
+ if target. kind . len ( ) > 1 || first. ends_with ( "lib" ) {
285
+ if let Err ( code) = process ( std:: iter:: once ( "--lib" . to_owned ( ) ) . chain ( args) ) {
286
+ std:: process:: exit ( code) ;
287
+ }
288
+ } else if [ "bin" , "example" , "test" , "bench" ] . contains ( & & * * first) {
289
+ if let Err ( code) = process (
290
+ vec ! [ format!( "--{}" , first) , target. name]
291
+ . into_iter ( )
292
+ . chain ( args) ,
293
+ ) {
294
+ std:: process:: exit ( code) ;
295
+ }
284
296
}
297
+ } else {
298
+ panic ! ( "badly formatted cargo metadata: target::kind is an empty array" ) ;
285
299
}
286
- } else {
287
- panic ! ( "badly formatted cargo metadata: target::kind is an empty array" ) ;
288
300
}
289
301
}
290
302
} else {
0 commit comments