File tree Expand file tree Collapse file tree 4 files changed +36
-27
lines changed
crates/cargo-test-support/src Expand file tree Collapse file tree 4 files changed +36
-27
lines changed Original file line number Diff line number Diff line change @@ -523,29 +523,6 @@ pub fn cargo_exe() -> PathBuf {
523
523
snapbox:: cmd:: cargo_bin ( "cargo" )
524
524
}
525
525
526
- /// A wrapper around `rustc` instead of calling `clippy`.
527
- pub fn wrapped_clippy_driver ( ) -> PathBuf {
528
- let clippy_driver = project ( )
529
- . at ( paths:: global_root ( ) . join ( "clippy-driver" ) )
530
- . file ( "Cargo.toml" , & basic_manifest ( "clippy-driver" , "0.0.1" ) )
531
- . file (
532
- "src/main.rs" ,
533
- r#"
534
- fn main() {
535
- let mut args = std::env::args_os();
536
- let _me = args.next().unwrap();
537
- let rustc = args.next().unwrap();
538
- let status = std::process::Command::new(rustc).args(args).status().unwrap();
539
- std::process::exit(status.code().unwrap_or(1));
540
- }
541
- "# ,
542
- )
543
- . build ( ) ;
544
- clippy_driver. cargo ( "build" ) . run ( ) ;
545
-
546
- clippy_driver. bin ( "clippy-driver" )
547
- }
548
-
549
526
/// This is the raw output from the process.
550
527
///
551
528
/// This is similar to `std::process::Output`, however the `status` is
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ use std::sync::OnceLock;
7
7
8
8
static ECHO_WRAPPER : OnceLock < Mutex < Option < PathBuf > > > = OnceLock :: new ( ) ;
9
9
static ECHO : OnceLock < Mutex < Option < PathBuf > > > = OnceLock :: new ( ) ;
10
+ static CLIPPY_DRIVER : OnceLock < Mutex < Option < PathBuf > > > = OnceLock :: new ( ) ;
10
11
11
12
/// Returns the path to an executable that works as a wrapper around rustc.
12
13
///
@@ -107,3 +108,34 @@ pub fn echo_subcommand() -> Project {
107
108
p. cargo ( "build" ) . run ( ) ;
108
109
p
109
110
}
111
+
112
+ /// A wrapper around `rustc` instead of calling `clippy`.
113
+ pub fn wrapped_clippy_driver ( ) -> PathBuf {
114
+ let mut lock = CLIPPY_DRIVER
115
+ . get_or_init ( || Default :: default ( ) )
116
+ . lock ( )
117
+ . unwrap ( ) ;
118
+ if let Some ( path) = & * lock {
119
+ return path. clone ( ) ;
120
+ }
121
+ let clippy_driver = project ( )
122
+ . at ( paths:: global_root ( ) . join ( "clippy-driver" ) )
123
+ . file ( "Cargo.toml" , & basic_manifest ( "clippy-driver" , "0.0.1" ) )
124
+ . file (
125
+ "src/main.rs" ,
126
+ r#"
127
+ fn main() {
128
+ let mut args = std::env::args_os();
129
+ let _me = args.next().unwrap();
130
+ let rustc = args.next().unwrap();
131
+ let status = std::process::Command::new(rustc).args(args).status().unwrap();
132
+ std::process::exit(status.code().unwrap_or(1));
133
+ }
134
+ "# ,
135
+ )
136
+ . build ( ) ;
137
+ clippy_driver. cargo ( "build" ) . run ( ) ;
138
+ let path = clippy_driver. bin ( "clippy-driver" ) ;
139
+ * lock = Some ( path. clone ( ) ) ;
140
+ path
141
+ }
Original file line number Diff line number Diff line change @@ -6,8 +6,8 @@ use crate::messages::raw_rustc_output;
6
6
use cargo_test_support:: install:: exe;
7
7
use cargo_test_support:: paths:: CargoPathExt ;
8
8
use cargo_test_support:: registry:: Package ;
9
+ use cargo_test_support:: tools;
9
10
use cargo_test_support:: { basic_bin_manifest, basic_manifest, git, project} ;
10
- use cargo_test_support:: { tools, wrapped_clippy_driver} ;
11
11
12
12
#[ cargo_test]
13
13
fn check_success ( ) {
@@ -1432,7 +1432,7 @@ fn check_fixable_warning_for_clippy() {
1432
1432
1433
1433
foo. cargo ( "check" )
1434
1434
// We can't use `clippy` so we use a `rustc` workspace wrapper instead
1435
- . env ( "RUSTC_WORKSPACE_WRAPPER" , wrapped_clippy_driver ( ) )
1435
+ . env ( "RUSTC_WORKSPACE_WRAPPER" , tools :: wrapped_clippy_driver ( ) )
1436
1436
. with_stderr_contains ( "[..] (run `cargo clippy --fix --lib -p foo` to apply 1 suggestion)" )
1437
1437
. run ( ) ;
1438
1438
}
Original file line number Diff line number Diff line change @@ -5,8 +5,8 @@ use cargo_test_support::compare::assert_match_exact;
5
5
use cargo_test_support:: git:: { self , init} ;
6
6
use cargo_test_support:: paths:: { self , CargoPathExt } ;
7
7
use cargo_test_support:: registry:: { Dependency , Package } ;
8
+ use cargo_test_support:: tools;
8
9
use cargo_test_support:: { basic_manifest, is_nightly, project, Project } ;
9
- use cargo_test_support:: { tools, wrapped_clippy_driver} ;
10
10
11
11
#[ cargo_test]
12
12
fn do_not_fix_broken_builds ( ) {
@@ -193,7 +193,7 @@ fn broken_clippy_fixes_backed_out() {
193
193
. env ( "__CARGO_FIX_YOLO" , "1" )
194
194
. env ( "RUSTC" , p. root ( ) . join ( "foo/target/debug/foo" ) )
195
195
// We can't use `clippy` so we use a `rustc` workspace wrapper instead
196
- . env ( "RUSTC_WORKSPACE_WRAPPER" , wrapped_clippy_driver ( ) )
196
+ . env ( "RUSTC_WORKSPACE_WRAPPER" , tools :: wrapped_clippy_driver ( ) )
197
197
. with_stderr_contains (
198
198
"warning: failed to automatically apply fixes suggested by rustc \
199
199
to crate `bar`\n \
You can’t perform that action at this time.
0 commit comments