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
276
277
278
279
280
281
|
#!/bin/sh
export LC_ALL="C"
## default config
PAUSE_SECONDS=$((15*60))
HTML_OUTPUT=0
SEND_MAIL=0
NICE=
OWNER=
MACHINE=`uname`
SMTP=
TINDERNAME=
## subroutines
usage ()
{
echo "Usage: $0 [options]"
echo "Options:"
echo "-h this help"
echo "-i run with ionice -c3, can be combined with -n"
echo "-l write html build log"
echo "-m <owner> mail errors to the committer, general errors to the <owner>"
echo "-n run with nice, can be combined with -i"
echo "-s <host> SMTP server"
echo "-t <name> send tinderbox mails, identify self as <name>"
echo "-w <N> specify timeout in secs between subsequent pull requests"
}
getCommitters ()
{
from_date="$1"
./g -s log '--pretty=tformat:%ce' --after="$from_date" | sort | uniq | tr '\n' ','
}
sendMailMsg ()
{
TO="$1"
SUBJECT="$2"
HEADERS="$3"
LOG="$4"
perl -e "
use MIME::Lite;
use Net::SMTP;
my \$text;
while (<>) {
\$text .= \$_;
}
\$msg = MIME::Lite->new(
From => '$OWNER',
To => '$TO',
Subject => '$SUBJECT',
Type => 'TEXT',
Data => \$text
$HEADERS
) or die \"Error creating multipart container: \$!\n\";
if ('$LOG' ne '' && -f '$LOG') {
\$msg->attach (
Type => 'application/x-gzip',
Path => '$LOG',
Filename => '$LOG',
Disposition => 'attachment'
) or die \"Error adding $LOG: \$!\n\";
}
MIME::Lite->send('smtp', '$SMTP', Timeout=>60);
\$msg->send;
print 'Sent a mail to \"$TO\" with subject \"$SUBJECT\".' . \"\n\";
"
}
reportError ()
{
error_kind="$1"
shift
rough_time="$1"
shift
to_mail=
if test "$SEND_MAIL" -eq 1; then
case "$error_kind" in
owner) to_mail="$OWNER"
message="box broken" ;;
*) if test -z "$last_success" ; then
# we need at least one successful build to
# be reliable
to_mail="$OWNER"
else
to_mail=`getCommitters "$last_success"`
fi
message="last success: $rough_time" ;;
esac
fi
echo "$*" 1>&2
echo "Last success: $rough_time" 1>&2
if test -n "$to_mail" ; then
TINDER1=
TINDER2=
if test "$SEND_MAIL" -eq 1 -a -n "$TINDERNAME" ; then
TINDER1=`echo -e "Full log available at http://tinderbox.go-oo.org/MASTER/status.html\n"`
TINDER2=`echo " Box name: $TINDERNAME"`
fi
cat <<EOF | sendMailMsg "$to_mail" "Tinderbox failure, $message"
Hi folks,
One of you broke the build of LibreOffice master with your commit :-(
Please commit and push a fix ASAP!
${TINDER1}Tinderbox info:
${TINDER2} `uname -a`
Configured with `cat autogen.lastrun`
Commits since the last success:
`./g log '--pretty=tformat:%h %s' --after="$last_success" | sed 's/^/ /'`
The error is:
$*
EOF
else
echo "$*" 1>&2
if test "$error_kind" = "owner" ; then
exit 1
fi
fi
}
gitHeads ()
{
./g rev-parse --verify HEAD
}
currentTime ()
{
if [ "X$MACHINE" == "XDarwin" ] ; then
date -u '+%Y-%m-%d %H:%M:%S'
else
date --utc --rfc-3339=seconds
fi
}
sendTinderboxLog ()
{
if test "$SEND_MAIL" -ne 1 -o -z "$TINDERNAME" ; then
return 0
fi
STARTTIME="$1"
STATUS="$2"
LOG="$3"
XTINDER=",'X-Tinder:'=>'cookie'"
GZLOG=
MESSAGE="
tinderbox: administrator: $OWNER
tinderbox: builddate: deprecated
tinderbox: starttime: `date '+%s' -d \"$STARTTIME\"`
tinderbox: buildname: $TINDERNAME
tinderbox: errorparser: unix
tinderbox: status: $STATUS
tinderbox: timenow: `date '+%s'`
tinderbox: tree: MASTER
tinderbox: END
"
if [ -n "$3" -a -f "$3" ] ; then
GZLOG="$LOG".gz
( echo "$MESSAGE" ; cat "$LOG" ) | gzip -c "$LOG" > "$GZLOG"
XTINDER=",'X-Tinder:'=>'gzookie'"
fi
echo "$MESSAGE" | sendMailMsg "tinderbox@gimli.documentfoundation.org" "tinderbox gzipped logfile" "$XTINDER" "$GZLOG"
}
## code
while getopts hilm:ns:t:w: opt ; do
case "$opt" in
h) usage; exit ;;
i) NICE="$NICE ionice -c3" ;;
l) HTML_OUTPUT=1 ;;
m) SEND_MAIL=1 ; OWNER="$OPTARG" ;;
n) NICE="$NICE nice" ;;
s) SMTP="$OPTARG" ;;
t) TINDERNAME="$OPTARG" ;;
w) PAUSE_SECONDS="$OPTARG" ;;
?) usage; exit ;;
esac
done
# sanity checks
which git > /dev/null 2>&1 || {
echo "You need git for this!"
exit 1
}
if test "$SEND_MAIL" -eq 1 ; then
if test -z "$OWNER" ; then
echo "Owner not set."
exit 1
fi
if test -z "$SMTP" ; then
echo "SMTP server not set."
exit 1
fi
if test "$OWNER" = `echo ${OWNER} | sed 's/\@/_/g'` ; then
echo "The owner address '$OWNER' does not look like an email address."
exit 1
fi
fi
# for build.pl
test $HTML_OUTPUT -eq 1 && export BUILD_HTML_OUTPUT=true
# main
prev_success=""
last_success=""
while true; do
err_msg=""
# cleanup
$NICE make clean-local
# FIXME we need a more exact way to determine a 'good' date; this is not accurate
rough_checkout_date="`currentTime`"
sendTinderboxLog "$rough_checkout_date" "building"
# try to build
build_status="build_failed"
if ! err_msg=$(./autogen.sh 2>&1); then
reportError committer "$rough_checkout_date" `printf "autogen.sh / configure failed - error is:\n\n$err_msg"`
elif ! $NICE make clean >clean.log 2>&1 ; then
reportError committer "$rough_checkout_date" `printf "cleaning up failed - error is:\n\n"` "$(tail -n100 clean.log)"
elif ! $NICE make >build.log 2>&1 ; then
reportError committer "$rough_checkout_date" `printf "building failed - error is:\n\n"` "$(tail -n100 build.log)"
# elif ! $NICE make smoketest > smoketest.log 2>&1 ; then
# reportError committer "$rough_checkout_date" `printf "smoketest failed - error is:\n\n"` "$(tail -n100 smoketest.log)"
elif ! $NICE make dev-install >install.log 2>&1 ; then
reportError committer "$rough_checkout_date" `printf "dev installation failed - error is:\n\n"` "$(tail -n100 install.log)"
else
echo "Build done - checkout from $rough_checkout_date successful."
gitHeads > prev-git-heads.txt
prev_success=$last_success
last_success=$rough_checkout_date
build_status="success"
fi
# send tinderbox mail
sendTinderboxLog "$rough_checkout_date" "$build_status" "build.log"
# save the old logs
for I in clean.log build.log smoketest.log install.log ; do
mv $I prev-$I 2>/dev/null
done
echo updating repo
# new commits?
while true; do
old_head=$(gitHeads) && err_msg="$(./g pull -r 2>&1)" ||
{
reportError owner "$rough_checkout_date" `printf "git repo broken - error is:\n\n$err_msg"`
}
new_head=$(gitHeads)
if test "$old_head" != "$new_head"; then
break
fi
echo "Waiting $PAUSE_SECONDS seconds."
sleep $PAUSE_SECONDS
done
done
|