haskell-te: 488cea58391c1b15413be73e989912006e8f0dde

     1: # Scripts which use our commands to generate data, and the results of running
     2: # these scripts on some selected examples. This can be used in a few ways:
     3: #
     4: #  - If we're writing a Nix expression which needs the output of one of our
     5: #    commands (e.g. some ASTs, a generated Haskell package, etc.) then we can
     6: #    use the relevant 'command' function from here to run it.
     7: #  - If we're defining a command, we don't want to expose an untested version,
     8: #    but we also want to make sure that the invocations we test are the same as
     9: #    the ones which will be used (also DRY!). We can do this by passing our
    10: #    untested version as the 'script' parameter of the relevant 'command'
    11: #    function, test the result, and use 'withDeps' to make the 'public' version
    12: #    of the command depend on these tests passing.
    13: #
    14: # Most tests should use the provided example data, since it's designed to be
    15: # fast. The only exception is when we're sampling, which obviously needs
    16: # TEBenchmark.
    17: { fail, haskellPackages, haskellPkgToAsts, haskellPkgToRawAsts, jq, lib,
    18:   makeHaskellPkgNixable, nixEnv, quickspec, quickspecAsts, runCommand,
    19:   stableHackageDb, tipBenchmarks, tipToHaskellPkg, unpack, withNix }:
    20: 
    21: with builtins;
    22: with lib;
    23: rec {
    24:   commands = {
    25:     asts = { dir, name, script ? null }: runCommand "asts-of-${name}"
    26:       (withNix {
    27:         src          = dir;
    28:         IN_SELF_TEST = "1";
    29:         SKIP_NIX     = "1";
    30:         buildInputs  = [
    31:           (haskellPkgToAsts { script = if script == null
    32:                                           then haskellPkgToRawAsts
    33:                                           else script; })
    34:         ];
    35:       })
    36:       ''
    37:         set -e
    38:         haskellPkgToAsts "$src" > "$out"
    39:       '';
    40: 
    41:     eqs = { asts, name, nixed, script ? null }: runCommand "eqs-of-${name}"
    42:       {
    43:         inherit asts nixed;
    44:         buildInputs = [ (if script == null then quickspecAsts else script) ];
    45:         MAX_SECS    = "180";
    46:         MAX_KB      = "1000000";
    47:         SKIP_NIX    = "1";
    48:       }
    49:       ''
    50:         set -e
    51:         quickspecAsts "$nixed" < "$asts" > "$out"
    52:       '';
    53: 
    54:     finalEqs = { name, pkg, script ? null }: runCommand "test-quickspec-${name}"
    55:       (nixEnv // {
    56:         p            = pkg;
    57:         buildInputs  = [ (if script == null then quickspec else script) ];
    58:         IN_SELF_TEST = "1";
    59:         MAX_SECS     = "180";
    60:         MAX_KB       = "1000000";
    61:         SKIP_NIX     = "1";
    62:       })
    63:       ''
    64:         set -e
    65:         quickspec "$p" > "$out"
    66:       '';
    67: 
    68:     haskellDrv = { dir, name, script ? null }: haskellPackages.callPackage
    69:       (commands.haskellNixed { inherit dir name script; }) {};
    70: 
    71:     haskellNix = { dir, name, script ? null }: runCommand "nixed-${name}"
    72:       {
    73:         inherit dir stableHackageDb;
    74:         buildInputs = [ fail (if script == null
    75:                                  then makeHaskellPkgNixable
    76:                                  else script) ];
    77:         SKIP_NIX    = "1";
    78:         n           = name;
    79:       }
    80:       ''
    81:         set -e
    82:         export HOME="$PWD"
    83:         ln -s "$stableHackageDb/.cabal" "$HOME/.cabal"
    84: 
    85:         X=$(makeHaskellPkgNixable "$dir") ||
    86:           fail "Package $n failed to nixify"
    87:         cp -r "$X" "$out"
    88:       '';
    89: 
    90:     haskellPkg = { name, script ? null, tip }:
    91:       runCommand "haskell-pkg-of-${name}"
    92:         {
    93:           inherit tip;
    94:           SKIP_NIX    = "1";
    95:           buildInputs = [ fail (if script == null
    96:                                    then tipToHaskellPkg
    97:                                    else script) ];
    98:         }
    99:         ''
   100:           set -e
   101:           D=$(tipToHaskellPkg < "$tip")
   102:           [[ -e "$D" ]] || fail "'$D' doesn't exist"
   103: 
   104:           X=$(readlink -f "$D")
   105:           [[ -d "$X" ]] || fail "'$X' isn't dir"
   106: 
   107:           cp -r "$X" "$out"
   108:         '';
   109:   };
   110: 
   111:   # Selected example data for tests to use. These should be reasonably quick to
   112:   # run.
   113: 
   114:   tip   = { test-theory = ./test-theory.smt2;       };
   115:   truth = { test-theory = ./test-theory-truth.smt2; };
   116: 
   117:   haskellPkgs = { script ? null }:
   118:     mapAttrs (name: tip: commands.haskellPkg { inherit name tip; }) tip;
   119: 
   120:   haskellDrvs = mapAttrs (name: dir: haskellPackages.callPackage dir {})
   121:                          (haskellNixed {});
   122: 
   123:   haskellNixed = { script ? null }:
   124:     mapAttrs (name: dir: commands.haskellNix { inherit dir name script; })
   125:              (haskellPkgs {});
   126: 
   127:   asts = { script ? null }:
   128:     mapAttrs (name: dir: commands.asts { inherit dir name script; })
   129:              (haskellNixed {});
   130: 
   131:   eqs = { script ? null }:
   132:     mapAttrs (name: asts: commands.eqs {
   133:                             inherit asts name script;
   134:                             nixed = getAttr name (haskellNixed {});
   135:                           })
   136:              (asts {});
   137: 
   138:   finalEqs = { script ? null }:
   139:     mapAttrs (name: pkg: commands.finalEqs { inherit name pkg script; })
   140:              (haskellPkgs {});
   141: 
   142:   # Resource-intensive data, which should be used sparingly
   143: 
   144:   tip-benchmark = rec {
   145:     asts = commands.asts {
   146:       name = "tip-benchmark";
   147:       dir  = nixed;
   148:     };
   149:     nixed = commands.haskellNix {
   150:       name = "tip-benchmark-haskell";
   151:       dir  = tipBenchmarks.tip-benchmark-haskell;
   152:     };
   153:   };
   154: 
   155:   isabelle-theories = genAttrs [ "list-full" "nat-full" "nat-simple" ] (name:
   156:     rec {
   157:       asts  = commands.asts { inherit name; dir = nixed; };
   158:       nixed = commands.haskellNix { inherit name; dir = pkg; };
   159:       pkg = commands.haskellPkg {
   160:         inherit name;
   161:         tip = ../benchmarks + "/${name}.smt2";
   162:       };
   163:     });
   164: }

Generated by git2html.