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

Side by Side Diff: tools/gyp-explain.py

Issue 8672006: Add a small tool to answer questions like "Why does target A depend on target B". (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ... Created 9 years 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2
3 # Copyright (c) 2011 Google Inc. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
7 """Prints paths between gyp targets.
8 """
9
10 import json
11 import os
12 import sys
13 import time
14
15 from collections import deque
16
17 def usage():
18 print """\
19 Usage:
20 tools/gyp-explain.py chrome_dll gtest#
21 """
22
23
24 def GetPath(graph, fro, to):
25 """Given a graph in (node -> list of successor nodes) dictionary format,
26 yields all paths from |fro| to |to|, starting with the shortest."""
27 # Storing full paths in the queue is a bit wasteful, but good enough for this.
28 q = deque([(fro, [])])
29 while len(q) > 0:
viettrungluu 2011/11/23 20:30:40 nit: |while q:|
Nico 2011/11/23 20:33:01 Done.
30 t, path = q.popleft()
31 if t == to:
32 yield path + [t]
33 for d in graph[t]:
34 q.append((d, path + [t]))
35
36
37 def MatchNode(graph, substring):
38 """Given a dictionary, returns the key that matches |substring| best. Exits
39 if there's not one single best match."""
40 candidates = []
41 for target in graph:
42 if substring in target:
43 candidates.append(target)
44
45 if not candidates:
46 print 'No targets match "%s"' % substring
47 sys.exit(1)
48 if len(candidates) > 1:
49 print 'More than one target matches "%s": %s' % (
50 substring, ' '.join(candidates))
51 sys.exit(1)
M-A Ruel 2011/11/23 20:35:57 I didn't mean to remove the calls in this function
52 return candidates[0]
53
54
55 def Main(argv):
56 # Check that dump.json exists and that it's not too old.
57 dump_json_dirty = False
58 try:
59 st = os.stat('dump.json')
60 file_age_s = time.time() - st.st_mtime
61 if file_age_s > 2 * 60 * 60:
62 print 'dump.json is more than 2 hours old.'
63 dump_json_dirty = True
64 except IOError:
65 print 'dump.json not found.'
66 dump_json_dirty = True
67
68 if dump_json_dirty:
69 print 'Run'
70 print ' GYP_GENERATORS=dump_dependency_json build/gyp_chromium'
71 print 'first, then try again.'
72 sys.exit(1)
73
74 g = json.load(open('dump.json'))
75
76 if len(argv) != 3:
77 usage()
78 sys.exit(1)
79
80 fro = MatchNode(g, argv[1])
81 to = MatchNode(g, argv[2])
82
83 paths = list(GetPath(g, fro, to))
84 if len(paths) > 0:
85 print 'These paths lead from %s to %s:' % (fro, to)
86 for path in paths:
87 print ' -> '.join(path)
88 else:
89 print 'No paths found from %s to %s.' % (fro, to)
90
91
92 if __name__ == '__main__':
93 Main(sys.argv)
OLDNEW
« 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