Add --svg and --dot args to soongdbg so you don't have to run graphviz by hand
Test: soongdbg between --svg ~/Desktop/foo.svg --label '"sdk_version="+.properties.Sdk_version' MODULE_1 MODULE_2 Change-Id: Idf5ee9a3ca2dc4b1fd3aa941fe641225336438fc
This commit is contained in:
49
bin/soongdbg
49
bin/soongdbg
@@ -3,6 +3,7 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import fnmatch
|
import fnmatch
|
||||||
import html
|
import html
|
||||||
|
import io
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
@@ -192,14 +193,41 @@ def load_and_filter_modules(args):
|
|||||||
yield m
|
yield m
|
||||||
|
|
||||||
|
|
||||||
def print_nodes(nodes, module_formatter):
|
def print_args(parser):
|
||||||
print("digraph {")
|
parser.add_argument("--label", action="append", metavar="JQ_FILTER",
|
||||||
|
help="jq query for each module metadata")
|
||||||
|
|
||||||
|
group = parser.add_argument_group("output formats",
|
||||||
|
"If no format is provided, a dot file will be written to"
|
||||||
|
+ " stdout.")
|
||||||
|
output = group.add_mutually_exclusive_group()
|
||||||
|
output.add_argument("--dot", type=str, metavar="FILENAME",
|
||||||
|
help="Write the graph to this file as dot (graphviz format)")
|
||||||
|
output.add_argument("--svg", type=str, metavar="FILENAME",
|
||||||
|
help="Write the graph to this file as svg")
|
||||||
|
|
||||||
|
|
||||||
|
def print_nodes(args, nodes, module_formatter):
|
||||||
|
# Generate the graphviz
|
||||||
|
dot = io.StringIO()
|
||||||
|
dot.write("digraph {\n")
|
||||||
for node in nodes:
|
for node in nodes:
|
||||||
print(f"\"{node.id}\"[label={format_node_label(node, module_formatter)}];")
|
dot.write(f"\"{node.id}\"[label={format_node_label(node, module_formatter)}];\n")
|
||||||
for dep in node.deps:
|
for dep in node.deps:
|
||||||
if dep in nodes:
|
if dep in nodes:
|
||||||
print(f"\"{node.id}\" -> \"{dep.id}\";")
|
dot.write(f"\"{node.id}\" -> \"{dep.id}\";\n")
|
||||||
print("}")
|
dot.write("}\n")
|
||||||
|
text = dot.getvalue()
|
||||||
|
|
||||||
|
# Write it somewhere
|
||||||
|
if args.dot:
|
||||||
|
with open(args.dot, "w") as f:
|
||||||
|
f.write(text)
|
||||||
|
elif args.svg:
|
||||||
|
subprocess.run(["dot", "-Tsvg", "-Nshape=box", "-o", args.svg],
|
||||||
|
input=text, text=True, check=True)
|
||||||
|
else:
|
||||||
|
sys.stdout.write(text)
|
||||||
|
|
||||||
|
|
||||||
def get_deps(nodes, root):
|
def get_deps(nodes, root):
|
||||||
@@ -240,12 +268,12 @@ class BetweenCommand:
|
|||||||
def args(self, parser):
|
def args(self, parser):
|
||||||
parser.add_argument("module", nargs=2,
|
parser.add_argument("module", nargs=2,
|
||||||
help="the two modules")
|
help="the two modules")
|
||||||
parser.add_argument("--label", action="append",
|
print_args(parser)
|
||||||
help="jq query for each module metadata")
|
|
||||||
|
|
||||||
def run(self, args):
|
def run(self, args):
|
||||||
graph = load_graph()
|
graph = load_graph()
|
||||||
print_nodes(graph.find_paths(args.module[0], args.module[1]), new_module_formatter(args))
|
print_nodes(args, graph.find_paths(args.module[0], args.module[1]),
|
||||||
|
new_module_formatter(args))
|
||||||
|
|
||||||
|
|
||||||
class DepsCommand:
|
class DepsCommand:
|
||||||
@@ -254,8 +282,7 @@ class DepsCommand:
|
|||||||
def args(self, parser):
|
def args(self, parser):
|
||||||
parser.add_argument("module", nargs="+",
|
parser.add_argument("module", nargs="+",
|
||||||
help="Module to print dependencies of")
|
help="Module to print dependencies of")
|
||||||
parser.add_argument("--label", action="append",
|
print_args(parser)
|
||||||
help="jq query for each module metadata")
|
|
||||||
|
|
||||||
def run(self, args):
|
def run(self, args):
|
||||||
graph = load_graph()
|
graph = load_graph()
|
||||||
@@ -270,7 +297,7 @@ class DepsCommand:
|
|||||||
get_deps(nodes, root)
|
get_deps(nodes, root)
|
||||||
if err:
|
if err:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
print_nodes(nodes, new_module_formatter(args))
|
print_nodes(args, nodes, new_module_formatter(args))
|
||||||
|
|
||||||
|
|
||||||
class IdCommand:
|
class IdCommand:
|
||||||
|
Reference in New Issue
Block a user