Skip to content

Commit 8e4b544

Browse files
use ui_test dependency builder for test dependencies (#14883)
changelog: none This tries to make progress on rust-lang/rust#78717 by using the ui_test dependency handling instead of linking in the dependencies of clippy itself with the tests. This partially reverts #11045. However, we still use the old style of dealing with dependencies for clippy's own crates and the "internal" tests, as otherwise those would get rebuilt which takes too long.
2 parents ebdbd7c + 5ff1a41 commit 8e4b544

File tree

4 files changed

+47
-46
lines changed

4 files changed

+47
-46
lines changed

Cargo.toml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ anstream = "0.6.18"
3434

3535
[dev-dependencies]
3636
cargo_metadata = "0.18.1"
37-
ui_test = "0.30.1"
37+
ui_test = "0.30.2"
3838
regex = "1.5.5"
3939
serde = { version = "1.0.145", features = ["derive"] }
4040
serde_json = "1.0.122"
@@ -45,14 +45,6 @@ itertools = "0.12"
4545
pulldown-cmark = { version = "0.11", default-features = false, features = ["html"] }
4646
askama = { version = "0.14", default-features = false, features = ["alloc", "config", "derive"] }
4747

48-
# UI test dependencies
49-
if_chain = "1.0"
50-
quote = "1.0.25"
51-
syn = { version = "2.0", features = ["full"] }
52-
futures = "0.3"
53-
parking_lot = "0.12"
54-
tokio = { version = "1", features = ["io-util"] }
55-
5648
[build-dependencies]
5749
rustc_tools_util = { path = "rustc_tools_util", version = "0.4.2" }
5850

clippy_test_deps/Cargo.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "clippy_test_deps"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# Add dependencies here to make them available in ui tests.
7+
8+
[dependencies]
9+
regex = "1.5.5"
10+
serde = { version = "1.0.145", features = ["derive"] }
11+
if_chain = "1.0"
12+
quote = "1.0.25"
13+
syn = { version = "2.0", features = ["full"] }
14+
futures = "0.3"
15+
parking_lot = "0.12"
16+
tokio = { version = "1", features = ["io-util"] }
17+
itertools = "0.12"

clippy_test_deps/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fn main() {}

tests/compile-test.rs

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use test_utils::IS_RUSTC_TEST_SUITE;
1616
use ui_test::custom_flags::Flag;
1717
use ui_test::custom_flags::edition::Edition;
1818
use ui_test::custom_flags::rustfix::RustfixMode;
19+
use ui_test::dependencies::DependencyBuilder;
1920
use ui_test::spanned::Spanned;
2021
use ui_test::status_emitter::StatusEmitter;
2122
use ui_test::{Args, CommandBuilder, Config, Match, error_on_output_conflict};
@@ -28,46 +29,26 @@ use std::path::{Path, PathBuf};
2829
use std::sync::mpsc::{Sender, channel};
2930
use 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-
4132
mod 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

121103
struct 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

Comments
 (0)