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

cargo-tree: Handle -e no-proc-macro when building the graph #12044

Merged
merged 2 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions src/cargo/ops/tree/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@ fn add_pkg(
if !opts.edge_kinds.contains(&EdgeKind::Dep(dep.kind())) {
return false;
}
// Filter out proc-macrcos if requested.
if opts.no_proc_macro && graph.package_for_id(dep_id).proc_macro() {
return false;
}
if dep.is_optional() {
// If the new feature resolver does not enable this
// optional dep, then don't use it.
Expand Down
18 changes: 0 additions & 18 deletions src/cargo/ops/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ fn print(
opts.prefix,
opts.no_dedupe,
opts.max_display_depth,
opts.no_proc_macro,
&mut visited_deps,
&mut levels_continue,
&mut print_stack,
Expand All @@ -288,7 +287,6 @@ fn print_node<'a>(
prefix: Prefix,
no_dedupe: bool,
max_display_depth: u32,
no_proc_macro: bool,
visited_deps: &mut HashSet<usize>,
levels_continue: &mut Vec<bool>,
print_stack: &mut Vec<usize>,
Expand Down Expand Up @@ -348,7 +346,6 @@ fn print_node<'a>(
prefix,
no_dedupe,
max_display_depth,
no_proc_macro,
visited_deps,
levels_continue,
print_stack,
Expand All @@ -369,7 +366,6 @@ fn print_dependencies<'a>(
prefix: Prefix,
no_dedupe: bool,
max_display_depth: u32,
no_proc_macro: bool,
visited_deps: &mut HashSet<usize>,
levels_continue: &mut Vec<bool>,
print_stack: &mut Vec<usize>,
Expand Down Expand Up @@ -405,19 +401,6 @@ fn print_dependencies<'a>(

let mut it = deps
.iter()
.filter(|dep| {
// Filter out proc-macro dependencies.
if no_proc_macro {
match graph.node(**dep) {
&Node::Package { package_id, .. } => {
!graph.package_for_id(package_id).proc_macro()
}
_ => true,
}
} else {
true
}
})
.filter(|dep| {
// Filter out packages to prune.
match graph.node(**dep) {
Expand All @@ -441,7 +424,6 @@ fn print_dependencies<'a>(
prefix,
no_dedupe,
max_display_depth,
no_proc_macro,
visited_deps,
levels_continue,
print_stack,
Expand Down
55 changes: 53 additions & 2 deletions tests/testsuite/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,59 @@ fn duplicates_with_target() {
p.cargo("tree -d --target=all").with_stdout("").run();
}

#[cargo_test]
fn duplicates_with_proc_macro() {
Package::new("dupe-dep", "1.0.0").publish();
Package::new("dupe-dep", "2.0.0").publish();
Package::new("proc", "1.0.0")
.proc_macro(true)
.dep("dupe-dep", "1.0")
.publish();
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"

[dependencies]
proc = "1.0"
dupe-dep = "2.0"
"#,
)
.file("src/lib.rs", "")
.build();

p.cargo("tree")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: would you be yup for splitting this commit into two, one commit that just adds tests, showing the existing behavior, with the second adding the fix and updating the tests?

As a reviewer this helps to show that this is indeed testing and fixing the right thing

.with_stdout(
"\
foo v0.1.0 ([..]/foo)
├── dupe-dep v2.0.0
└── proc v1.0.0 (proc-macro)
└── dupe-dep v1.0.0
",
)
.run();

p.cargo("tree --duplicates")
.with_stdout(
"\
dupe-dep v1.0.0
└── proc v1.0.0 (proc-macro)
└── foo v0.1.0 ([..]/foo)

dupe-dep v2.0.0
└── foo v0.1.0 ([..]/foo)
",
)
.run();

p.cargo("tree --duplicates --edges no-proc-macro")
.with_stdout("")
.run();
}

#[cargo_test]
fn charset() {
let p = make_simple_proj();
Expand Down Expand Up @@ -1540,8 +1593,6 @@ somedep v1.0.0
"\
somedep v1.0.0
└── foo v0.1.0 ([..]/foo)

somedep v1.0.0
",
)
.run();
Expand Down