Home | History | Annotate | Line # | Download | only in sets
      1  1.1  dyoung #!/bin/sh
      2  1.1  dyoung #
      3  1.1  dyoung # culldeps
      4  1.1  dyoung #
      5  1.1  dyoung # Filter redundant dependencies.
      6  1.1  dyoung #
      7  1.6     apb # Each line of input and output contains two syspkg names,
      8  1.6     apb # where the first syspkg depends on the second syspkg.
      9  1.6     apb #
     10  1.1  dyoung # Emit all the dependencies on the standard input to the standard
     11  1.1  dyoung # output EXCEPT the dependencies which can be derived from other
     12  1.1  dyoung # dependencies by the transitive rule. For example, omit both A C
     13  1.1  dyoung # and A D from
     14  1.1  dyoung #
     15  1.1  dyoung # 	A B
     16  1.1  dyoung # 	B C
     17  1.1  dyoung # 	C D
     18  1.1  dyoung # 	A C
     19  1.1  dyoung # 	A D
     20  1.1  dyoung #
     21  1.1  dyoung # because A C can be derived from A B and B C by transitivity,
     22  1.1  dyoung # and A D can be derived from A B, B C, C D by transitivity.
     23  1.1  dyoung #
     24  1.1  dyoung 
     25  1.3     apb prog="${0##*/}"
     26  1.4     apb rundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/"
     27  1.4     apb . "${rundir}/sets.subr"
     28  1.4     apb 
     29  1.3     apb SCRATCH="$(${MKTEMP} -d "/var/tmp/${prog}.XXXXXX")"
     30  1.3     apb NEXTLEFTOVERS="${SCRATCH}/leftovers0"
     31  1.3     apb LASTJOIN="${SCRATCH}/join0"
     32  1.3     apb NEXTJOIN="${SCRATCH}/join1"
     33  1.1  dyoung TAB="	"
     34  1.1  dyoung 
     35  1.3     apb ${SORT} -k 1 > "${LASTJOIN}"
     36  1.1  dyoung 
     37  1.3     apb LEFTOVERS="${LASTJOIN}"
     38  1.1  dyoung 
     39  1.3     apb while [ "$(${WC} -l "${LASTJOIN}" | ${AWK} '{ print $1; }')" -ne 0 ]; do
     40  1.1  dyoung 
     41  1.1  dyoung 	#
     42  1.3     apb 	# From dependencies X-requires-Y in ${LEFTOVERS} and Y-requires-Z in
     43  1.3     apb 	# ${LASTJOIN}, produce dependencies X-requires-Z and write them to
     44  1.3     apb 	# ${NEXTJOIN}.
     45  1.1  dyoung 	#
     46  1.3     apb 	${SORT} -k 2 < "${LEFTOVERS}" | \
     47  1.3     apb 	    ${JOIN} -1 2 -2 1 -o '1.1 2.2' - "${LASTJOIN}" | \
     48  1.3     apb 	    ${SORT} -u > "${NEXTJOIN}"
     49  1.1  dyoung 	if [ ${DEBUG:-0} -gt 0 ]; then
     50  1.5     apb 		echo >&2 "${prog}: ### begin filtered results ###"
     51  1.3     apb 		${JOIN} -t "${TAB}" "${NEXTJOIN}" "${LEFTOVERS}" | ${SORT} 1>&2
     52  1.5     apb 		echo >&2 "${prog}: ### end filtered results ###"
     53  1.1  dyoung 	fi
     54  1.1  dyoung 
     55  1.1  dyoung 	#
     56  1.3     apb 	# Filter out of ${LEFTOVERS} all of the dependencies X-requires-Z, which
     57  1.1  dyoung 	# were produced in the previous step. Write the new leftovers to
     58  1.3     apb 	# ${NEXTLEFTOVERS}.
     59  1.1  dyoung 	#
     60  1.3     apb 	${JOIN} -v 2 -t "${TAB}" "${NEXTJOIN}" "${LEFTOVERS}" | \
     61  1.3     apb 		${SORT} -u > "${NEXTLEFTOVERS}"
     62  1.1  dyoung 
     63  1.1  dyoung 	#
     64  1.1  dyoung 	# Swap output files before repeating. 
     65  1.1  dyoung 	#
     66  1.3     apb 	LASTJOIN="${NEXTJOIN}"
     67  1.3     apb 	if [ "$(basename "${NEXTJOIN}")" = join0 ]; then
     68  1.3     apb 		NEXTJOIN="${SCRATCH}/join1"
     69  1.1  dyoung 	else
     70  1.3     apb 		NEXTJOIN="${SCRATCH}/join0"
     71  1.1  dyoung 	fi
     72  1.3     apb 	LEFTOVERS="${NEXTLEFTOVERS}"
     73  1.3     apb 	if [ "$(basename "${NEXTLEFTOVERS}")" = leftovers0 ]; then
     74  1.3     apb 		NEXTLEFTOVERS="${SCRATCH}/leftovers1"
     75  1.1  dyoung 	else
     76  1.3     apb 		NEXTLEFTOVERS="${SCRATCH}/leftovers0"
     77  1.1  dyoung 	fi
     78  1.1  dyoung done
     79  1.1  dyoung 
     80  1.1  dyoung #
     81  1.1  dyoung # Output all of the dependencies that were not culled and clean up.
     82  1.1  dyoung #
     83  1.3     apb cat "${LEFTOVERS}"
     84  1.3     apb rm -r "${SCRATCH}"
     85