ghc: greatly simplify the GHC compiler wrapper

The wrapper script accumulated some cruft over the last couple of months
because we did changes in freaky ways to avoid triggering re-builds of all
Haskell packages. Most of these kludges have been thrown out now.

This patch doesn't change the behavior of the wrapper except for one thing: the
internal helper scripts "ghc-get-packages.sh" and "ghc-packages.sh" are no
longer installed in the bin directory of the generated derivation.
This commit is contained in:
Peter Simons 2013-04-20 23:20:47 +02:00
parent 4dd05a51ed
commit 431b774cc0
4 changed files with 59 additions and 67 deletions

View file

@ -144,7 +144,7 @@ assert enableCheckPhase -> stdenv.lib.versionOlder "7" ghc.ghcVersion;
./Setup build
export GHC_PACKAGE_PATH=$(ghc-packages)
export GHC_PACKAGE_PATH=$(${ghc.GHCPackages})
[ -n "$noHaddock" ] || ./Setup haddock
eval "$postBuild"

View file

@ -1,21 +0,0 @@
#! /bin/sh
# Usage:
# $1: version of GHC
# $2: invocation path of GHC
# $3: prefix
version="$1"
if test -z "$3"; then
prefix="-package-conf "
else
prefix="$3"
fi
PATH="$2:$PATH"
IFS=":"
for p in $PATH; do
PkgDir="$p/../lib/ghc-$version/package.conf.d"
for i in $PkgDir/*.installedconf; do
# output takes place here
test -f $i && echo -n " $prefix$i"
done
done
test -f "$2/../lib/ghc-$version/package.conf" && echo -n " $prefix$2/../lib/ghc-$version/package.conf"

View file

@ -1,10 +1,53 @@
{ stdenv, ghc, makeWrapper, coreutils, forUserEnv ? false }:
{ stdenv, ghc, makeWrapper, coreutils, writeScript }:
let
ghc761OrLater = !stdenv.lib.versionOlder ghc.version "7.6.1";
packageDBFlag = if ghc761OrLater then "-package-db" else "-package-conf";
GHCGetPackages = writeScript "ghc-get-packages.sh" ''
#! ${stdenv.shell}
# Usage:
# $1: version of GHC
# $2: invocation path of GHC
# $3: prefix
version="$1"
if test -z "$3"; then
prefix="${packageDBFlag} "
else
prefix="$3"
fi
PATH="$2:$PATH"
IFS=":"
for p in $PATH; do
PkgDir="$p/../lib/ghc-$version/package.conf.d"
for i in "$PkgDir/"*.installedconf; do
# output takes place here
test -f $i && echo -n " $prefix$i"
done
done
test -f "$2/../lib/ghc-$version/package.conf" && echo -n " $prefix$2/../lib/ghc-$version/package.conf"
'';
GHCPackages = writeScript "ghc-packages.sh" ''
#! ${stdenv.shell} -e
declare -A GHC_PACKAGES_HASH # using bash4 hashs to get uniq paths
for arg in $(${GHCGetPackages} ${ghc.version} "$(dirname $0)"); do
case "$arg" in
${packageDBFlag}) ;;
*)
CANONICALIZED="$(${coreutils}/bin/readlink -f -- "$arg")"
GHC_PACKAGES_HASH["$CANONICALIZED"]= ;;
esac
done
for path in ''${!GHC_PACKAGES_HASH[@]}; do
echo -n "$path:"
done
'';
in
stdenv.mkDerivation ({
stdenv.mkDerivation {
name = "ghc-${ghc.version}-wrapper";
buildInputs = [makeWrapper];
@ -12,53 +55,33 @@ stdenv.mkDerivation ({
unpackPhase = "true";
installPhase = ''
runHook preInstall
mkdir -p $out/bin
cp $GHCGetPackages $out/bin/ghc-get-packages.sh
chmod 755 $out/bin/ghc-get-packages.sh
for prg in ghc ghci ghc-${ghc.version} ghci-${ghc.version}; do
makeWrapper $ghc/bin/$prg $out/bin/$prg --add-flags "\$($out/bin/ghc-get-packages.sh ${ghc.version} \"\$(dirname \$0)\")"
makeWrapper $ghc/bin/$prg $out/bin/$prg --add-flags "\$(${GHCGetPackages} ${ghc.version} \"\$(dirname \$0)\")"
done
for prg in runghc runhaskell; do
makeWrapper $ghc/bin/$prg $out/bin/$prg --add-flags "\$($out/bin/ghc-get-packages.sh ${ghc.version} \"\$(dirname \$0)\" \" ${packageDBFlag} --ghc-arg=\")"
makeWrapper $ghc/bin/$prg $out/bin/$prg --add-flags "\$(${GHCGetPackages} ${ghc.version} \"\$(dirname \$0)\" \" ${packageDBFlag} --ghc-arg=\")"
done
for prg in ghc-pkg ghc-pkg-${ghc.version}; do
makeWrapper $ghc/bin/$prg $out/bin/$prg --add-flags "\$($out/bin/ghc-get-packages.sh ${ghc.version} \"\$(dirname \$0)\" -${packageDBFlag}=)"
makeWrapper $ghc/bin/$prg $out/bin/$prg --add-flags "\$(${GHCGetPackages} ${ghc.version} \"\$(dirname \$0)\" -${packageDBFlag}=)"
done
for prg in hp2ps hpc hasktags hsc2hs; do
test -x $ghc/bin/$prg && ln -s $ghc/bin/$prg $out/bin/$prg
done
cat >> $out/bin/ghc-packages << EOF
#! /bin/bash -e
declare -A GHC_PACKAGES_HASH # using bash4 hashs to get uniq paths
for arg in \$($out/bin/ghc-get-packages.sh ${ghc.version} \"\$(dirname \$0)\"); do
case "\$arg" in
${packageDBFlag}) ;;
*)
CANONICALIZED="\$(${stdenv.lib.optionalString stdenv.isDarwin "${coreutils}/bin/"}readlink -f "\$arg")"
GHC_PACKAGES_HASH["\$CANONICALIZED"]= ;;
esac
done
for path in \''${!GHC_PACKAGES_HASH[@]}; do
echo -n "\$path:"
done
EOF
chmod +x $out/bin/ghc-packages
mkdir -p $out/nix-support
ln -s $out/nix-support/propagated-build-inputs $out/nix-support/propagated-user-env-packages
mkdir -p $out/share/doc
ln -s $ghc/lib $out/lib
ln -s $ghc/share/doc/ghc $out/share/doc/ghc-${ghc.version}
runHook postInstall
'';
GHCGetPackages = ./ghc-get-packages.sh;
inherit ghc;
inherit ghc GHCGetPackages GHCPackages;
inherit (ghc) meta;
ghcVersion = ghc.version;
} // (stdenv.lib.optionalAttrs ghc761OrLater { preFixup = "sed -i -e 's|-package-conf|${packageDBFlag}|' $out/bin/ghc-get-packages.sh"; })
// (stdenv.lib.optionalAttrs forUserEnv {
postFixup= ''
ln -s $ghc/lib $out/lib;
mkdir -p $out/share/doc
ln -s $ghc/share/doc/ghc $out/share/doc/ghc-${ghc.version}
'';
}))
}

View file

@ -89,16 +89,6 @@ let result = let callPackage = x : y : modifyPrio (newScope result.final x y);
ghc = ghc; # refers to ghcPlain
};
# The normal GHC wrapper doesn't create links to the documentation in
# ~/.nix-profile. Having this second wrapper allows us to remedy the
# situation without re-building all Haskell packages. At the next
# stdenv-updates merge, this second wrapper will go away.
ghcUserEnvWrapper = pkgs.appendToName "new" (callPackage ../development/compilers/ghc/wrapper.nix {
ghc = ghc; # refers to ghcPlain
forUserEnv = true;
});
# An experimental wrapper around ghcPlain that does not automatically
# pick up packages from the profile, but instead has a fixed set of packages
# in its global database. The set of packages can be specified as an