haskell-te: fbbe3db17a09bf87b630a06f31b13efa9d23be1a

     1: { attrsToDirs, bash, cabal2nix, fail, inNixedDir, lib, mkBin, pipeToNix,
     2:   runCommand, testData, withDeps, withNix }:
     3: 
     4: with builtins;
     5: with lib;
     6: with rec {
     7:   hasCabalFile = mkBin {
     8:     name   = "hasCabalFile";
     9:     paths  = [ bash fail ];
    10:     script = ''
    11:       #!${bash}/bin/bash
    12:       set   -e
    13:       shopt -s nullglob
    14: 
    15:       COUNT=0
    16:       for F in "$1"/*.cabal
    17:       do
    18:         COUNT=$(( COUNT + 1 ))
    19:       done
    20: 
    21:       [[ "$COUNT" -eq 1 ]] ||
    22:         fail "No .cabal in '$1'; is it a build output? (We need the source)"
    23:     '';
    24:   };
    25: 
    26:   testHasCabalFile = runCommand "test-hasCabalFile"
    27:     rec {
    28:       foo     = toFile "foo" "foo";
    29:       tooFew  = attrsToDirs { inherit foo;       bar         = foo; };
    30:       justOne = attrsToDirs { "foo.cabal" = foo; bar         = foo; };
    31:       tooMany = attrsToDirs { "foo.cabal" = foo; "bar.cabal" = foo; };
    32:       buildInputs = [ fail hasCabalFile ];
    33:     }
    34:     ''
    35:       if GOT=$(hasCabalFile "$tooFew" 2>&1)
    36:       then
    37:         fail "Should have been too few\n$GOT"
    38:       fi
    39: 
    40:       if GOT=$(hasCabalFile "$tooMany" 2>&1)
    41:       then
    42:         fail "Should have been too many\n$GOT"
    43:       fi
    44: 
    45:       hasCabalFile "$justOne" || fail "Should've worked for one .cabal file"
    46: 
    47:       echo pass > "$out"
    48:     '';
    49: 
    50:   addNixFile = mkBin {
    51:     name   = "addNixFile";
    52:     paths  = [ bash cabal2nix ];
    53:     script = ''
    54:       #!${bash}/bin/bash
    55:       set -e
    56:       shopt -s nullglob
    57:       shopt -s dotglob
    58: 
    59:       cp -a "$DIR"/* ./
    60:       chmod +w -R ./*
    61: 
    62:       cabal2nix ./. > default.nix
    63:     '';
    64:   };
    65: 
    66:   makeHaskellPkgNixable = mkBin {
    67:     name   = "makeHaskellPkgNixable";
    68:     paths  = [ addNixFile cabal2nix fail hasCabalFile inNixedDir pipeToNix ];
    69:     script = ''
    70:       #!${bash}/bin/bash
    71:       set -e
    72:       set -o pipefail
    73: 
    74:       DIR=$(readlink -f "$1")
    75:       if [[ -d "$DIR" ]]
    76:       then
    77:         hasCabalFile "$DIR" || fail "Need .cabal file, aborting"
    78:         if [[ -e "$DIR/default.nix" ]]
    79:         then
    80:           echo "$DIR"
    81:         else
    82:           DIR="$DIR" inNixedDir addNixFile "withAddedNixFile"
    83:         fi
    84:       else
    85:         fail "Not a directory (or symlink) '$1'"
    86:       fi
    87:     '';
    88:   };
    89: 
    90:   testMakeHaskellPkgNixable = mapAttrs
    91:     (n: nixed: runCommand "testMakeHaskellPkgNixable-${n}"
    92:       (withNix {
    93:         inherit n nixed;
    94:         buildInputs = [ fail ];
    95:         expr        = ''builtins.typeOf (import (builtins.getEnv "F"))'';
    96:       })
    97:       ''
    98:         set -e
    99: 
   100:         [[ -n "$nixed" ]] || fail "No output for package $n"
   101:         Y=$(readlink -f "$nixed")
   102:         [[ -d "$Y" ]] || fail "Didn't make nixified dir for $n: '$nixed' ($Y)"
   103: 
   104:         T=$(F="$Y" nix-instantiate --show-trace --eval -E "$expr") ||
   105:           fail "Output for $n didn't parse"
   106:         [[ "x$T" = 'x"lambda"' ]] || fail "Expr type of $n was '$T'"
   107: 
   108:         mkdir "$out"
   109:       '')
   110:     {
   111:       inherit (testData.haskellNixed { script = makeHaskellPkgNixable; })
   112:         test-theory;
   113:     };
   114: };
   115: 
   116: withDeps ([ testHasCabalFile ] ++ (attrValues testMakeHaskellPkgNixable))
   117:          makeHaskellPkgNixable

Generated by git2html.