Thu Jul 9 20:10:39 2009 UTC ()
Pullup ticket #2804 - by he
mk/bulk/build: robustness improvement

Revisions pulled up:
- mk/bulk/build			1.106
---
Module Name:	pkgsrc
Committed By:	he
Date:		Thu Jul  9 12:46:50 UTC 2009

Modified Files:
	pkgsrc/mk/bulk: build

Log Message:
With the most recent pkg_install, directories are removed when the
last file in a directory is removed.  This might cause common and
expected-to-be-existing directories in /usr/pkg to be removed, and
a subsequent attempt at installing a file to the now non-existent
directory will instead create a file with the name of the expected
directory.

This will create PLIST errors for the package in question, but also will
cause the erroneously named file to not be removed on package removal.

This can cause cascading bulk build failures for subsequent packages.
To prevent this, after each package is done, check if some of the
common top-level expected-to-be directories are now files, and
remove them and emit an error message if so.

I *think* I already fixed the single package which had the unfortunate
problem of not declaring "include" as an installation directory, but
this should prevent the problem from re-occurring in the future as well.

Thanks to joerg@ for the hint for pulling in the value of PREFIX.


(tron)
diff -r1.105 -r1.105.14.1 pkgsrc/mk/bulk/build

cvs diff -r1.105 -r1.105.14.1 pkgsrc/mk/bulk/Attic/build (switch to unified diff)

--- pkgsrc/mk/bulk/Attic/build 2008/06/13 21:52:16 1.105
+++ pkgsrc/mk/bulk/Attic/build 2009/07/09 20:10:39 1.105.14.1
@@ -1,494 +1,505 @@ @@ -1,494 +1,505 @@
1#!/bin/sh 1#!/bin/sh
2# $NetBSD: build,v 1.105 2008/06/13 21:52:16 sketch Exp $ 2# $NetBSD: build,v 1.105.14.1 2009/07/09 20:10:39 tron Exp $
3 3
4# 4#
5# Copyright (c) 1999, 2000 Hubert Feyrer <hubertf@NetBSD.org> 5# Copyright (c) 1999, 2000 Hubert Feyrer <hubertf@NetBSD.org>
6# All rights reserved. 6# All rights reserved.
7# 7#
8# Redistribution and use in source and binary forms, with or without 8# Redistribution and use in source and binary forms, with or without
9# modification, are permitted provided that the following conditions 9# modification, are permitted provided that the following conditions
10# are met: 10# are met:
11# 1. Redistributions of source code must retain the above copyright 11# 1. Redistributions of source code must retain the above copyright
12# notice, this list of conditions and the following disclaimer. 12# notice, this list of conditions and the following disclaimer.
13# 2. Redistributions in binary form must reproduce the above copyright 13# 2. Redistributions in binary form must reproduce the above copyright
14# notice, this list of conditions and the following disclaimer in the 14# notice, this list of conditions and the following disclaimer in the
15# documentation and/or other materials provided with the distribution. 15# documentation and/or other materials provided with the distribution.
16# 3. All advertising materials mentioning features or use of this software 16# 3. All advertising materials mentioning features or use of this software
17# must display the following acknowledgement: 17# must display the following acknowledgement:
18# This product includes software developed by Hubert Feyrer for 18# This product includes software developed by Hubert Feyrer for
19# the NetBSD Project. 19# the NetBSD Project.
20# 20#
21# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31# 31#
32 32
33## 33##
34## Globals 34## Globals
35## 35##
36scriptdir=`dirname "$0"` 36scriptdir=`dirname "$0"`
37scriptdir=`cd "${scriptdir}" && pwd` 37scriptdir=`cd "${scriptdir}" && pwd`
38 38
39# 39#
40# Default values for command line options. 40# Default values for command line options.
41# 41#
42resume=no 42resume=no
43mirror_only=no 43mirror_only=no
44target=bulk-package 44target=bulk-package
45makeargs="" 45makeargs=""
46noemail=no 46noemail=no
47post_only=no 47post_only=no
48prepare_only=no 48prepare_only=no
49 49
50## 50##
51## Functions 51## Functions
52## 52##
53 53
54usage () { 54usage () {
55 cat <<EOF 55 cat <<EOF
56usage: $0 [options] 56usage: $0 [options]
57 $0 -h | --help 57 $0 -h | --help
58 58
59Runs a bulk pkgsrc build. 59Runs a bulk pkgsrc build.
60 60
61The following options are supported: 61The following options are supported:
62 62
63 -c | --config <file> 63 -c | --config <file>
64 Load the following configuration file instead of the default 64 Load the following configuration file instead of the default
65 one. 65 one.
66 66
67 -e | --no-email 67 -e | --no-email
68 Don't send email when the bulk build is finished. 68 Don't send email when the bulk build is finished.
69 69
70 -h | --help 70 -h | --help
71 Displays this message. 71 Displays this message.
72 72
73 -m | --mirror_only 73 -m | --mirror_only
74 Downloads all distfiles needed for the build but does not run 74 Downloads all distfiles needed for the build but does not run
75 the build. IMPORTANT: Note that this will still run all the 75 the build. IMPORTANT: Note that this will still run all the
76 pre-build stuff which involves removing all of your installed 76 pre-build stuff which involves removing all of your installed
77 packages. 77 packages.
78 78
79 The only difference between this option and a regular bulk build 79 The only difference between this option and a regular bulk build
80 is that the packages are not actually built. 80 is that the packages are not actually built.
81 81
82 -p | --post-build 82 -p | --post-build
83 Run the post-build processing and generate the report only. 83 Run the post-build processing and generate the report only.
84 84
85 --prepare 85 --prepare
86 Only generate the package database that will be used when bulk 86 Only generate the package database that will be used when bulk
87 building the packages. 87 building the packages.
88 88
89 -r | --resume 89 -r | --resume
90 Resume a previously interrupted bulk build. 90 Resume a previously interrupted bulk build.
91 91
92 The --resume option may be combined with the --mirror_only 92 The --resume option may be combined with the --mirror_only
93 option. 93 option.
94 94
95 -s | --specific-pkgs 95 -s | --specific-pkgs
96 Sets SPECIFIC_PKGS=1 when building packages. This option is 96 Sets SPECIFIC_PKGS=1 when building packages. This option is
97 used for building a subset of pkgsrc. 97 used for building a subset of pkgsrc.
98 98
99EOF 99EOF
100} 100}
101 101
102# print out error message and exit 1 102# print out error message and exit 1
103die () { 103die () {
104 echo "$0: error:" 1>&2 104 echo "$0: error:" 1>&2
105 for i in "$@"; do 105 for i in "$@"; do
106 echo " $i" 1>&2 106 echo " $i" 1>&2
107 done 107 done
108 exit 1 108 exit 1
109} 109}
110 110
111# This function can be overridden in the build.conf file to change the 111# This function can be overridden in the build.conf file to change the
112# output format of the bulk build. It is used in a pipe, so if you want 112# output format of the bulk build. It is used in a pipe, so if you want
113# the original output, just define post_filter_cmd() { cat; }. 113# the original output, just define post_filter_cmd() { cat; }.
114# 114#
115# For more sophisticated output, you may use all the variables that this 115# For more sophisticated output, you may use all the variables that this
116# example function uses. 116# example function uses.
117post_filter_cmd() { 117post_filter_cmd() {
118 ${SED} "s;^;`date '+%Y/%m/%d %H:%M:%S'` ${percent} ${pkgdir} @ ${MACHINE_ARCH}> ;g" 118 ${SED} "s;^;`date '+%Y/%m/%d %H:%M:%S'` ${percent} ${pkgdir} @ ${MACHINE_ARCH}> ;g"
119} 119}
120 120
121# perform post-processing of the bulk-build results 121# perform post-processing of the bulk-build results
122do_post_build () { 122do_post_build () {
123 echo "build> Post processing bulk build results..." 123 echo "build> Post processing bulk build results..."
124 124
125 # Re-install BULK_PREREQ as we may need functionality (e.g. SMTP) provided by 125 # Re-install BULK_PREREQ as we may need functionality (e.g. SMTP) provided by
126 # them for post-build to run. 126 # them for post-build to run.
127 echo "build> Re-installing prerequisite packages specified with BULK_PREREQ..." 127 echo "build> Re-installing prerequisite packages specified with BULK_PREREQ..."
128 for pkgdir in $BULK_PREREQ lang/perl5; do 128 for pkgdir in $BULK_PREREQ lang/perl5; do
129 echo "build> Installing prerequisite package $pkgdir" 129 echo "build> Installing prerequisite package $pkgdir"
130 ( cd "${pkgsrc_dir}/${pkgdir}" \ 130 ( cd "${pkgsrc_dir}/${pkgdir}" \
131 && ${BMAKE} bulk-install 131 && ${BMAKE} bulk-install
132 ) || die "Failed to install prerequisite packages." 132 ) || die "Failed to install prerequisite packages."
133 done 133 done
134 134
135 # 135 #
136 # Generate the post-build report. 136 # Generate the post-build report.
137 # 137 #
138 echo "build> Generating the bulk build report..." 138 echo "build> Generating the bulk build report..."
139 139
140 bulk_build_id=`cat "${BULK_BUILD_ID_FILE}"` \ 140 bulk_build_id=`cat "${BULK_BUILD_ID_FILE}"` \
141 || die "Could not read the bulk build ID from ${BULK_BUILD_ID_FILE}." 141 || die "Could not read the bulk build ID from ${BULK_BUILD_ID_FILE}."
142 142
143 report_dir="${REPORTS_DIR}/${bulk_build_id}" 143 report_dir="${REPORTS_DIR}/${bulk_build_id}"
144 ${MKDIR} "${report_dir}" 144 ${MKDIR} "${report_dir}"
145 ( cd "${pkgsrc_dir}" \ 145 ( cd "${pkgsrc_dir}" \
146 && ${PERL5} mk/bulk/post-build \ 146 && ${PERL5} mk/bulk/post-build \
147 > "${report_dir}/${REPORT_TXT_FILE}" 147 > "${report_dir}/${REPORT_TXT_FILE}"
148 ) || die "Could not write the results file." 148 ) || die "Could not write the results file."
149} 149}
150 150
151# Notify the ADMIN of the finished build. 151# Notify the ADMIN of the finished build.
152do_email () { 152do_email () {
153 case $noemail in 153 case $noemail in
154 no) cat "${report_dir}/${REPORT_TXT_FILE}" \ 154 no) cat "${report_dir}/${REPORT_TXT_FILE}" \
155 | ${MAIL_CMD} -s "pkgsrc ${OPSYS} ${OS_VERSION}/${MACHINE_ARCH} bulk build results ${bulk_build_id}" "$ADMIN" 155 | ${MAIL_CMD} -s "pkgsrc ${OPSYS} ${OS_VERSION}/${MACHINE_ARCH} bulk build results ${bulk_build_id}" "$ADMIN"
156 esac 156 esac
157} 157}
158 158
159# output final note that we're done 159# output final note that we're done
160do_done () { 160do_done () {
161 echo "" 161 echo ""
162 echo "build> Bulk build ended: `date`" 162 echo "build> Bulk build ended: `date`"
163} 163}
164 164
165# set all commonly used variables, prepare files etc. 165# set all commonly used variables, prepare files etc.
166do_common_setup () { 166do_common_setup () {
167 167
168 # 168 #
169 # Choose an appropriate value for BMAKE depending on the operating 169 # Choose an appropriate value for BMAKE depending on the operating
170 # system. 170 # system.
171 # 171 #
172 opsys=`uname -s` 172 opsys=`uname -s`
173 case "$opsys" in 173 case "$opsys" in
174 NetBSD) BMAKE=make ;; 174 NetBSD) BMAKE=make ;;
175 *) BMAKE=bmake ;; 175 *) BMAKE=bmake ;;
176 esac 176 esac
177 export BMAKE 177 export BMAKE
178 178
179 # 179 #
180 # Set resource limits as high as possible 180 # Set resource limits as high as possible
181 # 181 #
182 ulimit -S -s `ulimit -H -s` # XXX: why do we need unlimited stack? 182 ulimit -S -s `ulimit -H -s` # XXX: why do we need unlimited stack?
183 ulimit -S -d `ulimit -H -d` # some processes grow rather large 183 ulimit -S -d `ulimit -H -d` # some processes grow rather large
184 ulimit -S -t `ulimit -H -t` # pkgsrc bulk builds need _much_ time 184 ulimit -S -t `ulimit -H -t` # pkgsrc bulk builds need _much_ time
185 185
186 # 186 #
187 # Find the configuration file. 187 # Find the configuration file.
188 # 188 #
189 BULK_BUILD_CONF="${BULK_BUILD_CONF-${scriptdir}/build.conf}" 189 BULK_BUILD_CONF="${BULK_BUILD_CONF-${scriptdir}/build.conf}"
190 case $BULK_BUILD_CONF in 190 case $BULK_BUILD_CONF in
191 /*) ;; 191 /*) ;;
192 *) BULK_BUILD_CONF="${PWD}/${BULK_BUILD_CONF}" 192 *) BULK_BUILD_CONF="${PWD}/${BULK_BUILD_CONF}"
193 esac 193 esac
194 194
195 # 195 #
196 # Load the variables from the configuration file. 196 # Load the variables from the configuration file.
197 # 197 #
198 { test -f "${BULK_BUILD_CONF}" \ 198 { test -f "${BULK_BUILD_CONF}" \
199 && . "${BULK_BUILD_CONF}" \ 199 && . "${BULK_BUILD_CONF}" \
200 && . "${scriptdir}/post-build-conf" \ 200 && . "${scriptdir}/post-build-conf" \
201 && check_config_vars \ 201 && check_config_vars \
202 && export_config_vars 202 && export_config_vars
203 } || die "Cannot load config file ${BULK_BUILD_CONF}, aborting." 203 } || die "Cannot load config file ${BULK_BUILD_CONF}, aborting."
204 204
205 # 205 #
206 # Set the paths to commonly used directories. 206 # Set the paths to commonly used directories.
207 # 207 #
208 pkgsrc_dir="${USR_PKGSRC}" 208 pkgsrc_dir="${USR_PKGSRC}"
209 lintpkgsrc_dir="${USR_PKGSRC}/pkgtools/lintpkgsrc" 209 lintpkgsrc_dir="${USR_PKGSRC}/pkgtools/lintpkgsrc"
210 210
211 # 211 #
212 # Set up variables specific for the bulk build. 212 # Set up variables specific for the bulk build.
213 # 213 #
214 BATCH="1" 214 BATCH="1"
215 DEPENDS_TARGET="bulk-install" 215 DEPENDS_TARGET="bulk-install"
216 export BATCH DEPENDS_TARGET 216 export BATCH DEPENDS_TARGET
217 217
218 # 218 #
219 # Unset some environment variables that could disturbe the build. 219 # Unset some environment variables that could disturbe the build.
220 # 220 #
221 unset CDPATH || true # ensure cd does not print new cwd to stdout, which 221 unset CDPATH || true # ensure cd does not print new cwd to stdout, which
222 # confuses the printindex script. 222 # confuses the printindex script.
223 unset DISPLAY || true # allow sane failure for gimp, xlispstat 223 unset DISPLAY || true # allow sane failure for gimp, xlispstat
224} 224}
225 225
226# Check that the package tools are up to date. 226# Check that the package tools are up to date.
227check_tools () { 227check_tools () {
228 echo "build> Checking if the pkgtools are up-to-date" 228 echo "build> Checking if the pkgtools are up-to-date"
229 ( cd "${lintpkgsrc_dir}" \ 229 ( cd "${lintpkgsrc_dir}" \
230 && ${BMAKE} fetch >/dev/null 2>&1 230 && ${BMAKE} fetch >/dev/null 2>&1
231 ) || { 231 ) || {
232 echo "build> Updating pkgtools" 232 echo "build> Updating pkgtools"
233 ( cd "${pkgsrc_dir}/pkgtools/pkg_install" \ 233 ( cd "${pkgsrc_dir}/pkgtools/pkg_install" \
234 && ${BMAKE} clean \ 234 && ${BMAKE} clean \
235 && ${BMAKE} update 235 && ${BMAKE} update
236 ) || die "Could not update the package tools." 236 ) || die "Could not update the package tools."
237 } 237 }
238} 238}
239 239
240# Run the pre-build script if necessary. 240# Run the pre-build script if necessary.
241run_pre_build () { 241run_pre_build () {
242 case $resume in 242 case $resume in
243 yes) echo "build> Resuming -- skipping pre-build script";; 243 yes) echo "build> Resuming -- skipping pre-build script";;
244 *) # make veryveryclean :) 244 *) # make veryveryclean :)
245 ( cd "${pkgsrc_dir}" \ 245 ( cd "${pkgsrc_dir}" \
246 && /bin/sh mk/bulk/pre-build 246 && /bin/sh mk/bulk/pre-build
247 ) || die "Error during bulk-build preparations, aborting.";; 247 ) || die "Error during bulk-build preparations, aborting.";;
248 esac 248 esac
249} 249}
250 250
251# Load pkgsrc variables that affect the build process. 251# Load pkgsrc variables that affect the build process.
252load_vars () { 252load_vars () {
253 echo "+----------------------------------------+" 253 echo "+----------------------------------------+"
254 echo "| Some variables used in the bulk build: |" 254 echo "| Some variables used in the bulk build: |"
255 echo "+----------------------------------------+" 255 echo "+----------------------------------------+"
256 256
257 vars=" OPSYS OS_VERSION MACHINE_ARCH 257 vars=" OPSYS OS_VERSION MACHINE_ARCH
258 BULK_PREREQ 258 BULK_PREREQ
259 BULKFILESDIR 259 BULKFILESDIR
260 BULK_DBFILE DEPENDSFILE INDEXFILE ORDERFILE STARTFILE 260 BULK_DBFILE DEPENDSFILE INDEXFILE ORDERFILE STARTFILE
261 SUPPORTSFILE BULK_BUILD_ID_FILE BUILDLOG BROKENFILE 261 SUPPORTSFILE BULK_BUILD_ID_FILE BUILDLOG BROKENFILE
262 BROKENWRKLOG 262 BROKENWRKLOG
 263 PREFIX
263 AWK GREP MAIL_CMD MKDIR PAX PERL5 SED 264 AWK GREP MAIL_CMD MKDIR PAX PERL5 SED
264 PKG_DELETE PKG_INFO PKGBASE" 265 PKG_DELETE PKG_INFO PKGBASE"
265 266
266 values=`cd "$lintpkgsrc_dir" && $BMAKE show-vars VARNAMES="$vars" USE_TOOLS="awk grep mail mkdir pax perl sed"` 267 values=`cd "$lintpkgsrc_dir" && $BMAKE show-vars VARNAMES="$vars" USE_TOOLS="awk grep mail mkdir pax perl sed"`
267 268
268 for v in $vars; do 269 for v in $vars; do
269 eval "read $v" || die "Could not read value for $v" 270 eval "read $v" || die "Could not read value for $v"
270 eval "value=\$$v" 271 eval "value=\$$v"
271 if [ "$v" != "BULK_PREREQ" ] && [ ! "$value" ]; then 272 if [ "$v" != "BULK_PREREQ" ] && [ ! "$value" ]; then
272 die "$v must not be empty." 273 die "$v must not be empty."
273 fi 274 fi
274 printf "%-15s = %s\\n" "$v" "$value" 275 printf "%-15s = %s\\n" "$v" "$value"
275 done <<EOF 276 done <<EOF
276$values 277$values
277EOF 278EOF
278 echo "------------------------------------------" 279 echo "------------------------------------------"
279 [ "$PKGBASE" = "lintpkgsrc" ] \ 280 [ "$PKGBASE" = "lintpkgsrc" ] \
280 || die "Error reading the variables." \ 281 || die "Error reading the variables." \
281 "Try running $0 with another shell." 282 "Try running $0 with another shell."
282 283
283 # Get the location of commonly used files 284 # Get the location of commonly used files
284 main_buildlog="${BULKFILESDIR}/${BUILDLOG}" 285 main_buildlog="${BULKFILESDIR}/${BUILDLOG}"
285} 286}
286 287
287# Install prerequisite packages. 288# Install prerequisite packages.
288# 289#
289# Note: we do this _before_ the depends tree because some packages like 290# Note: we do this _before_ the depends tree because some packages like
290# xpkgwedge only become DEPENDS if they are installed. 291# xpkgwedge only become DEPENDS if they are installed.
291install_prereqs () { 292install_prereqs () {
292 echo "build> Installing prerequisite packages specified with BULK_PREREQ..." 293 echo "build> Installing prerequisite packages specified with BULK_PREREQ..."
293 for pkgdir in $BULK_PREREQ; do 294 for pkgdir in $BULK_PREREQ; do
294 echo "build> Installing prerequisite package $pkgdir" 295 echo "build> Installing prerequisite package $pkgdir"
295 ( cd "${pkgsrc_dir}/${pkgdir}" \ 296 ( cd "${pkgsrc_dir}/${pkgdir}" \
296 && ${BMAKE} bulk-install 297 && ${BMAKE} bulk-install
297 ) || die "Could not install prerequisite packages." 298 ) || die "Could not install prerequisite packages."
298 done 299 done
299} 300}
300 301
301# Everything is prepared. We can start building the real packages now. 302# Everything is prepared. We can start building the real packages now.
302# 303#
303# Loop over every package in the correct order. Before building 304# Loop over every package in the correct order. Before building
304# each one, check to see if we've already processed this package 305# each one, check to see if we've already processed this package
305# before. This could happen if the build got interrupted and we 306# before. This could happen if the build got interrupted and we
306# started it again with the '-resume' option. This prevents us 307# started it again with the '-resume' option. This prevents us
307# from having to do a potentially very large number of make's to 308# from having to do a potentially very large number of make's to
308# get back to where we let off. After we build each package, add 309# get back to where we let off. After we build each package, add
309# it to the top level buildlog 310# it to the top level buildlog
310# (usually '.make' or '.make.${MACHINE}'). As a side benefit, this 311# (usually '.make' or '.make.${MACHINE}'). As a side benefit, this
311# can make a progress-meter very simple to add! 312# can make a progress-meter very simple to add!
312do_real_bulk_build () { 313do_real_bulk_build () {
313 314
314 cd "${pkgsrc_dir}" || die "The pkgsrc directory does not exist." 315 cd "${pkgsrc_dir}" || die "The pkgsrc directory does not exist."
315 316
316 echo "build> Starting actual build using the order specified in $ORDERFILE..." 317 echo "build> Starting actual build using the order specified in $ORDERFILE..."
317 318
318 # make sure we have something to grep in in the build loop 319 # make sure we have something to grep in in the build loop
319 touch "${main_buildlog}" || die "Cannot write to ${main_buildlog}." 320 touch "${main_buildlog}" || die "Cannot write to ${main_buildlog}."
320 321
321 tot=`${AWK} 'END { print NR }' "${ORDERFILE}"` 322 tot=`${AWK} 'END { print NR }' "${ORDERFILE}"`
322 for pkgdir in `cat "${ORDERFILE}"` 323 for pkgdir in `cat "${ORDERFILE}"`
323 do 324 do
324 if ${GREP} -q "^${pkgdir}\$" "${main_buildlog}"; then 325 if ${GREP} -q "^${pkgdir}\$" "${main_buildlog}"; then
325 : "skip this package" 326 : "skip this package"
326 else 327 else
327 percent=`${AWK} -v tot="${tot}" ' 328 percent=`${AWK} -v tot="${tot}" '
328 END { 329 END {
329 printf("%d/%d=%4.1f%%", NR, tot, NR*100/tot); 330 printf("%d/%d=%4.1f%%", NR, tot, NR*100/tot);
330 }' "${main_buildlog}"` 331 }' "${main_buildlog}"`
331 ( cd "${pkgsrc_dir}/${pkgdir}" \ 332 ( cd "${pkgsrc_dir}/${pkgdir}" \
332 && ${NICE_LEVEL} ${BMAKE} USE_BULK_CACHE=yes "${target}" \ 333 && ${NICE_LEVEL} ${BMAKE} USE_BULK_CACHE=yes "${target}" \
333 $makeargs </dev/null | post_filter_cmd 334 $makeargs </dev/null | post_filter_cmd
334 ) || true 335 ) || true
335 echo "$pkgdir" >> "${main_buildlog}" 336 echo "$pkgdir" >> "${main_buildlog}"
 337 check_pkg_dirs
336 fi 338 fi
337 done 339 done
338 340
339 echo "build> Build finished." 341 echo "build> Build finished."
340} 342}
341 343
 344check_pkg_dirs () {
 345 for d in bin etc include info lib libexec man sbin share; do
 346 if [ -f $PREFIX/$d ]; then
 347 echo "Removing file, should be dir: $PREFIX/$d" >&2
 348 rm -f $PREFIX/$d
 349 fi
 350 done
 351}
 352
342# clean up installed packages left over 353# clean up installed packages left over
343do_bulk_cleanup () { 354do_bulk_cleanup () {
344 355
345 echo "build> Removing all installed packages left over from build..." 356 echo "build> Removing all installed packages left over from build..."
346 for pkgname in `${PKG_INFO} -e \*` 357 for pkgname in `${PKG_INFO} -e \*`
347 do 358 do
348 if ${PKG_INFO} -qe "${pkgname}"; then 359 if ${PKG_INFO} -qe "${pkgname}"; then
349 pkgdir=`${AWK} '$2 == "'"$pkgname"'" { print $1; }' "$INDEXFILE"` 360 pkgdir=`${AWK} '$2 == "'"$pkgname"'" { print $1; }' "$INDEXFILE"`
350 case "${BULK_PREREQ}" in 361 case "${BULK_PREREQ}" in
351 *"${pkgdir}"* ) 362 *"${pkgdir}"* )
352 echo "build> Keeping BULK_PREREQ: $pkgname ($pkgdir)" ; 363 echo "build> Keeping BULK_PREREQ: $pkgname ($pkgdir)" ;
353 ;; 364 ;;
354 * ) 365 * )
355 echo "build> ${PKG_DELETE} -r ${pkgname}" 366 echo "build> ${PKG_DELETE} -r ${pkgname}"
356 ${PKG_DELETE} -r "${pkgname}" 367 ${PKG_DELETE} -r "${pkgname}"
357 if ${PKG_INFO} -qe "${pkgname}"; then 368 if ${PKG_INFO} -qe "${pkgname}"; then
358 echo "build> $pkgname ($pkgdir) did not deinstall nicely. Forcing the deinstall" 369 echo "build> $pkgname ($pkgdir) did not deinstall nicely. Forcing the deinstall"
359 ${PKG_DELETE} -f "${pkgname}" || true 370 ${PKG_DELETE} -f "${pkgname}" || true
360 fi 371 fi
361 ;; 372 ;;
362 esac 373 esac
363 fi 374 fi
364 done 375 done
365} 376}
366 377
367# start the full bulk-build 378# start the full bulk-build
368do_bulk_build () { 379do_bulk_build () {
369 echo "build> Bulk build started: `date`" 380 echo "build> Bulk build started: `date`"
370 echo "" 381 echo ""
371 382
372 # this function from post-build-conf 383 # this function from post-build-conf
373 show_config_vars 384 show_config_vars
374 385
375 check_tools 386 check_tools
376 run_pre_build 387 run_pre_build
377 load_vars 388 load_vars
378 389
379 # 390 #
380 # Create the directory for the log files if necessary 391 # Create the directory for the log files if necessary
381 # 392 #
382 if [ "${BULKFILESDIR}" != "${pkgsrc_dir}" ]; then 393 if [ "${BULKFILESDIR}" != "${pkgsrc_dir}" ]; then
383 ${MKDIR} "${BULKFILESDIR}" 394 ${MKDIR} "${BULKFILESDIR}"
384 fi 395 fi
385 396
386 # 397 #
387 # Save the bulk build ID in a file, as it most often contains a time 398 # Save the bulk build ID in a file, as it most often contains a time
388 # stamp. 399 # stamp.
389 # 400 #
390 case $resume in 401 case $resume in
391 no) echo "${REPORT_BASEDIR}" > "${BULK_BUILD_ID_FILE}" \ 402 no) echo "${REPORT_BASEDIR}" > "${BULK_BUILD_ID_FILE}" \
392 || die "Could not save the bulk build ID in ${BULK_BUILD_ID_FILE}.";; 403 || die "Could not save the bulk build ID in ${BULK_BUILD_ID_FILE}.";;
393 esac 404 esac
394 405
395 install_prereqs 406 install_prereqs
396 407
397 # 408 #
398 # Create the bulk cache files. 409 # Create the bulk cache files.
399 # 410 #
400 if [ "x$resume" != "xyes" ]; then 411 if [ "x$resume" != "xyes" ]; then
401 ( cd "${pkgsrc_dir}" \ 412 ( cd "${pkgsrc_dir}" \
402 && env PKGLIST="${PKGLIST-}" ${BMAKE} bulk-cache $makeargs 413 && env PKGLIST="${PKGLIST-}" ${BMAKE} bulk-cache $makeargs
403 ) || die "Could not create the bulk build cache." 414 ) || die "Could not create the bulk build cache."
404 else 415 else
405 if [ ! -f "${ORDERFILE}" ]; then 416 if [ ! -f "${ORDERFILE}" ]; then
406 die "The ${ORDERFILE} does not exist." \ 417 die "The ${ORDERFILE} does not exist." \
407 "(You cannot resume a bulk build that has not yet started.)" 418 "(You cannot resume a bulk build that has not yet started.)"
408 fi 419 fi
409 fi 420 fi
410 421
411 # XXX: This looks like a hack, and indeed, the functions in this file 422 # XXX: This looks like a hack, and indeed, the functions in this file
412 # should be reorganized to better reflect the phases of the bulk build. 423 # should be reorganized to better reflect the phases of the bulk build.
413 if [ $prepare_only = yes ]; then 424 if [ $prepare_only = yes ]; then
414 exit 0 425 exit 0
415 fi 426 fi
416 427
417 do_real_bulk_build 428 do_real_bulk_build
418 do_bulk_cleanup 429 do_bulk_cleanup
419} 430}
420 431
421 432
422## 433##
423## main 434## main
424## 435##
425 436
426# 437#
427# Parse the command line. 438# Parse the command line.
428# 439#
429while test $# -gt 0; do 440while test $# -gt 0; do
430 case $1 in 441 case $1 in
431 -c|--config) 442 -c|--config)
432 shift 443 shift
433 BULK_BUILD_CONF=$1; shift 444 BULK_BUILD_CONF=$1; shift
434 ;; 445 ;;
435 -e|--no-email) 446 -e|--no-email)
436 noemail=yes 447 noemail=yes
437 shift 448 shift
438 ;; 449 ;;
439 -h|--help) 450 -h|--help)
440 usage 451 usage
441 exit 0 452 exit 0
442 ;; 453 ;;
443 -m|--mirror_only) 454 -m|--mirror_only)
444 mirror_only=yes 455 mirror_only=yes
445 target=mirror-distfiles 456 target=mirror-distfiles
446 shift 457 shift
447 ;; 458 ;;
448 -p|--post-build) 459 -p|--post-build)
449 post_only=yes 460 post_only=yes
450 shift 461 shift
451 ;; 462 ;;
452 --prepare) 463 --prepare)
453 prepare_only=yes 464 prepare_only=yes
454 shift 465 shift
455 ;; 466 ;;
456 -r|--resume|--restart|restart) 467 -r|--resume|--restart|restart)
457 resume=yes 468 resume=yes
458 shift 469 shift
459 ;; 470 ;;
460 -s|--specific-pkgs) 471 -s|--specific-pkgs)
461 makeargs="$makeargs SPECIFIC_PKGS=1" 472 makeargs="$makeargs SPECIFIC_PKGS=1"
462 shift 473 shift
463 ;; 474 ;;
464 *) 475 *)
465 echo "unknown option: $1" 1>&2 476 echo "unknown option: $1" 1>&2
466 usage 1>&2 477 usage 1>&2
467 exit 1 478 exit 1
468 ;; 479 ;;
469 esac 480 esac
470done 481done
471 482
472do_common_setup 483do_common_setup
473 484
474if [ "x$post_only" = "xyes" ]; then 485if [ "x$post_only" = "xyes" ]; then
475 load_vars 486 load_vars
476 do_post_build 487 do_post_build
477 exit 0 488 exit 0
478fi 489fi
479 490
480do_bulk_build 491do_bulk_build
481 492
482# for now, just quit if we were only mirroring distfiles. At somepoint we 493# for now, just quit if we were only mirroring distfiles. At somepoint we
483# should teach the post-build script to generate a nice report about how many 494# should teach the post-build script to generate a nice report about how many
484# distfiles were downloaded, how many had bad checksums, failed master sites, 495# distfiles were downloaded, how many had bad checksums, failed master sites,
485# network speed, etc. 496# network speed, etc.
486if [ "x$mirror_only" = "xyes" ]; then 497if [ "x$mirror_only" = "xyes" ]; then
487 echo "build> Bulk mirror of distfiles completed: `date`" 498 echo "build> Bulk mirror of distfiles completed: `date`"
488 exit 0 499 exit 0
489fi 500fi
490 501
491do_post_build 502do_post_build
492do_email 503do_email
493do_done 504do_done
494 505