@@ -16,6 +16,7 @@ use test_utils::IS_RUSTC_TEST_SUITE;
1616use ui_test:: custom_flags:: Flag ;
1717use ui_test:: custom_flags:: edition:: Edition ;
1818use ui_test:: custom_flags:: rustfix:: RustfixMode ;
19+ use ui_test:: dependencies:: DependencyBuilder ;
1920use ui_test:: spanned:: Spanned ;
2021use ui_test:: status_emitter:: StatusEmitter ;
2122use ui_test:: { Args , CommandBuilder , Config , Match , error_on_output_conflict} ;
@@ -28,46 +29,26 @@ use std::path::{Path, PathBuf};
2829use std:: sync:: mpsc:: { Sender , channel} ;
2930use std:: { fs, iter, thread} ;
3031
31- // Test dependencies may need an `extern crate` here to ensure that they show up
32- // in the depinfo file (otherwise cargo thinks they are unused)
33- extern crate futures;
34- extern crate if_chain;
35- extern crate itertools;
36- extern crate parking_lot;
37- extern crate quote;
38- extern crate syn;
39- extern crate tokio;
40-
4132mod test_utils;
4233
43- /// All crates used in UI tests are listed here
44- static TEST_DEPENDENCIES : & [ & str ] = & [
45- "clippy_config" ,
46- "clippy_lints" ,
47- "clippy_utils" ,
48- "futures" ,
49- "if_chain" ,
50- "itertools" ,
51- "parking_lot" ,
52- "quote" ,
53- "regex" ,
54- "serde_derive" ,
55- "serde" ,
56- "syn" ,
57- "tokio" ,
58- ] ;
59-
60- /// Produces a string with an `--extern` flag for all UI test crate
61- /// dependencies.
34+ /// All crates used in internal UI tests are listed here.
35+ /// We directly re-use these crates from their normal clippy builds, so we don't have them
36+ /// in `clippy_test_devs`. That saves a lot of time but also means they don't work in a stage 1
37+ /// test in rustc bootstrap.
38+ static INTERNAL_TEST_DEPENDENCIES : & [ & str ] = & [ "clippy_config" , "clippy_lints" , "clippy_utils" ] ;
39+
40+ /// Produces a string with an `--extern` flag for all `INTERNAL_TEST_DEPENDENCIES`.
6241///
6342/// The dependency files are located by parsing the depinfo file for this test
6443/// module. This assumes the `-Z binary-dep-depinfo` flag is enabled. All test
6544/// dependencies must be added to Cargo.toml at the project root. Test
6645/// dependencies that are not *directly* used by this test module require an
6746/// `extern crate` declaration.
68- fn extern_flags ( ) -> Vec < String > {
47+ fn internal_extern_flags ( ) -> Vec < String > {
48+ let current_exe_path = env:: current_exe ( ) . unwrap ( ) ;
49+ let deps_path = current_exe_path. parent ( ) . unwrap ( ) ;
6950 let current_exe_depinfo = {
70- let mut path = env :: current_exe ( ) . unwrap ( ) ;
51+ let mut path = current_exe_path . clone ( ) ;
7152 path. set_extension ( "d" ) ;
7253 fs:: read_to_string ( path) . unwrap ( )
7354 } ;
@@ -89,15 +70,15 @@ fn extern_flags() -> Vec<String> {
8970 Some ( ( name, path_str) )
9071 } ;
9172 if let Some ( ( name, path) ) = parse_name_path ( )
92- && TEST_DEPENDENCIES . contains ( & name)
73+ && INTERNAL_TEST_DEPENDENCIES . contains ( & name)
9374 {
9475 // A dependency may be listed twice if it is available in sysroot,
9576 // and the sysroot dependencies are listed first. As of the writing,
9677 // this only seems to apply to if_chain.
9778 crates. insert ( name, path) ;
9879 }
9980 }
100- let not_found: Vec < & str > = TEST_DEPENDENCIES
81+ let not_found: Vec < & str > = INTERNAL_TEST_DEPENDENCIES
10182 . iter ( )
10283 . copied ( )
10384 . filter ( |n| !crates. contains_key ( n) )
@@ -112,6 +93,7 @@ fn extern_flags() -> Vec<String> {
11293 crates
11394 . into_iter ( )
11495 . map ( |( name, path) | format ! ( "--extern={name}={path}" ) )
96+ . chain ( [ format ! ( "-Ldependency={}" , deps_path. display( ) ) ] )
11597 . collect ( )
11698}
11799
@@ -120,7 +102,6 @@ const RUN_INTERNAL_TESTS: bool = cfg!(feature = "internal");
120102
121103struct TestContext {
122104 args : Args ,
123- extern_flags : Vec < String > ,
124105 diagnostic_collector : Option < DiagnosticCollector > ,
125106 collector_thread : Option < thread:: JoinHandle < ( ) > > ,
126107}
@@ -135,7 +116,6 @@ impl TestContext {
135116 . unzip ( ) ;
136117 Self {
137118 args,
138- extern_flags : extern_flags ( ) ,
139119 diagnostic_collector,
140120 collector_thread,
141121 }
@@ -159,6 +139,15 @@ impl TestContext {
159139 } ;
160140 let defaults = config. comment_defaults . base ( ) ;
161141 defaults. set_custom ( "edition" , Edition ( "2024" . into ( ) ) ) ;
142+ defaults. set_custom (
143+ "dependencies" ,
144+ DependencyBuilder {
145+ program : CommandBuilder :: cargo ( ) ,
146+ crate_manifest_path : Path :: new ( "clippy_test_deps" ) . join ( "Cargo.toml" ) ,
147+ build_std : None ,
148+ bless_lockfile : self . args . bless ,
149+ } ,
150+ ) ;
162151 defaults. exit_status = None . into ( ) ;
163152 if mandatory_annotations {
164153 defaults. require_annotations = Some ( Spanned :: dummy ( true ) ) . into ( ) ;
@@ -183,12 +172,10 @@ impl TestContext {
183172 "-Zui-testing" ,
184173 "-Zdeduplicate-diagnostics=no" ,
185174 "-Dwarnings" ,
186- & format ! ( "-Ldependency={}" , deps_path. display( ) ) ,
187175 ]
188176 . map ( OsString :: from) ,
189177 ) ;
190178
191- config. program . args . extend ( self . extern_flags . iter ( ) . map ( OsString :: from) ) ;
192179 // Prevent rustc from creating `rustc-ice-*` files the console output is enough.
193180 config. program . envs . push ( ( "RUSTC_ICE" . into ( ) , Some ( "0" . into ( ) ) ) ) ;
194181
@@ -228,6 +215,10 @@ fn run_internal_tests(cx: &TestContext) {
228215 return ;
229216 }
230217 let mut config = cx. base_config ( "ui-internal" , true ) ;
218+ config
219+ . program
220+ . args
221+ . extend ( internal_extern_flags ( ) . iter ( ) . map ( OsString :: from) ) ;
231222 config. bless_command = Some ( "cargo uitest --features internal -- -- --bless" . into ( ) ) ;
232223
233224 ui_test:: run_tests_generic (
0 commit comments