Skip to content

Commit e8592b9

Browse files
authored
Merge pull request #329 from RalfJung/dependencies
dependencies: heuristic to distinguish host and target artifacts
2 parents 977b22b + a754014 commit e8592b9

File tree

12 files changed

+66
-11
lines changed

12 files changed

+66
-11
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414

1515
### Changed
1616

17+
- DependencyBuilder: if `config.target` is set (which is always the case if you use `run_tests_generic`),
18+
ui_test now supports the same crate showing up as a direct dependency and a dependency of a proc-macro.
19+
1720
### Removed
1821

1922
## [0.30.1] - 2025-05-28

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ui_test"
3-
version = "0.30.1"
3+
version = "0.30.2"
44
edition = "2021"
55
license = "MIT OR Apache-2.0"
66
description = "A test framework for testing rustc diagnostics output"

src/dependencies.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,50 @@ fn build_dependencies_inner(
156156
{
157157
continue;
158158
}
159+
if let Some(target) = &config.target {
160+
// We passed `--target` to cargo. This means host and target dependencies will
161+
// end up in different folders, which we can use to distinguish them! We only
162+
// want to add target dependencies, and their folder will look something like:
163+
// ```
164+
// .../target/ui_test/0/x86_64-unknown-linux-gnu/debug/deps/libquote-031e34ffdd9a346e.rlib
165+
// ```
166+
// So we skip all artifacts where, popping the top 3 components, we do not see
167+
// the target. However, we do *not* do this for proc-macro crates as those will
168+
// only ever show up as host crates anyway.
169+
let skip_crate = 'skip_crate: {
170+
let Some(filename) = artifact.filenames.first() else {
171+
// No filename? No idea what this is...
172+
break 'skip_crate false;
173+
};
174+
if artifact
175+
.target
176+
.crate_types
177+
.iter()
178+
.any(|ctype| ctype == "proc-macro")
179+
{
180+
// Proc macros are only ever built for the host, don't skip that.
181+
break 'skip_crate false;
182+
}
183+
// Not a proc macro, let's check the path.
184+
let mut filename = filename.to_path_buf();
185+
filename.pop();
186+
// We also validate that the path looks as expected before we actually skip.
187+
if filename.file_name().unwrap_or_default() != "deps" {
188+
// Either cargo changed or this is a weird corner case, let's just
189+
// keep it.
190+
break 'skip_crate false;
191+
}
192+
filename.pop();
193+
// This is the profile name, `debug` or `release` or so.
194+
filename.pop();
195+
// And now this should be the target name.
196+
// If not, skip it.
197+
filename.file_name().unwrap_or_default() != target
198+
};
199+
if skip_crate {
200+
continue;
201+
}
202+
}
159203
for filename in &artifact.filenames {
160204
import_paths.insert(filename.parent().unwrap().into());
161205
}

tests/integrations/basic-bin/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integrations/basic-fail-mode/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integrations/basic-fail/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integrations/basic/Cargo.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integrations/basic/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ edition = "2021"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9+
# A proc-macro dependency, needs special treatment.
910
serde_derive = "1.0"
11+
# `quote` now shows up both as host and target dependency -- let's make sure that works.
12+
quote = "1.0.25"
1013

1114
[dev-dependencies]
1215
ui_test = { path = "../../.."}

tests/integrations/cargo-run/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)