haskell-te: c8033432175481d1ddce8bc5b64e89c2e04dd2b3
1: { allDrvsIn, attrsToDirs, bash, cabal-install, coreutils, extractedEnv,
2: extraHaskellPackages, fail, haskellPackages, jq, lib, makeHaskellPkgNixable,
3: mkBin, nix, nixEnv, runCommand, testData, timeout, utillinux, withDeps, wrap,
4: writeScript }:
5: with builtins;
6: with lib;
7: with rec {
8: untested = mkBin {
9: name = "concurrentQuickspec";
10: paths = [ coreutils ];
11: vars = {
12: runner = wrap {
13: name = "explore-runner";
14: paths = [ fail haskellPackages.mlspec jq makeHaskellPkgNixable nix
15: timeout ];
16: vars = nixEnv;
17: script = ''
18: #!${bash}/bin/bash
19: set -e
20: set -o pipefail
21:
22: function noDepth {
23: grep -v "^Depth" || true # Don't abort if nothing found
24: }
25:
26: function checkForErrors {
27: ERR=0
28: while read -r LINE
29: do
30: echo "$LINE"
31: if echo "$LINE" | grep "No instance for" > /dev/null
32: then
33: ERR=1
34: fi
35: done
36: [[ "$ERR" -eq 0 ]] || fail "Haskell error, aborting"
37: }
38:
39: function nixify {
40: for D in "$@"
41: do
42: makeHaskellPkgNixable "$D" | jq -R '.'
43: done | jq -s '.'
44: }
45:
46: function onlyQuickspecable {
47: jq 'map(if type == "object"
48: then select(.quickspecable)
49: else map(select(.quickspecable))
50: end)'
51: }
52:
53: if [[ -n "$OUT_DIRS" ]]
54: then
55: echo "Using existing OUT_DIRS" 1>&2
56: else
57: if [[ -n "$IN_BENCHMARK" ]]
58: then
59: fail "No OUT_DIRS in benchmark, aborting"
60: else
61: OUT_DIRS=$(nixify "$@")
62: export OUT_DIRS
63: fi
64: fi
65:
66: # limit time/memory
67: onlyQuickspecable | withTimeout MLSpec 2> >(checkForErrors 1>&2) |
68: noDepth | jq -s '.'
69: '';
70: };
71: };
72: script = ''
73: #!${bash}/bin/bash
74: set -e
75: if [[ -n "$MAX_SECS" ]]
76: then
77: timeout "$MAX_SECS" "$runner" "$@"
78: else
79: "$runner" "$@"
80: fi
81: '';
82: };
83:
84: data = mapAttrs
85: (n: f: runCommand "data-${n}"
86: {
87: inherit f;
88: buildInputs = [ jq ];
89: }
90: ''
91: set -e
92: jq '[map(select(.quickspecable))]' < "$f" > "$out"
93: '')
94: (testData.asts {});
95:
96: mkBuildInputs = args: extractedEnv args ++ [ untested fail ];
97:
98: checks = {
99: mlspec-test = runCommand "mlspec-test"
100: (nixEnv // {
101: buildInputs = [
102: cabal-install
103: (haskellPackages.ghcWithPackages (h: [ h.mlspec ]))
104: jq
105: nix
106: utillinux
107: ];
108: dir = haskellPackages.mlspec.src;
109: })
110: ''
111: set -e
112: echo "Appeasing Cabal's impurities" 1>&2
113: export HOME="$PWD"
114: GHC_PKG=$(ghc-pkg list | head -n 1 | tr -d ':')
115:
116: cp -r "$dir" ./dir
117: chmod +w -R ./dir
118: cd ./dir
119:
120: cabal configure --package-db="$GHC_PKG" 1>&2
121: ./test.sh
122: mkdir "$out"
123: '';
124: } // mapAttrs (_: f: mapAttrs f data) {
125: exit-success = name: f: runCommand "exploreExitSuccess-${name}"
126: {
127: inherit f;
128: buildInputs = mkBuildInputs {
129: inherit f;
130: standalone = getAttr name (testData.haskellNixed {});
131: };
132: }
133: ''
134: set -e
135: OUTPUT=$(concurrentQuickspec < "$f") || {
136: echo "$OUTPUT" 1>&2
137: fail "Exit failure for '$f'"
138: }
139: mkdir "$out"
140: '';
141:
142: find-equations = name: f: runCommand "find-equations-in-${name}"
143: {
144: inherit f;
145: buildInputs = mkBuildInputs {
146: inherit f;
147: standalone = getAttr name (testData.haskellNixed {});
148: };
149: }
150: ''
151: set -e
152: set -o pipefail
153:
154: DONE=0
155:
156: function finish {
157: if [[ "$DONE" -eq 0 ]]
158: then
159: if [[ -e serr ]]
160: then
161: echo -e "\n\nstderr:\n\n" 1>&2
162: cat serr 1>&2
163: else
164: echo "No stderr produced" 1>&2
165: fi
166:
167: echo "COUNT: $COUNT" 1>&2
168: fi
169: }
170: trap finish EXIT
171:
172: echo "Exploring '$f'" 1>&2
173: RESULT=$(concurrentQuickspec < "$f" 2> serr) || {
174: echo "$RESULT" 1>&2
175: fail "Equation finding failed for '$f'"
176: }
177:
178: if grep "No clusters found" < serr
179: then
180: fail "Did concurrentQuickspec receive any input?"
181: fi
182:
183: COUNT=$(echo "$RESULT" | jq 'length')
184:
185: if [[ "$COUNT" -eq 0 ]]
186: then
187: fail "Couldn't find any equations in output of '$f'"
188: else
189: echo "Found '$COUNT' equations for '$f'" 1>&2
190: fi
191:
192: DONE=1
193:
194: mkdir "$out"
195: '';
196:
197: no-dupes = name: f: runCommand "no-dupes-for-${name}"
198: {
199: inherit f;
200: buildInputs = mkBuildInputs {};
201: nixed = [(getAttr name (testData.haskellNixed {}))];
202: NIX_EVAL_HASKELL_PKGS = (filterSource
203: (path: type: hasSuffix ".nix" path || elem (baseNameOf path) [
204: "benchmarks" "nix-support"
205: ])
206: ./..) + "/nix-support/customHs.nix";
207: }
208: ''
209: set -e
210: set -o pipefail
211:
212: function noDupes {
213: echo "Removing dupes" 1>&2
214: DUPES=$(grep "^building path.*repo-head" |
215: sed -e 's/.*head-//g' |
216: sort |
217: uniq -D) || DUPES=""
218: [[ -z "$DUPES" ]] || {
219: echo "Made redundant package lookups: $DUPES" 1>&2
220: exit 1
221: }
222: }
223:
224: echo "Exploring '$f'" 1>&2
225: OUTPUT=$(concurrentQuickspec "$nixed" < "$f" 2>&1) || {
226: echo "$OUTPUT" 1>&2
227: fail "Failed to explore '$f'"
228: }
229:
230: echo "$OUTPUT" | noDupes
231: mkdir "$out"
232: '';
233: };
234: };
235: withDeps (allDrvsIn checks) untested
Generated by git2html.