@@ -0,0 +1,2833 @@
+#!/usr/bin/python%0A%0A# Copyright (c) 2011 Google Inc. All rights reserved.%0A# Use of this source code is governed by a BSD-style license that can be%0A# found in the LICENSE file.%0A%0A%22%22%22Using the JSON dumped by the dump-dependency-json generator,%0Agenerate input suitable for graphviz to render a dependency graph of%0Atargets.%22%22%22%0A%0Aimport collections%0Aimport json%0Aimport sys%0A%0A%0Adef ParseTarget(target):%0A  target, _, suffix = target.partition('#')%0A  filename, _, target = target.partition(':')%0A  return filename, target, suffix%0A%0A%0Adef LoadEdges(filename, targets):%0A  %22%22%22Load the edges map from the dump file, and filter it to only%0A  show targets in %7Ctargets%7C and their depedendents.%22%22%22%0A%0A  file = open('dump.json')%0A  edges = json.load(file)%0A  file.close()%0A%0A  # Copy out only the edges we're interested in from the full edge list.%0A  target_edges = %7B%7D%0A  to_visit = targets%5B:%5D%0A  while to_visit:%0A    src = to_visit.pop()%0A    if src in target_edges:%0A      continue%0A    target_edges%5Bsrc%5D = edges%5Bsrc%5D%0A    to_visit.extend(edges%5Bsrc%5D)%0A%0A  return target_edges%0A%0A%0Adef WriteGraph(edges):%0A  %22%22%22Print a graphviz graph to stdout.%0A  %7Cedges%7C is a map of target to a list of other targets it depends on.%22%22%22%0A%0A  # Bucket targets by file.%0A  files = collections.defaultdict(list)%0A  for src, dst in edges.items():%0A    build_file, target_name, toolset = ParseTarget(src)%0A    files%5Bbuild_file%5D.append(src)%0A%0A  print 'digraph D %7B'%0A  print '  fontsize=8'  # Used by subgraphs.%0A  print '  node %5Bfontsize=8%5D'%0A%0A  # Output nodes by file.  We must first write out each node within%0A  # its file grouping before writing out any edges that may refer%0A  # to those nodes.%0A  for filename, targets in files.items():%0A    if len(targets) == 1:%0A      # If there's only one node for this file, simplify%0A      # the display by making it a box without an internal node.%0A      target = targets%5B0%5D%0A      build_file, target_name, toolset = ParseTarget(target)%0A      print '  %22%25s%22 %5Bshape=box, label=%22%25s%5C%5Cn%25s%22%5D' %25 (target, filename,%0A                                                     target_name)%0A    else:%0A      # Group multiple nodes together in a subgraph.%0A      print '  subgraph %22cluster_%25s%22 %7B' %25 filename%0A      print '    label = %22%25s%22' %25 filename%0A      for target in targets:%0A        build_file, target_name, toolset = ParseTarget(target)%0A        print '    %22%25s%22 %5Blabel=%22%25s%22%5D' %25 (target, target_name)%0A      print '  %7D'%0A%0A  # Now that we've placed all the nodes within subgraphs, output all%0A  # the edges between nodes.%0A  for src, dsts in edges.items():%0A    for dst in dsts:%0A      print '  %22%25s%22 -%3E %22%25s%22' %25 (src, dst)%0A%0A  print '%7D'%0A%0A%0Aif __name__ == '__main__':%0A  if len(sys.argv) %3C 2:%0A    print %3E%3Esys.stderr, __doc__%0A    print %3E%3Esys.stderr%0A    print %3E%3Esys.stderr, 'usage: %25s target1 target2...' %25 (sys.argv%5B0%5D)%0A    sys.exit(1)%0A%0A  edges = LoadEdges('dump.json', sys.argv%5B1:%5D)%0A%0A  WriteGraph(edges)%0A

Check in a tool that dumps graphviz output.