findredundantdeps(1)

NAME
findredundantdeps - display unnecessary dependencies of a port

SYNOPSIS
findredundantdeps [-s|-f|-v] <portname1> [portname2 ...]

DESCRIPTION
analyze the dependencies listed for the given port(s) and display any item in the "Depends on:" field that also appears deeper in the dependency tree.

The script requires prt-get(8).

OPTIONS

-s  suggest: suggest the proper "Depends on:" line

-f  fix the Pkgfile and create a backup

-v  verbose: in addition to the output for ports that have unnecessary "Depends on:" entries, also print a message for each port that appears ok.

EXAMPLES

finderedundantdeps -f apache
    find redundant deps of the apache port and fix the Pkgfile if needed.

findredundantdeps -s -f gunicorn
    find redundant deps of the gunicorn port, suggest the correct Pkgfile header, and fix the Pkgfile if needed.

COMPARISON WITH OTHER UTILITIES
findredundantdeps does not care about $PWD; it treats each non-option argument as the name of a port and relies solely on prt-get(8) to obtain the necessary information. If any non-option argument is not a port in the active collections, findredundantdeps will inform the user about the ignored argument and proceed to the next one. For direct and indirect dependencies, however, there is no warning issued when encountering a dependency that cannot be found among the active collections; traversal of the dependency tree along that branch simply stops. Hence it is possible to obtain a false negative result by deactivating from prt-get.conf(5) the collection where an offending port resides. You are encouraged to check for missing dependencies first, either by

prt-get depends apache | sed '1,/^-- missing/d'

or by the more verbose

prtverify -m missing-deps -c /usr/ports/core -c /usr/ports/xorg -c /usr/ports/opt /usr/ports/opt/apache

Note that non-option arguments to prtverify(1) must be directories (not port names). Hence when running prtverify you must either know the absolute path of the desired port, or its location relative to $PWD. Meanwhile, findredundantdeps can be invoked from anywhere in the filesystem. The 'suggest' and 'fix' options, and the ability to run from anywhere on the filesystem without knowing which collection has the desired port, offer compelling reasons for keeping findredundantdeps in the port maintainer's toolbox.

The deptree command of prt-get(8) displays all the direct dependencies at one level of indentation, and all the indirect dependencies at a deeper level of indentation. Hence the core logic of findredundantdeps (except for the -s, -f, and -v options) is built around one or two prt-get processes and one gawk process, which you could add to your ~/.profile as a shell function:

    findredundantdeps() {
      for p in "$@"; do
        prt-get info "$p" >/dev/null || { echo "no port $p in the active collections"; continue; }
        prt-get deptree "$p" | awk -v PORT="$p" \
                 '/^...[[:space:]]{3}[a-z].*[^>]$/ {dd[$NF]}
                  /^...[[:space:]]{4}.*[^>]$/      {id[$NF]}
                  /^...[[:space:]]{3}[a-z].*-->$/ {dd[$(NF-1)]}
                  /^...[[:space:]]{4}.*-->$/      {id[$(NF-1)]}
                  END{
                     for (i in id) { if (i in dd) rd[i] }
                     if (typeof(rd)=="array") {
                         print ("Redundant dependencies for " PORT ":")
                         for (i in rd) { print i }
                     }
                  }'
      done
    }

In contrast, the number of child prt-get processes spawned in earlier implementations is only limited by the size of your ports collection, if someone is so curious as to write a "Depends on:" line that contains every known port [1]). Defining findredundantdeps as a shell function should result in faster startup times, as the code will already be present in memory and need not be loaded from a file. On modern hardware the slowdown of having to read a script from disk is basically imperceptible, so the script in /usr/bin is equipped with additional useful post-processing: the "suggest" and "fix" modes.

The "-->" annotation (appended by prt-get when displaying a dependency already "seen before") might seem like an easier clue to identify redundant dependencies, but there's no guarantee that such a port was "seen before" at the first level of the tree. Hence the awk program constructs two different sets, deferring until the END block the test for non-empty intersection.

Future versions of prt-get might acquire the ability to recognize optional dependencies. Having the line "softdeps yes" in /etc/prt-get.conf would then clutter the dependency tree with branches that follow these soft dependencies, and the logic of the above shell snippet would produce too many false positives. Hence the test of ‘prt-get version‘ at the start of findredundantdeps, to ensure that a softdeps-aware prt-get is invoked with --config-set="softdeps no", and the printed tree will be the same as produced by earlier versions of prt-get.

REFERENCES
[1] See https://boehs.org/node/npm-everything for an example from the JavaScript world.

AUTHORS
Han Boetes <han@mijncomputer.nl>

Johannes Winkelmann <jw@tks6.net>

John McQuah <jmcquah@disroot.org>

SEE ALSO
prt-get(8), prtverify(1)