-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrun.sh
executable file
·275 lines (244 loc) · 7.13 KB
/
run.sh
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#!/usr/bin/env bash
unset CDPATH
BASEDIR="/srv"
export PATH=$HOME/bin:$PATH
ACTION=$1
# --------------
# - Detect number of usable CPUs.
#
# NOTE: if a single machine gets leased multiple times, this will
# probably suck.
detect_cpu_count() {
if [ "x$CPUS" = "x" ]; then
# Windows standard environment variable
CPUS="$NUMBER_OF_PROCESSORS"
fi
if [ "x$CPUS" = "x" ]; then
# Linux
CPUS=`getconf _NPROCESSORS_ONLN 2>/dev/null`
fi
if [ "x$CPUS" = "x" ]; then
# FreeBSD
CPUS=`getconf NPROCESSORS_ONLN 2>/dev/null`
fi
if [ "x$CPUS" = "x" ]; then
# nothing helped
CPUS="1"
fi
}
detect_cpu_count
# --------------
# Run a program in the background with some console output
waiting_progress() {
RUNPID=$!
trap "kill $RUNPID 2> /dev/null" EXIT
while kill -0 $RUNPID 2> /dev/null; do
sleep $1
echo -n "."
done
trap - EXIT
wait $RUNPID
RESULT=$?
}
clone_ghc() {
BDIR=$1
TEMPLOG=`mktemp /tmp/phab-git-log-XXXXXX.txt`
echo -n " - Cloning repository..."
START=$(date +%s.%N)
(git clone git://git.haskell.org/ghc.git $BDIR > $TEMPLOG 2>&1) &
waiting_progress 5
END=$(date +%s.%N)
if [ "$RESULT" != "0" ]; then
echo "ERROR: Couldn't clone git repository!"
echo "ERROR: Couldn't clone git repository!" >&2
rm -rf $TEMPLOG $BDIR
exit 1
fi
echo " OK (took about" $(echo "$END - $START" | bc) "seconds)"
mv $TEMPLOG $BDIR/build-log.txt
}
# expects cwd == $BDIR
update_submodules() {
echo -n " - Updating HEAD and grabbing submodules..."
START=$(date +%s.%N)
(git checkout $COMMIT >> build-log.txt 2>&1 && \
git submodule init >> build-log.txt 2>&1 && \
git submodule update >> build-log.txt 2>&1) &
waiting_progress 5
END=$(date +%s.%N)
if [ "$RESULT" != "0" ]; then
echo "ERROR: Couldn't clone git repository!"
echo "ERROR: Couldn't clone git repository! Logs:" >&2
cat build-log.txt >&2
RET=1
return 1
else
echo " OK (took about" $(echo "$END - $START" | bc) "seconds)"
fi
}
# --------------
# - Build a GHC commit that has been pushed to the repository
#
# NOTE: this function assumes that there won't be concurrent versions
# of the same build running at once. Generally this shouldn't happen,
# although builds could get restarted or something. Also, in
# Harbormaster, this build step should have a dependency to wait for
# all previous commits to build.
build_ghc_commit() {
RET=0
BDIR="$BASEDIR/builds/commits/r$REPO/B$BUILDID-$COMMIT"
cd $BASEDIR
mkdir -p $BDIR
# -- Setup git repositories
echo "Now building B$BUILDID: commit r$REPO$COMMIT"
echo " - Base directory: $BDIR"
clone_ghc $BDIR
cd $BDIR
# -- Clone submodules
if ! update_submodules; then
echo " OK (took about" $(echo "$END - $START" | bc) "seconds)"
# -- Begin building
echo
echo "OK, starting build on" $(date)
echo " - Using $CPUS CPUs on" $(uname -a)
echo -n " - Running validate..."
START=$(date +%s.%N)
(./validate --quiet >> build-log.txt 2>&1) &
waiting_progress 20
END=$(date +%s.%N)
if [ "$RESULT" != "0" ]; then
echo "ERROR: validate failed!"
echo "ERROR: validate failed! Last 1000 lines of log file:" >&2
tail -1000 build-log.txt >&2
RET=1
else
echo " OK (took about" $(echo "$END - $START" | bc) "seconds)"
fi
fi
## -- Done
echo -n " - LZMA compressing full build logs..."
START=$(date +%s.%N)
(xz -9 build-log.txt) &
waiting_progress 5
END=$(date +%s.%N)
if [ "$RESULT" != "0" ]; then
echo "ERROR: log compression failed!"
echo "ERROR: log compression failed!" >&2
RET=1
else
echo " OK (took about" $(echo "$END - $START" | bc) "seconds)"
mv build-log.txt.xz /srv/logs/r$REPO-B$BUILDID-$COMMIT-logs.txt.xz
fi
if [ -f "testsuite_summary.txt" ]; then
echo
echo "================== Testsuite summary =================="
cat testsuite_summary.txt
if grep -q '^TEST=' testsuite_summary.txt; then
# re-run tests w/ high verbosity
make -C testsuite VERBOSE=4 $(grep '^TEST=' testsuite_summary.txt) | grep -v '^====> Scanning'
fi
fi
rm -rf $BDIR
exit $RET
}
# --------------
# - Build a GHC patch that has been submitted with Arcanist
#
build_ghc_diff() {
RET=0
BDIR="$BASEDIR/builds/patches/r$REPO/B$BUILDID-D$REVISION-$DIFF"
cd $BASEDIR
mkdir -p $BDIR
# -- Setup git repositories
echo "Now building B$BUILDID: patch r$REPO/D$REVISION:$DIFF"
echo " - Base directory: $BDIR"
clone_ghc $BDIR
cd $BDIR
# -- Clone submodules
echo -n " - Updating HEAD and grabbing submodules..."
START=$(date +%s.%N)
# we do not initialise submodules here to let arc patch change where
# submodules are pointing to. Thereby allowing patches affecting submodules to
# validate.
(git checkout $COMMIT >> build-log.txt 2>&1) &
waiting_progress 5
END=$(date +%s.%N)
if [ "$RESULT" != "0" ]; then
echo "ERROR: Couldn't clone git repository!"
echo "ERROR: Couldn't clone git repository! Logs:" >&2
cat build-log.txt >&2
RET=1
else
echo " OK (took about" $(echo "$END - $START" | bc) "seconds)"
# -- Apply patches
echo -n " - Applying diff $DIFF via Arcanist... "
START=$(date +%s.%N)
arc patch --force --nocommit --nobranch --diff $DIFF >> build-log.txt 2>&1
END=$(date +%s.%N)
echo "OK (took about" $(echo "$END - $START" | bc) "seconds)"
# -- Begin building
echo
echo "OK, starting build on" $(date)
echo " - Using $CPUS CPUs on" $(uname -a)
echo -n " - Running validate..."
START=$(date +%s.%N)
(./validate --quiet >> build-log.txt 2>&1) &
waiting_progress 20
END=$(date +%s.%N)
if [ "$RESULT" != "0" ]; then
echo "ERROR: validate failed!"
echo "ERROR: validate failed! Last 1000 lines of log file:" >&2
tail -1000 build-log.txt >&2
RET=1
else
echo " OK (took about" $(echo "$END - $START" | bc) "seconds)"
fi
fi
## -- Done
echo -n " - LZMA compressing full build logs..."
START=$(date +%s.%N)
(xz -9 build-log.txt) &
waiting_progress 5
END=$(date +%s.%N)
if [ "$RESULT" != "0" ]; then
echo "ERROR: log compression failed!"
echo "ERROR: log compression failed!" >&2
RET=1
else
echo " OK (took about" $(echo "$END - $START" | bc) "seconds)"
mv build-log.txt.xz /srv/logs/r$REPO-B$BUILDID-D$REVISION-$DIFF-logs.txt.xz
fi
if [ -f "testsuite_summary.txt" ]; then
echo
echo "================== Testsuite summary =================="
cat testsuite_summary.txt
if grep -q '^TEST=' testsuite_summary.txt; then
# re-run tests w/ high verbosity
make -C testsuite VERBOSE=4 $(grep '^TEST=' testsuite_summary.txt) | grep -v '^====> Scanning'
fi
fi
rm -rf $BDIR
exit $RET
}
# --------------
# -- Main
if [ "x$ACTION" == "xcommit" ]; then
REPO=$2
BUILDID=$3
COMMIT=$4
build_ghc_commit
fi
if [ "x$ACTION" == "xdiff" ]; then
REPO=$2
BUILDID=$3
REVISION=$4
DIFF=$5
build_ghc_diff
fi
echo "Invalid action: $ACTION"; exit 1
# Local Variables:
# fill-column: 80
# indent-tabs-mode: nil
# c-basic-offset: 2
# buffer-file-coding-system: utf-8-unix
# End: