Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(404)

Unified Diff: tools/gyp-explain.py

Issue 15026004: Add --dot option to gyp-explain (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: docstring Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gyp-explain.py
diff --git a/tools/gyp-explain.py b/tools/gyp-explain.py
index 35b4667816eff7c4349e61fbe8c6762722154bec..824f72f1d65b9126ba671a31e13cea3267d7ee7f 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)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698