author | MattD <mattd@symbian.org> |
Sun, 13 Jun 2010 20:39:03 +0100 | |
branch | DBRToolsDev |
changeset 285 | 6a928cf9e181 |
parent 5 | 842a773e65f2 |
permissions | -rw-r--r-- |
5
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
1 |
# Copyright (c) 2009 Symbian Foundation Ltd |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
2 |
# This component and the accompanying materials are made available |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
3 |
# under the terms of the License "Eclipse Public License v1.0" |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
4 |
# which accompanies this distribution, and is available |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
5 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html". |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
6 |
# |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
7 |
# Initial Contributors: |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
8 |
# Symbian Foundation Ltd - initial contribution. |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
9 |
# |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
10 |
# Contributors: |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
11 |
# |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
12 |
# Description: |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
13 |
# Walk all nodes in the dependency graph to create a dependency report. |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
14 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
15 |
"""Walk a dependency graph to find dependencies for a particular set of |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
16 |
components. This script uses the output of build_graph.py to trace |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
17 |
dependencies. |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
18 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
19 |
The directory_list refer to diretories in the source tree for which |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
20 |
you wish to trace dependencies. The script will find all components |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
21 |
in the graph file under these directories and trace dependencies from |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
22 |
that point. |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
23 |
""" |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
24 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
25 |
from optparse import OptionParser |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
26 |
from _common import Node |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
27 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
28 |
import sys |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
29 |
import pickle |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
30 |
import logging |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
31 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
32 |
__author__ = 'James Aley' |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
33 |
__email__ = 'jamesa@symbian.org' |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
34 |
__version__ = '1.0' |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
35 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
36 |
_LOG_FORMAT = '%(levelname)s: %(message)s' |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
37 |
logging.basicConfig(format=_LOG_FORMAT, level=logging.WARNING, stream=sys.stdout) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
38 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
39 |
# Internalized graph object |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
40 |
graph = {} |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
41 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
42 |
# Report formatting |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
43 |
_REPORT_HEADER = """// Generated by get_deps.py |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
44 |
// |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
45 |
// Dependency information for: |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
46 |
// |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
47 |
%s |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
48 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
49 |
""" |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
50 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
51 |
_DEPENDENCY_FORMAT = """ |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
52 |
// Required components: |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
53 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
54 |
%s |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
55 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
56 |
""" |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
57 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
58 |
_MISSING_FORMAT = """ |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
59 |
// The following binary objects were referenced from the build files for |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
60 |
// components required by your specified root components. However, there |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
61 |
// were no build files for these objects found in the source tree parsing, |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
62 |
// so dependencies for them may be missing in the above listing. |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
63 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
64 |
%s |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
65 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
66 |
""" |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
67 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
68 |
def load_graph(path): |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
69 |
"""Return the internalized graph dictionary object. |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
70 |
""" |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
71 |
graph_file = None |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
72 |
graph_loaded = {} |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
73 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
74 |
try: |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
75 |
graph_file = open(path, 'rb') |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
76 |
except IOError, e: |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
77 |
logging.critical('Unable to open graph from file: %s: %s' % (path, repr(e))) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
78 |
exit(1) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
79 |
try: |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
80 |
graph_loaded = pickle.load(graph_file) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
81 |
except Exception, e: |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
82 |
logging.critical('File %s does not contain a valid graph: %s' % (path, repr(e))) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
83 |
return graph_loaded |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
84 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
85 |
def find_roots(root_dirs): |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
86 |
"""Return a list of root nodes from the graph for tracing, based on |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
87 |
the specified component directories in the root_dirs list. |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
88 |
""" |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
89 |
roots = [] |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
90 |
for root in root_dirs: |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
91 |
for node in graph.keys(): |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
92 |
if node.startswith(root.lower()): |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
93 |
if node not in roots: |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
94 |
roots.append(node) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
95 |
return roots |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
96 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
97 |
def trace(root, visited = set()): |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
98 |
"""Return a list of components required to support root. |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
99 |
""" |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
100 |
node = graph[root] |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
101 |
visited |= set([node.node_path]) | set(node.dependencies) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
102 |
for dep in node.dependencies: |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
103 |
if dep not in visited: |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
104 |
return trace(dep, visited) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
105 |
return visited |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
106 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
107 |
def unresolved(deps): |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
108 |
"""Return a set of components with unknown dependencies from a |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
109 |
provided list of node names. |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
110 |
""" |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
111 |
unresolved = set() |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
112 |
for dep in deps: |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
113 |
node = graph[dep] |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
114 |
unresolved |= set(node.unresolved) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
115 |
return unresolved |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
116 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
117 |
def report(out_path, roots, dependencies, missing): |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
118 |
"""Output the dependency information to file. |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
119 |
""" |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
120 |
# open report file |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
121 |
out_file = None |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
122 |
try: |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
123 |
out_file = open(out_path, 'w') |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
124 |
except IOError, e: |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
125 |
logging.critical('Unable to write report: %s' % (repr(e))) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
126 |
exit(1) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
127 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
128 |
# easier to read report with these sorted |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
129 |
roots.sort() |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
130 |
dependencies.sort() |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
131 |
missing.sort() |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
132 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
133 |
# format report |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
134 |
formatted_header = _REPORT_HEADER % ('\n'.join(['// %s' % (line, ) for line in roots]), ) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
135 |
formatted_body = _DEPENDENCY_FORMAT % ('\n'.join(dependencies)) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
136 |
formatted_missing = _MISSING_FORMAT % ('\n'.join(['// %s' % (line, ) for line in missing]), ) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
137 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
138 |
# write report |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
139 |
out_file.write(formatted_header) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
140 |
out_file.write(formatted_body) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
141 |
out_file.write(formatted_missing) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
142 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
143 |
out_file.close() |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
144 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
145 |
if __name__ == '__main__': |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
146 |
# Options config |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
147 |
parser = OptionParser() |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
148 |
parser.set_description(__doc__) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
149 |
parser.set_usage('python get_deps.py [options] directory_list') |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
150 |
parser.add_option('-g', '--graph', dest='graph_file', |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
151 |
help='File name to write the graph to.', |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
152 |
metavar='GRAPH_FILE', default='dependencies.graph') |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
153 |
parser.add_option('-o', '--output', dest='output_file', |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
154 |
help='File to write the dependency report to.', |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
155 |
metavar='OUT_FILE', default='dependencies.txt') |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
156 |
(options, args) = parser.parse_args() |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
157 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
158 |
# Intenalize the graph file |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
159 |
print 'Loading graph from %s' % (options.graph_file, ) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
160 |
graph = load_graph(options.graph_file) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
161 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
162 |
# Extract relevant slices and merge dependencies |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
163 |
roots = find_roots(args) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
164 |
print 'Tracing dependencies for %d components under %s' % (len(roots), ', '.join(args)) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
165 |
deps = set() |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
166 |
for root in roots: |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
167 |
deps |= trace(root) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
168 |
print 'Dependency graph slice yields %d of %d components.' % (len(deps), len(graph)) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
169 |
unresolved_deps = unresolved(deps) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
170 |
print 'Component dependencies for %d binaries are unresolved' % (len(unresolved_deps, )) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
171 |
|
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
172 |
# Write the report to the output file |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
173 |
report(options.output_file, roots, list(deps), list(unresolved_deps)) |
842a773e65f2
Adding some dependency analysis scripts
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
174 |
print 'Report written to: %s' % (options.output_file, ) |