]> git.proxmox.com Git - debcargo-conf.git/blob - dev/list-rdeps.sh
ssh2 - new upstream release.
[debcargo-conf.git] / dev / list-rdeps.sh
1 #!/bin/bash
2 #
3 # Envvars:
4 # INST_CACHE
5 # If running this script multiple times, set this to a path where we will
6 # write data to be re-used next time. This makes the script slightly
7 # quicker, but if the data is too old it will give inaccurate results.
8
9 set -e
10 shopt -s lastpipe # important for populating associative arrays via pipes
11
12 abort() { local x=$1; shift; for i in "$@"; do echo >&2 "$0: abort: $i"; done; exit "$x"; }
13
14 type grep-dctrl >/dev/null || abort 1 "grep-dctrl not found, install dctrl-tools"
15 type aptitude >/dev/null || abort 1 "aptitude not found, install it"
16 type gawk >/dev/null || abort 1 "gawk not found, install gawk"
17
18 ARCHIVE="${ARCHIVE:-unstable}"
19 ARCHIVT="${ARCHIVT:-testing}"
20
21 grep_sources_entry() {
22 grep '^deb[^#]*://[^#[:space:]]*[[:space:]]*'"$@"
23 }
24
25 if ! grep_sources_entry "$ARCHIVE" -qR /etc/apt/sources.list /etc/apt/sources.list.d/ || \
26 ! grep_sources_entry "$ARCHIVT" -qR /etc/apt/sources.list /etc/apt/sources.list.d/; then
27 cat <<-eof
28 To make this script work, you will need Debian Testing *AND* Debian Unstable
29 in your sources.list. If you want your system to prefer Debian Testing, be
30 sure to also add these lines to your /etc/apt/apt.conf:
31
32 APT::Default-Release "$ARCHIVT";
33
34 After these changes, make sure to re-run \`apt-get update\`.
35 eof
36 exit 1
37 fi
38
39 if [ $(($(date +%s) - $(stat -c %Y /var/cache/apt/pkgcache.bin))) -gt 7200 ]; then
40 read -p "APT cache is a bit old, update? [Y/n] " x
41 if [ "$x" != "n" ]; then sudo apt update; fi
42 fi
43
44 apt_versions() {
45 aptitude versions --disable-columns -F '%e %p %t' --group-by=none "~rnative $1" || true
46 }
47
48 all_rust_packages="$(apt_versions "~e^rust-")"
49 quick_apt_versions() {
50 printf "%s\n" "$all_rust_packages" | gawk "\$1 ~ /$1/ && \$2 ~ /$2/ && \$3 ~ /$3/ && \$4 ~ /$4/ { ${5:-print} }"
51 }
52
53 # versions of source packages in unstable. used to ignore cruft (i.e. binary
54 # packages left over in unstable after an update, no longer built by a source)
55 declare -A srcver
56 src_version() {
57 local src="$1"
58 if [ -z "${srcver[$src]}" ]; then
59 srcver["$src"]="$(quick_apt_versions "" "^librust-${src}-dev$" "" "\y$ARCHIVE\y" 'print $3')"
60 fi
61 echo "${srcver[$src]}"
62 }
63
64 if [ -n "$INST_CACHE" ]; then
65 inst_cache="$INST_CACHE"
66 else
67 inst_cache=$(mktemp)
68 # https://stackoverflow.com/a/14812383 inside "trap" avoids running handler twice
69 trap 'excode=$?; rm -rf "'"$inst_cache"'"; trap - EXIT' EXIT HUP INT QUIT PIPE TERM
70 fi
71
72 installability() {
73 local r=$(grep -F "$1=$2" "$inst_cache" | cut -f2)
74 if [ -n "$r" ]; then
75 echo "$r"
76 else
77 if apt -t "$ARCHIVE" -s install "$1=$2" 2>/dev/null >/dev/null; then
78 r=" "
79 else
80 r="X"
81 fi
82 printf "%s=%s\t%s\n" "$1" "$2" "$r" >> "$inst_cache"
83 echo "$r"
84 fi
85 }
86
87 # variables for BFS over rdeps
88 declare -A seen
89 declare -a queue
90
91 list_rdeps() {
92 pkg="${1//_/-}"
93 pkg="${pkg#rust-}"
94 declare -a binpkgs
95
96 echo "Versions of rust-${pkg} in $ARCHIVE:"
97 quick_apt_versions "^rust-${pkg}$" "" "" "\y$ARCHIVE\y" | sort | while read srcpkg binpkg ver archive; do
98 if [ "$ver" != "$(src_version "$pkg")" ]; then continue; fi
99 local stat="$(installability "$binpkg" "$ver")"
100 printf "%s %-48s %-16s\n" "$stat" "$binpkg" "$ver"
101 binpkgs+=("$binpkg=$ver")
102 done
103 echo
104
105 echo "Versions of rdeps of rust-${pkg} in $ARCHIVE, that also exist in $ARCHIVT:"
106 local rdeps="$(apt_versions "~D^librust-${pkg}~(\+~|-[0-9]~).*-dev$")"
107 printf "%s\n" "$rdeps" | grep "$ARCHIVE" | while read src rdep ver archive; do
108 # we're interested in packages in both archives.
109 if ! printf "%s\n" "$rdeps" | grep "$ARCHIVT" | grep -qF "$rdep"; then
110 local rdepv="$(echo "$rdep" | sed -E -e 's/-[0-9.]+-dev$/-dev/')"
111 # we're also interested in old-semver packages where the main version is in testing,
112 # since this implies that we're interested in trying to migrate the old-semver package
113 if ! printf "%s\n" "$rdeps" | grep "$ARCHIVT" | grep -qF "$rdepv"; then
114 # if a rdep matches none of these, we're not interested (at this time) in migrating them;
115 # they will show up on `dev/rust-excuses.mk` later in a more obvious way
116 continue
117 fi
118 fi
119 apt-cache show "${rdep}=${ver}" \
120 | grep-dctrl -FDepends -e "librust-${pkg}(\+|-[0-9]).*-dev" -sPackage,Version,Depends - \
121 | cut -d: -f2 | cut '-d ' -f2- \
122 | sed -z -e 's/\n\n/\t/g' -e 's/\n/ /g' -e 's/\t/\n/g'
123 done | sort | while read rdep ver deps; do
124 local src="$(apt-cache show "$rdep=$ver" | grep-dctrl -n -sSource - | sed -Ee 's/^rust-(\S*).*/\1/g')"
125 if [ -n "$src" ] && [ -z "${seen[$src]}" ]; then
126 seen["$src"]="1"
127 queue+=("$src") # subprocess, var doesn't write to parent
128 fi
129 if [ "$ver" != "$(src_version "$src")" ]; then continue; fi
130 local rustdeps="$(printf "%s" "$deps" | tr ',' '\n' | grep -E -wo "librust-${pkg}(\+|-[0-9])\S*-dev[^,]*" | tr '\n' '\t' | sed -e 's/\t/, /g')"
131 local stat="$(installability "$rdep" "$ver")"
132 printf "%s %-48s %-16s depends on %s\n" "$stat" "$rdep" "$ver" "$rustdeps"
133 done
134 echo
135
136 echo "Source packages in unstable whose autopkgtests are triggered by rust-$pkg:"
137 while [ -n "${binpkgs[0]}" ]; do
138 local binver="${binpkgs[0]}"
139 binpkgs=("${binpkgs[@]:1}")
140
141 local binpkg="${binver/=*/}"
142 binpkg="$(apt-cache show "$binver" | grep-dctrl -F Package -ns Package -s Provides -e "${binpkg//\+/\\+}" | tr '\n' '|' | sed -e 's/ \+\(([^)]*)\)\?,\? */|/g' -e 's/+/\\+/g' -e 's/|\+$//g' -e 's/|{2,}/|/g')"
143 # check for bin package + all its provided virtual feature packages in one go
144 grep-dctrl -F Testsuite-Triggers -s Package,Version -w "$binpkg" /var/lib/apt/lists/*_dists_"$ARCHIVE"_*_source_Sources* \
145 | cut -d: -f2 | cut '-d ' -f2- \
146 | sed -z -e 's/\n\n/\t/g' -e 's/\n/ /g' -e 's/\t/\n/g' \
147 | while read triggered ver; do
148 printf " %-48s %-16s triggered by %s\n" "$triggered" "$ver" "$binver"
149 done
150 done
151 echo
152 }
153
154 if [ "$1" = "@" ]; then
155 shift
156 queue+=("$@")
157 while [ -n "${queue[0]}" ]; do
158 echo "queue: ${queue[@]}"
159 src="${queue[0]}"
160 seen["$src"]="1"
161 queue=("${queue[@]:1}")
162 list_rdeps "$src"
163 done
164 else
165 for i in "$@"; do list_rdeps "$i"; done
166 fi
167
168 cat <<eof
169 If any package is marked "X" (to the left of the package) it means it is not
170 installable even in $ARCHIVE - you should check why this is so by attempting to
171 install it yourself, e.g. via aptitude, and see why it can't be installed. This
172 must be fixed before migration is attempted. For example, it may depend on a
173 package which is not yet in Debian. Make sure you give the \`-t $ARCHIVE\` flag
174 so it chooses packages from the correct archive.
175
176 One common reason, for an rdep, is that its dependency is out of date - check
177 the "depends" column above to see if this is the case. If so, you must upgrade
178 it to the current version, by patching Cargo.toml to accept the new version of
179 the dependency. Of course, check that the build works - if it doesn't, then
180 you'll need to further patch the source code of the rdep to use the API of the
181 new version of the dependency.
182
183 Alternatively, if any rdep is obsolete (i.e. nothing else depends on it) then
184 you should file a RM request to remove it from the Debian archive. See the
185 section "Remove an obsolete package" in RELEASE.rst for instructions on that.
186 eof