@@ -16,6 +16,7 @@ use test_utils::IS_RUSTC_TEST_SUITE;
16
16
use ui_test:: custom_flags:: Flag ;
17
17
use ui_test:: custom_flags:: edition:: Edition ;
18
18
use ui_test:: custom_flags:: rustfix:: RustfixMode ;
19
+ use ui_test:: dependencies:: DependencyBuilder ;
19
20
use ui_test:: spanned:: Spanned ;
20
21
use ui_test:: status_emitter:: StatusEmitter ;
21
22
use ui_test:: { Args , CommandBuilder , Config , Match , error_on_output_conflict} ;
@@ -28,46 +29,26 @@ use std::path::{Path, PathBuf};
28
29
use std:: sync:: mpsc:: { Sender , channel} ;
29
30
use std:: { fs, iter, thread} ;
30
31
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
-
41
32
mod test_utils;
42
33
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`.
62
41
///
63
42
/// The dependency files are located by parsing the depinfo file for this test
64
43
/// module. This assumes the `-Z binary-dep-depinfo` flag is enabled. All test
65
44
/// dependencies must be added to Cargo.toml at the project root. Test
66
45
/// dependencies that are not *directly* used by this test module require an
67
46
/// `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 ( ) ;
69
50
let current_exe_depinfo = {
70
- let mut path = env :: current_exe ( ) . unwrap ( ) ;
51
+ let mut path = current_exe_path . clone ( ) ;
71
52
path. set_extension ( "d" ) ;
72
53
fs:: read_to_string ( path) . unwrap ( )
73
54
} ;
@@ -89,15 +70,15 @@ fn extern_flags() -> Vec<String> {
89
70
Some ( ( name, path_str) )
90
71
} ;
91
72
if let Some ( ( name, path) ) = parse_name_path ( )
92
- && TEST_DEPENDENCIES . contains ( & name)
73
+ && INTERNAL_TEST_DEPENDENCIES . contains ( & name)
93
74
{
94
75
// A dependency may be listed twice if it is available in sysroot,
95
76
// and the sysroot dependencies are listed first. As of the writing,
96
77
// this only seems to apply to if_chain.
97
78
crates. insert ( name, path) ;
98
79
}
99
80
}
100
- let not_found: Vec < & str > = TEST_DEPENDENCIES
81
+ let not_found: Vec < & str > = INTERNAL_TEST_DEPENDENCIES
101
82
. iter ( )
102
83
. copied ( )
103
84
. filter ( |n| !crates. contains_key ( n) )
@@ -112,6 +93,7 @@ fn extern_flags() -> Vec<String> {
112
93
crates
113
94
. into_iter ( )
114
95
. map ( |( name, path) | format ! ( "--extern={name}={path}" ) )
96
+ . chain ( [ format ! ( "-Ldependency={}" , deps_path. display( ) ) ] )
115
97
. collect ( )
116
98
}
117
99
@@ -120,7 +102,6 @@ const RUN_INTERNAL_TESTS: bool = cfg!(feature = "internal");
120
102
121
103
struct TestContext {
122
104
args : Args ,
123
- extern_flags : Vec < String > ,
124
105
diagnostic_collector : Option < DiagnosticCollector > ,
125
106
collector_thread : Option < thread:: JoinHandle < ( ) > > ,
126
107
}
@@ -135,7 +116,6 @@ impl TestContext {
135
116
. unzip ( ) ;
136
117
Self {
137
118
args,
138
- extern_flags : extern_flags ( ) ,
139
119
diagnostic_collector,
140
120
collector_thread,
141
121
}
@@ -159,6 +139,15 @@ impl TestContext {
159
139
} ;
160
140
let defaults = config. comment_defaults . base ( ) ;
161
141
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
+ ) ;
162
151
defaults. exit_status = None . into ( ) ;
163
152
if mandatory_annotations {
164
153
defaults. require_annotations = Some ( Spanned :: dummy ( true ) ) . into ( ) ;
@@ -183,12 +172,10 @@ impl TestContext {
183
172
"-Zui-testing" ,
184
173
"-Zdeduplicate-diagnostics=no" ,
185
174
"-Dwarnings" ,
186
- & format ! ( "-Ldependency={}" , deps_path. display( ) ) ,
187
175
]
188
176
. map ( OsString :: from) ,
189
177
) ;
190
178
191
- config. program . args . extend ( self . extern_flags . iter ( ) . map ( OsString :: from) ) ;
192
179
// Prevent rustc from creating `rustc-ice-*` files the console output is enough.
193
180
config. program . envs . push ( ( "RUSTC_ICE" . into ( ) , Some ( "0" . into ( ) ) ) ) ;
194
181
@@ -228,6 +215,10 @@ fn run_internal_tests(cx: &TestContext) {
228
215
return ;
229
216
}
230
217
let mut config = cx. base_config ( "ui-internal" , true ) ;
218
+ config
219
+ . program
220
+ . args
221
+ . extend ( internal_extern_flags ( ) . iter ( ) . map ( OsString :: from) ) ;
231
222
config. bless_command = Some ( "cargo uitest --features internal -- -- --bless" . into ( ) ) ;
232
223
233
224
ui_test:: run_tests_generic (
0 commit comments