Chromium Code Reviews| Index: tools/gyp-explain.py |
| diff --git a/tools/gyp-explain.py b/tools/gyp-explain.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..4def5a17f3e57a566d8362520ecc199dc417674a |
| --- /dev/null |
| +++ b/tools/gyp-explain.py |
| @@ -0,0 +1,87 @@ |
| +#!/usr/bin/env python |
| + |
|
M-A Ruel
2011/11/23 20:06:30
Copyright
Nico
2011/11/23 20:12:07
Done.
|
| +"""Prints paths between gyp targets. |
| +""" |
| + |
| +import json |
| +import os |
| +import sys |
| +import time |
| + |
| +from collections import deque |
| + |
| +def usage(): |
| + print """\ |
| +Usage: |
| + tools/gyp-explain.sh chrome_dll gtest# |
|
viettrungluu
2011/11/23 20:19:51
Drive-by: ".sh"?
It might be more helpful to put:
Nico
2011/11/23 20:22:58
Done.
|
| +""" |
| + |
| +def GetPath(graph, fro, to, get_all=False): |
|
viettrungluu
2011/11/23 20:19:51
Is get_all even necessary, given that you're retur
Nico
2011/11/23 20:22:58
Oh, good point. Removed.
|
| + """Given a graph in (node -> list of successor nodes) dictionary format, |
| + yields either the shortest path from |fro| to |to|, or if |get_all| is True, |
| + all paths from |fro| to |to|.""" |
| + # Storing full paths in the queue is a bit wasteful, but good enough for this. |
| + q = deque([(fro, [])]) |
| + while len(q) > 0: |
| + t, path = q.popleft() |
| + if t == to: |
| + yield path + [t] |
| + if not get_all: |
| + break |
| + for d in g[t]: |
| + q.append((d, path + [t])) |
| + |
| + |
| +def MatchNode(graph, substring): |
| + """Given a dictionary, returns the key that matches |substring| best. Exits |
| + if there's not one single best match.""" |
| + candidates = [] |
| + for target in g: |
| + if substring in target: |
| + candidates.append(target) |
| + |
| + if not candidates: |
| + print 'No targets match "%s"' % substring |
| + sys.exit(1) |
| + if len(candidates) > 1: |
| + print 'More than one target matches "%s": %s' % ( |
| + substring, ' '.join(candidates)) |
| + sys.exit(1) |
| + return candidates[0] |
| + |
| + |
| +if __name__ == '__main__': |
|
M-A Ruel
2011/11/23 20:06:30
Use a main()
Nico
2011/11/23 20:12:07
Done.
|
| + # Check that dump.json exists and that it's not too old. |
| + dump_json_dirty = False |
| + try: |
| + st = os.stat('dump.json') |
| + file_age_s = time.time() - st.st_mtime |
| + if file_age_s > 2 * 60 * 60: |
| + print 'dump.json is more than 2 hours old.' |
| + dump_json_dirty = True |
| + except IOError: |
| + print 'dump.json not found.' |
| + dump_json_dirty = True |
| + |
| + if dump_json_dirty: |
| + print 'Run' |
| + print ' GYP_GENERATORS=dump_dependency_json build/gyp_chromium' |
| + print 'first, then try again.' |
| + sys.exit(1) |
| + |
| + g = json.load(open('dump.json')) |
| + |
| + if len(sys.argv) != 3: |
| + usage() |
| + sys.exit(1) |
| + |
| + fro = MatchNode(g, sys.argv[1]) |
| + to = MatchNode(g, sys.argv[2]) |
| + |
| + paths = list(GetPath(g, fro, to, get_all=True)) |
| + if len(paths) > 0: |
| + 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) |