forked from scottellis/oe-deptools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oey.py
executable file
·274 lines (195 loc) · 5.62 KB
/
oey.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#!/usr/bin/env python
import sys, getopt
# keyed by package-name, contains the list of package dependencies
pn = {}
# keyed by package-name, contains the list of dependent packages
rev_pn = {}
show_parent_deps = False
show_verbose_messages = False
indent_str = '\t'
def parse_pn_depends():
try:
fh = open('pn-depends.dot')
except:
print 'File pn-depends.dot not found'
print 'Generate the file with bitbake -g <recipe>'
sys.exit()
try:
raw_lines = fh.read().splitlines()
finally:
fh.close()
for line in raw_lines:
line = line.rstrip()
fields = line.split(' ')
if len(fields) < 3 or fields[1] != '->':
continue
if len(fields) == 3:
name = fields[0][1:-1]
depend = fields[2][1:-1]
if not pn.has_key(name):
pn[name] = []
pn[name].append(depend)
elif len(fields) == 4:
if fields[0] == fields[2]:
continue
name = fields[0][1:-1]
depend = fields[2][1:-1]
if pn.has_key(depend) and name in pn[depend]:
if show_verbose_messages:
print '\n*** Found loop dependency'
print '\t', name, '->', depend
print '\t', depend, '->', name, '\n'
continue
if not pn.has_key(name):
pn[name] = []
pn[name].append(depend)
elif not depend in pn[name]:
pn[name].append(depend)
def build_reverse_dependencies():
for key in pn:
for name in pn[key]:
if not rev_pn.has_key(name):
rev_pn[name] = []
rev_pn[name].append(key)
def list_packages():
for key in sorted(pn):
print key
print '\n',
def list_deps_recurse(package, parent_deps, depth, max_depth):
if depth > max_depth:
return;
if pn.has_key(package):
tab_str = indent_str * depth
for dep in sorted(pn[package]):
if show_parent_deps or dep not in parent_deps:
print tab_str, dep
list_deps_recurse(dep, pn[package], depth + 1, max_depth)
def list_deps(package, max_depth):
if pn.has_key(package):
print '\nPackage [', package, '] depends on'
list_deps_recurse(package, (), 1, max_depth)
elif rev_pn.has_key(package):
print 'Package [', package, '] has no dependencies'
else:
print 'Package [', package, '] not found'
print '\n',
def list_reverse_deps_recurse(package, depth, max_depth):
if depth > max_depth:
return;
if rev_pn.has_key(package):
tab_str = indent_str * depth
for dep in sorted(rev_pn[package]):
print tab_str, dep
list_reverse_deps_recurse(dep, depth + 1, max_depth)
def list_reverse_deps(package, max_depth):
if rev_pn.has_key(package):
print '\nPackage [', package, '] is needed by'
list_reverse_deps_recurse(package, 1, max_depth)
elif pn.has_key(package):
print 'No package depends on [', package, ']'
else:
print 'Package [', package, '] not found'
print '\n',
def collect_deps_flat(src, d, package, depth, max_depth):
if depth > max_depth:
return;
if src.has_key(package):
for dep in src[package]:
if dep not in d:
d.append(dep)
collect_deps_flat(src, d, dep, depth + 1, max_depth)
def list_deps_flat(package, max_depth):
d = []
if pn.has_key(package):
for dep in pn[package]:
if dep not in d:
d.append(dep)
collect_deps_flat(pn, d, dep, 2, max_depth)
print '\nPackage [', package, '] depends on'
for dep in sorted(d):
print '\t', dep
elif rev_pn.has_key(package):
print 'Package [', package, '] has no dependencies'
else:
print 'Package [', package, '] not found'
print '\n',
def list_reverse_deps_flat(package, max_depth):
d = []
if rev_pn.has_key(package):
for dep in rev_pn[package]:
if dep not in d:
d.append(dep)
collect_deps_flat(rev_pn, d, dep, 2, max_depth)
print '\nPackage [', package, '] is needed by'
for dep in sorted(d):
print '\t', dep
elif pn.has_key(package):
print 'No package depends on [', package, ']'
else:
print 'Package [', package, '] not found'
print '\n',
def usage():
print '\nUsage: %s [options] [package]\n' % (sys.argv[0])
print 'Displays OE build dependencies for a given package or recipe.'
print 'Uses the pn-depends.dot file for its raw data.'
print 'Generate a pn-depends.dot file by running bitbake -g <recipe>.\n'
print 'Options:'
print '-h\tShow this help message and exit'
print '-v\tShow error messages such as recursive dependencies'
print '-r\tShow reverse dependencies, i.e. packages dependent on package'
print '-f\tFlat output instead of default tree output'
print '-d <depth>\tMaximum depth to follow dependencies, default and max is 10'
print '-s\tShow child package dependencies that are already listed'
print '\tas direct parent dependencies.\n'
print "Provide a package name from the generated pn-depends.dot file."
print 'Run the program without a package name to get a list of'
print 'available package names.\n'
if __name__ == '__main__':
try:
opts, args = getopt.getopt(sys.argv[1:], 'hvrfd:s')
except getopt.GetoptError, err:
print str(err)
usage()
sys.exit(2)
depth = 10
reverse = False
flat = False
for o, a in opts:
if o in ('-h'):
usage()
sys.exit()
elif o in ('-v'):
show_verbose_messages = True
elif o in ('-r'):
reverse = True
elif o in ('-f'):
flat = True
elif o in ('-s'):
show_parent_deps = True
elif o in ('-d'):
try:
depth = int(a, 10)
except ValueError:
print 'Bad depth argument: ', a
usage()
sys.exit(1)
else:
assert False, 'unhandled option'
if depth > 10:
print 'Limiting depth to 10 levels'
depth = 10
parse_pn_depends()
build_reverse_dependencies()
if len(args) > 0:
if reverse:
if flat:
list_reverse_deps_flat(args[0], depth)
else:
list_reverse_deps(args[0], depth)
else:
if flat:
list_deps_flat(args[0], depth)
else:
list_deps(args[0], depth)
else:
list_packages()