lol

Add haskell.lib.setBuiltTarget, and support non library compiling of a single target

authored by

Isaac Shapira and committed by
(cdep)illabout
d725ac79 111151c4

+69 -1
+6 -1
pkgs/development/haskell-modules/generic-builder.nix
··· 464 464 installPhase = '' 465 465 runHook preInstall 466 466 467 - ${if !isLibrary then "${setupCommand} install" else '' 467 + ${if !isLibrary && buildTarget == "" then "${setupCommand} install" 468 + # ^^ if the project is not a library, and no build target is specified, we can just use "install". 469 + else if !isLibrary then "${setupCommand} copy ${buildTarget}" 470 + # ^^ if the project is not a library, and we have a build target, then use "copy" to install 471 + # just the target specified; "install" will error here, since not all targets have been built. 472 + else '' 468 473 ${setupCommand} copy 469 474 local packageConfDir="$out/lib/${ghc.name}/package.conf.d" 470 475 local packageConfFile="$packageConfDir/${pname}-${version}.conf"
+10
pkgs/development/haskell-modules/lib.nix
··· 196 196 appendPatch = drv: x: appendPatches drv [x]; 197 197 appendPatches = drv: xs: overrideCabal drv (drv: { patches = (drv.patches or []) ++ xs; }); 198 198 199 + /* Set a specific build target instead of compiling all targets in the package. 200 + * For example, imagine we have a .cabal file with a library, and 2 executables "dev" and "server". 201 + * We can build only "server" and not wait on the compilation of "dev" by useing setBuildTarget as follows: 202 + * 203 + * setBuildTarget (callCabal2nix "thePackageName" thePackageSrc {}) "server" 204 + * 205 + */ 206 + setBuildTargets = drv: xs: overrideCabal drv (drv: { buildTarget = lib.concatStringsSep " " xs; }); 207 + setBuildTarget = drv: x: setBuildTargets drv [x]; 208 + 199 209 doHyperlinkSource = drv: overrideCabal drv (drv: { hyperlinkSource = true; }); 200 210 dontHyperlinkSource = drv: overrideCabal drv (drv: { hyperlinkSource = false; }); 201 211
+1
pkgs/test/haskell/default.nix
··· 3 3 lib.recurseIntoAttrs { 4 4 shellFor = callPackage ./shellFor { }; 5 5 documentationTarball = callPackage ./documentationTarball { }; 6 + setBuildTarget = callPackage ./setBuildTarget { }; 6 7 }
+4
pkgs/test/haskell/setBuildTarget/Bar.hs
··· 1 + module Main where 2 + 3 + main :: IO () 4 + main = putStrLn "Hello, Bar!"
+4
pkgs/test/haskell/setBuildTarget/Foo.hs
··· 1 + module Main where 2 + 3 + main :: IO () 4 + main = putStrLn "Hello, Foo!"
+2
pkgs/test/haskell/setBuildTarget/Setup.hs
··· 1 + import Distribution.Simple 2 + main = defaultMain
+26
pkgs/test/haskell/setBuildTarget/default.nix
··· 1 + { pkgs, haskellPackages }: with pkgs.haskell.lib; 2 + 3 + 4 + let 5 + drv = haskellPackages.callCabal2nix "haskell-setBuildTarget" ./. {}; 6 + test = target: excluded: 7 + 8 + let only = setBuildTarget drv target; 9 + in '' 10 + if [[ ! -f "${only}/bin/${target}" ]]; then 11 + echo "${target} was not built" 12 + exit 1 13 + fi 14 + 15 + if [[ -f "${only}/bin/${excluded}" ]]; then 16 + echo "${excluded} was built, when it should not have been" 17 + exit 1 18 + fi 19 + ''; 20 + 21 + in pkgs.runCommand "test haskell.lib.setBuildTarget" {} '' 22 + ${test "foo" "bar"} 23 + ${test "bar" "foo"} 24 + touch "$out" 25 + '' 26 +
+16
pkgs/test/haskell/setBuildTarget/haskell-setBuildTarget.cabal
··· 1 + cabal-version: >=1.10 2 + name: haskell-setBuildTarget 3 + version: 0.1.0.0 4 + author: Isaac Shapira 5 + maintainer: fresheyeball@protonmail.com 6 + build-type: Simple 7 + 8 + executable foo 9 + main-is: Foo.hs 10 + build-depends: base 11 + default-language: Haskell2010 12 + 13 + executable bar 14 + main-is: Bar.hs 15 + build-depends: base 16 + default-language: Haskell2010