From 64b8c083f9685b15b9c9eb9af787f679daad012c Mon Sep 17 00:00:00 2001 From: Zach van Rijn Date: Sat, 30 Apr 2022 01:00:37 -0500 Subject: scripts/*: add dependency resolver. --- scripts/deplist | 179 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100755 scripts/deplist (limited to 'scripts/deplist') diff --git a/scripts/deplist b/scripts/deplist new file mode 100755 index 000000000..5eb51c95b --- /dev/null +++ b/scripts/deplist @@ -0,0 +1,179 @@ +#!/bin/sh -e + +## e.g. +# +# $ ./scripts/setup +# $ ./scripts/deplist system | ./scripts/depsort +# + +HERE="$(dirname $(readlink -f ${0}))"; +BASE="${HERE}/.."; + +## +# Usage +# +if test ${#} = 0; then + cat <&2; + exit 1; + fi +done + +## +# Find a package by name or find the parent package of a subpackage. +# Note that the index is padded by a space on either side for easy grep. +# +# Usage: parent PACKAGE +# +parent () +{ + a=$("${HERE}"/sgrep " ${1} " "${HERE}"/.index | cut -d' ' -f2 | xargs); + if test -n "${a}"; then + r=${a}; + else + b=$(grep " ${1} " "${HERE}"/.index | cut -d' ' -f2 | xargs); + r=${b}; + fi + printf "%s" "${r}"; +} + +## +# Do everything at once. +# +for repo in ${@}; do + find "${BASE}/${repo}" -mindepth 1 -maxdepth 1 -type d | while read k; do + ( + ## + # Source APKBUILD in a subshell to avoid contamination. + # + . "${k}/APKBUILD"; + + ## + # Special-case some options. For example, '!check' means + # that the 'checkdepends=' variable is not used. Ignore. + # + for m in ${options}; do + case ${m} in + !check) checkdepends=; ;; + esac + done + + ## + # Aggregate all possible depends. Obviously if something + # is not specified, it will be empty anyway. + # + # FIXME: Clean this up somehow. + # + cats=$(tr ' ' '\n' <*}; # remove >version + _d=${_d%<*}; # remove &2; + exit 1; + fi + path="${repo}/${_d}"; + ;; + user) # packages in user might depend on something in system + if ! test -f "${BASE}/${repo}/${_d}/APKBUILD"; then + if test -f "${BASE}/system/${_d}/APKBUILD"; then + path="system/${_d}"; + else + printf "E: dependency '%s' not found or excepted\n" "${_d}" 1>&2; + exit 1; + fi + else + path="${repo}/${_d}"; + fi + ;; + esac + + ## + # Print remaining columns of output if not parent. + # + printf " %s" "${path}"; + done | tr ' ' '\n' | sed -e "\@${p}\$@d" | sort -u | xargs; # sort and remove duplicates + ) + done | sort; # sort only within a repo +done -- cgit v1.2.3-60-g2f50