Skip to content

Commit aefc3cf

Browse files
committed
Auto merge of #10466 - hi-rustin:rustin-patch-tree, r=weihanglo
Don't treat host/target duplicates as duplicates ### What does this PR try to resolve? close #9519 Don't treat host/target duplicates as duplicates. ### How should we test and review this PR? - Unit test. - Create a manifest where a dependency shows up as both a normal dependency and a build-dependency. Run `cargo tree -d --target x86_64-unknown-linux-gnu`
2 parents 9090042 + c45c2a5 commit aefc3cf

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

src/cargo/ops/tree/graph.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,33 @@ impl<'a> Graph<'a> {
233233

234234
let mut dupes: Vec<(&Node, usize)> = packages
235235
.into_iter()
236-
.filter(|(_name, indexes)| indexes.len() > 1)
236+
.filter(|(_name, indexes)| {
237+
indexes
238+
.into_iter()
239+
.map(|(node, _)| {
240+
match node {
241+
Node::Package {
242+
package_id,
243+
features,
244+
..
245+
} => {
246+
// Do not treat duplicates on the host or target as duplicates.
247+
Node::Package {
248+
package_id: package_id.clone(),
249+
features: features.clone(),
250+
kind: CompileKind::Host,
251+
}
252+
}
253+
_ => unreachable!(),
254+
}
255+
})
256+
.collect::<HashSet<_>>()
257+
.len()
258+
> 1
259+
})
237260
.flat_map(|(_name, indexes)| indexes)
238261
.collect();
262+
239263
// For consistent output.
240264
dupes.sort_unstable();
241265
dupes.into_iter().map(|(_node, i)| i).collect()

tests/testsuite/tree.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,51 @@ cat v2.0.0
984984
.run();
985985
}
986986

987+
#[cargo_test]
988+
fn duplicates_with_target() {
989+
// --target flag
990+
if cross_compile::disabled() {
991+
return;
992+
}
993+
Package::new("a", "1.0.0").publish();
994+
Package::new("dog", "1.0.0").publish();
995+
996+
let p = project()
997+
.file(
998+
"Cargo.toml",
999+
r#"
1000+
[package]
1001+
name = "foo"
1002+
version = "0.1.0"
1003+
1004+
[dependencies]
1005+
a = "1.0"
1006+
dog = "1.0"
1007+
1008+
[build-dependencies]
1009+
a = "1.0"
1010+
dog = "1.0"
1011+
1012+
"#,
1013+
)
1014+
.file("src/lib.rs", "")
1015+
.file("build.rs", "fn main() {}")
1016+
.build();
1017+
p.cargo("tree -d").with_stdout("").run();
1018+
1019+
p.cargo("tree -d --target")
1020+
.arg(alternate())
1021+
.with_stdout("")
1022+
.run();
1023+
1024+
p.cargo("tree -d --target")
1025+
.arg(rustc_host())
1026+
.with_stdout("")
1027+
.run();
1028+
1029+
p.cargo("tree -d --target=all").with_stdout("").run();
1030+
}
1031+
9871032
#[cargo_test]
9881033
fn charset() {
9891034
let p = make_simple_proj();

0 commit comments

Comments
 (0)