Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't treat host/target duplicates as duplicates #10466

Merged
merged 2 commits into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, _)| {
Rustin170506 marked this conversation as resolved.
Show resolved Hide resolved
// 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
Rustin170506 marked this conversation as resolved.
Show resolved Hide resolved
})
.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