2 # aur-depends - retrieve package dependencies using AurJson
3 [[ -v AUR_DEBUG
]] && set -o xtrace
5 PS4
='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
12 resolve_checkdepends
=1
16 jq
-r '.resultcount' "$1" |
awk '{s += $1} END {print s}'
20 jq
-r -f /dev
/stdin
"$1" <<'EOF'
25 | [[$result.Name, $result.Name, $result.PackageBase, $result.Version, "Self"]]
27 # enumerate dependencies per kind
29 "Depends", "MakeDepends", "CheckDepends", "OptDepends"
33 | [$result.Name, ., $result.PackageBase, $result.Version, $kind]
40 # $1 pkgname $2 depends $3 pkgbase $4 pkgver $5 depends_type
42 awk -v deps
="$1" -v mdeps
="$2" -v cdeps
="$3" -v odeps
="$4" '
44 $5 ~ /^Depends$/ && deps {print}
45 $5 ~ /^MakeDepends$/ && mdeps {print}
46 $5 ~ /^CheckDepends$/ && cdeps {print}
47 $5 ~ /^OptDepends$/ && odeps {print}
51 # $1 pkgname $2 depends $3 pkgbase
53 awk -v type="$1" 'FNR == NR {
58 if (type == "pkgname") {
59 printf("%s\t%s\n", $1, $2)
60 } else if (type == "pkgbase") {
61 printf("%s\t%s\n", $3, map[$2])
67 sed -r 's/[<>=].*$//g'
70 # shellcheck disable=SC2086
73 local select_args
=("$1" "$2" "$3" "$4")
76 aur query
-t info
"$@" > json
/0 ||
exit
79 if (( num
< 1 )); then
80 printf >&2 '%s: no packages found\n' "$argv0"
84 # In the below, all intermediary results are stored (originally done to
85 # simplify debugging). Strictly speaking, only the current and previous
86 # step are required. With a limited amount of requests (e.g. ~7 total
87 # for large meta-packages such as ros-indigo-desktop and ~250 AUR
88 # dependencies) the difference is unlikely to be noticeable.
89 for (( a
= 1; a
<= max_request
; ++a
)); do
91 tabulate json
/$sub | select_deps
"${select_args[@]}" |
tee -a tsv
/n
> tsv
/$sub
93 # Avoid querying duplicates (#4)
94 cut
-f1 tsv
/$sub >> seen
# pkgname
95 cut
-f2 tsv
/$sub | tr_ver |
grep -Fxvf seen | \
96 aur query
-t info
- > json
/$a ||
exit # rpc error
98 if [[ -s json
/$a ]]; then
101 return $a # no unique results (seen \ tsv == [empty])
104 if (( num
>= 1 )); then
105 cut
-f2 tsv
/$sub >> seen
# depends
107 return $a # no results, recursion complete
111 # recursion limit exceeded
116 if [[ ! -v AUR_DEBUG
]]; then
119 printf >&2 'AUR_DEBUG: %s: temporary files at %s\n' "$argv0" "$tmp"
124 printf >&2 'usage: %s [-abGnt]\n' "$argv0"
128 source /usr
/share
/makepkg
/util
/parseopts.sh
131 opt_long
=('table' 'pkgbase' 'pkgname' 'pkgname-all' 'graph' 'optdepends'
132 'no-depends' 'no-makedepends' 'no-checkdepends')
133 opt_hidden
=('dump-options')
135 if ! parseopts
"$opt_short" "${opt_long[@]}" "${opt_hidden[@]}" -- "$@"; then
138 set -- "${OPTRET[@]}"
149 mode
=pkgbase_graph
;;
155 resolve_makedepends
=0 ;;
157 resolve_checkdepends
=0 ;;
159 resolve_optdepends
=1 ;;
161 printf -- '--%s\n' "${opt_long[@]}" ${AUR_DEBUG+"${opt_hidden[@]}"}
162 printf -- '%s' "${opt_short}" | sed 's/.:\?/-&\n/g'
169 # shellcheck disable=SC2174
170 mkdir -pm 0700 "${TMPDIR:-/tmp}/aurutils-
$UID"
171 tmp=$(mktemp -d --tmpdir "aurutils-
$UID/$argv0.XXXXXXXX
") || exit
172 trap 'trap_exit' EXIT
175 if cd "$tmp" && mkdir json tsv; then
176 # tsv/n: pkgname\tdepends\tpkgbase\pkgver
177 chain "$resolve_depends" "$resolve_makedepends" "$resolve_checkdepends" "$resolve_optdepends" "$@
" || rings=$?
180 # check iteration number
182 1) true # no dependencies
185 printf >&2 '%s: total requests: %d (out of range)\n' "$argv0" $(( max_request + 1 ))
190 # pkgname (AUR, total order)
192 grep -Fxf <(cut -f1 "$deptable") <(cut -f1,2 "$deptable" | tsort | tac)
194 # pkgname (all, total order)
196 cut -f1,2 "$deptable" | tsort | tac
198 # pkgbase (AUR, total order)
200 package_graph 'pkgbase' "$deptable" "$deptable" | tsort | tac
202 # pkgbase (AUR, graph)
204 package_graph 'pkgbase' "$deptable" "$deptable" | sort -k1b,1 -k1 -u
211 printf >&2 '%s: invalid argument' "$argv0"
218 # vim: set et sw=4 sts=4 ft=sh: