Mon Apr 30 13:59:39 2012 UTC ()
Use " for PKGNAME_REQUIRED, so that ${pkg} is expanded.

Resolves at least some issues with finding the right pyNN-foo, when
replacing packages that don't match PYTHON_VERSION_DEFAULT.

(This was a stray change in my tree not committed for a while, but
it's been working ok.)

Now 0.24.1.


(gdt)
diff -r1.32 -r1.33 pkgsrc/pkgtools/pkg_rolling-replace/Makefile
diff -r1.31 -r1.32 pkgsrc/pkgtools/pkg_rolling-replace/files/pkg_rolling-replace.sh

cvs diff -r1.32 -r1.33 pkgsrc/pkgtools/pkg_rolling-replace/Makefile (switch to unified diff)

--- pkgsrc/pkgtools/pkg_rolling-replace/Makefile 2011/03/22 04:04:58 1.32
+++ pkgsrc/pkgtools/pkg_rolling-replace/Makefile 2012/04/30 13:59:38 1.33
@@ -1,59 +1,59 @@ @@ -1,59 +1,59 @@
1# $NetBSD: Makefile,v 1.32 2011/03/22 04:04:58 obache Exp $ 1# $NetBSD: Makefile,v 1.33 2012/04/30 13:59:38 gdt Exp $
2 2
3DISTNAME= pkg_rolling-replace-0.24 3DISTNAME= pkg_rolling-replace-0.24.1
4CATEGORIES= pkgtools 4CATEGORIES= pkgtools
5MASTER_SITES= # empty 5MASTER_SITES= # empty
6DISTFILES= # empty 6DISTFILES= # empty
7 7
8MAINTAINER= ngoffee@bbn.com 8MAINTAINER= ngoffee@bbn.com
9COMMENT= Replace/upgrade packages in-place 9COMMENT= Replace/upgrade packages in-place
10 10
11DEPENDS+= pkg_chk>=1.76:../../pkgtools/pkg_chk 11DEPENDS+= pkg_chk>=1.76:../../pkgtools/pkg_chk
12DEPENDS+= pkg_tarup>=1.6.6:../../pkgtools/pkg_tarup 12DEPENDS+= pkg_tarup>=1.6.6:../../pkgtools/pkg_tarup
13 13
14PKG_INSTALLATION_TYPES= overwrite pkgviews 14PKG_INSTALLATION_TYPES= overwrite pkgviews
15PKG_DESTDIR_SUPPORT= user-destdir 15PKG_DESTDIR_SUPPORT= user-destdir
16 16
17USE_TOOLS+= patch 17USE_TOOLS+= patch
18 18
19WRKSRC= ${WRKDIR} 19WRKSRC= ${WRKDIR}
20NO_BUILD= yes 20NO_BUILD= yes
21USE_LANGUAGES= # none 21USE_LANGUAGES= # none
22 22
23INSTALLATION_DIRS= sbin ${PKGMANDIR}/man8 23INSTALLATION_DIRS= sbin ${PKGMANDIR}/man8
24 24
25PKG_CHK?= ${PREFIX}/sbin/pkg_chk 25PKG_CHK?= ${PREFIX}/sbin/pkg_chk
26 26
27SUBST_CLASSES+= tools 27SUBST_CLASSES+= tools
28SUBST_STAGE.tools= pre-configure 28SUBST_STAGE.tools= pre-configure
29SUBST_MESSAGE.tools= Substituting tool locations. 29SUBST_MESSAGE.tools= Substituting tool locations.
30SUBST_FILES.tools= pkg_rolling-replace.sh 30SUBST_FILES.tools= pkg_rolling-replace.sh
31SUBST_VARS.tools= PKG_INFO_CMD MAKE PKG_CHK AWK MKDIR SETENV 31SUBST_VARS.tools= PKG_INFO_CMD MAKE PKG_CHK AWK MKDIR SETENV
32 32
33SUBST_CLASSES+= prefix 33SUBST_CLASSES+= prefix
34SUBST_STAGE.prefix= pre-configure 34SUBST_STAGE.prefix= pre-configure
35SUBST_MESSAGE.prefix= Substituting PREFIX location. 35SUBST_MESSAGE.prefix= Substituting PREFIX location.
36SUBST_FILES.prefix= pkg_rolling-replace.8 36SUBST_FILES.prefix= pkg_rolling-replace.8
37SUBST_VARS.prefix= PREFIX 37SUBST_VARS.prefix= PREFIX
38 38
39SUBST_CLASSES+= makeconf 39SUBST_CLASSES+= makeconf
40SUBST_STAGE.makeconf= pre-configure 40SUBST_STAGE.makeconf= pre-configure
41SUBST_MESSAGE.makeconf= Recording default path of mk.conf. 41SUBST_MESSAGE.makeconf= Recording default path of mk.conf.
42SUBST_FILES.makeconf= pkg_rolling-replace.sh pkg_rolling-replace.8 42SUBST_FILES.makeconf= pkg_rolling-replace.sh pkg_rolling-replace.8
43SUBST_SED.makeconf= -e 's,@MAKECONF@,${MAKE:T:Mbmake:S/bmake/${PREFIX}/g}/etc/mk.conf,g' 43SUBST_SED.makeconf= -e 's,@MAKECONF@,${MAKE:T:Mbmake:S/bmake/${PREFIX}/g}/etc/mk.conf,g'
44 44
45REPLACE_SH+= pkg_rolling-replace.sh 45REPLACE_SH+= pkg_rolling-replace.sh
46 46
47.include "../../mk/bsd.prefs.mk" 47.include "../../mk/bsd.prefs.mk"
48 48
49do-extract: 49do-extract:
50 cp ${FILESDIR}/pkg_rolling-replace.sh ${WRKSRC} 50 cp ${FILESDIR}/pkg_rolling-replace.sh ${WRKSRC}
51 cp ${FILESDIR}/pkg_rolling-replace.8 ${WRKSRC} 51 cp ${FILESDIR}/pkg_rolling-replace.8 ${WRKSRC}
52 52
53do-install: 53do-install:
54 ${INSTALL_SCRIPT} ${WRKSRC}/pkg_rolling-replace.sh \ 54 ${INSTALL_SCRIPT} ${WRKSRC}/pkg_rolling-replace.sh \
55 ${DESTDIR}${PREFIX}/sbin/pkg_rolling-replace 55 ${DESTDIR}${PREFIX}/sbin/pkg_rolling-replace
56 ${INSTALL_MAN} ${WRKSRC}/pkg_rolling-replace.8 \ 56 ${INSTALL_MAN} ${WRKSRC}/pkg_rolling-replace.8 \
57 ${DESTDIR}${PREFIX}/${PKGMANDIR}/man8/pkg_rolling-replace.8 57 ${DESTDIR}${PREFIX}/${PKGMANDIR}/man8/pkg_rolling-replace.8
58 58
59.include "../../mk/bsd.pkg.mk" 59.include "../../mk/bsd.pkg.mk"

cvs diff -r1.31 -r1.32 pkgsrc/pkgtools/pkg_rolling-replace/files/pkg_rolling-replace.sh (switch to unified diff)

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