Skip to content

Commit

Permalink
Fix additional issue
Browse files Browse the repository at this point in the history
Noticed this when adding the new test case, if not filtering targets then expressions that could never evaluate to true were causing graph inclusion
  • Loading branch information
Jake-Shadle committed Apr 11, 2024
1 parent 1c5dbc2 commit 19a4fcb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 48 deletions.
14 changes: 14 additions & 0 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1279,6 +1279,20 @@ impl Builder {
if !matched {
return None;
}
} else if cfg.starts_with("cfg(") {
// This is _basically_ a tortured way to evaluate `cfg(any())`, which is always false but
// is used by eg. serde -> serde_derive. If not filtering targets this would mean that
// serde_derive and all of its dependencies would be pulled into the graph, even if the
// only edge was the cfg(any()).
if let Ok(expr) = cfg_expr::Expression::parse(cfg) {
// We can't just do an eval and always return true, as that then would cause any
// not() expressions to evaluate to false
if expr.predicates().count() == 0 {
if !expr.eval(|_| true) {
return None;
}
}
}
}

Some(cfg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,6 @@ digraph {
128 -> 32 [ label = "" ]
128 -> 102 [ label = "" ]
131 -> 132 [ label = "" ]
132 -> 253 [ label = " 'cfg(any())'" ]
132 -> 253 [ label = "" ]
133 -> 180 [ label = "" ]
133 -> 182 [ label = "" ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,12 @@ expression: dotgraph
---
digraph {
0 [ label = "crate features-2 0.1.0 path+file:///krates/tests/features-2" ]
1 [ label = "crate proc-macro2 1.0.79" ]
2 [ label = "crate quote 1.0.36" ]
3 [ label = "crate serde 1.0.197" ]
4 [ label = "crate serde_derive 1.0.197" ]
5 [ label = "crate smallvec 1.13.2" ]
6 [ label = "crate syn 2.0.58" ]
7 [ label = "crate unicode-ident 1.0.12" ]
8 [ label = "feature serde" ]
9 [ label = "feature proc-macro" ]
10 [ label = "feature default" ]
11 [ label = "feature proc-macro" ]
12 [ label = "feature clone-impls" ]
13 [ label = "feature derive" ]
14 [ label = "feature parsing" ]
15 [ label = "feature printing" ]
16 [ label = "feature proc-macro" ]
0 -> 5 [ label = "" ]
0 -> 8 [ label = " 'cfg(target_os = \"android\")'" ]
1 -> 7 [ label = "" ]
1 [ label = "crate serde 1.0.197" ]
2 [ label = "crate smallvec 1.13.2" ]
3 [ label = "feature serde" ]
0 -> 2 [ label = "" ]
0 -> 3 [ label = " 'cfg(target_os = \"android\")'" ]
2 -> 1 [ label = "" ]
2 -> 9 [ label = "" ]
3 -> 10 [ label = " 'cfg(any())'" ]
4 -> 9 [ label = "" ]
4 -> 11 [ label = "" ]
4 -> 12 [ label = "" ]
4 -> 13 [ label = "" ]
4 -> 14 [ label = "" ]
4 -> 15 [ label = "" ]
4 -> 16 [ label = "" ]
5 -> 3 [ label = "" ]
6 -> 1 [ label = "" ]
6 -> 9 [ label = "" ]
6 -> 2 [ label = "" ]
6 -> 11 [ label = "" ]
6 -> 7 [ label = "" ]
9 -> 1 [ label = "" ]
11 -> 2 [ label = "" ]
11 -> 9 [ label = "" ]
10 -> 4 [ label = "" ]
8 -> 5 [ label = "" ]
8 -> 3 [ label = "" ]
16 -> 6 [ label = "" ]
16 -> 9 [ label = "" ]
15 -> 6 [ label = "" ]
15 -> 2 [ label = "" ]
14 -> 6 [ label = "" ]
13 -> 6 [ label = "" ]
12 -> 6 [ label = "" ]
3 -> 2 [ label = "" ]
3 -> 1 [ label = "" ]
}

0 comments on commit 19a4fcb

Please sign in to comment.