haskell-te: 37bb4d91baa23e3eb91458a313accf7f0556c59d

     1: # Check that the required Haskell packages are found in the environment
     2: { bash, extraHaskellPackages, fail, haskellPackages, jq, runCommand, unlines,
     3:   withDeps, wrap, writeScript }:
     4: 
     5: with builtins;
     6: with rec {
     7:   findHsPkgReferences = wrap {
     8:     name = "unique-references";
     9:     vars = {
    10:       hsPkgNames = writeScript "haskell-names"
    11:                      (unlines (builtins.attrNames haskellPackages));
    12: 
    13:       extractionScript = writeScript "find-references" ''
    14:         #!${bash}/bin/bash
    15:         set -e
    16: 
    17:         # Allow package names to be given directly, one per line (limit to
    18:         # 128 chars to avoid craziness)
    19:         GOT=$(cat)
    20:         echo "$GOT" | cut -c1-128
    21: 
    22:         # Take package names from JSON fields. These include:
    23:         #
    24:         #  - Objects with a 'package' field
    25:         #  - Arrays of such objects
    26:         #  - Arrays of arrays of such objects
    27:         #
    28:         # We should be able to ignore dependencies, as they'll be brought in
    29:         # automatically.
    30:         FLATTEN='if type == "array" then .[] else .'
    31:         echo "$GOT" | jq -r "$FLATTEN | $FLATTEN | .package" 2> /dev/null ||
    32:           true
    33:       '';
    34:     };
    35:     script = ''
    36:       INPUT=$(cat | grep '[a-zA-Z_]')
    37:       while read -r NAME
    38:       do
    39:         if grep -xF "$NAME" < "$hsPkgNames" > /dev/null
    40:         then
    41:           echo "$NAME"
    42:         fi
    43:       done < <(echo "$INPUT" | "$extractionScript" | sort -u | grep '^.')
    44:     '';
    45:   };
    46: 
    47:   go = extra: wrap {
    48:     name = "checkHsEnv";
    49:     vars = {
    50:       inherit findHsPkgReferences;
    51:       allGiven = unlines (extra ++ extraHaskellPackages);
    52:     };
    53:     script = ''
    54:       #!${bash}/bin/bash
    55:       set -e
    56:       set -o pipefail
    57: 
    58:       function ensurePkg {
    59:         # Skip empty lines
    60:         echo "$1" | grep '[a-zA-Z_]' > /dev/null || return 0
    61: 
    62:         if ghc-pkg list "$1" | grep "$1" > /dev/null
    63:         then
    64:           return 0
    65:         fi
    66: 
    67:         echo "Aborting. Didn't find Haskell package '$1' in" 1>&2
    68:         ghc-pkg list 1>&2
    69:         exit 1
    70:       }
    71: 
    72:       # We must have ghc-pkg, or else we can't even check the others
    73:       command -v "ghc-pkg" > /dev/null 2>&1 || {
    74:         echo "No ghc-pkg command in environment" 1>&2
    75:         exit 1
    76:       }
    77: 
    78:       # '|| true' to appease 'set -e' when we have no input
    79:       INPUT=""
    80:       [ -t 0 ] || INPUT=$(sort -u | grep "^." | cut -c1-128) || true
    81: 
    82:       if [[ -n "$INPUT" ]]
    83:       then
    84:         while read -r PKG
    85:         do
    86:           ensurePkg "$PKG"
    87:         done < <(echo "$INPUT"    |
    88:                  grep '[a-zA-Z_]' |
    89:                  "$findHsPkgReferences")
    90:       fi
    91: 
    92:       while read -r PKG
    93:       do
    94:         ensurePkg "$PKG"
    95:       done < <(echo "$allGiven")
    96: 
    97:       exit 0
    98:     '';
    99:   };
   100: 
   101:   test = runCommand "test-checkHsEnv"
   102:     {
   103:       buildInputs = [
   104:         fail
   105:         jq
   106:         ((haskellPackages.ghcWithPackages (h: map (n: getAttr n h)
   107:                                                   extraHaskellPackages)).override {
   108:           ignoreCollisions = true;
   109:         })
   110:       ];
   111:     }
   112:     ''
   113:       #!${bash}/bin/bash
   114:       set -e
   115: 
   116:       "${go [                                    ]}" || fail "Empty"
   117:       "${go ["text"                              ]}" || fail "text"
   118:       "${go ["text" "containers"                 ]}" || fail "containers"
   119:       "${go ["text" "containers" "parsec"        ]}" || fail "parsec"
   120:       "${go ["text" "containers" "parsec" "aeson"]}" || fail "aeson"
   121: 
   122:       mkdir "$out"
   123:     '';
   124: };
   125: extra: withDeps [ test ] (go extra)

Generated by git2html.