summaryrefslogtreecommitdiff
path: root/pkgs/test/haskell/setBuildTarget/default.nix
blob: 1fd6721d5f337ced9a5fc0269993f5431cf39d4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
{ pkgs, haskellPackages }:

let
  # This can be regenerated by running `cabal2nix ./src` in the current directory.
  pkgDef =
    {
      mkDerivation,
      base,
      lib,
    }:
    mkDerivation {
      pname = "haskell-setBuildTarget";
      version = "0.1.0.0";
      src = ./src;
      isLibrary = false;
      isExecutable = true;
      executableHaskellDepends = [ base ];
      license = pkgs.lib.licenses.mit;
    };

  drv = haskellPackages.callPackage pkgDef { };

  test =
    target: excluded:
    let
      only = pkgs.haskell.lib.compose.setBuildTarget target drv;
    in
    ''
      if [[ ! -f "${only}/bin/${target}" ]]; then
        echo "${target} was not built"
        exit 1
      fi

      if [[ -f "${only}/bin/${excluded}" ]]; then
        echo "${excluded} was built, when it should not have been"
        exit 1
      fi
    '';

in
pkgs.runCommand "test haskell.lib.compose.setBuildTarget"
  {
    meta = {
      inherit (drv.meta) platforms;
    };
  }
  ''
    ${test "foo" "bar"}
    ${test "bar" "foo"}
    touch "$out"
  ''