list-rdeps: hide cruft packages
Ximin Luo
3 years ago
0 | 0 | #!/bin/bash |
1 | 1 | |
2 | 2 | set -e |
3 | shopt -s lastpipe # important for populating associative arrays via pipes | |
3 | 4 | |
4 | 5 | abort() { local x=$1; shift; for i in "$@"; do echo >&2 "$0: abort: $i"; done; exit "$x"; } |
5 | 6 | |
32 | 33 | aptitude versions --disable-columns -F '%p %t' --group-by=none "~rnative $1" || true |
33 | 34 | } |
34 | 35 | |
36 | # versions of source packages in unstable. used to ignore cruft (i.e. binary | |
37 | # packages left over in unstable after an update, no longer built by a source) | |
38 | declare -A srcver | |
39 | src_version() { | |
40 | local src="$1" | |
41 | if [ -z "${srcver[$src]}" ]; then | |
42 | srcver["$src"]="$(apt_versions "librust-${src}-dev" | grep "$ARCHIVE" | cut '-d ' -f2)" | |
43 | fi | |
44 | echo "${srcver[$src]}" | |
45 | } | |
46 | ||
35 | 47 | if [ -n "$INST_CACHE" ]; then |
36 | 48 | inst_cache="$INST_CACHE" |
37 | 49 | else |
58 | 70 | # variables for BFS over rdeps |
59 | 71 | declare -A seen |
60 | 72 | declare -a queue |
61 | shopt -s lastpipe | |
62 | 73 | |
63 | 74 | list_rdeps() { |
64 | 75 | pkg="${1//_/-}" |
66 | 77 | |
67 | 78 | echo "Versions of rust-${pkg} in $ARCHIVE:" |
68 | 79 | apt_versions "~e^rust-${pkg}$" | grep "$ARCHIVE" | sort | while read binpkg ver archive; do |
80 | if [ "$ver" != "$(src_version "$pkg")" ]; then continue; fi | |
69 | 81 | local stat="$(installability "$binpkg" "$ver")" |
70 | 82 | printf "%s %-48s %-16s\n" "$stat" "$binpkg" "$ver" |
71 | 83 | done |
72 | 84 | echo |
73 | 85 | |
74 | 86 | echo "Versions of rdeps of rust-${pkg} in $ARCHIVE, that also exist in $ARCHIVT:" |
75 | local versions="$(apt_versions "~D^librust-${pkg}~(\+~|-[0-9]~).*-dev$")" | |
76 | printf "%s\n" "$versions" | grep "$ARCHIVE" | while read rdep ver archive; do | |
87 | local rdeps="$(apt_versions "~D^librust-${pkg}~(\+~|-[0-9]~).*-dev$")" | |
88 | printf "%s\n" "$rdeps" | grep "$ARCHIVE" | while read rdep ver archive; do | |
77 | 89 | # we're interested in packages in both archives. |
78 | if ! printf "%s\n" "$versions" | grep "$ARCHIVT" | grep -qF "$rdep"; then | |
90 | if ! printf "%s\n" "$rdeps" | grep "$ARCHIVT" | grep -qF "$rdep"; then | |
79 | 91 | local rdepv="$(echo "$rdep" | sed -E -e 's/-[0-9.]+-dev$/-dev/')" |
80 | 92 | # we're also interested in old-semver packages where the main version is in testing, |
81 | 93 | # since this implies that we're interested in trying to migrate the old-semver package |
82 | if ! printf "%s\n" "$versions" | grep "$ARCHIVT" | grep -qF "$rdepv"; then | |
94 | if ! printf "%s\n" "$rdeps" | grep "$ARCHIVT" | grep -qF "$rdepv"; then | |
83 | 95 | # if a rdep matches none of these, we're not interested (at this time) in migrating them; |
84 | 96 | # they will show up on `dev/rust-excuses.mk` later in a more obvious way |
85 | 97 | continue |
90 | 102 | | cut -d: -f2 | cut '-d ' -f2- \ |
91 | 103 | | sed -z -e 's/\n\n/\t/g' -e 's/\n/ /g' -e 's/\t/\n/g' |
92 | 104 | done | sort | while read rdep ver deps; do |
93 | local rustdeps="$(printf "%s" "$deps" | tr ',' '\n' | egrep -wo "librust-${pkg}(\+|-[0-9])\S*-dev[^,]*" | tr '\n' '\t' | sed -e 's/\t/, /g')" | |
94 | local stat="$(installability "$rdep" "$ver")" | |
95 | printf "%s %-48s %-16s depends on %s\n" "$stat" "$rdep" "$ver" "$rustdeps" | |
96 | 105 | local src="$(apt-cache show "$rdep=$ver" | grep-dctrl -n -sSource - | sed -Ee 's/^rust-(\S*).*/\1/g')" |
97 | 106 | if [ -n "$src" ] && [ -z "${seen[$src]}" ]; then |
98 | 107 | seen["$src"]="1" |
99 | 108 | queue+=("$src") # subprocess, var doesn't write to parent |
100 | 109 | fi |
110 | if [ "$ver" != "$(src_version "$src")" ]; then continue; fi | |
111 | local rustdeps="$(printf "%s" "$deps" | tr ',' '\n' | egrep -wo "librust-${pkg}(\+|-[0-9])\S*-dev[^,]*" | tr '\n' '\t' | sed -e 's/\t/, /g')" | |
112 | local stat="$(installability "$rdep" "$ver")" | |
113 | printf "%s %-48s %-16s depends on %s\n" "$stat" "$rdep" "$ver" "$rustdeps" | |
101 | 114 | done |
102 | 115 | echo |
103 | 116 | } |