Skip to content

Commit a285008

Browse files
committed
Auto merge of #12044 - jrose-signal:cargo-tree-no-proc-macro, r=epage
cargo-tree: Handle -e no-proc-macro when building the graph ### What does this PR try to resolve? Makes `-e no-proc-macro` more useful when combined with `-i` or `-d`. Fixes #12030. ### How should we test and review this PR? The new and existing tests should cover this, I hope! ### Additional information Pruning proc-macro crates during graph construction is closer to how the edge-based filters work (`[no-]build` etc.), so even though `no-proc-macro` isn't technically filtering on edges, it's following a well-established code path.
2 parents 221051e + a0576d1 commit a285008

File tree

3 files changed

+57
-20
lines changed

3 files changed

+57
-20
lines changed

src/cargo/ops/tree/graph.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,10 @@ fn add_pkg(
362362
if !opts.edge_kinds.contains(&EdgeKind::Dep(dep.kind())) {
363363
return false;
364364
}
365+
// Filter out proc-macrcos if requested.
366+
if opts.no_proc_macro && graph.package_for_id(dep_id).proc_macro() {
367+
return false;
368+
}
365369
if dep.is_optional() {
366370
// If the new feature resolver does not enable this
367371
// optional dep, then don't use it.

src/cargo/ops/tree/mod.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ fn print(
267267
opts.prefix,
268268
opts.no_dedupe,
269269
opts.max_display_depth,
270-
opts.no_proc_macro,
271270
&mut visited_deps,
272271
&mut levels_continue,
273272
&mut print_stack,
@@ -288,7 +287,6 @@ fn print_node<'a>(
288287
prefix: Prefix,
289288
no_dedupe: bool,
290289
max_display_depth: u32,
291-
no_proc_macro: bool,
292290
visited_deps: &mut HashSet<usize>,
293291
levels_continue: &mut Vec<bool>,
294292
print_stack: &mut Vec<usize>,
@@ -348,7 +346,6 @@ fn print_node<'a>(
348346
prefix,
349347
no_dedupe,
350348
max_display_depth,
351-
no_proc_macro,
352349
visited_deps,
353350
levels_continue,
354351
print_stack,
@@ -369,7 +366,6 @@ fn print_dependencies<'a>(
369366
prefix: Prefix,
370367
no_dedupe: bool,
371368
max_display_depth: u32,
372-
no_proc_macro: bool,
373369
visited_deps: &mut HashSet<usize>,
374370
levels_continue: &mut Vec<bool>,
375371
print_stack: &mut Vec<usize>,
@@ -405,19 +401,6 @@ fn print_dependencies<'a>(
405401

406402
let mut it = deps
407403
.iter()
408-
.filter(|dep| {
409-
// Filter out proc-macro dependencies.
410-
if no_proc_macro {
411-
match graph.node(**dep) {
412-
&Node::Package { package_id, .. } => {
413-
!graph.package_for_id(package_id).proc_macro()
414-
}
415-
_ => true,
416-
}
417-
} else {
418-
true
419-
}
420-
})
421404
.filter(|dep| {
422405
// Filter out packages to prune.
423406
match graph.node(**dep) {
@@ -441,7 +424,6 @@ fn print_dependencies<'a>(
441424
prefix,
442425
no_dedupe,
443426
max_display_depth,
444-
no_proc_macro,
445427
visited_deps,
446428
levels_continue,
447429
print_stack,

tests/testsuite/tree.rs

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,59 @@ fn duplicates_with_target() {
10851085
p.cargo("tree -d --target=all").with_stdout("").run();
10861086
}
10871087

1088+
#[cargo_test]
1089+
fn duplicates_with_proc_macro() {
1090+
Package::new("dupe-dep", "1.0.0").publish();
1091+
Package::new("dupe-dep", "2.0.0").publish();
1092+
Package::new("proc", "1.0.0")
1093+
.proc_macro(true)
1094+
.dep("dupe-dep", "1.0")
1095+
.publish();
1096+
let p = project()
1097+
.file(
1098+
"Cargo.toml",
1099+
r#"
1100+
[package]
1101+
name = "foo"
1102+
version = "0.1.0"
1103+
1104+
[dependencies]
1105+
proc = "1.0"
1106+
dupe-dep = "2.0"
1107+
"#,
1108+
)
1109+
.file("src/lib.rs", "")
1110+
.build();
1111+
1112+
p.cargo("tree")
1113+
.with_stdout(
1114+
"\
1115+
foo v0.1.0 ([..]/foo)
1116+
├── dupe-dep v2.0.0
1117+
└── proc v1.0.0 (proc-macro)
1118+
└── dupe-dep v1.0.0
1119+
",
1120+
)
1121+
.run();
1122+
1123+
p.cargo("tree --duplicates")
1124+
.with_stdout(
1125+
"\
1126+
dupe-dep v1.0.0
1127+
└── proc v1.0.0 (proc-macro)
1128+
└── foo v0.1.0 ([..]/foo)
1129+
1130+
dupe-dep v2.0.0
1131+
└── foo v0.1.0 ([..]/foo)
1132+
",
1133+
)
1134+
.run();
1135+
1136+
p.cargo("tree --duplicates --edges no-proc-macro")
1137+
.with_stdout("")
1138+
.run();
1139+
}
1140+
10881141
#[cargo_test]
10891142
fn charset() {
10901143
let p = make_simple_proj();
@@ -1540,8 +1593,6 @@ somedep v1.0.0
15401593
"\
15411594
somedep v1.0.0
15421595
└── foo v0.1.0 ([..]/foo)
1543-
1544-
somedep v1.0.0
15451596
",
15461597
)
15471598
.run();

0 commit comments

Comments
 (0)