(edges)
Print a graphviz graph to stdout.
  |edges| is a map of target to a list of other targets it depends on.
Print a graphviz graph to stdout.
  |edges| is a map of target to a list of other targets it depends on.
Print a graphviz graph to stdout . |edges| is a map of target to a list of other targets it depends on .
def WriteGraph(edges):
  """Print a graphviz graph to stdout.
  |edges| is a map of target to a list of other targets it depends on."""

  # Bucket targets by file.
  files = collections.defaultdict(list)
  for src, dst in edges.items():
    build_file, target_name, toolset = ParseTarget(src)
    files[build_file].append(src)

  print 'digraph D {'
  print '  fontsize=8'  # Used by subgraphs.
  print '  node [fontsize=8]'

  # Output nodes by file.  We must first write out each node within
  # its file grouping before writing out any edges that may refer
  # to those nodes.
  for filename, targets in files.items():
    if len(targets) == 1:
      # If there's only one node for this file, simplify
      # the display by making it a box without an internal node.
      target = targets[0]
      build_file, target_name, toolset = ParseTarget(target)
      print '  "%s" [shape=box, label="%s\\n%s"]' % (target, filename,
                                                     target_name)
    else:
      # Group multiple nodes together in a subgraph.
      print '  subgraph "cluster_%s" {' % filename
      print '    label = "%s"' % filename
      for target in targets:
        build_file, target_name, toolset = ParseTarget(target)
        print '    "%s" [label="%s"]' % (target, target_name)
      print '  }'

  # Now that we've placed all the nodes within subgraphs, output all
  # the edges between nodes.
  for src, dsts in edges.items():
    for dst in dsts:
      print '  "%s" -> "%s"' % (src, dst)

  print '}'
def WriteGraph ( edges ) : # Bucket targets by file. files = collections . defaultdict ( list ) for src , dst in edges . items ( ) : build_file , target_name , toolset = ParseTarget ( src ) files [ build_file ] . append ( src ) print 'digraph D {' print '  fontsize=8' # Used by subgraphs. print '  node [fontsize=8]' # Output nodes by file.  We must first write out each node within # its file grouping before writing out any edges that may refer # to those nodes. for filename , targets in files . items ( ) : if len ( targets ) == 1 : # If there's only one node for this file, simplify # the display by making it a box without an internal node. target = targets [ 0 ] build_file , target_name , toolset = ParseTarget ( target ) print '  "%s" [shape=box, label="%s\\n%s"]' % ( target , filename , target_name ) else : # Group multiple nodes together in a subgraph. print '  subgraph "cluster_%s" {' % filename print '    label = "%s"' % filename for target in targets : build_file , target_name , toolset = ParseTarget ( target ) print '    "%s" [label="%s"]' % ( target , target_name ) print '  }' # Now that we've placed all the nodes within subgraphs, output all # the edges between nodes. for src , dsts in edges . items ( ) : for dst in dsts : print '  "%s" -> "%s"' % ( src , dst ) print '}'