-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildbot.sh
executable file
·346 lines (278 loc) · 8.54 KB
/
buildbot.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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
#!/bin/sh
REPONAME=openbricks
REPOBRANCH=master
REPOURL="https://github.com/OpenBricks/openbricks.git"
# specify the PID of the currently running build to exit gracefully
CANCEL_PID=""
ACTIVE_CONFIGS=" \
geexbox-kodi-armada5xx-cubox \
geexbox-kodi-bcm2708-raspberrypi \
geexbox-kodi-bcm2709-raspberrypi2 \
geexbox-kodi-i386-generic \
geexbox-kodi-imx6-cuboxi \
geexbox-kodi-imx6-utilite \
geexbox-kodi-x86_64-generic \
geexbox-xbmc-a10-cubieboard \
"
BASE=/home/geexbox/bot/buildbot
BUILD=$BASE/build
REPO=$BASE/src/$REPONAME
SOURCES=$BASE/src/sources
STAMPSGET=$BASE/src/.stamps
SNAPSHOTS=$BASE/snapshots
SNAPSHOTSD=$BASE/snapshots/data
LOGS=$BASE/logs
LOGFILE=$BASE/logs/$REPONAME.log
STAMPS=$BASE/stamps
PIDFILE=$STAMPS/lock
BRKFILE=$STAMPS/cancel
DATE=`date +%Y%m%d`
log() {
NOW=`date "+%b %d %T"`
echo "$NOW [$$] $1" >> $LOGFILE
}
compress() {
[ -n "$2" ] && log "Archiving log $2"
#lbzip2 -9f $1
xz -zfe $1
}
mailfail() {
cat > /tmp/mesg.txt <<EOF
Hi,
I was trying to build '$CONFNAME', but something went wrong. The build
failed at '$1' stage,
----------
I was building from the $REPONAME repository at $REV revision on $DATE.
Attached, the log messages
buildbot
EOF
mpack -s "[buildbot] $CONFNAME failed to build" -d /tmp/mesg.txt $BUILDLOG.?z* $REPOOWNERS
}
create_img () {
local name=`basename *.tar.xz .tar.xz`
if [ -f make-sdcard ]; then
sudo rm -f /tmp/$CONFNAME.img*
sudo ./make-sdcard /tmp/$CONFNAME.img $name.tar.xz
sudo chown --reference=$name.tar.xz /tmp/$CONFNAME.img*
[ -f /tmp/$CONFNAME.img.xz ] && mv /tmp/$CONFNAME.img.xz ./$name.img.xz
rm -f /tmp/$CONFNAME.img*
fi
}
clean_old_data () {
# keep only 3 builds
ls -dt $1/* | tail -n +4 | xargs rm -rf || true
}
git_pull_branch () {
rm -f .GIT_REVISION
git fetch origin >> $2 2>&1
git branch $1 -t origin/$1 > /dev/null 2>&1 || true
if git branch -l | grep -qw $1; then
git checkout $1 >> $2 2>&1
git merge origin/$1 >> $2 2>&1
git log -1 --pretty="%h" > .GIT_REVISION
echo "Branch $1, revision `cat .GIT_REVISION`" >> $2
else
echo "Branch $1 does not exist" >> $2
fi
}
prepare_to_build() {
CONFNAME=$1
CONFFILE=$2
# remove symlink
[ -L /tmp/openbricks ] && rm /tmp/openbricks
BUILDLOG="$LOGS/$REPONAME/$CONFNAME.$DATE.log"
rm -f "$BUILDLOG"
# create sub-repo
log "Building $CONFNAME"
if [ ! -d "$CONFNAME" ]; then
log "Cloning $CONFNAME"
rm -f $STAMPS/$CONFNAME
git clone $REPO $CONFNAME > $BUILDLOG
# set links to source packages and download timestamps
ln -s $SOURCES $CONFNAME/sources
ln -s $STAMPSGET $CONFNAME/.stamps
fi
# refresh sub-repo
rm -f $CONFNAME/.NEED_REBUILD
if [ -z "$CONFFILE" ] || \
[ ! -e "$STAMPS/$REPONAME/$CONFNAME" ] || \
[ "$CONFFILE" -nt "$STAMPS/$REPONAME/$CONFNAME" ]; then
rm -f "$STAMPS/$REPONAME/$CONFNAME"
log "Pulling $CONFNAME/$REPOBRANCH"
(cd $CONFNAME; git_pull_branch $REPOBRANCH $BUILDLOG)
if [ -r $CONFNAME/.GIT_REVISION ]; then
touch $CONFNAME/.NEED_REBUILD
else
log "Branch $REPOBRANCH does not exist, skipping"
fi
else
rm -f "$BUILDLOG"
log "Build $CONFNAME is up to date"
fi
}
# Create directories
mkdir -p $BUILD $SOURCES $STAMPSGET $SNAPSHOTS/$REPONAME $SNAPSHOTSD/$REPONAME $STAMPS/$REPONAME $LOGS/$REPONAME
log "Starting buildbot"
# Check for re-entry
if [ -r $PIDFILE ]; then
other=`cat $PIDFILE`
log "Another buildbot instance ($other) is running, aborting."
if [ -n "$CANCEL_PID" ] && [ "$CANCEL_PID" = "$other" ]; then
log "Issuing cancel request for instance $other"
cp $PIDFILE $BRKFILE
fi
exit 1
fi
/bin/echo -n $$ > $PIDFILE
# delete old builds (!!! forces a full rebuild each time !!!)
log "Cleaning build directory"
rm -rf $BUILD/*
# delete old logs
find $LOGS/$REPONAME -name "*.log*" -mtime +7 -delete
# delete inactive snapshots
for d in $SNAPSHOTSD/$REPONAME/*; do
if [ -d $d ]; then
n=`basename $d`
if echo "$ACTIVE_CONFIGS" | grep -qvw $n; then
log "Removing inactive platform $n"
rm -rf $d $SNAPSHOTS/$REPONAME/$n $LOGS/$REPONAME/$n.*
fi
fi
done
# Create repo
if [ ! -d $REPO ]; then
log "Cloning repo $REPONAME"
git clone $REPOURL $REPO > /dev/null 2>&1
fi
# Refresh repo
log "Pulling $REPONAME/$REPOBRANCH"
(cd $REPO; git_pull_branch $REPOBRANCH /dev/null)
if [ ! -r $REPO/.GIT_REVISION ]; then
log "Branch $REPOBRANCH does not exist, aborting."
rm -f $PIDFILE
exit 1
fi
REV=`cat $REPO/.GIT_REVISION`
if [ -r $STAMPS/$REPONAME/rev ]; then
OLDREV=`cat $STAMPS/$REPONAME/rev`
fi
if [ "$REV" = "$OLDREV" ]; then
log "Nothing new"
else
log "Found new rev $REV, rebuilding everything"
rm -f $STAMPS/$REPONAME/*
echo $REV > $STAMPS/$REPONAME/rev
fi
# build documentation
cd $BUILD
prepare_to_build docs "$STAMPS/$REPONAME/rev"
if [ -e $CONFNAME/.NEED_REBUILD ]; then
cd $CONFNAME/DOCS
log "Cleaning $CONFNAME"
make clean >> $BUILDLOG 2>&1
if [ $? -ne 0 ]; then
log "$CONFNAME clean failed"
else
log "Making $CONFNAME"
make >> $BUILDLOG 2>&1
if [ $? -ne 0 ]; then
log "$CONFNAME build failed"
else
log "$CONFNAME build successful"
mkdir -p $SNAPSHOTS/$REPONAME/$CONFNAME/$DATE
cp -PR *.html *.pdf images $SNAPSHOTS/$REPONAME/$CONFNAME/$DATE/
#cp -P $BASE/src/docs/*.png $SNAPSHOTS/$REPONAME/$CONFNAME/$DATE/images/
rm -f $SNAPSHOTS/$REPONAME/$CONFNAME/latest
clean_old_data $SNAPSHOTS/$REPONAME/$CONFNAME
ln -sf $DATE $SNAPSHOTS/$REPONAME/$CONFNAME/latest
echo $DATE > $STAMPS/$REPONAME/$CONFNAME
fi
fi
compress $BUILDLOG $CONFNAME
fi
# build active configurations
for c in $ACTIVE_CONFIGS; do
# check for cancel request
if [ -r $BRKFILE ] && [ "$$" = "`cat $BRKFILE`" ]; then
log "Cancelled after making $CONFNAME"
rm -f $BRKFILE
break
fi
cd $BUILD
prepare_to_build "$c" "$REPO/config/defconfigs/$c.conf"
if [ -e $CONFNAME/.NEED_REBUILD ]; then
cd $CONFNAME
log "Configuring $CONFNAME"
./scripts/kconfiginit >> $BUILDLOG 2>&1
if grep -q 'CONFIG_OPT_TARGET_FLAT=y' $CONFFILE; then
sed \
-e 's:CONFIG_OPT_TARGET_FLAT=y:# CONFIG_OPT_TARGET_FLAT is not set:' \
-e 's:# CONFIG_OPT_TARGET_TARBALL is not set:CONFIG_OPT_TARGET_TARBALL=y:' \
-e 's:CONFIG_OPT_CONCURRENCY_MAKE_LEVEL=[0|9]:CONFIG_OPT_CONCURRENCY_MAKE_LEVEL=8:' \
< $CONFFILE > `ls -d build/build.host/kconfig-frontends-*`/.config
else
cp -P $CONFFILE `ls -d build/build.host/kconfig-frontends-*`/.config
fi
make silentoldconfig >> $BUILDLOG 2>&1 || true
log "Cleaning $CONFNAME"
make quickclean >> $BUILDLOG 2>&1
if [ $? -ne 0 ]; then
log "$CONFNAME quickclean failed"
compress $BUILDLOG $CONFNAME
mailfail clean
rm -f $STAMPS/$REPONAME/$CONFNAME
continue
fi
log "Making $CONFNAME"
rm -rf binaries
local_rev=`git log -1 --pretty="%h"`
make >> $BUILDLOG 2>&1
if [ $? -ne 0 ]; then
echo "Build failed : local revision is $local_rev" >> $BUILDLOG
log "$CONFNAME build failed"
compress $BUILDLOG $CONFNAME
mailfail build
rm -f $STAMPS/$REPONAME/$CONFNAME
make quickclean > /dev/null 2>&1
continue
fi
echo "Build successful : local revision is $local_rev" >> $BUILDLOG
log "$CONFNAME build successful"
echo $DATE > $STAMPS/$REPONAME/$CONFNAME
# create data directory
mkdir -p $SNAPSHOTSD/$REPONAME/$CONFNAME/$DATE
rm -rf $SNAPSHOTSD/$REPONAME/$CONFNAME/$DATE/*
# delete debug packages
find binaries/binaries.* -name "*-dbg_*.opk" -delete
# move binaries
mv binaries/binaries.* $SNAPSHOTSD/$REPONAME/$CONFNAME/$DATE
if [ $? -ne 0 ]; then
log "$CONFNAME move failed"
mailfail move
rm -f $STAMPS/$REPONAME/$CONFNAME
fi
# create disk images
(cd $SNAPSHOTSD/$REPONAME/$CONFNAME/$DATE/binaries.*; create_img)
# remove old snapshots
clean_old_data $SNAPSHOTSD/$REPONAME/$CONFNAME
# create link directory
mkdir -p $SNAPSHOTS/$REPONAME/$CONFNAME
# re-create links
rm -f $SNAPSHOTS/$REPONAME/$CONFNAME/*
for d in $SNAPSHOTSD/$REPONAME/$CONFNAME/*; do
n=`basename $d`
ln -sf ../../data/$REPONAME/$CONFNAME/$n $SNAPSHOTS/$REPONAME/$CONFNAME/$n
done
ln -sf $DATE $SNAPSHOTS/$REPONAME/$CONFNAME/latest
make quickclean > /dev/null 2>&1
compress $BUILDLOG $CONFNAME
fi
done
# rotate log file
log "Quitting"
touch $LOGFILE
mv -f $LOGFILE $LOGS/$REPONAME/$REPONAME.$DATE.log
compress $LOGS/$REPONAME/$REPONAME.$DATE.log
rm -f $PIDFILE
exit 0