Source-Changes-HG archive

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

[src/trunk]: src/distrib/sets * Make regpkgset accept all the new args that r...



details:   https://anonhg.NetBSD.org/src/rev/4584ed38d89d
branches:  trunk
changeset: 586863:4584ed38d89d
user:      apb <apb%NetBSD.org@localhost>
date:      Wed Jan 04 14:18:00 2006 +0000

description:
* Make regpkgset accept all the new args that regpkg takes.
* Sort the pkgs into dependency order before invoking regpkg.
* Better cleanup.

Reviewed by agc

diffstat:

 distrib/sets/regpkgset |  144 +++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 128 insertions(+), 16 deletions(-)

diffs (192 lines):

diff -r ed8572923b22 -r 4584ed38d89d distrib/sets/regpkgset
--- a/distrib/sets/regpkgset    Wed Jan 04 14:14:35 2006 +0000
+++ b/distrib/sets/regpkgset    Wed Jan 04 14:18:00 2006 +0000
@@ -1,6 +1,6 @@
 #! /bin/sh
 #
-# $NetBSD: regpkgset,v 1.5 2006/01/03 18:31:09 apb Exp $
+# $NetBSD: regpkgset,v 1.6 2006/01/04 14:18:00 apb Exp $
 #
 # Copyright (c) 2003 Alistair G. Crooks.  All rights reserved.
 #
@@ -33,25 +33,93 @@
 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #
 
-# Usage: regpkgset set
+# Usage: regpkgset [options] set
+#
+# Options:
+#   -q         Quiet.
+#   -v         Verbose.
+#   -f         Force.
+#   -m         Ignore errors from missing files.
+#   -u         Update.
+#   -c         Cache some information in ${BUILD_INFO_CACHE}.
+#   -d destdir Sets DESTDIR.
+#   -t binpkgdir Create a binary package (in *.tgz format) in the
+#              specified directory.  Without this option, a binary
+#              package is not created.
+#   -M metalog Use the specified metalog file to override file
+#              or directory attributes when creating a binary package.
+#   -N etcdir  Use the specified directory for passwd and group files.
 
+prog="${0##*/}"
+toppid=$$
 rundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/"
+. "${rundir}/sets.subr"
+
+bomb()
+{
+       kill ${toppid}          # in case we were invoked from a subshell
+       exit 1
+}
+
+# A literal newline
+nl='
+'
 
-verbose=""
-cache=""
+#
+# cleanup() deletes temporary files.
+#
+es=0
+cleanup ()
+{
+       trap - 0
+       [ x"${BUILD_INFO_CACHE}" != x ] && rm -f "${BUILD_INFO_CACHE}"
+       exit ${es}
+}
+trap 'es=128; cleanup' 1 2 3 13 15     # HUP INT QUIT PIPE TERM
+trap 'es=$?; cleanup' 0                # EXIT
 
+#
+# Parse command line args.
+#
+verbose=false
+quiet=false
+force=false
+allowmissing=false
+update=false
+cache=false
+pkgdir=""
+metalog=""
+etcdir=""
+all_options=""
 while [ $# -gt 1 ]; do
+       # XXX: ${all_options} doesn't correctly handle args with
+       # embedded shell special characters.
        case "$1" in
-       -v)     verbose="$1" ;;
-       -c)     cache="$1" ;;
+       -q)     quiet=true ; verbose=false ;;
+       -v)     verbose=true ; quiet=false ;;
+       -f)     force=true ;;
+       -m)     allowmissing=true ;;
+       -u)     update=true ;;
+       -c)     cache=true ;;
+       -d)     DESTDIR="$2" ; all_options="${all_options} $1" ; shift ;;
+       -d*)    DESTDIR="${1#-?}" ;;
+       -t)     pkgdir="$2" ; all_options="${all_options} $1" ; shift ;;
+       -t*)    pkgdir="${1#-?}" ;;
+       -M)     metalog="$2" ; all_options="${all_options} $1" ; shift ;;
+       -M*)    metalog="${1#-?}" ;;
+       -N)     etcdir="$2" ; all_options="${all_options} $1" ; shift ;;
+       -N*)    etcdir="${1#-?}" ;;
+       -*)     echo "Usage: regpkgset [options] set ..." ; bomb ;;
        *)      break ;;
        esac
+       all_options="${all_options} $1"
        shift
 done
+export DESTDIR
 
 if [ $# -lt 1 ]; then
-       echo "Usage: regpkgset pkgset..."
-       exit 1
+       echo "Usage: regpkgset [options] set ..."
+       bomb
 fi
 
 case "$1" in
@@ -59,10 +127,12 @@
 *)     list="$*" ;;
 esac
 
-if [ x"${cache}" != x ]; then
-       BUILD_INFO_CACHE="$(${MKTEMP} "/var/tmp/${0##*/}-BUILD_INFO.XXXXXX")"
+if ${cache} ; then
+       BUILD_INFO_CACHE="$(${MKTEMP} "/var/tmp/${prog}-BUILD_INFO.XXXXXX")"
        export BUILD_INFO_CACHE
        {
+       # These variables describe the build
+       # environment, not the target.
        echo "OPSYS=$(${UNAME} -s)"
        echo "OS_VERSION=$(${UNAME} -r)"
        ${MAKE} -f- all <<EOF
@@ -72,16 +142,58 @@
        @echo MACHINE_ARCH=${MACHINE_ARCH}
        @echo MACHINE_GNU_ARCH=${MACHINE_GNU_ARCH}
 EOF
+       # XXX: what's the point of reporting _PKGTOOLS_VER
+       # when we roll everything by hand without using
+       # the pkg tools?
        echo "_PKGTOOLS_VER=$(${PKG_CREATE} -V)"
        } > "${BUILD_INFO_CACHE}"
 fi
 
-for pkgset in ${list}; do
-       for pkg in $("${rundir}/listpkgs" "${pkgset}"); do
-               "${rundir}/regpkg" ${verbose} "${pkgset}" "${pkg}"
-       done
+#
+# For each pkgset mentioned in ${list}, get a list of all pkgs in the pkgset.
+#
+# Sort all the pkgs into dependency order (with prerequisite pkgs before
+# pkgs that depend on them).
+#
+# Invoke ${rundir}/regpkg for each pkg, taking care to do it in dependency
+# order.  If there were any pkgs for which we failed to find dependency
+# information, handle them at the end.
+#
+pkgs="$( for pkgset in ${list}; do
+               ${HOST_SH} "${rundir}/listpkgs" "${pkgset}" || bomb
+        done )"
+tsort_input="$( ${AWK} '{print $2 " " $1}' <"${rundir}/deps" || bomb )"
+tsort_output="$( echo "${tsort_input}" | ${TSORT} || bomb )"
+for pkg in ${tsort_output} ; do
+       case "${nl}${pkgs}${nl}" in
+       *"${nl}${pkg}${nl}"*)
+               # We want this pkg.
+               pkgset="${pkg%%-*}"
+               ${verbose} && echo "${prog}: registering ${pkg}"
+               ${HOST_SH} "${rundir}/regpkg" ${all_options} \
+                       "${pkgset}" "${pkg}" || bomb
+               ;;
+       *)      # pkg is mentioned in ${tsort_output} but not in ${pkgs}.
+               # We do not want this pkg.
+               ;;
+       esac
+done
+for pkg in ${pkgs} ; do
+       case "${nl}${tsort_output}${nl}" in
+       *"${nl}${pkg}${nl}"*)
+               # pkg was in the tsort output, so it would have been
+               # handled above.
+               ;;
+       *)      # This pkg was not in the tsort output.
+               # This is probably an error, but process the
+               # pkg anyway.
+               echo >&2 "${prog}: WARNING: ${pkg} is not mentioned in deps file"
+               pkgset="${pkg%%-*}"
+               ${verbose} && echo "${prog}: registering ${pkg}"
+               ${HOST_SH} "${rundir}/regpkg" ${all_options} \
+                       "${pkgset}" "${pkg}" || bomb
+               ;;
+       esac
 done
 
-[ x"${BUILD_INFO_CACHE}" != x ] && rm -f "${BUILD_INFO_CACHE}"
-
 exit 0



Home | Main Index | Thread Index | Old Index