-
Notifications
You must be signed in to change notification settings - Fork 25
/
pre-commit
executable file
·132 lines (106 loc) · 4.05 KB
/
pre-commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env bash
# This is a pre-commit hook that validates code formatting.
#
# Install this by running the script with an argument of "install",
# which installs a symlink to .git/hooks/precommit:
# $ ln -s ../../hooks/pre-commit .git/hooks/pre-commit
root="$(git rev-parse --show-toplevel 2>/dev/null)"
set -e
# Some sanity checking.
hash cargo
[[ -n "$root" ]]
# Installation.
if [[ "$1" == "install" ]]; then
hook="$root"/.git/hooks/pre-commit
if [[ ! -e "$hook" ]]; then
ln -s ../../pre-commit "$hook"
echo "Installed git pre-commit hook at $hook"
else
echo "Hook already installed"
fi
exit
fi
save_merge_files() {
# Move MERGE_[HEAD|MODE|MSG] files to the root directory, and let `git stash push` save them.
for f in "$root"/.git/MERGE_*; do
if [[ -e "$f" ]]; then
t=$(basename $f)
mv -f "$f" "$t"
fi
done
}
restore_merge_files() {
# Moves MERGE files restored by `git stash pop` back into .git/ directory.
for f in MERGE_*; do
if [[ -e "$f" ]]; then
if [[ -e "${root}/.git/${f}" ]]; then
echo "Failed to restore ${f}. File already exists" 1>&2
else
mv -f "$f" "${root}/.git/${f}"
fi
fi
done
}
# Check formatting.
stashfile=$(mktemp .pre-commit.stashXXXXXX)
trap 'set +e;git stash pop -q; rm -f "$stashfile"; restore_merge_files' EXIT
save_merge_files
git stash push -k -u -q -m "pre-commit stash"
fmtconfig="imports_granularity=Crate,group_imports=StdExternalCrate"
if ! errors=($(cargo fmt --all -- --check --config "$fmtconfig" -l)); then
echo "Formatting errors found."
echo "Run \`cargo fmt --all -- --config \"$fmtconfig\"\` to fix the following files:"
for err in "${errors[@]}"; do
echo " $err"
done
exit 1
fi
check() {
msg="$1"
shift
if "$@"; then
echo "$msg: OK"
else
res=$?
echo "-----------------------"
echo "$msg: FAILED ($res)"
if [[ "$BASH_VERSINFO" -ge 4 ]]; then
echo " ${@@Q}"
else
echo "$*"
fi
exit $res
fi
}
check "Clippy checks" \
cargo clippy --features="cli test-fixture" --tests -- -D warnings
check "Tests" \
cargo test --features="cli test-fixture relaxed-dp"
if [ -n "$EXEC_SLOW_TESTS" ]
then
check "Benchmark compilation" \
cargo build --benches --no-default-features --features "enable-benches compact-gate"
check "Clippy concurrency checks" \
cargo clippy --tests --features shuttle -- -D warnings
check "Clippy web checks" \
cargo clippy --tests --no-default-features --features "cli web-app real-world-infra test-fixture compact-gate" -- -D warnings
# The tests here need to be kept in sync with scripts/coverage-ci.
check "Web tests" \
cargo test -p ipa-core --no-default-features --features "cli web-app real-world-infra test-fixture compact-gate"
check "Web tests (descriptive gate)" \
cargo test -p ipa-core --no-default-features --features "cli web-app real-world-infra test-fixture descriptive-gate"
check "Concurrency tests" \
cargo test -p ipa-core --release --features "shuttle multi-threading"
check "IPA benchmark" \
cargo bench --bench oneshot_ipa --no-default-features --features="enable-benches compact-gate" -- -n 62 -c 16
check "Arithmetic circuit benchmark" \
cargo bench --bench oneshot_arithmetic --no-default-features --features "enable-benches compact-gate"
check "Slow tests: Compact Gate" \
cargo test --release --test "compact_gate" --no-default-features --features "cli web-app real-world-infra test-fixture compact-gate"
check "Slow tests: Helper Networks" \
cargo test --release --test "helper_networks" --no-default-features --features "cli web-app real-world-infra test-fixture compact-gate"
check "Slow tests: Hybrid tests" \
cargo test --release --test "hybrid" --features "cli test-fixture"
check "Slow tests: IPA with Relaxed DP" \
cargo test --release --test "ipa_with_relaxed_dp" --no-default-features --features "cli web-app real-world-infra test-fixture compact-gate relaxed-dp"
fi