Skip to content

Instantly share code, notes, and snippets.

@luser
Created May 25, 2018 12:41
Show Gist options
  • Save luser/932edaf55b575cf1147c1fa724a3878b to your computer and use it in GitHub Desktop.
Save luser/932edaf55b575cf1147c1fa724a3878b to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# Takes the output of `cargo +nightly build -Z unstable-options --build-plan` and produces
# a graphviz .dot file.
from __future__ import print_function, unicode_literals
import sys
import json
with open(sys.argv[1]) as f:
data = json.load(f)
invocations = data['invocations']
def display_name(invocation):
return '%s v%s %s %s' % (
invocation['package_name'],
invocation['package_version'],
invocation['target_kind'][0],
invocation['kind'],
)
def get_node(key):
invocation = invocations[key]
name = display_name(invocation)
return name.replace(' ', '_').replace('(', '_').replace(')', '_').replace('.', '_').replace('-', '_').replace(':', '_').replace('/', '_')
dag = set()
def graph_node(key):
invocation = invocations[key]
print('%d [label="%s"];' % (key, display_name(invocation)))
for dep in invocations[key]['deps']:
edge = (key, dep)
if edge not in dag:
print('%d -> %d [dir=back,arrowtail=\"empty\"];' % edge)
dag.add(edge)
print("digraph G {")
for key, invocation in enumerate(invocations):
graph_node(key)
print("}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment