From 54bbfd544087dcaf422899191db2a0ce4425b67f Mon Sep 17 00:00:00 2001 From: Peter Simons Date: Fri, 16 Jan 2015 20:54:35 +0100 Subject: [PATCH] haskell-generic-builder: re-factor for improved modularity --- .../haskell-modules/generic-builder.nix | 128 +++++++++++------- .../haskell-modules/with-packages-wrapper.nix | 2 +- 2 files changed, 78 insertions(+), 52 deletions(-) diff --git a/pkgs/development/haskell-modules/generic-builder.nix b/pkgs/development/haskell-modules/generic-builder.nix index 0f98ded5eb14..a4368838fe43 100644 --- a/pkgs/development/haskell-modules/generic-builder.nix +++ b/pkgs/development/haskell-modules/generic-builder.nix @@ -7,6 +7,7 @@ , sha256 ? null , src ? fetchurl { url = "mirror://hackage/${pname}-${version}.tar.gz"; inherit sha256; } , buildDepends ? [] +, buildTarget ? "" , buildTools ? [] , configureFlags ? [] , description ? "" @@ -50,6 +51,11 @@ let inherit (stdenv.lib) optional optionals optionalString versionOlder concatStringsSep enableFeature optionalAttrs; + newCabalFile = fetchurl { + url = "http://hackage.haskell.org/package/${pname}-${version}/${pname}.cabal"; + sha256 = editedCabalFile; + }; + defaultSetupHs = builtins.toFile "Setup.hs" '' import Distribution.Simple main = defaultMain @@ -58,7 +64,18 @@ let ghc76xOrLater = stdenv.lib.versionOlder "7.6" ghc.version; packageDbFlag = if ghc76xOrLater then "package-db" else "package-conf"; + hasActiveLibrary = isLibrary && (enableStaticLibraries || enableSharedLibraries || enableLibraryProfiling); + + enableParallelBuilding = versionOlder "7.8" ghc.version && !hasActiveLibrary; + defaultConfigureFlags = [ + "--verbose" "--prefix=$out" "--libdir=\\$prefix/lib/\\$compiler" "--libsubdir=\\$pkgid" + "--with-gcc=$CC" # Clang won't work without that extra information. + "--package-db=$packageConfDir" + (optionalString (enableSharedExecutables && stdenv.isLinux) "--ghc-option=-optl=-Wl,-rpath=$out/lib/${ghc.name}/${pname}-${version}") + (optionalString (enableSharedExecutables && stdenv.isDarwin) "--ghc-option=-optl=-Wl,-headerpad_max_install_names") + (optionalString enableParallelBuilding "--ghc-option=-j$NIX_BUILD_CORES") + (optionalString (useCpphs) "--with-cpphs=${cpphs}/bin/cpphs --ghc-options=-cpp --ghc-options=-pgmP${cpphs}/bin/cpphs --ghc-options=-optP--cpp") (enableFeature enableSplitObjs "split-objs") (enableFeature enableLibraryProfiling "library-profiling") (enableFeature enableSharedLibraries "shared") @@ -67,21 +84,21 @@ let (optionalString (versionOlder "7" ghc.version) (enableFeature doCheck "tests")) ]; - hasActiveLibrary = isLibrary && (enableStaticLibraries || enableSharedLibraries); + setupCompileFlags = [ + (optionalString (!coreSetup) "-${packageDbFlag}=$packageConfDir") + (optionalString (versionOlder "7.8" ghc.version) "-j$NIX_BUILD_CORES") + ]; - newCabalFile = fetchurl { - url = "http://hackage.haskell.org/package/${pname}-${version}/${pname}.cabal"; - sha256 = editedCabalFile; - }; - - isHaskellPkg = x: (x ? pname) && (x ? version); + isHaskellPkg = x: (x ? pname) && (x ? version) && (x ? env); isSystemPkg = x: !isHaskellPkg x; - allBuildInputs = stdenv.lib.filter (x: x != null) ( - buildDepends ++ extraLibraries ++ buildTools ++ + propagatedBuildInputs = buildDepends; + otherBuildInputs = extraLibraries ++ + buildTools ++ optionals (pkgconfigDepends != []) ([pkgconfig] ++ pkgconfigDepends) ++ - optionals doCheck testDepends - ); + optionals doCheck testDepends; + allBuildInputs = propagatedBuildInputs ++ otherBuildInputs; + haskellBuildInputs = stdenv.lib.filter isHaskellPkg allBuildInputs; systemBuildInputs = stdenv.lib.filter isSystemPkg allBuildInputs; @@ -91,46 +108,31 @@ in stdenv.mkDerivation ({ name = "${optionalString hasActiveLibrary "haskell-"}${pname}-${version}"; + prePhases = ["setupCompilerEnvironmentPhase"]; + preConfigurePhases = ["jailbreakPhase" "compileBuildDriverPhase"]; + preInstallPhases = ["haddockPhase"]; + inherit src; - nativeBuildInputs = extraLibraries ++ buildTools ++ - optionals (pkgconfigDepends != []) ([pkgconfig] ++ pkgconfigDepends) ++ - optionals doCheck testDepends ++ - optionals (!hasActiveLibrary) buildDepends; - propagatedNativeBuildInputs = optionals hasActiveLibrary buildDepends; + nativeBuildInputs = otherBuildInputs ++ optionals (!hasActiveLibrary) propagatedBuildInputs; + propagatedNativeBuildInputs = optionals hasActiveLibrary propagatedBuildInputs; - # GHC needs the locale configured during the Haddock phase. - LANG = "en_US.UTF-8"; + LANG = "en_US.UTF-8"; # GHC needs the locale configured during the Haddock phase. LOCALE_ARCHIVE = optionalString stdenv.isLinux "${glibcLocales}/lib/locale/locale-archive"; - configurePhase = '' - runHook preConfigure + setupCompilerEnvironmentPhase = '' + runHook preSetupCompilerEnvironment echo "Building with ${ghc}." export PATH="${ghc}/bin:$PATH" ${optionalString (hasActiveLibrary && hyperlinkSource) "export PATH=${hscolour}/bin:$PATH"} - configureFlags="--verbose --prefix=$out --libdir=\$prefix/lib/\$compiler --libsubdir=\$pkgid $configureFlags" - configureFlags+=' ${concatStringsSep " " defaultConfigureFlags}' - ${optionalString (enableSharedExecutables && stdenv.isLinux) '' - configureFlags+=" --ghc-option=-optl=-Wl,-rpath=$out/lib/${ghc.name}/${pname}-${version}" - ''} - ${optionalString (enableSharedExecutables && stdenv.isDarwin) '' - configureFlags+=" --ghc-option=-optl=-Wl,-headerpad_max_install_names" - ''} - ${optionalString (versionOlder "7.8" ghc.version && !isLibrary) '' - configureFlags+=" --ghc-option=-j$NIX_BUILD_CORES" - setupCompileFlags="-j$NIX_BUILD_CORES" - ''}${optionalString stdenv.isDarwin '' - configureFlags+=" --with-gcc=$CC" # Cabal won't find clang without help. - ''}${optionalString useCpphs '' - configureFlags+=" --with-cpphs=${cpphs}/bin/cpphs" - configureFlags+=" --ghc-options=-cpp --ghc-options=-pgmP${cpphs}/bin/cpphs --ghc-options=-optP--cpp" - ''} - packageConfDir="$TMP/package.conf.d" mkdir -p $packageConfDir + setupCompileFlags="${concatStringsSep " " setupCompileFlags}" + configureFlags="${concatStringsSep " " defaultConfigureFlags} $configureFlags" + local inputClosure="" for i in $propagatedNativeBuildInputs $nativeBuildInputs; do findInputs $i inputClosure propagated-native-build-inputs @@ -150,25 +152,43 @@ stdenv.mkDerivation ({ done done ghc-pkg --${packageDbFlag}="$packageConfDir" recache - configureFlags+=" --package-db=$packageConfDir" + + runHook postSetupCompilerEnvironment + ''; + + jailbreakPhase = '' + runHook preJailbreak ${optionalString (editedCabalFile != null) '' echo "Replacing Cabal file with edited version ${newCabalFile}." cp ${newCabalFile} ${pname}.cabal - ''} - - ${optionalString jailbreak '' + ''}${optionalString jailbreak '' echo "Running jailbreak-cabal to lift version restrictions on build inputs." ${jailbreak-cabal}/bin/jailbreak-cabal ${pname}.cabal ''} + runHook postJailbreak + ''; + + compileBuildDriverPhase = '' + runHook preCompileBuildDriver + for i in Setup.hs Setup.lhs ${defaultSetupHs}; do test -f $i && break done - ghc ${optionalString (! coreSetup) "-${packageDbFlag}=$packageConfDir "}$setupCompileFlags --make -o Setup -odir $TMPDIR -hidir $TMPDIR $i + + echo setupCompileFlags: $setupCompileFlags + ghc $setupCompileFlags --make -o Setup -odir $TMPDIR -hidir $TMPDIR $i + + runHook postCompileBuildDriver + ''; + + configurePhase = '' + runHook preConfigure + + unset GHC_PACKAGE_PATH # Cabal complains if this variable is set during configure. echo configureFlags: $configureFlags - unset GHC_PACKAGE_PATH # Cabal complains if this variable is set during configure. ./Setup configure $configureFlags 2>&1 | ${coreutils}/bin/tee "$NIX_BUILD_TOP/cabal-configure.log" if ${gnugrep}/bin/egrep -q '^Warning:.*depends on multiple versions' "$NIX_BUILD_TOP/cabal-configure.log"; then echo >&2 "*** abort because of serious configure-time warning from Cabal" @@ -182,12 +202,7 @@ stdenv.mkDerivation ({ buildPhase = '' runHook preBuild - ./Setup build - ${optionalString (!noHaddock && hasActiveLibrary) '' - ./Setup haddock --html \ - ${optionalString doHoogle "--hoogle"} \ - ${optionalString (hasActiveLibrary && hyperlinkSource) "--hyperlink-source"} - ''} + ./Setup build ${buildTarget} runHook postBuild ''; @@ -197,6 +212,16 @@ stdenv.mkDerivation ({ runHook postCheck ''; + haddockPhase = '' + runHook preHaddock + ${optionalString (!noHaddock && hasActiveLibrary) '' + ./Setup haddock --html \ + ${optionalString doHoogle "--hoogle"} \ + ${optionalString (hasActiveLibrary && hyperlinkSource) "--hyperlink-source"} + ''} + runHook postHaddock + ''; + installPhase = '' runHook preInstall @@ -242,10 +267,11 @@ stdenv.mkDerivation ({ }; - meta = { inherit homepage license platforms hydraPlatforms; } + meta = { inherit homepage license platforms; } // optionalAttrs broken { inherit broken; } // optionalAttrs (description != "") { inherit description; } // optionalAttrs (maintainers != []) { inherit maintainers; } + // optionalAttrs (hydraPlatforms != platforms) { inherit hydraPlatforms; } ; } diff --git a/pkgs/development/haskell-modules/with-packages-wrapper.nix b/pkgs/development/haskell-modules/with-packages-wrapper.nix index 4648050dd739..2824296c08fc 100644 --- a/pkgs/development/haskell-modules/with-packages-wrapper.nix +++ b/pkgs/development/haskell-modules/with-packages-wrapper.nix @@ -30,7 +30,7 @@ let libDir = "$out/lib/ghc-${ghc.version}"; docDir = "$out/share/doc/ghc/html"; packageCfgDir = "${libDir}/package.conf.d"; - isHaskellPkg = x: (x ? pname) && (x ? version); + isHaskellPkg = x: (x ? pname) && (x ? version) && (x ? env); paths = stdenv.lib.filter isHaskellPkg (stdenv.lib.closePropagation packages); in if paths == [] then ghc else