Graph scope options.

This commit is contained in:
Sleepy Monax 2023-02-06 18:11:35 +01:00
parent db9b3f25f9
commit 38d3e28527
2 changed files with 26 additions and 5 deletions

View file

@ -39,7 +39,9 @@ def runCmd(args: Args):
if componentSpec is None:
raise Exception("Component not specified")
builder.build(componentSpec, targetSpec)
exe = builder.build(componentSpec, targetSpec)
shell.exec(exe)
cmds += [Cmd("r", "run", "Run the target", runCmd)]
@ -141,9 +143,12 @@ def graphCmd(args: Args):
targetSpec = cast(str, args.consumeOpt(
"target", "host-" + shell.uname().machine))
scope: str | None = cast(str | None, args.tryConsumeOpt("scope"))
onlyLibs: bool = args.consumeOpt("only-libs", False) == True
context = contextFor(targetSpec, {})
graph.view(context)
graph.view(context, scope=scope, showExe=not onlyLibs)
cmds += [Cmd("g", "graph", "Show dependency graph", graphCmd)]

View file

@ -1,20 +1,36 @@
from graphviz import Digraph
from osdk.context import Context
from osdk import vt100
def view(context: Context, showExe: bool = True):
def view(context: Context, scope: str | None = None, showExe: bool = True):
g = Digraph(context.target.id, filename='graph.gv')
g.attr('graph', splines='ortho', rankdir='BT')
g.attr('node', shape='ellipse')
g.attr(
'graph', label=f"<<B>{scope or 'Full Dependency Graph'}</B><BR/>{context.target.id}>", labelloc='t')
scopeInstance = None
if scope is not None:
scopeInstance = context.componentByName(scope)
for instance in context.instances:
if not instance.isLib() and not showExe:
continue
g.node(instance.manifest.id, f"<<B>{instance.manifest.id}</B><BR/>{instance.manifest.decription}>",
shape="plaintext", style="filled", fillcolor="lightgrey" if instance.isLib() else "lightblue")
if scopeInstance is not None and \
instance.manifest.id != scope and \
instance.manifest.id not in scopeInstance.resolved:
continue
fillcolor = "lightgrey" if instance.isLib() else "lightblue"
shape = "plaintext" if not scope == instance.manifest.id else 'box'
g.node(instance.manifest.id, f"<<B>{instance.manifest.id}</B><BR/>{vt100.wordwrap(instance.manifest.decription, 40,newline='<BR/>')}>",
shape=shape, style="filled", fillcolor=fillcolor)
for req in instance.manifest.requires:
g.edge(instance.manifest.id, req)