NetBSD/distrib/sets/culldeps
dyoung 4d23e6d82c For System Packages, two new utilities, a subroutine library, and
a new list:

sets.subr -- The set-listing code that is common to makeplist,
	     makeflist, and regpkg has moved here.

syspkgdeps -- Compute naive dependencies for system packages based
	      on directory containment. I.e., if package A contains
	      path /p/q, and package B contains path /p, then B is
	      considered a dependency of A. As Jim Wise remarks,
	      this is not quite right: system-package dependencies
	      should indicate a functional dependency. Nevertheless,
	      these naive dependencies protect us from orphaning
	      files when pkg_delete'ing system packages.

culldeps -- Helper for syspkgdeps. Removes redundant dependencies
	    from a dependencies table.  Essentially does the opposite
	    of a transitive closure on a dependencies table: if
	    the table contains A depends-on B, B depends-on C, and
	    A depends-on C, then A depends-on C is removed because
	    it can be derived from the prior two dependencies.

deps -- Dependencies computed by syspkgdeps.
2003-06-23 09:02:31 +00:00

76 lines
1.7 KiB
Bash
Executable File

#!/bin/sh
#
# culldeps
#
# Filter redundant dependencies.
#
# Emit all the dependencies on the standard input to the standard
# output EXCEPT the dependencies which can be derived from other
# dependencies by the transitive rule. For example, omit both A C
# and A D from
#
# A B
# B C
# C D
# A C
# A D
#
# because A C can be derived from A B and B C by transitivity,
# and A D can be derived from A B, B C, C D by transitivity.
#
SCRATCH=$(mktemp -d /var/tmp/$0.XXXXXX)
NEXTLEFTOVERS=$SCRATCH/leftovers0
LASTJOIN=$SCRATCH/join0
NEXTJOIN=$SCRATCH/join1
TAB=" "
sort -k 1 > $LASTJOIN
LEFTOVERS=$LASTJOIN
while [ $(wc -l $LASTJOIN | awk '{ print $1; }') -ne 0 ]; do
#
# From dependencies X-requires-Y in $LEFTOVERS and Y-requires-Z in
# $LASTJOIN, produce dependencies X-requires-Z and write them to
# $NEXTJOIN.
#
sort -k 2 < $LEFTOVERS | join -1 2 -2 1 -o '1.1 2.2' - $LASTJOIN | \
sort -u > $NEXTJOIN
if [ ${DEBUG:-0} -gt 0 ]; then
echo "### filtered ###" 1>&2
join -t "$TAB" $NEXTJOIN $LEFTOVERS | sort 1>&2
echo "###" 1>&2
fi
#
# Filter out of $LEFTOVERS all of the dependencies X-requires-Z, which
# were produced in the previous step. Write the new leftovers to
# $NEXTLEFTOVERS.
#
join -v 2 -t "$TAB" $NEXTJOIN $LEFTOVERS | sort -u > $NEXTLEFTOVERS
#
# Swap output files before repeating.
#
LASTJOIN=$NEXTJOIN
if [ $(basename $NEXTJOIN) = join0 ]; then
NEXTJOIN=$SCRATCH/join1
else
NEXTJOIN=$SCRATCH/join0
fi
LEFTOVERS=$NEXTLEFTOVERS
if [ $(basename $NEXTLEFTOVERS) = leftovers0 ]; then
NEXTLEFTOVERS=$SCRATCH/leftovers1
else
NEXTLEFTOVERS=$SCRATCH/leftovers0
fi
done
#
# Output all of the dependencies that were not culled and clean up.
#
cat $LEFTOVERS
rm -r $SCRATCH