Hi Ingo,

On Sun, 19 Apr 2020, at 15:36, Ingo Schwarze wrote:
> The above list is not complete.  For example, i skipped ways to
> inspect test dependencies, and i refrained from explaining
> possibilities that use the port "databases/sqlports", which
> is very powerful.  Finally, i may have missed some ways this
> can be done.

Perhaps not complete but certainly many options. Thank you for
taking the time to write them all down.

> We certainly don't need yet more ways to do the same, and certainly
> not by creating wrappers around what is already there.  Besides,
> directly inspecting the contents of /var/db/pkg/ by anything that
> is not part of the pkg tools is fragile and not acceptable.

Yes, I agree; messing around in /var/db/pkg was just a means to an
end but I certainly didn't consider it stable.

> All that said, it might be useful if, in addition to -S, pkg_add(1)
> could recursively list run-time dependencies. [...]
> 
>  * writing your own script recursively calling "pkg_info -qS",
>    then postprocessing with sort(1) and uniq(1)

I modified my original script to make use of pkg_info -qS as suggested
by yourself and Erling. pkg_info(1) is able to query $PKG_PATH when
a dependency is not installed locally. This has the nice benefit
of being able to examine all the dependencies before they hit your
system.

Another benefit over the original script I posted is that it reuses
pkg_* tool's pkg-name format as a consequence of using pkg_info(1)
so now things like python--%3.7, mutt--gpgme, etc. are possible.

$ pkg_dependents python
pkg_dependents: Ambiguous:
        python-2.7.16p1
        python-3.7.4

$ pkg_dependents python--%3.7
Information for inst:python-3.7.4

Directly depends on:
bzip2-1.0.8
gettext-runtime-0.20.1p0
libffi-3.2.1p5
sqlite3-3.29.0
xz-5.2.4

Transitively depends on:
libiconv-1.16p0

$ pkg_dependents mutt
pkg_dependents: Ambiguous:
        mutt-1.12.2v3
        mutt-1.12.2v3-gpgme
        mutt-1.12.2v3-gpgme-sasl
        mutt-1.12.2v3-sasl
        mutt-1.12.2v3-sasl-slang

$ pkg_dependents mutt--gpgme
Information for inst:mutt-1.12.2v3-gpgme

Directly depends on:
gettext-runtime-0.20.1p0
gpgme-1.13.1p0
libidn2-2.0.0p0
qdbm-1.8.78p2

Transitively depends on:
bzip2-1.0.8
curl-7.66.0
gnupg-1.4.23p3
libassuan-2.5.1p0
libgpg-error-1.36p0
libiconv-1.16p0
libunistring-0.9.7
nghttp2-1.39.2

--
Chris Rawnsley



#!/bin/sh

bin=$(basename "$0")

usage() {
        cat <<EOF
usage: ${bin} pkg-name
EOF
}

direct_deps=$(mktemp -t "${bin}.direct_deps.XXXXXX")
temp_deps=$(mktemp -t "${bin}.temp_deps.XXXXXX")
all_deps=$(mktemp -t "${bin}.all_deps.XXXXXX")

cleanup() {
        rm -f "${direct_deps}" "${temp_deps}" "${all_deps}"
}
trap cleanup INT TERM QUIT

deps_from_sig() {
        pkg_sig=$1
        printf '%s\n' "${pkg_sig}" | tr ',' '\n' | sed -n 's/^@//p'
}

if ! touch "${direct_deps}" "${temp_deps}" "${all_deps}" 2>/dev/null; then
        printf '%s\n' "${bin}: unable to create temporary files" 1>&2
        cleanup; exit 1
fi

if ! pkg_sig=$(pkg_info -qS "$1"); then
        printf '%s\n' "${bin}: unable to find package" 1>&2
        cleanup; exit 1
fi

if [ $(printf '%s\n' "${pkg_sig}" | wc -l) -gt 1 ]; then
        printf '%s\n' "${bin}: Ambiguous:" 1>&2
        printf '        %s\n' $(printf '%s\n' "${pkg_sig}" | cut -d, -f1) 1>&2
        cleanup; exit 1
fi

pkg=$(printf '%s' "${pkg_sig}" | cut -d, -f1)

deps_from_sig "${pkg_sig}" | sort | tee "${temp_deps}" >"${direct_deps}"

while deps=$(comm -23 "${temp_deps}" "${all_deps}" | grep .); do
        printf '%s\n' ${deps} >>"${all_deps}"
        deps_from_sig "$(pkg_info -qS ${deps})" >>"${temp_deps}"
        sort -uo "${all_deps}" "${all_deps}"
        sort -uo "${temp_deps}" "${temp_deps}"
done

printf 'Information for inst:%s\n\n' "${pkg}"

printf 'Directly depends on:\n'
printf '%s\n' $(cat ${direct_deps})

printf '\n'

printf 'Transitively depends on:\n'
        
printf '%s\n' $(comm -23 "${all_deps}" "${direct_deps}")

cleanup

Reply via email to