@@ -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:: { Args , CommandBuilder , Config , Match , error_on_output_conflict} ;
21
22
@@ -27,46 +28,26 @@ use std::path::{Path, PathBuf};
27
28
use std:: sync:: mpsc:: { Sender , channel} ;
28
29
use std:: { fs, iter, thread} ;
29
30
30
- // Test dependencies may need an `extern crate` here to ensure that they show up
31
- // in the depinfo file (otherwise cargo thinks they are unused)
32
- extern crate futures;
33
- extern crate if_chain;
34
- extern crate itertools;
35
- extern crate parking_lot;
36
- extern crate quote;
37
- extern crate syn;
38
- extern crate tokio;
39
-
40
31
mod test_utils;
41
32
42
- /// All crates used in UI tests are listed here
43
- static TEST_DEPENDENCIES : & [ & str ] = & [
44
- "clippy_config" ,
45
- "clippy_lints" ,
46
- "clippy_utils" ,
47
- "futures" ,
48
- "if_chain" ,
49
- "itertools" ,
50
- "parking_lot" ,
51
- "quote" ,
52
- "regex" ,
53
- "serde_derive" ,
54
- "serde" ,
55
- "syn" ,
56
- "tokio" ,
57
- ] ;
58
-
59
- /// Produces a string with an `--extern` flag for all UI test crate
60
- /// dependencies.
33
+ /// All crates used in internal UI tests are listed here.
34
+ /// We directly re-use these crates from their normal clippy builds, so we don't have them
35
+ /// in `clippy_test_devs`. That saves a lot of time but also means they don't work in a stage 1
36
+ /// test in rustc bootstrap.
37
+ static INTERNAL_TEST_DEPENDENCIES : & [ & str ] = & [ "clippy_config" , "clippy_lints" , "clippy_utils" ] ;
38
+
39
+ /// Produces a string with an `--extern` flag for all `INTERNAL_TEST_DEPENDENCIES`.
61
40
///
62
41
/// The dependency files are located by parsing the depinfo file for this test
63
42
/// module. This assumes the `-Z binary-dep-depinfo` flag is enabled. All test
64
43
/// dependencies must be added to Cargo.toml at the project root. Test
65
44
/// dependencies that are not *directly* used by this test module require an
66
45
/// `extern crate` declaration.
67
- fn extern_flags ( ) -> Vec < String > {
46
+ fn internal_extern_flags ( ) -> Vec < String > {
47
+ let current_exe_path = env:: current_exe ( ) . unwrap ( ) ;
48
+ let deps_path = current_exe_path. parent ( ) . unwrap ( ) ;
68
49
let current_exe_depinfo = {
69
- let mut path = env :: current_exe ( ) . unwrap ( ) ;
50
+ let mut path = current_exe_path . clone ( ) ;
70
51
path. set_extension ( "d" ) ;
71
52
fs:: read_to_string ( path) . unwrap ( )
72
53
} ;
@@ -88,15 +69,15 @@ fn extern_flags() -> Vec<String> {
88
69
Some ( ( name, path_str) )
89
70
} ;
90
71
if let Some ( ( name, path) ) = parse_name_path ( )
91
- && TEST_DEPENDENCIES . contains ( & name)
72
+ && INTERNAL_TEST_DEPENDENCIES . contains ( & name)
92
73
{
93
74
// A dependency may be listed twice if it is available in sysroot,
94
75
// and the sysroot dependencies are listed first. As of the writing,
95
76
// this only seems to apply to if_chain.
96
77
crates. insert ( name, path) ;
97
78
}
98
79
}
99
- let not_found: Vec < & str > = TEST_DEPENDENCIES
80
+ let not_found: Vec < & str > = INTERNAL_TEST_DEPENDENCIES
100
81
. iter ( )
101
82
. copied ( )
102
83
. filter ( |n| !crates. contains_key ( n) )
@@ -111,6 +92,7 @@ fn extern_flags() -> Vec<String> {
111
92
crates
112
93
. into_iter ( )
113
94
. map ( |( name, path) | format ! ( "--extern={name}={path}" ) )
95
+ . chain ( [ format ! ( "-Ldependency={}" , deps_path. display( ) ) ] )
114
96
. collect ( )
115
97
}
116
98
@@ -119,7 +101,6 @@ const RUN_INTERNAL_TESTS: bool = cfg!(feature = "internal");
119
101
120
102
struct TestContext {
121
103
args : Args ,
122
- extern_flags : Vec < String > ,
123
104
diagnostic_collector : Option < DiagnosticCollector > ,
124
105
collector_thread : Option < thread:: JoinHandle < ( ) > > ,
125
106
}
@@ -134,7 +115,6 @@ impl TestContext {
134
115
. unzip ( ) ;
135
116
Self {
136
117
args,
137
- extern_flags : extern_flags ( ) ,
138
118
diagnostic_collector,
139
119
collector_thread,
140
120
}
@@ -158,6 +138,15 @@ impl TestContext {
158
138
} ;
159
139
let defaults = config. comment_defaults . base ( ) ;
160
140
defaults. set_custom ( "edition" , Edition ( "2024" . into ( ) ) ) ;
141
+ defaults. set_custom (
142
+ "dependencies" ,
143
+ DependencyBuilder {
144
+ program : CommandBuilder :: cargo ( ) ,
145
+ crate_manifest_path : Path :: new ( "clippy_test_deps" ) . join ( "Cargo.toml" ) ,
146
+ build_std : None ,
147
+ bless_lockfile : self . args . bless ,
148
+ } ,
149
+ ) ;
161
150
defaults. exit_status = None . into ( ) ;
162
151
if mandatory_annotations {
163
152
defaults. require_annotations = Some ( Spanned :: dummy ( true ) ) . into ( ) ;
@@ -182,12 +171,10 @@ impl TestContext {
182
171
"-Zui-testing" ,
183
172
"-Zdeduplicate-diagnostics=no" ,
184
173
"-Dwarnings" ,
185
- & format ! ( "-Ldependency={}" , deps_path. display( ) ) ,
186
174
]
187
175
. map ( OsString :: from) ,
188
176
) ;
189
177
190
- config. program . args . extend ( self . extern_flags . iter ( ) . map ( OsString :: from) ) ;
191
178
// Prevent rustc from creating `rustc-ice-*` files the console output is enough.
192
179
config. program . envs . push ( ( "RUSTC_ICE" . into ( ) , Some ( "0" . into ( ) ) ) ) ;
193
180
@@ -227,6 +214,10 @@ fn run_internal_tests(cx: &TestContext) {
227
214
return ;
228
215
}
229
216
let mut config = cx. base_config ( "ui-internal" , true ) ;
217
+ config
218
+ . program
219
+ . args
220
+ . extend ( internal_extern_flags ( ) . iter ( ) . map ( OsString :: from) ) ;
230
221
config. bless_command = Some ( "cargo uitest --features internal -- -- --bless" . into ( ) ) ;
231
222
232
223
ui_test:: run_tests_generic (
0 commit comments