pkgsrc-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: A stupid bash function to check missing dependencies



    Date:        Mon, 23 Sep 2019 09:12:41 -0500
    From:        Jason Bacon <outpaddling%yahoo.com@localhost>
    Message-ID:  <71a014de-ead0-57fa-21dc-7e5259498a84%yahoo.com@localhost>

  | Nice work...  Have you thought about making this available as part of a 
  | package, or perhaps a new make target like "missing-depends"?

In case it assists anyone (do not expect this to work as is) I am
attaching a script (pb-order ... for "package build order") which I
used to use (years ago, when I did regular package building, just for
fun - and to look for build problems) which takes a list of packages
that need to be built (for whatever reason) and looks for all of their
dependencies, generating a list of everything that needs building, in
the order in which they should be built, that any which are dependencies
of others in the list get built in the correct order.

I used to use a locally modified pkg_comp and set up a new build
environment for each package build - building exactly one package
(and any dependendencies required - using the make target which
installs binary packages if they exist, otherwise builds them)
in that environment before destroying it and starting again (the
output was the binary package file, nothing actually ever gets installed
by this process).    A dependency is (was) not required to be built
iff a binary package for the correct version existed.

This script just generates the build order (ie: outputs the same package
list as input, but with the one that should be built first listed first,
etc), the actual building was done by another script which calls this one
(but that isn't germane to this discussion).

Feel free to ask questions, but I am not sure I remember all of the
details any more.   Ths point of this here, is that it shows a mathod
I used to find dependencies, and their deoendencies, ... long ago.

kre

ps: the script does nothing if there is only one package in the arg
list, as there's nothing to order (unless the -deplist=filename option is
given (must be the first arg), which causes a file containing the
dependencies is generated).

pps: if I were writing this now, I'd use printf instead of echo throughout.
#! /bin/sh

: ${NOISE:=:}
: ${TMPDIR:=/tmp}
: ${DEBUG:=}

case "$#" in
1)	echo "$1"; exit 0;;	# no point doing all the work for 1 pkg...
esac

if [ -z "$PKGSRCDIR" ]
then
	eval $( grep '^PKGSRCDIR=' /etc/mk.conf 2>/dev/null )
fi

: ${PKGSRCDIR:=/usr/pkgsrc}

cd "${PKGSRCDIR}" || exit 1

TF="${TMPDIR}/pbo-$$"

DF=/dev/null
case "$1" in
	-depfile=*)	DF="${1#-depfile=}"; shift;;
esac

for pkg
do
	echo "${pkg}"
done > "${TF}"

mk_depend()
{
	if [ $(id -u) -eq 0 ]
	then
			GETOPT_COMPATIBLE=true \
			POSIXLY_CORRECT=true \
			SHELL=/bin/sh \
			pkg_comp ${PB_CONFIG} -Q chroot \
		cd /usr/pkgsrc/"'$1'" '&&' \
		make show-depends-pkgpaths '||' \
			echo '>&2' "' ..... show-depends-pkgpaths failed for ${1}'"
	else
		make show-depends-pkgpaths ||
			echo >&2 " ..... show-depends-pkgpaths failed for ${1}"
	fi
}

deplist()
{
	echo "$1"
	(
		cd "$1" || exit 1

		${NOISE} deplist: "${1}" >&2

		mk_depend "$1"
	)
}

rdeplist()
{
	${NOISE} rdeplist: "$1" >&2
	for x in $( deplist "$1" )
	do
		echo "${x}"
		${NOISE} rdeplist: dep-found "${x}" >&2
		grep -q -s '^'"${x}"'$' "${TF}" >/dev/null || {
			echo "${x}" >> "${TF}"
			${NOISE} rdeplist: recurse "${x}" >&2
			rdeplist "${x}"
		}
	done
}

I=0
for pkg
do
	for x in $( rdeplist "${pkg}" )
	do
		echo "${pkg}	${x}"
	done
done | sort -u | tee "${DF}" | tsort | while read name
do
	I=$(( ${I} + 1 ))
	echo "${I}	${name}"
done | sort -rn | while read index name
do
	for pkg
	do
		if [ "${pkg}" = "${name}" ]
		then
			echo "${name}"
			break
		fi
	done
done

${DEBUG} rm -f "${TF}"


Home | Main Index | Thread Index | Old Index