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

This is closer to how the edge-based filters work ([no-]build etc.),
and results in a more useful behavior when combined with -i or -d.
This commit is contained in:
Jordan Rose 2023-04-27 10:54:51 -07:00
parent 747a5924a0
commit a0576d1767
3 changed files with 5 additions and 28 deletions

View file

@ -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.

View file

@ -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,
@ -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>,
@ -348,7 +346,6 @@ fn print_node<'a>(
prefix,
no_dedupe,
max_display_depth,
no_proc_macro,
visited_deps,
levels_continue,
print_stack,
@ -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>,
@ -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) {
@ -441,7 +424,6 @@ fn print_dependencies<'a>(
prefix,
no_dedupe,
max_display_depth,
no_proc_macro,
visited_deps,
levels_continue,
print_stack,

View file

@ -1134,14 +1134,7 @@ dupe-dep v2.0.0
.run();
p.cargo("tree --duplicates --edges no-proc-macro")
.with_stdout(
"\
dupe-dep v1.0.0
dupe-dep v2.0.0
foo v0.1.0 ([..]/foo)
",
)
.with_stdout("")
.run();
}
@ -1600,8 +1593,6 @@ somedep v1.0.0
"\
somedep v1.0.0
foo v0.1.0 ([..]/foo)
somedep v1.0.0
",
)
.run();