-
Notifications
You must be signed in to change notification settings - Fork 0
/
.check-build
executable file
·137 lines (115 loc) · 3.03 KB
/
.check-build
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
133
134
135
136
137
#!/usr/bin/env bash
set -eu
REFERENCE_FILES=(
# lab 1
src/mrapps/crash.go
src/mrapps/indexer.go
src/mrapps/mtiming.go
src/mrapps/nocrash.go
src/mrapps/rtiming.go
src/mrapps/wc.go
src/main/mrsequential.go
src/main/mrcoordinator.go
src/main/mrworker.go
# lab 2
src/kvsrv/test_test.go
src/kvsrv/config.go
# lab 3
src/raft/persister.go
src/raft/test_test.go
src/raft/config.go
src/labrpc/labrpc.go
# lab 4
src/kvraft/test_test.go
src/kvraft/config.go
# lab 5a
src/shardctrler/test_test.go
src/shardctrler/config.go
# lab 5b
src/shardkv/test_test.go
src/shardkv/config.go
)
main() {
upstream="$1"
labnum="$2"
# make sure we have reference copy of lab, in FETCH_HEAD
git fetch "$upstream" 2>/dev/null || die "unable to git fetch $upstream"
# copy existing directory
tmpdir="$(mktemp -d)"
find src -type s -delete # cp can't copy sockets
cp -r src "$tmpdir"
orig="$PWD"
cd "$tmpdir"
# check out reference files
for f in ${REFERENCE_FILES[@]}; do
mkdir -p "$(dirname $f)"
git --git-dir="$orig/.git" show "FETCH_HEAD:$f" > "$f"
done
case $labnum in
"lab1") check_lab1;;
"lab2") check_lab2;;
"lab3a"|"lab3b"|"lab3c"|"lab3d") check_lab3;;
"lab4a"|"lab4b") check_lab4;;
"lab5a") check_lab5a;;
"lab5b") check_lab5b;;
*) die "unknown lab: $labnum";;
esac
cd
rm -rf "$tmpdir"
}
check_lab1() {
check_cmd cd src/mrapps
check_cmd go build -buildmode=plugin wc.go
check_cmd go build -buildmode=plugin indexer.go
check_cmd go build -buildmode=plugin mtiming.go
check_cmd go build -buildmode=plugin rtiming.go
check_cmd go build -buildmode=plugin crash.go
check_cmd go build -buildmode=plugin nocrash.go
check_cmd cd ../main
check_cmd go build mrcoordinator.go
check_cmd go build mrworker.go
check_cmd go build mrsequential.go
}
check_lab2() {
check_cmd cd src/kvsrv
check_cmd go test -c
}
check_lab3() {
check_cmd cd src/raft
check_cmd go test -c
}
check_lab4() {
check_cmd cd src/kvraft
check_cmd go test -c
}
check_lab5a() {
check_cmd cd src/shardctrler
check_cmd go test -c
}
check_lab5b() {
check_cmd cd src/shardkv
check_cmd go test -c
# also check other labs/parts
cd "$tmpdir"
check_lab5a
cd "$tmpdir"
check_lab4
cd "$tmpdir"
check_lab3
}
check_cmd() {
if ! "$@" >/dev/null 2>&1; then
echo "We tried building your source code with testing-related files reverted to original versions, and the build failed. This copy of your code is preserved in $tmpdir for debugging purposes. Please make sure the code you are trying to hand in does not make changes to test code." >&2
echo >&2
echo "The build failed while trying to run the following command:" >&2
echo >&2
echo "$ $@" >&2
echo " (cwd: ${PWD#$tmpdir/})" >&2
exit 1
fi
}
die() {
echo "$1" >&2
exit 1
}
main "$@"