I don't like cluttering up scripts using many ifs.. Do you like an assertEnvExists function ? I think we might want to use it more than twice in the future.

svn path=/nixpkgs/trunk/; revision=9224
This commit is contained in:
Marc Weber 2007-08-31 03:58:40 +00:00
parent b3d955ae2e
commit c383f04b8f

View File

@ -1,4 +1,5 @@
set -e set -e
set -x
test -z $NIX_GCC && NIX_GCC=@gcc@ test -z $NIX_GCC && NIX_GCC=@gcc@
@ -53,6 +54,13 @@ installBin() {
cp "$@" $out/bin cp "$@" $out/bin
} }
assertEnvExists(){
if test -z "${!1}"; then
msg=${2:-error: assertion failed: env var $1 is required}
echo $msg >&2; exit 1
fi
}
# Called when some build action fails. If $succeedOnFailure is set, # Called when some build action fails. If $succeedOnFailure is set,
# create the file `$out/nix-support/failed' to signal failure, and # create the file `$out/nix-support/failed' to signal failure, and
# exit normally. Otherwise, exit with failure. # exit normally. Otherwise, exit with failure.
@ -145,20 +153,15 @@ if test -z "$NIX_STRIP_DEBUG"; then
fi fi
# Do we know where the store is? This is required for purity checking. assertEnvExists NIX_STORE \
if test -z "$NIX_STORE"; then "Error: you have an old version of Nix that does not set the
echo "Error: you have an old version of Nix that does not set the" \ NIX_STORE variable. This is required for purity checking.
"NIX_STORE variable. Please upgrade." >&2 Please upgrade."
exit 1
fi
assertEnvExists NIX_BUILD_TOP \
# We also need to know the root of the build directory for purity checking. "Error: you have an old version of Nix that does not set the
if test -z "$NIX_BUILD_TOP"; then NIX_BUILD_TOP variable. This is required for purity checking.
echo "Error: you have an old version of Nix that does not set the" \ Please upgrade."
"NIX_BUILD_TOP variable. Please upgrade." >&2
exit 1
fi
# Set the TZ (timezone) environment variable, otherwise commands like # Set the TZ (timezone) environment variable, otherwise commands like