2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 """Prints paths between gyp targets.
14 from collections
import deque
19 tools/gyp-explain.py chrome_dll# gtest#
23 def GetPath(graph
, fro
, to
):
24 """Given a graph in (node -> list of successor nodes) dictionary format,
25 yields all paths from |fro| to |to|, starting with the shortest."""
26 # Storing full paths in the queue is a bit wasteful, but good enough for this.
27 q
= deque([(fro
, [])])
33 q
.append((d
, path
+ [t
]))
36 def MatchNode(graph
, substring
):
37 """Given a dictionary, returns the key that matches |substring| best. Exits
38 if there's not one single best match."""
41 if substring
in target
:
42 candidates
.append(target
)
45 print 'No targets match "%s"' % substring
47 if len(candidates
) > 1:
48 print 'More than one target matches "%s": %s' % (
49 substring
, ' '.join(candidates
))
55 # Check that dump.json exists and that it's not too old.
56 dump_json_dirty
= False
58 st
= os
.stat('dump.json')
59 file_age_s
= time
.time() - st
.st_mtime
60 if file_age_s
> 2 * 60 * 60:
61 print 'dump.json is more than 2 hours old.'
62 dump_json_dirty
= True
64 print 'dump.json not found.'
65 dump_json_dirty
= True
69 print ' GYP_GENERATORS=dump_dependency_json build/gyp_chromium'
70 print 'first, then try again.'
73 g
= json
.load(open('dump.json'))
79 fro
= MatchNode(g
, argv
[1])
80 to
= MatchNode(g
, argv
[2])
82 paths
= list(GetPath(g
, fro
, to
))
84 print 'These paths lead from %s to %s:' % (fro
, to
)
86 print ' -> '.join(path
)
88 print 'No paths found from %s to %s.' % (fro
, to
)
91 if __name__
== '__main__':