1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
11 BASE_DIR
= os
.path
.dirname(os
.path
.abspath(__file__
))
15 if len(sys
.argv
) != 2:
16 print 'usage: %s <output.html>' % sys
.argv
[0]
18 env
= os
.environ
.copy()
19 env
['GYP_GENERATORS'] = 'dump_dependency_json'
20 print 'Dumping dependencies...'
21 popen
= subprocess
.Popen(
22 ['python', 'build/gyp_chromium'],
25 if popen
.returncode
!= 0:
26 return popen
.returncode
27 print 'Finding problems...'
28 popen
= subprocess
.Popen(
29 ['python', 'tools/gyp-explain.py', '--dot',
30 'chrome.gyp:browser#', 'core.gyp:webcore#'],
31 stdout
=subprocess
.PIPE
,
33 out
, _
= popen
.communicate()
34 if popen
.returncode
!= 0:
35 return popen
.returncode
37 # Break into pairs to uniq to make graph less of a mess.
38 print 'Simplifying...'
40 lines
= out
.splitlines()[2:-1]
42 line
= line
.strip('\r\n ;')
43 pairs
= line
.split(' -> ')
44 for i
in range(len(pairs
) - 1):
45 deduplicated
.add('%s -> %s;' % (pairs
[i
], pairs
[i
+ 1]))
46 graph
= 'strict digraph {\n' + '\n'.join(sorted(deduplicated
)) + '\n}'
48 print 'Writing report to %s...' % sys
.argv
[1]
49 path_count
= len(out
.splitlines())
50 with
open(os
.path
.join(BASE_DIR
, 'viz.js', 'viz.js')) as f
:
52 with
open(sys
.argv
[1], 'w') as f
:
53 f
.write(PREFIX
% path_count
)
55 f
.write(SUFFIX
% viz_js
)
59 PREFIX
= r
'''<!DOCTYPE html>
62 <meta charset="utf-8">
63 <title>Undesirable Dependencies</title>
66 <h1>Undesirable Dependencies</h1>
67 <h2>browser → webcore</h2>
69 <script type="text/vnd.graphviz" id="graph">
76 <div id="output">Rendering...</div>
78 setTimeout(function() {
79 document.getElementById("output").innerHTML =
80 Viz(document.getElementById("graph").innerHTML, "svg");
88 if __name__
== '__main__':