3 # syspkgdeps [-a arch] [-m machine] [-s setsdir] [-p prefix] sets
5 # Compute naive package dependencies based on file & directory
6 # nesting. E.g., if pkg P contains /foo/bar and Q contains /foo,
7 # then Q is considered a dependency of P.
9 # Each line of output contains two syspkg names,
10 # where the first syspkg depends on the second syspkg.
16 rundir
="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/"
17 .
"${rundir}/sets.subr"
27 Usage: ${0##*/} [-a arch] [-m machine] [-s setsdir] [-p prefix] setname [...]
28 -a arch set arch (e.g, m68k, mips, powerpc) [${MACHINE_ARCH}]
29 -m machine set machine (e.g, amiga, i386, macppc) [${MACHINE}]
30 -s setsdir directory to find sets [${setsdir}]
31 -p prefix prefix for created plist [${prefix}]
32 setname [...] sets to find dependencies for
38 while getopts a
:m
:p
:s
: ch
; do
41 MACHINE_ARCH
="${OPTARG}"
42 MACHINE_CPU
="$(arch_to_cpu "${OPTARG}")"
58 shift $
((${OPTIND} - 1))
65 all
) sets
="${nlists}" ;;
69 SCRATCH
="$(${MKTEMP} -d "/var
/tmp
/${prog}.XXXXXX
")"
72 echo >&2 "${prog}: Could not create scratch directory."
76 PATH_MEMBERSHIP
="${SCRATCH}/path-membership"
77 PATH_TO_PKGNAME
="${SCRATCH}/pathpkg.db"
78 PARENT_PKGNAMES
="${SCRATCH}/parent-pkgnames"
79 PARENT_PATHNAMES
="${SCRATCH}/parent-pathnames"
81 echo >&2 "${prog}: indexing packages by pathnames"
83 list_set_files
${sets} |
${SED} 's/^\.\///' | \
84 ${ENV_CMD} PREFIX="${prefix}" ${AWK} '{
86 print ENVIRON["PREFIX"] " " $2;
88 print ENVIRON["PREFIX"] $1 " " $2;
90 }' |
${SORT} -k 1 -u > "${PATH_MEMBERSHIP}"
92 ${DB} -q -w -f - btree "${PATH_TO_PKGNAME}" < "${PATH_MEMBERSHIP}"
95 echo >&2 "${prog}: error creating database
, aborting
"
99 echo >&2 "${prog}: computing parent pathnames
"
101 while read pathname pkgname; do
102 # print parent pathname.
103 # (This uses a cheap implementation of dirname from sets.subr.)
104 dirname "${pathname}"
105 done < "${PATH_MEMBERSHIP}" > "${PARENT_PATHNAMES}"
107 echo >&2 "${prog}: selecting parent packages using parent pathnames
"
109 ${DB} -q -f - btree "${PATH_TO_PKGNAME}" < "${PARENT_PATHNAMES}" | \
110 ${PASTE} "${PATH_MEMBERSHIP}" - | \
111 ${AWK} '{ if ($2 != $4) print $2 " " $4; }' | \
112 ${SORT} -u > "${SCRATCH}/alldeps"
114 if [ $?
-ne 0 ]; then
115 echo >&2 "${prog}: error in parent-directory lookup, aborting"
119 echo >&2 "${prog}: checking for cyclic dependencies"
121 tsort_errors
="$(${TSORT} < "${SCRATCH}/alldeps
" 2>&1 >/dev/null)"
123 if [ -n "${tsort_errors}" ]; then
124 # Errors from tsort are usually to do with cyclic dependencies.
125 # The most likely underlying cause is that /foo and /foo/bar/baz
126 # are in syspkg A, but /foo/bar is in syspkg B.
127 echo >&2 "${tsort_errors}" # this is likely to be multiple lines
128 echo >&2 "${prog}: Above messages probably indicate an error in the lists"
132 echo >&2 "${prog}: removing redundant dependencies"
134 ${HOST_SH} "${rundir}/culldeps" < "${SCRATCH}/alldeps
"
136 if [ $? -ne 0 ]; then
137 echo >&2 "${prog}: error
in culldeps
, aborting
"