blob: c836bfc2d8658c55eac4ab767696ac422365ea72 (
plain)
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
|
#!/bin/bash
# first, reduce the deptree
deptree="$(cat "$1")"
while grep -q '\[ *\]' <<< "$deptree"; do
pkg=$(grep '\[ *\]' <<< "$deptree" | head -n1 | awk '{print $1}')
echo "consuming pkg: $pkg"
deptree="$(sed "/^$pkg :/d; s/ / /g; s/ $pkg / /g; s/ ${pkg%-breakdeps} / /g; s/ */ /g" <<< "$deptree")"
done
printf "%s" "$deptree" > DEPTREE.reduced
echo "unresolved pkgs: $(wc -l < DEPTREE.reduced)"
read -r -d '' CMD << 'EOF'
import sys
import networkx as nx
import itertools
graph = nx.DiGraph()
with open(sys.argv[1]) as deptree:
for line in deptree:
line = line.split('#')[0]
lhs, rhs = line.split(':')
lhs = lhs.strip()
rhs = rhs.lstrip(' [').rstrip('] ')
graph.add_node(lhs)
for dep in rhs.split():
if not dep in graph:
graph.add_node(dep)
graph.add_edge(lhs, dep)
cycles=nx.simple_cycles(graph)
for cycle in cycles:
print(cycle)
EOF
echo "crunching cycles... (press CTRL-C to stop)"
# second, find cycles (sample for up to 5 seconds)
python -c "$CMD" DEPTREE.reduced > DEPTREE.cycles
echo "found cycles: $(wc -l < DEPTREE.cycles)"
echo "collecting stats..."
# third, count occurrences of pkgnames in the cycles
for pkg in $(awk '{print $1}' < DEPTREE.reduced); do
count=$(grep "'$pkg'" DEPTREE.cycles | wc -l)
[ $count -gt 0 ] && echo "$pkg: $count"
done | sort -rgk2 > DEPTREE.stats
echo "all done."
|