Skip to content

Commit b414110

Browse files
committed
Add greposcope: script for downloading and searching pattern in diffoscope output of unreproducible packages
> Usage: greposcope [OPTIONS] pattern > > Download and search for 'pattern' in diffoscope outputs of every unreproducible packages reported at https://reproducible.archlinux.org. > This is useful to identify packages that are unreproducible because of a specific issue. > > OPTIONS > -h, --help Show this message > -i, --ignore-case Ignore case distinctions in patterns and input data > > Examples: > $ greposcope "gzip compressed data" > $ greposcope -i zipinfo Diffoscope outputs are downloaded under `${TMPDIR:-/tmp}/greposcope-${UID}"`. Only diffoscope outputs that haven't been downloaded yet (as in, not found in `${TMPDIR:-/tmp}/greposcope-${UID}"`) are downloaded, so only the first run of the script downloads "world" (so we don't make a huge amount of requests to our `rebuilderd` instance at each run). Tasks are parallelized to reduce execution time. Dependencies: `rebuilderd-tools` & `parallel`
1 parent 0095ad7 commit b414110

File tree

2 files changed

+90
-1
lines changed

2 files changed

+90
-1
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ BASH_SCRIPTS = \
1010
package/parse-submodules \
1111
package/pkgsearch \
1212
package/rebuild-todo \
13-
package/pkggrep
13+
package/pkggrep \
14+
package/greposcope
1415

1516
PYTHON_SCRIPTS = \
1617
package/staging2testing \

package/greposcope

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/bin/bash
2+
3+
# SPDX-License-Identifier: GPL-2.0
4+
5+
# Dependencies:
6+
# rebuilderd-tools
7+
# parallel
8+
9+
progname="greposcope"
10+
tmp_dir="${TMPDIR:-/tmp}/${progname}-${UID}"
11+
rebuilderd_host="https://reproducible.archlinux.org"
12+
13+
help() {
14+
cat <<EOF
15+
Usage: ${progname} [OPTIONS] pattern
16+
17+
Download and search for 'pattern' in diffoscope outputs of every unreproducible packages reported at ${rebuilderd_host}.
18+
This is useful to identify packages that are unreproducible because of a specific issue.
19+
20+
OPTIONS
21+
-h, --help Show this message
22+
-i, --ignore-case Ignore case distinctions in patterns and input data
23+
24+
Examples:
25+
$ ${progname} "gzip compressed data"
26+
$ ${progname} -i zipinfo
27+
EOF
28+
}
29+
30+
while ((${#})); do
31+
case "${1}" in
32+
-h|--help)
33+
help
34+
exit 0
35+
;;
36+
-i|--ignore-case)
37+
extra_grep_opt="--ignore-case"
38+
;;
39+
--)
40+
shift
41+
break
42+
;;
43+
-*)
44+
echo -e >&2 "Invalid argument -- '${1}'\nTry '${progname} --help' for more information"
45+
exit 1
46+
;;
47+
*)
48+
pattern="${1}"
49+
;;
50+
esac
51+
shift
52+
done
53+
54+
if [ -z "${pattern}" ]; then
55+
echo -e >&2 "No pattern provided\nTry '${progname} --help' for more information"
56+
exit 1
57+
fi
58+
59+
mkdir -p "${tmp_dir}"
60+
61+
echo -e "==> Fetching the list of unreproducible packages...\n"
62+
mapfile -t pkg_list < <(rebuildctl -H "${rebuilderd_host}" pkgs ls --status BAD | awk '{print $3}')
63+
64+
if [ ${#pkg_list[@]} -eq 0 ]; then
65+
echo "==> No unreproducible packages found"
66+
exit 0
67+
fi
68+
69+
updated_pkg_list=()
70+
for pkg in "${pkg_list[@]}"; do
71+
if [ ! -f "${tmp_dir}/${pkg}.diffoscope" ]; then
72+
updated_pkg_list+=("${pkg}")
73+
fi
74+
done
75+
76+
pkg_list=("${updated_pkg_list[@]}")
77+
78+
if [ ${#pkg_list[@]} -eq 0 ]; then
79+
echo "==> All diffoscope outputs are already downloaded"
80+
else
81+
echo -e "==> Downloading diffoscope outputs of ${#pkg_list[@]} unreproducible packages...\nThis may take some time...\n"
82+
parallel --bar -j "$(nproc)" \
83+
rebuildctl -H "${rebuilderd_host}" pkgs diffoscope --name {} "&>" "${tmp_dir}/{}.diffoscope" ::: "${pkg_list[@]}"
84+
fi
85+
86+
echo -e "\n==> Searching for \"${pattern}\" in diffoscope outputs...\n"
87+
parallel --silent -j "$(nproc)" \
88+
"grep --color=always --with-filename --line-number ${extra_grep_opt} '${pattern}' {}" ::: "${tmp_dir}"/*.diffoscope || true

0 commit comments

Comments
 (0)