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