* Hook variables in the generic builder are now executed using eval.

This has a major advantage: you can write hooks directly in Nix
  expressions.  For instance, rather than write a builder like this:

    source $stdenv/setup

    postInstall=postInstall
    postInstall() {
        ln -sf gzip $out/bin/gunzip
        ln -sf gzip $out/bin/zcat
    }

    genericBuild

  (the gzip builder), you can just add this attribute to the
  derivation:

    postInstall = "ln -sf gzip $out/bin/gunzip; ln -sf gzip $out/bin/zcat";

  and so a separate build script becomes unnecessary.  This should
  allow us to get rid of most builders in Nixpkgs.

* Allow configure and make arguments to contain whitespace.
  Previously, you could say, for instance

    configureFlags="CFLAGS=-O0"

  but not

    configureFlags="CFLAGS=-O0 -g"

  since the `-g' would be interpreted as a separate argument to
  configure.  Now you can say

    configureFlagsArray=("CFLAGS=-O0 -g")

  or similarly

    configureFlagsArray=("CFLAGS=-O0 -g" "LDFLAGS=-L/foo -L/bar")

  which does the right thing.  Idem for makeFlags, installFlags,
  checkFlags and distFlags.

  Unfortunately you can't pass arrays to Bash through the environment,
  so you can't put the array above in a Nix expression, e.g.,

    configureFlagsArray = ["CFLAGS=-O0 -g"];

  since it would just be flattened to a since string.  However, you
  can use the inline hooks described above:

    preConfigure = "configureFlagsArray=(\"CFLAGS=-O0 -g\")";


svn path=/nixpkgs/trunk/; revision=6863
This commit is contained in:
Eelco Dolstra 2006-10-26 22:20:25 +00:00
parent c8cc992038
commit 0b7e256162
3 changed files with 32 additions and 61 deletions

View File

@ -62,9 +62,7 @@ fail() {
# 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
# point; here we have a basic Unix environment).
if test -n "$addInputsHook"; then
$addInputsHook
fi
eval "$addInputsHook"
# Recursively find all build inputs.
@ -319,7 +317,7 @@ unpackFile() {
unpackW() {
if test -n "$unpackPhase"; then
$unpackPhase
eval "$unpackPhase"
return
fi
@ -349,7 +347,7 @@ unpackW() {
# Find the source directory.
if test -n "$setSourceRoot"; then
$setSourceRoot
eval "$setSourceRoot"
else
sourceRoot=
for i in *; do
@ -382,10 +380,8 @@ unpackW() {
if test "dontMakeSourcesWritable" != 1; then
chmod -R +w $sourceRoot
fi
if test -n "$postUnpack"; then
$postUnpack
fi
eval "$postUnpack"
}
@ -400,7 +396,7 @@ unpackPhase() {
patchW() {
if test -n "$patchPhase"; then
$patchPhase
eval "$patchPhase"
return
fi
@ -430,13 +426,11 @@ fixLibtool() {
configureW() {
if test -n "$configurePhase"; then
$configurePhase
eval "$configurePhase"
return
fi
if test -n "$preConfigure"; then
$preConfigure
fi
eval "$preConfigure"
if test -z "$prefix"; then
prefix="$out";
@ -465,12 +459,10 @@ configureW() {
configureFlags="--prefix=$prefix $configureFlags"
fi
echo "configure flags: $configureFlags"
$configureScript $configureFlags || fail
echo "configure flags: $configureFlags ${configureFlagsArray[@]}"
$configureScript $configureFlags"${configureFlagsArray[@]}" || fail
if test -n "$postConfigure"; then
$postConfigure
fi
eval "$postConfigure"
}
@ -485,20 +477,16 @@ configurePhase() {
buildW() {
if test -n "$buildPhase"; then
$buildPhase
eval "$buildPhase"
return
fi
if test -n "$preBuild"; then
$preBuild
fi
eval "$preBuild"
echo "make flags: $makeFlags"
make $makeFlags || fail
echo "make flags: $makeFlags ${makeFlagsArray[@]}"
make $makeFlags "${makeFlagsArray[@]}" || fail
if test -n "$postBuild"; then
$postBuild
fi
eval "$postBuild"
}
@ -516,7 +504,7 @@ buildPhase() {
checkW() {
if test -n "$checkPhase"; then
$checkPhase
eval "$checkPhase"
return
fi
@ -524,8 +512,8 @@ checkW() {
checkTarget="check"
fi
echo "check flags: $checkFlags"
make $checkFlags $checkTarget || fail
echo "check flags: $checkFlags ${checkFlagsArray[@]}"
make $checkFlags "${checkFlagsArray[@]}" $checkTarget || fail
}
@ -554,19 +542,17 @@ patchELF() {
installW() {
if test -n "$installPhase"; then
$installPhase
eval "$installPhase"
return
fi
if test -n "$preInstall"; then
$preInstall
fi
eval "$preInstall"
ensureDir "$prefix"
if test -z "$dontMakeInstall"; then
echo "install flags: $installFlags"
make install $installFlags || fail
echo "install flags: $installFlags ${installFlagsArray[@]}"
make install $installFlags "${installFlagsArray[@]}" || fail
fi
if test -z "$dontStrip" -a "$NIX_STRIP_DEBUG" = 1; then
@ -583,9 +569,7 @@ installW() {
echo "$propagatedBuildInputs" > "$out/nix-support/propagated-build-inputs"
fi
if test -n "$postInstall"; then
$postInstall
fi
eval "$postInstall"
}
@ -603,20 +587,18 @@ installPhase() {
distW() {
if test -n "$distPhase"; then
$distPhase
eval "$distPhase"
return
fi
if test -n "$preDist"; then
$preDist
fi
eval "$preDist"
if test -z "$distTarget"; then
distTarget="dist"
fi
echo "dist flags: $distFlags"
make $distFlags $distTarget || fail
echo "dist flags: $distFlags ${distFlagsArray[@]}"
make $distFlags "${distFlagsArray[@]}" $distTarget || fail
if test "$dontCopyDist" != 1; then
ensureDir "$out/tarballs"
@ -630,9 +612,7 @@ distW() {
cp -pvd $tarballs $out/tarballs
fi
if test -n "$postDist"; then
$postDist
fi
eval "$postDist"
}
@ -661,7 +641,7 @@ genericBuild() {
for i in $phases; do
dumpVars
$i
eval "$i"
done
stopNest

View File

@ -1,9 +0,0 @@
source $stdenv/setup
postInstall=postInstall
postInstall() {
ln -sf gzip $out/bin/gunzip
ln -sf gzip $out/bin/zcat
}
genericBuild

View File

@ -6,5 +6,5 @@ stdenv.mkDerivation {
url = http://nix.cs.uu.nl/dist/tarballs/gzip-1.3.3.tar.gz;
md5 = "52eaf713673507d21f7abefee98ba662";
};
builder = ./builder.sh;
postInstall = "ln -sf gzip $out/bin/gunzip; ln -sf gzip $out/bin/zcat";
}