3
0
Fork 0
forked from mirrors/nixpkgs

* Implement the succeedOnFailure flag by trapping EXIT. This makes

the fail() function unnecessary.
* Flag showBuildStats to print execution times on builder exit.

svn path=/nixpkgs/branches/stdenv-updates/; revision=11688
This commit is contained in:
Eelco Dolstra 2008-04-23 07:19:48 +00:00
parent a218b9b2e7
commit 16f2d8b2d5

View file

@ -1,3 +1,44 @@
exitHandler() {
exitCode=$?
set +e
closeNest
if test -n "$showBuildStats"; then
times > $NIX_BUILD_TOP/.times
local -a times=($(cat $NIX_BUILD_TOP/.times))
# Print the following statistics:
# - user time for the shell
# - system time for the shell
# - user time for all child processes
# - system time for all child processes
echo "build time elapsed: " ${times[*]}
fi
if test $exitCode != 0; then
eval "$failureHook"
# If the builder had a non-zero exit code and
# $succeedOnFailure is set, create the file
# `$out/nix-support/failed' to signal failure, and exit
# normally. Otherwise, return the original exit code.
if test -n "$succeedOnFailure"; then
echo "build failed with exit code $exitCode (ignored)"
ensureDir "$out/nix-support"
echo -n $exitCode > "$out/nix-support/failed"
exit 0
fi
else
eval "$exitHook"
fi
exit $exitCode
}
trap "exitHandler" EXIT
###################################################################### ######################################################################
# Helper functions that might be useful in setup hooks. # Helper functions that might be useful in setup hooks.
@ -17,8 +58,7 @@ addToSearchPathWithCustomDelimiter() {
fi fi
} }
addToSearchPath() addToSearchPath() {
{
addToSearchPathWithCustomDelimiter "${PATH_DELIMITER}" "$@" addToSearchPathWithCustomDelimiter "${PATH_DELIMITER}" "$@"
} }
@ -88,20 +128,6 @@ assertEnvExists(){
fi fi
} }
# Called when some build action fails. If $succeedOnFailure is set,
# create the file `$out/nix-support/failed' to signal failure, and
# exit normally. Otherwise, exit with failure.
fail() {
exitCode=$?
if test "$succeedOnFailure" = 1; then
ensureDir "$out/nix-support"
touch "$out/nix-support/failed"
exit 0
else
exit $?
fi
}
# Allow the caller to augment buildInputs (it's not always possible to # Allow the caller to augment buildInputs (it's not always possible to
# do this before the call to setup.sh, since the PATH is empty at that # do this before the call to setup.sh, since the PATH is empty at that
@ -110,8 +136,7 @@ eval "$addInputsHook"
# Recursively find all build inputs. # Recursively find all build inputs.
findInputs() findInputs() {
{
local pkg=$1 local pkg=$1
case $pkgs in case $pkgs in
@ -144,13 +169,12 @@ done
# Set the relevant environment variables to point to the build inputs # Set the relevant environment variables to point to the build inputs
# found above. # found above.
addToEnv() addToEnv() {
{
local pkg=$1 local pkg=$1
if test "$ignoreFailedInputs" != "1" -a -e $1/nix-support/failed; then if test "$ignoreFailedInputs" != "1" -a -e $1/nix-support/failed; then
echo "failed input $1" >&2 echo "failed input $1" >&2
fail exit 1
fi fi
if test -d $1/bin; then if test -d $1/bin; then
@ -341,8 +365,6 @@ closeNest() {
done done
} }
trap "closeNest" EXIT
# This function is useful for debugging broken Nix builds. It dumps # This function is useful for debugging broken Nix builds. It dumps
# all environment variables to a file `env-vars' in the build # all environment variables to a file `env-vars' in the build
@ -426,21 +448,21 @@ unpackFile() {
case "$file" in case "$file" in
*.tar) *.tar)
tar xvf $file || fail tar xvf $file
;; ;;
*.tar.gz | *.tgz | *.tar.Z) *.tar.gz | *.tgz | *.tar.Z)
gzip -d < $file | tar xvf - || fail gzip -d < $file | tar xvf -
;; ;;
*.tar.bz2 | *.tbz2) *.tar.bz2 | *.tbz2)
bzip2 -d < $file | tar xvf - || fail bzip2 -d < $file | tar xvf -
;; ;;
*.zip) *.zip)
unzip $file || fail unzip $file
;; ;;
*) *)
if test -d "$file"; then if test -d "$file"; then
stripHash $file stripHash $file
cp -prvd $file $strippedName || fail cp -prvd $file $strippedName
else else
if test -n "$findUnpacker"; then if test -n "$findUnpacker"; then
$findUnpacker $1; $findUnpacker $1;
@ -449,7 +471,7 @@ unpackFile() {
echo "source archive $file has unknown type" echo "source archive $file has unknown type"
exit 1 exit 1
fi fi
eval "$unpackCmd" || fail eval "$unpackCmd"
fi fi
;; ;;
esac esac
@ -555,7 +577,7 @@ patchPhase() {
uncompress="bzip2 -d" uncompress="bzip2 -d"
;; ;;
esac esac
$uncompress < $i | patch $patchFlags || fail $uncompress < $i | patch $patchFlags
stopNest stopNest
done done
@ -604,7 +626,7 @@ configurePhase() {
fi fi
echo "configure flags: $configureFlags ${configureFlagsArray[@]}" echo "configure flags: $configureFlags ${configureFlagsArray[@]}"
$configureScript $configureFlags"${configureFlagsArray[@]}" || fail $configureScript $configureFlags"${configureFlagsArray[@]}"
eval "$postConfigure" eval "$postConfigure"
} }
@ -626,7 +648,7 @@ buildPhase() {
echo "make flags: $makeFlags ${makeFlagsArray[@]} $buildFlags ${buildFlagsArray[@]}" echo "make flags: $makeFlags ${makeFlagsArray[@]} $buildFlags ${buildFlagsArray[@]}"
make ${makefile:+-f $makefile} \ make ${makefile:+-f $makefile} \
$makeFlags "${makeFlagsArray[@]}" \ $makeFlags "${makeFlagsArray[@]}" \
$buildFlags "${buildFlagsArray[@]}" || fail $buildFlags "${buildFlagsArray[@]}"
eval "$postBuild" eval "$postBuild"
} }
@ -647,7 +669,7 @@ checkPhase() {
echo "check flags: $makeFlags ${makeFlagsArray[@]} $checkFlags ${checkFlagsArray[@]}" echo "check flags: $makeFlags ${makeFlagsArray[@]} $checkFlags ${checkFlagsArray[@]}"
make ${makefile:+-f $makefile} \ make ${makefile:+-f $makefile} \
$makeFlags "${makeFlagsArray[@]}" \ $makeFlags "${makeFlagsArray[@]}" \
$checkFlags "${checkFlagsArray[@]}" $checkTarget || fail $checkFlags "${checkFlagsArray[@]}" $checkTarget
eval "$postCheck" eval "$postCheck"
} }
@ -683,7 +705,7 @@ installPhase() {
echo "install flags: $installTargets $makeFlags ${makeFlagsArray[@]} $installFlags ${installFlagsArray[@]}" echo "install flags: $installTargets $makeFlags ${makeFlagsArray[@]} $installFlags ${installFlagsArray[@]}"
make ${makefile:+-f $makefile} $installTargets \ make ${makefile:+-f $makefile} $installTargets \
$makeFlags "${makeFlagsArray[@]}" \ $makeFlags "${makeFlagsArray[@]}" \
$installFlags "${installFlagsArray[@]}" || fail $installFlags "${installFlagsArray[@]}"
else else
eval "$installCommand" eval "$installCommand"
fi fi
@ -766,7 +788,7 @@ distPhase() {
fi fi
echo "dist flags: $distFlags ${distFlagsArray[@]}" echo "dist flags: $distFlags ${distFlagsArray[@]}"
make ${makefile:+-f $makefile} $distFlags "${distFlagsArray[@]}" $distTarget || fail make ${makefile:+-f $makefile} $distFlags "${distFlagsArray[@]}" $distTarget
if test "$dontCopyDist" != 1; then if test "$dontCopyDist" != 1; then
ensureDir "$out/tarballs" ensureDir "$out/tarballs"