Skip to content

Commit

Permalink
Don't treat host/target duplicates as duplicates
Browse files Browse the repository at this point in the history
Signed-off-by: hi-rustin <[email protected]>
  • Loading branch information
Rustin170506 committed Mar 8, 2022
1 parent c5cdd25 commit 58906aa
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/cargo/ops/tree/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,34 @@ impl<'a> Graph<'a> {

let mut dupes: Vec<(&Node, usize)> = packages
.into_iter()
.filter(|(_name, indexes)| indexes.len() > 1)
.filter(|(_name, indexes)| {
let mut pkg_map = HashMap::new();
indexes
.into_iter()
.filter(|(node, _)| {
// Do not treat duplicates on the host or target as duplicates.
let ignore_kind_package = match node {
Node::Package {
package_id,
features,
..
} => Node::Package {
package_id: package_id.clone(),
features: features.clone(),
kind: CompileKind::Host,
},
_ => unreachable!(),
};
!pkg_map.contains_key(&ignore_kind_package)
&& pkg_map.insert(ignore_kind_package, ()).is_none()
})
.collect::<Vec<&(&Node, usize)>>()
.len()
> 1
})
.flat_map(|(_name, indexes)| indexes)
.collect();

// For consistent output.
dupes.sort_unstable();
dupes.into_iter().map(|(_node, i)| i).collect()
Expand Down
45 changes: 45 additions & 0 deletions tests/testsuite/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,51 @@ cat v2.0.0
.run();
}

#[cargo_test]
fn duplicates_with_target() {
// --target flag
if cross_compile::disabled() {
return;
}
Package::new("a", "1.0.0").publish();
Package::new("dog", "1.0.0").publish();

let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
[dependencies]
a = "1.0"
dog = "1.0"
[build-dependencies]
a = "1.0"
dog = "1.0"
"#,
)
.file("src/lib.rs", "")
.file("build.rs", "fn main() {}")
.build();
p.cargo("tree -d").with_stdout("").run();

p.cargo("tree -d --target")
.arg(alternate())
.with_stdout("")
.run();

p.cargo("tree -d --target")
.arg(rustc_host())
.with_stdout("")
.run();

p.cargo("tree -d --target=all").with_stdout("").run();
}

#[cargo_test]
fn charset() {
let p = make_simple_proj();
Expand Down

0 comments on commit 58906aa

Please sign in to comment.