warbo-utilities: 826d81b279cb61829e13389238f6806356b2ba00
1: #!/usr/bin/env bash
2: set -e
3:
4: CODE=0
5: function fail {
6: echo "$*" 1>&2
7: CODE=1
8: [[ -z "$FAILFAST" ]] || exit "$CODE"
9: }
10:
11: # Simple, quick sanity check. Useful as a git pre-commit hook.
12: while read -r F
13: do
14: echo "Checking '$F'" 1>&2
15: nix-instantiate --parse "$F" > /dev/null || fail "Couldn't instantiate '$F'"
16: if command -v nixfmt > /dev/null
17: then
18: nixfmt -w 80 -c "$F" || {
19: fail "Unformatted '$F'"
20: if [[ -n "$REFORMAT" ]]
21: then
22: nixfmt -w 80 "$F"
23: else
24: echo "Set REFORMAT to auto-format" 1>&2
25: fi
26: }
27: fi
28: done < <(find . -name "*.nix" -type f)
29:
30: echo "Looking for dodgy path references" 1>&2
31: while read -r F # grep -R is slow
32: do
33: if grep '\.\./raw' < "$F"
34: then
35: echo "Don't use 'raw' as a path in '$F', use the 'raw' variable" 1>&2
36: fail "since that preserves relative paths between files."
37: fi
38: done < <(find . -not -path '*/\.*' -name '*.nix')
39:
40: echo "Checking dependencies are up to date" 1>&2
41: F="warbo-packages.nix"
42: diff "$F" <(update-nix-fetchgit < "$F") || {
43: fail "Out of date: $F"
44: }
45:
46: echo "Checking that haskell-nix derivations are cached" 1>&2
47: while read -r F
48: do
49: grep -q 'plan-sha256' < "$F" || {
50: echo "File '$F' uses haskell-nix without caching a plan-sha256" 1>&2
51: fail "Build the package and follow the instructions in 'trace'"
52: }
53: grep -q 'materialized' < "$F" || {
54: echo "File '$F' uses haskell-nix without a materialised plan" 1>&2
55: fail "Build the package and follow the instructions in 'trace'"
56: }
57:
58: GOT=$(grep -o 'raw\.[^;]*plan[^;]*' < "$F") ||
59: fail "Couldn't find any '../raw' reference in haskell-nix file '$F'"
60: D=$(echo "$GOT" | head -n1 | sed -e 's@raw\.@raw/@g' -e 's@$@/.plan.nix@g')
61: unset GOT
62:
63: [[ -d "$D" ]] || fail "Couldn't find cache directory '$D' for '$F'"
64: COUNT=$(find "$D" -type f -name '*.nix' | wc -l)
65: [[ "$COUNT" -gt 0 ]] || fail "No .nix files in '$D'"
66: if [[ "$COUNT" -eq 1 ]]
67: then
68: X=$(readlink -f "$D"/*.nix)
69: else
70: # There are multiple files which may contain the main definition we're
71: # using. Try finding one whose name also appears in $F.
72: FOUND=0
73: for POSSIBLE in "$D"/*.nix
74: do
75: N=$(basename "$POSSIBLE" .nix)
76: if grep -q "\"$N\"" < "$F"
77: then
78: [[ "$FOUND" -eq 0 ]] ||
79: fail "Ambiguity: Multiple files in '$D' are found in '$F'"
80: X="$POSSIBLE"
81: fi
82: done
83: unset FOUND
84: unset POSSIBLE
85: fi
86:
87: FOUNDNAME=$(grep 'identifier' < "$X" |
88: grep -o 'name *= *"[^"]*"' |
89: grep -o '"[^"]*"' ) || fail "No name in '$X'"
90: FOUNDVERSION=$(grep 'identifier' < "$X" |
91: grep -o 'version *= *"[^"]*"' |
92: grep -o '"[^"]*"' ) || fail "No version '$X'"
93: unset D
94:
95: grep -q -F "$FOUNDNAME" < "$F" ||
96: fail "Expected name '$FOUNDNAME' in '$F', not found"
97: grep -q -F "$FOUNDVERSION" < "$F" ||
98: fail "Expected version '$FOUNDVERSION' in '$F', not found"
99: unset FOUNDNAME
100: unset FOUNDVERSION
101: done < <(grep -R -l 'haskell-nix' | grep '\.nix$')
102:
103: exit "$CODE"
Generated by git2html.