Annotation of pkgsrc/pkgtools/pkg_rolling-replace/files/pkg_rolling-replace.sh, revision 1.41

1.1       gdt         1: #!/bin/sh
                      2: 
1.41    ! rhialto     3: # $NetBSD: pkg_rolling-replace.sh,v 1.40 2019/08/27 19:30:36 gdt Exp $
1.1       gdt         4: #<license>
                      5: # Copyright (c) 2006 BBN Technologies Corp.  All rights reserved.
                      6: #
                      7: # Redistribution and use in source and binary forms, with or without
                      8: # modification, are permitted provided that the following conditions
                      9: # are met:
                     10: # 1. Redistributions of source code must retain the above copyright
                     11: #    notice, this list of conditions and the following disclaimer.
                     12: # 2. Redistributions in binary form must reproduce the above copyright
                     13: #    notice, this list of conditions and the following disclaimer in the
                     14: #    documentation and/or other materials provided with the distribution.
                     15: # 3. Neither the name of BBN Technologies nor the names of its contributors
                     16: #    may be used to endorse or promote products derived from this software
                     17: #    without specific prior written permission.
                     18: #
                     19: # THIS SOFTWARE IS PROVIDED BY BBN TECHNOLOGIES AND CONTRIBUTORS ``AS IS''
                     20: # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     21: # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     22: # ARE DISCLAIMED.  IN NO EVENT SHALL BBN TECHNOLOGIES OR CONTRIBUTORS BE
                     23: # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                     24: # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     25: # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     26: # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     27: # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     28: # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     29: # POSSIBILITY OF SUCH DAMAGE.
                     30: #
                     31: # Effort sponsored in part by the Defense Advanced Research Projects
                     32: # Agency (DARPA) and the Department of the Interior National Business
                     33: # Center under agreement number NBCHC050166.
                     34: #</license>
                     35: 
                     36: # REVIEW NOTATION LEGEND
                     37: #   XXX marks things that are broken/kludgy
                     38: #   TODO marks things that need to be done
                     39: #   FIXED marks items fixed, needs review and deletion of FIXED comment
                     40: 
                     41: # Items to be completed for initial release:
                     42: 
                     43: # TODO: move bulk of help into a real man page.
                     44: 
                     45: # Items for future work (some imply changes in pkgsrc, not necessarily here)
                     46: #
                     47: #   Make a pass over all packages for build depends, and rememeber
                     48: # which packages have been so checked.  Check newly unsafe packages.
                     49: # The current lazy evaluation can perhaps fail to do things in the
                     50: # right order.  Alternatively, explain why the current scheme is safe
                     51: # and preferred.
                     52: #
                     53: #   Consider expansion to update via binary packages.  This raises
                     54: # interesting questions about ABIs and binary builds
                     55: #
                     56: #   Deal with conflicts in a smarter way, perhaps more automatically.
                     57: # This is hard because just removing packages is not ok.
                     58: #
                     59: #   Handle foo being split into foo and foo-share.  Now, make replace
                     60: # of foo pulls in foo-share which conflicts with foo.  This needlessly
                     61: # loses.
                     62: #
                     63: 
1.3       tnn        64: # Substituted by pkgsrc at pre-configure time.
1.4       tnn        65: MAKE="@MAKE@"
1.15      tnn        66: AWK="@AWK@"
1.3       tnn        67: 
1.19      apb        68: if [ -z "$MAKECONF" ] ; then
                     69:     for mkconf in "@MAKECONF@" "@PREFIX@/etc/mk.conf" /etc/mk.conf ; do
                     70:        if [ -f "$mkconf" ] ; then
                     71:            MAKECONF="$mkconf"
                     72:            break
                     73:        fi
                     74:     done
                     75: fi
                     76: if [ -z "$MAKECONF" -o ! -f "$MAKECONF" ] ; then
                     77:     MAKECONF=/dev/null
                     78: fi
1.7       tnn        79: test -f "$MAKECONF" && test -z "$PKGSRCDIR" && PKGSRCDIR="` \
                     80:     printf '.include "%s"\n_print_pkgsrcdir:\n\t@echo "${PKGSRCDIR}"\n' \
1.8       tnn        81:     "$MAKECONF" | "$MAKE" -f - BSD_PKG_MK=1 _print_pkgsrcdir`"
1.19      apb        82: if [ -z "$PKGSRCDIR" ] ; then
                     83:     for dir in . .. ../.. /usr/pkgsrc ; do
                     84:        if [ -f "${dir}/mk/bsd.pkg.mk" ]; then
                     85:            case "${dir}" in
                     86:            /*) PKGSRCDIR="${dir}" ;;
                     87:            *)  PKGSRCDIR="$( cd "${dir}" >/dev/null 2>&1 && pwd )" ;;
                     88:            esac
                     89:            break
                     90:        fi
                     91:     done
                     92: fi
                     93: test -z "$PKGSRCDIR" && echo >&2 "Please set PKGSRCDIR" && exit 1
1.12      tnn        94: test -z "$PKG_CHK" && PKG_CHK="@PKG_CHK@"
                     95: test -z "$PKG_INFO" && PKG_INFO="@PKG_INFO_CMD@"
1.1       gdt        96: 
1.19      apb        97: export PKGSRCDIR
                     98: 
1.1       gdt        99: unset PKG_PATH || true  #or pkgsrc makefiles will complain
                    100: 
                    101: usage()
                    102: {
                    103:     echo "Usage: pkg_rolling-replace [opts]
                    104:         -h         This help
1.34      abs       105:         -B         Pass -B to pkg_chk (only applies with -u)
1.22      sno       106:         -F         Fetch sources (including depends) only, don't build
                    107:         -k         Keep running, even on error
1.1       gdt       108:         -n         Don't actually do make replace
1.13      tnn       109:         -r         Just replace, don't create binary packages
                    110:         -s         Replace even if the ABIs are still compatible ("strict")
1.41    ! rhialto   111:         -u         Update mismatched packages
1.1       gdt       112:         -v         Verbose
1.25      sno       113:        -D VAR=VAL Passes given variables and values to make
1.22      sno       114:         -L <path>  Log to path (<path>/pkgdir/pkg)
1.20      wiz       115:         -X <pkg>   exclude <pkg> from being rebuilt
1.41    ! rhialto   116:         -x <pkg>   exclude <pkg> from mismatch check
1.1       gdt       117: 
                    118: pkg_rolling-replace does 'make replace' on one package at a time,
                    119: tsorting the packages being replaced according to their
                    120: interdependencies, which avoids most duplicate rebuilds.
                    121: 
                    122: pkg_rolling-replace can be used in one of two ways:
                    123: 
                    124:     - 'make replace' is unsafe in that, if the replaced package's ABI
                    125:       changes, its dependent packages may break.  If this happens, run
                    126:       'pkg_rolling-replace' (no arguments) to rebuild them against the
                    127:       new version.
                    128: 
1.41    ! rhialto   129:     - 'pkg_chk -u' will delete all your mismatched packages (where the
        !           130:       package version does not match the pkgsrc version), then reinstall
        !           131:       them one at a time, leaving you without those packages in the
        !           132:       meantime.  'pkg_rolling-replace -u' will instead upgrade them in
        !           133:       place, allowing you to keep using your system in the meantime
        !           134:       (maybe...if you're lucky...because pkg_rolling-replace replaces
        !           135:       the \"deepest\" dependency first, things could still break if that
        !           136:       happens to be a fundamental library whose ABI has changed).
1.1       gdt       137: "
                    138:     exit 1
                    139: }
                    140: 
                    141: # pkg_rolling-replace's output is intermingled with pkgsrc make
                    142: # output.  Thus, we use a different prefix.  pkgsrc uses '===>' for
                    143: # major steps, and '=>' for minor ones.  Thus, we use 'RR>'.
                    144: 
                    145: OPI='RR>'
                    146: OPC='rr>' # continuation
                    147: 
                    148: 
                    149: # Echo the names of packages needing updates, versions stripped.  This
                    150: # has been tested with pkg_chk 1.76.  Older versions are not
                    151: # supported.  Newer versions may or may not work (patches welcome).
                    152: check_packages_mismatched()
                    153: {
1.39      gdt       154:     ${PKG_CHK} -u -q $opt_B | egrep -v missing | while read line; do
1.1       gdt       155:         # duplicate output of pkg_chk to stderr (bypass $(...) or `...`)
1.11      tnn       156:         echo "${OPC} $line" 1>&2
1.1       gdt       157:        # Look for the first thing that looks like pkg-version rather
                    158:        # than category/pkg and remove the version.
                    159:         for word in $line; do
1.5       tnn       160:             if [ "$(echo $word | egrep '^[^/]+-[0-9][^-/]*$')" ]; then
1.41    ! rhialto   161:                if [ -z "$opt_F" ]; then
        !           162:                    pkg_admin set mismatch=YES "$word" 1>&2
        !           163:                fi
1.5       tnn       164:                 echo $word | sed 's/-[0-9][^-]*$//'
1.1       gdt       165:                 break  #done with this line
                    166:             fi
                    167:         done
                    168:     done
                    169: }
                    170: 
                    171: # usage: check_packages_w_flag flag
                    172: # echo packages with flag=YES
                    173: check_packages_w_flag()
                    174: {
                    175:     _flag=$1; shift
1.12      tnn       176:     for pkgver in $(${PKG_INFO} -e '*'); do
                    177:         if ${PKG_INFO} -Bq $pkgver \
1.1       gdt       178:                 | egrep "^$_flag=[Yy][Ee][Ss]" > /dev/null; then
1.5       tnn       179:             echo $pkgver | sed 's/-[0-9][^-]*$//'
1.1       gdt       180:         fi
                    181:     done
                    182: }
                    183: 
                    184: # echo dep->pkg edges for all installed packages
                    185: depgraph_installed()
                    186: {
1.15      tnn       187:        ${PKG_INFO} -N '*' | ${AWK} '                                   \
                    188:                /^Information for/ {                                    \
                    189:                        pkg=$3; sub("-[0-9][^-]*:$", "", pkg);          \
                    190:                        print pkg" "pkg;                                \
                    191:                        state=1;                                        \
                    192:                }                                                       \
1.16      gdt       193:                /^\** PACKAGE MAY NOT BE DELETED \**$/ { state=3; }     \
1.15      tnn       194:                /^./ {                                                  \
                    195:                        if (state == 2) {                               \
                    196:                                dep=$1; sub("-[0-9][^-]*$", "", dep);   \
                    197:                                print dep" "pkg;                        \
                    198:                        }                                               \
                    199:                }                                                       \
                    200:                /^Built using/ {                                        \
                    201:                        state=2                                         \
                    202:                }                                                       \
                    203:        '
1.1       gdt       204: }
                    205: 
                    206: # usage: who_requires pkg --in-graph DEPGRAPH
                    207: who_requires()
                    208: {
                    209:     _target=$1; shift
                    210:     test "$1" = '--in-graph' && shift || return $((false))
                    211: 
                    212:     while [ $# -gt 0 ]; do
                    213:         _dep=$1; _pkg=$2; shift 2;
                    214:         if [ $_dep = $_target -a $_dep != $_pkg ]; then
                    215:             echo $_pkg
                    216:         fi
                    217:     done
                    218: }
                    219: 
                    220: # usage: is_member x list
                    221: # return true (0) if x appears in list, false (1) otherwise
                    222: is_member()
                    223: {
                    224:     _x="$1"; shift;
                    225:     while [ $# -gt 0 -a "$1" != "$_x" ]; do
                    226:         shift
                    227:     done
                    228: 
                    229:     test $# -gt 0
                    230: }
                    231: 
                    232: # usage: exclude list1 --from list2
                    233: # echo list2 with items from list1 excluded
                    234: exclude()
                    235: {
                    236:     _excl=
                    237:     while [ $# -gt 0 -a $1 != "--from" ]; do
                    238:         _excl="$_excl $1"
                    239:         shift
                    240:     done
                    241:     if [ $# -gt 0 ]; then
                    242:         shift  #discard '--from'
                    243:     fi
                    244:     while [ $# -gt 0 ]; do
                    245:         is_member $1 $_excl || echo $1
                    246:         shift
                    247:     done
                    248: }
                    249: 
                    250: # usage: uniquify list
                    251: # just does sort -u on list (equiv. to sort | uniq)
                    252: # CAUTION: reorders list
                    253: uniqify()
                    254: {
                    255:     for _x in $*; do echo $_x; done | sort -u
                    256: }
                    257: 
                    258: verbose()
                    259: {
                    260:     if [ -n "$opt_v" ]; then
                    261:         echo "$@"
                    262:     fi
                    263: }
                    264: 
                    265: vsleep()
                    266: {
                    267:     if [ -n "$opt_v" ]; then
                    268:         sleep $1
                    269:     fi
                    270: }
                    271: 
1.22      sno       272: report()
                    273: {
1.26      tnn       274:     for a in $SUCCEEDED; do
1.22      sno       275:         verbose "+ $a"
                    276:     done
                    277: 
                    278:     for a in $FAILED; do
                    279:         verbose "- $a"
                    280:     done
                    281: }
                    282: 
1.13      tnn       283: abort()
                    284: {
1.26      tnn       285:     echo "*** $1"
                    286:     echo "*** Please read the errors listed above, fix the problem,"
                    287:     echo "*** then re-run pkg_rolling-replace to continue."
                    288:     report
                    289:     exit 1
                    290: }
                    291: 
                    292: error()
                    293: {
1.28      tnn       294:     if [ -z "$opt_k" ]; then
1.26      tnn       295:         abort "$1"
                    296:     fi
                    297:     echo "*** $1"
                    298: }
                    299: 
                    300: mark_as_succeeded()
                    301: {
1.27      tnn       302:     SUCCEEDED=$(uniqify $SUCCEEDED $1)
1.26      tnn       303: }
                    304: 
                    305: mark_as_failed()
                    306: {
1.27      tnn       307:     FAILED=$(uniqify $FAILED $1)
1.13      tnn       308: }
                    309: 
1.22      sno       310: todo()
                    311: {
                    312:     if [ -z "$opt_F" ]; then
                    313:         verbose "${OPI} Packages to rebuild:"
                    314:         verbose "${OPC} MISMATCH_TODO=[$(echo $MISMATCH_TODO)]"  #strip newlines
                    315:         verbose "${OPC} REBUILD_TODO=[$(echo $REBUILD_TODO)]"
                    316:         verbose "${OPC} UNSAFE_TODO=[$(echo $UNSAFE_TODO)]"
                    317:         REPLACE_TODO=$(uniqify $MISMATCH_TODO $REBUILD_TODO $UNSAFE_TODO)
                    318:     else
                    319:         REPLACE_TODO=$(uniqify $MISMATCH_TODO)
                    320:         verbose "${OPI} Packages to fetch:"
                    321:         verbose "${OPC} MISMATCH_TODO=[$(echo $MISMATCH_TODO)]"  #strip newlines
                    322:     fi
                    323:     REPLACE_TODO=$(exclude $REALLYEXCLUDE --from $REPLACE_TODO)
                    324:     if [ -n "$FAILED" ]; then
                    325:         REPLACE_TODO=$(exclude $FAILED --from $REPLACE_TODO)
                    326:     fi
                    327:     vsleep 2
                    328: }
                    329: 
1.1       gdt       330: ######################################################################
                    331: ##
                    332: ## main()
                    333: ##
                    334: 
                    335: EXCLUDE=
1.25      sno       336: MAKE_VAR="IN_PKG_ROLLING_REPLACE=1"
                    337: MAKE_VAR_SEP=" "
1.1       gdt       338: 
1.34      abs       339: args=$(getopt BFhknursvD:x:X:L: $*)
1.1       gdt       340: if [ $? -ne 0 ]; then
                    341:     opt_h=1
                    342: fi
                    343: set -- $args
                    344: while [ $# -gt 0 ]; do
                    345:     case "$1" in
1.34      abs       346:         -B) opt_B=-B ;;
1.22      sno       347:         -F) opt_F=1 ;;
1.1       gdt       348:         -h) opt_h=1 ;;
1.22      sno       349:         -k) opt_k=1 ;;
1.1       gdt       350:         -n) opt_n=1 ;;
1.13      tnn       351:         -r) opt_r=1 ;;
                    352:         -s) opt_s=1 ;;
1.1       gdt       353:         -u) opt_u=1 ;;
                    354:         -v) opt_v=1 ;;
1.25      sno       355:        -D) MAKE_VAR="${MAKE_VAR}${MAKE_VAR_SEP}$2"; MAKE_VAR_SEP=" "; shift ;;
1.1       gdt       356:         -x) EXCLUDE="$EXCLUDE $(echo $2 | sed 's/,/ /g')" ; shift ;;
1.17      apb       357:         -X) REALLYEXCLUDE="$REALLYEXCLUDE $(echo $2 | sed 's/,/ /g')" ; shift ;;
1.22      sno       358:         -L) LOGPATH="$2"; shift ;;
1.1       gdt       359:         --) shift; break ;;
                    360:     esac
                    361:     shift
                    362: done
                    363: 
                    364: if [ -n "$opt_h" ]; then
                    365:     usage
                    366: fi
                    367: 
1.13      tnn       368: if [ -n "$opt_s" ]; then
                    369:     UNSAFE_VAR=unsafe_depends_strict
                    370: else
                    371:     UNSAFE_VAR=unsafe_depends
                    372: fi
                    373: 
1.25      sno       374: MAKE="${MAKE}${MAKE_VAR_SEP}${MAKE_VAR}"
                    375: 
1.26      tnn       376: SUCCEEDED=""
1.22      sno       377: FAILED=""
                    378: 
1.1       gdt       379: MISMATCH_TODO=
1.41    ! rhialto   380: if [ -n "$opt_u" ]; then
1.1       gdt       381:     echo "${OPI} Checking for mismatched installed packages using pkg_chk"
                    382:     MISMATCH_TODO=$(check_packages_mismatched)
1.41    ! rhialto   383: else
        !           384:     echo "${OPI} Checking for mismatched installed packages (mismatch=YES)"
        !           385:     MISMATCH_TODO=$(check_packages_w_flag 'mismatch')
1.1       gdt       386: fi
                    387: 
1.41    ! rhialto   388: echo "${OPI} Excluding the following mismatched packages:"
        !           389: echo "${OPC} EXCLUDE=[$EXCLUDE]"
        !           390: MISMATCH_TODO=$(exclude $EXCLUDE --from $MISMATCH_TODO)
        !           391: 
1.22      sno       392: if [ -z "$opt_F" ]; then
                    393:     echo "${OPI} Checking for rebuild-requested installed packages (rebuild=YES)"
                    394:     REBUILD_TODO=$(check_packages_w_flag 'rebuild')
1.1       gdt       395: 
1.22      sno       396:     echo "${OPI} Checking for unsafe installed packages (${UNSAFE_VAR}=YES)"
                    397:     UNSAFE_TODO=$(check_packages_w_flag ${UNSAFE_VAR})
                    398: fi
1.1       gdt       399: 
                    400: # DEPGRAPH_INSTALLED is rebuilt each round.  DEPGRAPH_SRC will collect
                    401: # edges that we discover using 'make show-depends', but that weren't
                    402: # listed as depends by the installed version of a package, and
                    403: # DEPENDS_CHECKED lists packages for which we've already done that
                    404: # check.
                    405: DEPGRAPH_INSTALLED=
                    406: DEPGRAPH_SRC=
                    407: DEPENDS_CHECKED=
                    408: 
1.22      sno       409: todo
1.1       gdt       410: 
                    411: depgraph_built=0
                    412: 
                    413: while [ -n "$REPLACE_TODO" ]; do
1.22      sno       414:     fail=
                    415: 
1.1       gdt       416:     # don't rebuild depgraph if we continued from new-depends step below
                    417:     if [ "$depgraph_built" -eq 0 ]; then
                    418:         echo "${OPI} Building dependency graph for installed packages"
                    419:         DEPGRAPH_INSTALLED=$(depgraph_installed)
                    420:         depgraph_built=1
                    421:     fi
                    422: 
                    423:     echo "${OPI} Tsorting dependency graph"
                    424:     TSORTED=$(echo $DEPGRAPH_INSTALLED $DEPGRAPH_SRC | tsort)
1.29      gdt       425:     pkgdir=
1.1       gdt       426:     for pkg in $TSORTED; do
                    427:         if is_member $pkg $REPLACE_TODO; then
1.29      gdt       428:            pkgdir=$(${PKG_INFO} -Q PKGPATH $pkg)
1.40      gdt       429:            if [ -n "$pkgdir" ]; then
                    430:                break;
                    431:            else
                    432:                error "Couldn't extract PKGPATH from installed package $pkg"
                    433:            fi
1.1       gdt       434:         fi
                    435:     done
1.29      gdt       436:     # loop should never exit without selecting a package
                    437:     [ -n "$pkgdir" ] || abort "pkg_chk reports the following packages need replacing, but they are not installed: $REPLACE_TODO"
1.26      tnn       438: 
1.1       gdt       439:     echo "${OPI} Selecting $pkg ($pkgdir) as next package to replace"
                    440:     sleep 1
                    441: 
                    442:     # Newer versions in pkgsrc sometimes have more depends than are
                    443:     # recorded for the installed version (this is entirely to be
                    444:     # expected as packages are split, renamed, and add new features).
                    445:     # When this happens, add the new edges to the graph and re-tsort.
                    446:     # Don't re-tsort if the new edges were already installed once
                    447:     # (otherwise we'll go into a loop).
                    448: 
                    449:     # XXX I'm not sure that DEPENDS_CHECKED is necessary, or whether
                    450:     # simply ignoring new deps that aren't in $REPLACE_TODO would have
                    451:     # been sufficient.  The DEPENDS_CHECKED approach causes one extra
                    452:     # tsort in some cases, which isn't overly expensive.
                    453: 
                    454:     # XXX After tsorting and choosing what to 'make replace', we
                    455:     # filter out packages that aren't already installed and marked for
                    456:     # replacement.  This is safe, since uninstalled depends will be
                    457:     # pulled in automatically by 'make replace'; but in rare cases it
                    458:     # might be non-optimal, leading to a duplicate rebuild that we
                    459:     # would have avoided had we selected the uninstalled package in
                    460:     # tsorted order and run 'make install' on it.  This seems like
                    461:     # such a rare case that the added complexity isn't worth it.
                    462: 
1.30      gdt       463:     # Set PKGNAME_REQD to give underlying make processes a chance to
                    464:     # set options derived from the package name.  For example,
                    465:     # the appropriate version of Python can be derived from the
1.35      wiz       466:     # package name (so, when building py34-foo, use python-3.4,
1.33      wiz       467:     # not python-2.7).
1.32      gdt       468:     MAKE_SET_VARS="PKGNAME_REQD=${pkg}-*"
1.30      gdt       469: 
1.1       gdt       470:     if ! is_member $pkg $DEPENDS_CHECKED; then
                    471:        echo "${OPI} Checking if $pkg has new depends..."
1.12      tnn       472:        OLD_DEPENDS=$(${PKG_INFO} -Nq $pkg | sed 's/-[0-9][^-]*$//')
1.1       gdt       473:        NEW_DEPENDS=
                    474:        cd "$PKGSRCDIR/$pkgdir"
1.31      obache    475:        bdeps=$(@SETENV@ ${MAKE_SET_VARS} ${MAKE} show-depends VARNAME=BUILD_DEPENDS)
1.37      gdt       476:        tdeps=$(@SETENV@ ${MAKE_SET_VARS} ${MAKE} show-depends VARNAME=TOOL_DEPENDS)
1.31      obache    477:        rdeps=$(@SETENV@ ${MAKE_SET_VARS} ${MAKE} show-depends)
1.37      gdt       478:        for depver in $bdeps $tdeps $rdeps; do
1.10      tnn       479:            dep=$(echo $depver | sed -e 's/[:[].*$/0/' -e 's/[<>]=/-/' \
                    480:                -e 's/-[0-9][^-]*$//')
1.1       gdt       481:            if ! is_member $dep $OLD_DEPENDS $NEW_DEPENDS; then
                    482:                NEW_DEPENDS="$NEW_DEPENDS $dep"
                    483:                DEPGRAPH_SRC="$DEPGRAPH_SRC $dep $pkg"
                    484:            fi
                    485:        done
                    486:        DEPENDS_CHECKED="$DEPENDS_CHECKED $pkg"
                    487:        if [ -n "$NEW_DEPENDS" ]; then
                    488:            echo "${OPI} $pkg has the following new depends (need to re-tsort):"
                    489:            echo "${OPC} [$(echo $NEW_DEPENDS)]"
                    490:            sleep 2
                    491:            continue
                    492:        fi
                    493:     fi
                    494: 
1.22      sno       495:     pkgname=$(${PKG_INFO} -e $pkg)
                    496:     if [ -n "$LOGPATH" ]; then
                    497:         logdir="$LOGPATH/`dirname $pkgdir`"
                    498:         logfile="$logdir/$pkgname"
                    499:         @MKDIR@ "$logdir" || abort "mkdir -p '$logdir' failed"
                    500:         exec 3>"$logfile"
                    501:         tail -f "$logfile" &
                    502:         TAILPID=$!
                    503:     fi
                    504: 
1.1       gdt       505:     # Do make replace, with clean before, and package and clean afterwards.
1.13      tnn       506:     fail=
1.23      sno       507:     if [ -d "$PKGSRCDIR/$pkgdir" ]; then
                    508:        cd "$PKGSRCDIR/$pkgdir";
1.22      sno       509:     else
1.36      gdt       510:        fail=1
1.26      tnn       511:         mark_as_failed $pkg
                    512:        error "No package directory '$pkgdir' for $pkg."
1.22      sno       513:     fi
1.23      sno       514: 
                    515:     if [ -z "$fail" ]; then
                    516:        if [ -z "$opt_F" ]; then
                    517:            echo "${OPI} Replacing $pkgname"
1.31      obache    518:            cmd="@SETENV@ ${MAKE_SET_VARS} ${MAKE} clean || fail=1"
1.23      sno       519:            if [ -n "$opt_n" ]; then
                    520:                echo "${OPI} Would run: $cmd"
                    521:            else
                    522:                if [ -n "$logfile" ]; then
                    523:                    eval "$cmd" >&3 2>&3
                    524:                else
                    525:                    eval "$cmd"
                    526:                fi
                    527:                if [ -n "$fail" ]; then
1.26      tnn       528:                     mark_as_failed $pkg
                    529:                    error "'make clean' failed for package $pkg."
1.23      sno       530:                fi
                    531:            fi
1.31      obache    532:            cmd="@SETENV@ ${MAKE_SET_VARS} ${MAKE} replace || fail=1" # XXX OLDNAME= support? xmlrpc-c -> xmlrpc-c-ss
1.23      sno       533:        else
                    534:            echo "${OPI} Fetching $pkgname"
1.31      obache    535:            cmd="@SETENV@ ${MAKE_SET_VARS} ${MAKE} fetch depends-fetch || fail=1"
1.23      sno       536:        fi
                    537:     fi
                    538: 
1.22      sno       539:     if [ -n "$opt_n" -a -z "$fail" ]; then
1.13      tnn       540:        echo "${OPI} Would run: $cmd"
1.22      sno       541:     elif [ -z "$fail" ]; then
                    542:         if [ -n "$logfile" ]; then
                    543:             eval "$cmd" >&3 2>&3
                    544:         else
                    545:             eval "$cmd"
                    546:         fi
                    547:        if [ -n "$fail" ]; then
1.26      tnn       548:             mark_as_failed $pkg
                    549:             error "'make replace' failed for package $pkg."
1.22      sno       550:         fi
1.13      tnn       551:     fi
1.22      sno       552:     if [ -z "$opt_n" -a -z "$opt_k" -a -z "$opt_F" ]; then
1.13      tnn       553:        [ -z "$(${PKG_INFO} -Q unsafe_depends_strict $pkg)" ] || \
                    554:            abort "package $pkg still has unsafe_depends_strict."
                    555:        [ -z "$(${PKG_INFO} -Q unsafe_depends $pkg)" ] || \
                    556:            abort "package $pkg still has unsafe_depends."
                    557:        [ -z "$(${PKG_INFO} -Q rebuild $pkg)" ] || \
                    558:            abort "package $pkg is still requested to be rebuilt."
1.41    ! rhialto   559:        [ -z "$(${PKG_INFO} -Q mismatch $pkg)" ] || \
        !           560:            abort "package $pkg is still a mismatched version."
1.1       gdt       561:     fi
1.18      gdt       562:     # If -r not given, make a binary package.
1.22      sno       563:     if [ -z "$opt_r" -a -z "$fail" -a -z "$opt_F" ]; then
1.13      tnn       564:        echo "${OPI} Packaging $(${PKG_INFO} -e $pkg)"
1.31      obache    565:        cmd="@SETENV@ ${MAKE_SET_VARS} ${MAKE} package || fail=1"
1.22      sno       566:        if [ -n "$opt_n" -a -z "$fail" ]; then
1.13      tnn       567:            echo "${OPI} Would run: $cmd"
1.22      sno       568:        elif [ -z "$fail" ]; then
                    569:             if [ -n "$logfile" ]; then
                    570:                 eval "$cmd" >&3 2>&3
                    571:             else
                    572:                 eval "$cmd"
                    573:             fi
                    574:             if [ -n "$fail" ]; then
1.26      tnn       575:                 mark_as_failed $pkg
                    576:                 error "'make package' failed for package $pkg."
1.22      sno       577:             fi
1.13      tnn       578:        fi
1.1       gdt       579:     fi
1.18      gdt       580:     # Clean
1.22      sno       581:     if [ -z "$opt_n" -a -z "$fail" -a -z "$opt_F" ]; then
1.31      obache    582:         cmd="@SETENV@ ${MAKE_SET_VARS} ${MAKE} clean || fail=1"
1.22      sno       583:         if [ -n "$logfile" ]; then
                    584:             eval "$cmd" >&3 2>&3
                    585:         else
                    586:             eval "$cmd"
                    587:         fi
                    588:        if [ -n "$fail" ]; then
1.26      tnn       589:             mark_as_failed $pkg
                    590:             error "'make clean' failed for package $pkg."
1.22      sno       591:         fi
                    592:     fi
                    593: 
                    594:     if [ -z "$fail" ]; then
1.26      tnn       595:         mark_as_succeeded $pkg
1.18      gdt       596:     fi
                    597: 
1.1       gdt       598:     sleep 1
                    599: 
                    600:     # remove just-replaced package from all *_TODO lists
                    601:     MISMATCH_TODO=$(exclude $pkg --from $MISMATCH_TODO)
                    602:     REBUILD_TODO=$(exclude $pkg --from $REBUILD_TODO)
                    603:     UNSAFE_TODO=$(exclude $pkg --from $UNSAFE_TODO)
                    604: 
1.13      tnn       605:     echo "${OPI} Re-checking for unsafe installed packages (${UNSAFE_VAR}=YES)"
1.1       gdt       606:     if [ -n "$opt_n" ]; then
                    607:        # With -n, the replace didn't happen, and thus the packages that would
                    608:        # have been marked unsafe_depends=YES were not.  Add the set that
                    609:        # would have been marked so we can watch what pkg_rolling-replace
                    610:        # would have done (approximately).
                    611:         UNSAFE_TODO=$(uniqify $UNSAFE_TODO \
                    612:             $(who_requires $pkg --in-graph $DEPGRAPH_INSTALLED))
                    613:         sleep 1
                    614:     else
1.13      tnn       615:         UNSAFE_TODO=$(check_packages_w_flag ${UNSAFE_VAR})
1.1       gdt       616:     fi
                    617: 
1.22      sno       618:     depgraph_built=0
                    619: 
                    620:     todo
                    621:     vsleep 2
1.1       gdt       622: 
1.22      sno       623:     if [ -n "$logfile" ]; then
                    624:         exec 3>&-
                    625:         kill $TAILPID
                    626:     fi
1.1       gdt       627: done
                    628: 
                    629: echo "${OPI} No more packages to replace; done."
1.22      sno       630: 
                    631: report

CVSweb <webmaster@jp.NetBSD.org>