diff options
author | scottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-07 21:56:21 +0000 |
---|---|---|
committer | scottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-07 21:56:21 +0000 |
commit | 4410f24191123cc440450270c4826e3932885c28 (patch) | |
tree | 3af9472b468a794e28c4b55ffe9a22923f5c71d9 /tools/gyp-explain.py | |
parent | 33c6408b4ed43b088ebdf8948fd891251df8fe26 (diff) | |
download | chromium_src-4410f24191123cc440450270c4826e3932885c28.zip chromium_src-4410f24191123cc440450270c4826e3932885c28.tar.gz chromium_src-4410f24191123cc440450270c4826e3932885c28.tar.bz2 |
Add --dot option to gyp-explain
To allow generating a graph of linkage information that gyp-explain
outputs. Output example: http://i.imgur.com/7WWRvpA.jpg
R=thakis@chromium.org
BUG=237249
Review URL: https://codereview.chromium.org/15026004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@198806 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/gyp-explain.py')
-rwxr-xr-x | tools/gyp-explain.py | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/tools/gyp-explain.py b/tools/gyp-explain.py index 35b4667..824f72f 100755 --- a/tools/gyp-explain.py +++ b/tools/gyp-explain.py @@ -16,7 +16,7 @@ from collections import deque def usage(): print """\ Usage: - tools/gyp-explain.py chrome_dll# gtest# + tools/gyp-explain.py [--dot] chrome_dll# gtest# """ @@ -51,6 +51,26 @@ def MatchNode(graph, substring): return candidates[0] +def EscapeForDot(string): + suffix = '#target' + if string.endswith(suffix): + string = string[:-len(suffix)] + string = string.replace('\\', '\\\\') + return '"' + string + '"' + + +def GenerateDot(fro, to, paths): + """Generates an input file for graphviz's dot program.""" + prefixes = [os.path.commonprefix(path) for path in paths] + prefix = os.path.commonprefix(prefixes) + print '// Build with "dot -Tpng -ooutput.png this_file.dot"' + # "strict" collapses common paths. + print 'strict digraph {' + for path in paths: + print (' -> '.join(EscapeForDot(item[len(prefix):]) for item in path)), ';' + print '}' + + def Main(argv): # Check that dump.json exists and that it's not too old. dump_json_dirty = False @@ -72,18 +92,25 @@ def Main(argv): g = json.load(open('dump.json')) - if len(argv) != 3: + if len(argv) not in (3, 4): usage() sys.exit(1) + generate_dot = argv[1] == '--dot' + if generate_dot: + argv.pop(1) + fro = MatchNode(g, argv[1]) to = MatchNode(g, argv[2]) paths = list(GetPath(g, fro, to)) if len(paths) > 0: - print 'These paths lead from %s to %s:' % (fro, to) - for path in paths: - print ' -> '.join(path) + if generate_dot: + GenerateDot(fro, to, paths) + else: + print 'These paths lead from %s to %s:' % (fro, to) + for path in paths: + print ' -> '.join(path) else: print 'No paths found from %s to %s.' % (fro, to) |