Skip to content

Commit 58906aa

Browse files
committed
Don't treat host/target duplicates as duplicates
Signed-off-by: hi-rustin <[email protected]>
1 parent c5cdd25 commit 58906aa

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

src/cargo/ops/tree/graph.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,34 @@ 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+
let mut pkg_map = HashMap::new();
238+
indexes
239+
.into_iter()
240+
.filter(|(node, _)| {
241+
// Do not treat duplicates on the host or target as duplicates.
242+
let ignore_kind_package = match node {
243+
Node::Package {
244+
package_id,
245+
features,
246+
..
247+
} => Node::Package {
248+
package_id: package_id.clone(),
249+
features: features.clone(),
250+
kind: CompileKind::Host,
251+
},
252+
_ => unreachable!(),
253+
};
254+
!pkg_map.contains_key(&ignore_kind_package)
255+
&& pkg_map.insert(ignore_kind_package, ()).is_none()
256+
})
257+
.collect::<Vec<&(&Node, usize)>>()
258+
.len()
259+
> 1
260+
})
237261
.flat_map(|(_name, indexes)| indexes)
238262
.collect();
263+
239264
// For consistent output.
240265
dupes.sort_unstable();
241266
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)