# HG changeset patch # User Doug Simon # Date 1382972698 -3600 # Node ID a9f750305a38bf3bbd36716a193370699825f3d8 # Parent 62b05f62a75cce9cb7fc8a6f82d019cdfc13d3a0 added --igv option to "mx projectgraph" command for sending output to IGV instead diff -r 62b05f62a75c -r a9f750305a38 mxtool/mx.py --- a/mxtool/mx.py Mon Oct 28 16:04:12 2013 +0100 +++ b/mxtool/mx.py Mon Oct 28 16:04:58 2013 +0100 @@ -34,6 +34,7 @@ import sys, os, errno, time, subprocess, shlex, types, urllib2, contextlib, StringIO, zipfile, signal, xml.sax.saxutils, tempfile, fnmatch import textwrap +import socket import xml.parsers.expat import shutil, re, xml.dom.minidom from collections import Callable @@ -2534,7 +2535,7 @@ suppliedParser = parser is not None - parser = parser if suppliedParser else ArgumentParser(prog='mx build') + parser = parser if suppliedParser else ArgumentParser(prog='mx clean') parser.add_argument('--no-native', action='store_false', dest='native', help='do not clean native projects') parser.add_argument('--no-java', action='store_false', dest='java', help='do not clean Java projects') @@ -2600,8 +2601,56 @@ print 'mx {0} {1}\n\n{2}\n'.format(name, usage, doc) def projectgraph(args, suite=None): - """create dot graph for project structure ("mx projectgraph | dot -Tpdf -oprojects.pdf")""" - + """create graph for project structure ("mx projectgraph | dot -Tpdf -oprojects.pdf" or "mx projectgraph --igv")""" + + parser = ArgumentParser(prog='mx projectgraph') + parser.add_argument('--igv', action='store_true', help='output to IGV listening on 127.0.0.1:4444') + parser.add_argument('--igv-format', action='store_true', help='output graph in IGV format') + + args = parser.parse_args(args) + + if args.igv or args.igv_format: + ids = {} + nextToIndex = {} + igv = XMLDoc() + igv.open('graphDocument') + igv.open('group') + igv.open('properties') + igv.element('p', {'name' : 'name'}, 'GraalProjectDependencies') + igv.close('properties') + igv.open('graph', {'name' : 'dependencies'}) + igv.open('nodes') + for p in sorted_deps(includeLibs=True): + ident = len(ids) + ids[p.name] = str(ident) + igv.open('node', {'id' : str(ident)}) + igv.open('properties') + igv.element('p', {'name' : 'name'}, p.name) + igv.close('properties') + igv.close('node') + igv.close('nodes') + igv.open('edges') + for p in projects(): + fromIndex = 0 + for dep in p.canonical_deps(): + toIndex = nextToIndex.get(dep, 0) + nextToIndex[dep] = toIndex + 1 + igv.element('edge', {'from' : ids[p.name], 'fromIndex' : str(fromIndex), 'to' : ids[dep], 'toIndex' : str(toIndex), 'label' : 'dependsOn'}) + fromIndex = fromIndex + 1 + igv.close('edges') + igv.close('graph') + igv.close('group') + igv.close('graphDocument') + + if args.igv: + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.connect(('127.0.0.1', 4444)) + s.send(igv.xml()) + else: + print igv.xml(indent=' ', newl='\n'); + return + + print 'digraph projects {' print 'rankdir=BT;' print 'node [shape=rect];'