Skip to content

Commit

Permalink
Fixes to visualisations for xdot (pantsbuild#18421)
Browse files Browse the repository at this point in the history
xdot was having trouble consuming the dot files generated by the
`--engine-visualize-to` option.
- the comment with the queries was all on one line, which exceeded the
16k character limit. I simply printed them on multiple lines
- the double escaping led to `unexpected char b'\\'` errors, because it
found `\\\"`. We manually expand `"` to `\\\"`. I found removing that
worked anyhow, I think there's escaping happening in the format call
later

~I broke up the rule name and its value on separate lines, so the lines
are just a bit shorter~ turns out fmt_for_graph is used by the normal
fmt method, so this has wider effects.

Also I have no idea what I'm doing with Rust and just followed along
when the compiler suggested things.
  • Loading branch information
lilatomic authored Mar 7, 2023
1 parent d37d57a commit b233fa0
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 14 deletions.
63 changes: 51 additions & 12 deletions src/python/pants/engine/rules_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,10 @@ def a_from_suba(suba: SubA) -> A:
dedent(
f"""\
digraph {{
// queries: Query(A for SubA)
/*
queries:
Query(A for SubA)
*/
// root entries
{fmt_non_param_edge(A, SubA)}
{fmt_non_param_edge(A, SubA, RuleFormatRequest(a_from_suba))}
Expand All @@ -581,7 +584,11 @@ def b_from_a(a: A) -> B:
dedent(
f"""\
digraph {{
// queries: Query(A for SubA), Query(B for A)
/*
queries:
Query(A for SubA),
Query(B for A)
*/
// root entries
{fmt_non_param_edge(A, SubA)}
{fmt_non_param_edge(A, SubA, RuleFormatRequest(a_from_suba))}
Expand All @@ -606,7 +613,10 @@ def a_from_suba(suba: SubA) -> A:
dedent(
f"""\
digraph {{
// queries: Query(A for SubA)
/*
queries:
Query(A for SubA)
*/
// root entries
{fmt_non_param_edge(A, SubA)}
{fmt_non_param_edge(A, SubA, RuleFormatRequest(a_from_suba))}
Expand All @@ -632,7 +642,10 @@ def b() -> B:
dedent(
f"""\
digraph {{
// queries: Query(A for SubA)
/*
queries:
Query(A for SubA)
*/
// root entries
{fmt_non_param_edge(A, SubA)}
{fmt_non_param_edge(A, SubA, RuleFormatRequest(a_from_suba_and_b))}
Expand Down Expand Up @@ -671,7 +684,10 @@ def suba_from_c(c: C) -> SubA:
dedent(
f"""\
digraph {{
// queries: Query(A for SubA)
/*
queries:
Query(A for SubA)
*/
// root entries
{fmt_non_param_edge(A, SubA)}
{fmt_non_param_edge(A, SubA, return_func=RuleFormatRequest(a, gets=[("B", "C")]))}
Expand Down Expand Up @@ -700,7 +716,10 @@ def b_from_suba(suba: SubA) -> B:
dedent(
f"""\
digraph {{
// queries: Query(A for SubA)
/*
queries:
Query(A for SubA)
*/
// root entries
{fmt_non_param_edge(A, SubA)}
{fmt_non_param_edge(A, SubA, RuleFormatRequest(a_from_b))}
Expand Down Expand Up @@ -733,7 +752,10 @@ def b_singleton() -> B:
dedent(
f"""\
digraph {{
// queries: Query(A for SubA)
/*
queries:
Query(A for SubA)
*/
// root entries
{fmt_non_param_edge(A, ())}
{fmt_non_param_edge(a, (), rule_type=GraphVertexType.singleton)}
Expand Down Expand Up @@ -762,7 +784,10 @@ def a() -> A:
dedent(
f"""\
digraph {{
// queries: Query(A for SubA)
/*
queries:
Query(A for SubA)
*/
// root entries
{fmt_non_param_edge(A, ())}
{fmt_non_param_edge(a, (), rule_type=GraphVertexType.singleton)}
Expand Down Expand Up @@ -866,7 +891,10 @@ def b_singleton() -> B:
dedent(
f"""\
digraph {{
// queries: Query(A for SubA)
/*
queries:
Query(A for SubA)
*/
// root entries
{fmt_non_param_edge(A, SubA)}
{fmt_non_param_edge(A, SubA, RuleFormatRequest(a_from_suba))}
Expand Down Expand Up @@ -900,7 +928,10 @@ def b_from_a(a: A) -> B:
dedent(
f"""\
digraph {{
// queries: Query(A for SubA)
/*
queries:
Query(A for SubA)
*/
// root entries
{fmt_non_param_edge(B, SubA)}
{fmt_non_param_edge(B, SubA, RuleFormatRequest(b_from_a))}
Expand Down Expand Up @@ -938,7 +969,12 @@ def c_from_a(a: A) -> C:
dedent(
f"""\
digraph {{
// queries: Query(A for SubA), Query(B for SubA), Query(C for SubA)
/*
queries:
Query(A for SubA),
Query(B for SubA),
Query(C for SubA)
*/
// root entries
{fmt_non_param_edge(A, SubA)}
{fmt_non_param_edge(A, SubA, RuleFormatRequest(a_from_suba))}
Expand Down Expand Up @@ -972,7 +1008,10 @@ async def b_from_d(d: D) -> B:
dedent(
f"""\
digraph {{
// queries: Query(A for SubA)
/*
queries:
Query(A for SubA)
*/
// root entries
{fmt_non_param_edge(A, ())}
{fmt_non_param_edge(RuleFormatRequest(a, gets=[("B", "D")]), (), rule_type=GraphVertexType.singleton)}
Expand Down
2 changes: 1 addition & 1 deletion src/rust/engine/graph/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,6 @@ impl<N: Node> Entry<N> {
}
None => "<None>".to_string(),
};
format!("{} == {}", self.node, state).replace('"', "\\\"")
format!("{} == {}", self.node, state)
}
}
13 changes: 12 additions & 1 deletion src/rust/engine/rule_graph/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,18 @@ impl<R: Rule> RuleGraph<R> {
.collect::<Vec<String>>();
queries_strs.sort();
writeln!(f, "digraph {{")?;
writeln!(f, " // queries: {}", queries_strs.join(", "))?;
writeln!(f, " /*")?;
writeln!(f, " queries:")?;
writeln!(
f,
"{}",
queries_strs
.iter()
.map(|q| format!(" {}", q))
.collect::<Vec<String>>()
.join(",\n")
)?;
writeln!(f, " */")?;
writeln!(f, " // root entries")?;
let mut root_rule_strs = self
.rule_dependency_edges
Expand Down

0 comments on commit b233fa0

Please sign in to comment.