1- use crate :: utils:: { cargo_clippy_path, cargo_cmd, run_success} ;
2- use std:: fs;
3- use std:: process:: { self , Command } ;
1+ use crate :: utils:: { ErrAction , cargo_cmd, expect_action, run_success} ;
2+ use std:: path:: PathBuf ;
3+ use std:: process:: Command ;
4+ use std:: { env, fs} ;
45
56pub fn run < ' a > ( path : & str , edition : & str , args : impl Iterator < Item = & ' a String > ) {
6- let is_file = match fs:: metadata ( path) {
7- Ok ( metadata) => metadata. is_file ( ) ,
8- Err ( e) => {
9- eprintln ! ( "Failed to read {path}: {e:?}" ) ;
10- process:: exit ( 1 ) ;
11- } ,
12- } ;
13-
7+ let is_file = expect_action ( fs:: metadata ( path) , ErrAction :: Read , path) . is_file ( ) ;
148 if is_file {
159 run_success (
1610 "cargo run" ,
@@ -25,10 +19,29 @@ pub fn run<'a>(path: &str, edition: &str, args: impl Iterator<Item = &'a String>
2519 . env ( "RUSTC_ICE" , "0" ) ,
2620 ) ;
2721 } else {
28- run_success ( "cargo build" , cargo_cmd ( ) . arg ( "build" ) ) ;
22+ // FIXME: This should be using `cargo run`, but can't since cargo loads the config from the
23+ // current directory. Either we need a way to change the current directory between building
24+ // running `cargo-clippy` as this currently does by running in two steps, or we need a way
25+ // to change where cargo loads the config.
26+ // See https://github.com/rust-lang/cargo/issues/9769
27+
28+ run_success ( "cargo build" , cargo_cmd ( ) . args ( [ "build" , "--bin" , "cargo-clippy" ] ) ) ;
29+
30+ let mut exe = match env:: current_exe ( ) {
31+ Ok ( mut exe) => {
32+ exe. pop ( ) ;
33+ exe
34+ } ,
35+ Err ( _) => PathBuf :: from ( "target/debug" ) ,
36+ } ;
37+ #[ cfg( windows) ]
38+ exe. push ( "cargo-clippy.exe" ) ;
39+ #[ cfg( not( windows) ) ]
40+ exe. push ( "cargo-clippy" ) ;
41+
2942 run_success (
30- "cargo clippy " ,
31- Command :: new ( cargo_clippy_path ( ) )
43+ "cargo run " ,
44+ Command :: new ( exe )
3245 . arg ( "clippy" )
3346 . args ( args)
3447 // Prevent rustc from creating `rustc-ice-*` files the console output is enough.
0 commit comments