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