1 # -*- mode: shell-script; sh-indentation: 8; indent-tabs-mode: t; -*-
3 # build_farm -- distributed build/test architecture for samba, rsync, etc
5 # Copyright (C) 2001 by Andrew Tridgell <tridge@samba.org>
6 # Copyright (C) 2001 by Andrew Bartlett <abartlet@samba.org>
7 # Copyright (C) 2001, 2003 by Martin Pool <mbp@samba.org>
9 # default maximum runtime for any command
11 RUN_FROM_BUILD_FARM=yes
12 export RUN_FROM_BUILD_FARM
14 #############################
15 # build a signature of a tree, used to see if we
21 find $sum_tree_test_root/$sum_tree_tree -type f -print | grep -v '.svn' | grep -v version.h | sort | xargs sum > $sum_tree_sum
22 sum build_test build_test.fns >> $sum_tree_sum
24 if [ -f "$host.fns" ]; then
25 sum $host.fns >> $sum_tree_sum
27 sum generic.fns >> $sum_tree_sum
31 #############################
32 # send the logs to the master site
34 if [ "$nologreturn" = "yes" ]; then
35 echo "skipping log transfer"
39 chmod 0644 "$log" "$err"
40 rsync -q --password-file=.password -cz --timeout=200 \
41 "$log" "$err" $host@samba.org::build_farm_data/
45 ############################
46 # fetch the latest copy of the tree
48 if [ "$norsync" = "yes" ]; then
49 echo "skipping tree transfer"
52 if rsync --exclude=autom4te.cache/ --exclude=.svn/ --delete-excluded -q --partial --timeout=200 -crlpz --delete --ignore-errors \
53 samba.org::ftp/unpacked/$fetchtree/ $test_root/$fetchtree; then
54 echo "transferred $fetchtree OK"
56 echo "transfer of $fetchtree failed code $?"
63 ############################
64 # fetch the latest copy of the svn entries file
67 # skip products still in CVS.
69 ccache | distcc | rsync)
75 if [ "$norsync" = "yes" ]; then
76 echo "skipping svn transfer"
78 if [ -r $test_root/$tree.svn ]; then
79 rm -f $test_root/$tree.svn.old
80 mv $test_root/$tree.svn $test_root/$tree.svn.old
82 rsync -q --timeout=200 -clz --ignore-errors \
83 samba.org::ftp/unpacked/$tree/.svn/entries $test_root/$tree.svn
85 if [ -r $test_root/$tree.svn ]; then
91 ############################
92 # grab a lock file. Not atomic, but close :)
93 # tries to cope with NFS
96 machine=`cat "$lck" 2> /dev/null | cut -d: -f1`
97 pid=`cat "$lck" 2> /dev/null | cut -d: -f2`
100 ( [ $machine != $host ] || kill -0 $pid ) 2> /dev/null; then
101 echo "lock file $lck is valid for $machine:$pid"
105 echo "$host:$$" > "$lck"
109 ############################
116 ############################
117 # run make, and print trace
126 if [ x"$BUILD_FARM_NUM_JOBS" = x ]; then
128 ./timelimit $MAXTIME "$MAKE" "$t"
131 # we can parallelize everything and all targets
132 if [ x"$t" = xeverything ] || [ x"$t" = xall]; then
133 echo "$MAKE" "-j$BUILD_FARM_NUM_JOBS" "$t"
134 ./timelimit $MAXTIME "$MAKE" "-j$BUILD_FARM_NUM_JOBS" "$t"
138 ./timelimit $MAXTIME "$MAKE" "$t"
143 if [ $status != 0 ]; then
152 ############################
155 if [ ! -x configure ]; then
159 echo "CFLAGS=$CFLAGS"
160 echo configure options: $config_and_prefix
161 echo CC="$CCACHE $compiler" $srcdir/configure $config_and_prefix
162 CC="$CCACHE $compiler"
164 ./timelimit $MAXTIME $srcdir/configure $config_and_prefix
166 echo "CONFIGURE STATUS: $cstatus"
167 if [ $cstatus != 0 ]; then
168 echo "contents of config.log:"
174 ############################
179 # the 2nd 'make everything' is to work around a bug
181 do_make proto showflags everything
183 do_make bin/smbtorture
186 do_make proto everything torture
194 echo "BUILD STATUS: $bstatus"
196 if [ "$tree" = "samba4" ] && [ -n "$smbtorture4" ] && [ -f bin/smbtorture ]; then
198 cp bin/smbtorture $smbtorture4
203 ############################
204 # show static analysis results
205 action_cc_checker() {
207 # default to passing the cc_checker
210 if [ -f ibm_checker.out ]; then
212 cccstatus=`cat ibm_checker.out | grep '^\-\- ' | wc -l`
215 echo "CC_CHECKER STATUS: $cccstatus"
219 ############################
222 if [ -d $prefix ]; then
223 if [ "$noclean" != "yes" ]; then
230 echo "INSTALL STATUS: $istatus"
234 ############################
236 action_test_samba() {
239 return "$totalstatus"
242 action_test_generic() {
247 echo "TEST STATUS: $totalstatus"
248 return "$totalstatus"
251 action_test_lorikeet_heimdal() {
256 echo "TEST STATUS: $totalstatus"
257 return "$totalstatus"
261 #############################
262 # attempt some basic tests of functionaility
263 # starting as basic as possible, and getting incresingly complex
266 # Samba needs crufty code of its own for backward
267 # compatiblity. I think a better way to do this in the future
268 # is to just call 'make installcheck'.
274 action_test_lorikeet_heimdal
282 ###########################
283 # do a test build of a particular tree
291 if [ "$compiler" = "gcc" ] && [ "$tree" != "ccache" ] && ccache -V > /dev/null; then
298 # limit our resource usage
305 if [ -z "$test_root" ]; then
309 log="build.$tree.$host.$compiler.log"
310 err="build.$tree.$host.$compiler.err"
311 sum="build.$tree.$host.$compiler.sum"
312 lck="$test_root/build.$tree.lck"
313 srcdir="$test_root/$tree/$source"
316 tdb | talloc | ldb | libreplace)
317 builddir=$srcdir/tmpbuild
326 if ! lock_file "$lck"; then
330 # pull the svn entries, if any
331 if fetch_svn "$tree"; then
332 rm -f $test_root/$tree.$compiler.svn.old
333 mv $test_root/$tree.$compiler.svn $test_root/$tree.$compiler.svn.old
334 cp $test_root/$tree.svn $test_root/$tree.$compiler.svn
335 if cmp $test_root/$tree.$compiler.svn $test_root/$tree.$compiler.svn.old > /dev/null; then
336 echo "skip: $tree.$compiler nothing changed in svn"
338 send_logs "$log" "$err"
345 if ! fetch_tree "$tree"; then
350 if [ ! -x $srcdir/configure ]; then
351 echo "skip: $tree.$compiler configure not present, try again next time!"
356 if [ ! $USER = "" ]; then
359 if [ ! $LOGNAME = "" ]; then
366 prefix="$test_root/prefix"
367 if [ ! -d $prefix ]; then
370 prefix="$prefix/$tree"
372 smbtorture4=$test_root/smbtorture4
377 config="$config --enable-socket-wrapper"
380 config="$config --enable-socket-wrapper"
381 if [ -f $smbtorture4 ]; then
382 # we create a local copy to make sure the same binary is used for all tests
383 cp $smbtorture4 $smbtorture4.$tree
384 config="$config --with-smbtorture4-path=$smbtorture4.$tree"
388 # try to avoid having extra copies of popt lying around, or
389 # depending on libpopt-dev on every system
390 config="$config --with-popt-src=../../popt"
394 fetch_tree libreplace
401 config_and_prefix="$config --prefix=$prefix"
403 # see if we need to rebuild
404 sum_tree $test_root $tree $sum
405 echo "CFLAGS=$CFLAGS $config_and_prefix" >> $sum
407 if cmp "$sum" "$sum.old" > /dev/null; then
408 echo "skip: $tree.$compiler nothing changed"
410 send_logs "$log" "$err"
415 # we do need to rebuild - save the old sum
421 if [ "$actions" = "" ]; then
422 actions="configure build install test"
429 # we need to be able to see if a build farm machine is accumulating
430 # stuck processes. We do this in two ways, as we don't know what style
433 ps -fu $USER 2> /dev/null
435 echo "building $tree with CC=$compiler on $host at "`date`
437 # build the timelimit utility
438 echo "Building timelimit"
440 $compiler $TIMELIMIT_FLAGS -o $builddir/timelimit $test_root/timelimit.c || exit 1
442 if [ -r $test_root/$tree.svn ]; then
443 h_rev=`grep revision= $test_root/$tree.svn | head -1 | cut -d'"' -f2`
444 if [ -n "$h_rev" ]; then
445 echo "HIGHEST SVN REVISION: $h_rev"
447 rev=`grep committed-rev= $test_root/$tree.svn | head -1 | cut -d'"' -f2`
448 if [ -n "$rev" ]; then
449 echo "BUILD REVISION: $rev"
453 for action in $actions; do
455 echo Running action $action
459 cd $builddir || exit 1
468 if [ $action_status != 0 ]; then
469 echo "ACTION FAILED: $action";
471 echo "ACTION PASSED: $action";
474 if [ $action_status != 0 ]; then
480 if [ "$noclean" = "yes" ]; then
481 echo cleanup skipped!
490 # send the logs to the master site
491 send_logs "$log" "$err"
498 #########################################################
499 # enable this on a per host basis only when needed please
500 # (at least for the moment)
501 kill_old_processes() {
502 # this should work on systems with linux like ps
503 (ps uxfw | grep /build | grep -v grep | egrep 'AM|PM|Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec' | awk '{print $2}' | xargs kill -9) 2> /dev/null
504 # and this should work on sysv style ps
505 (ps -fu $USER | grep /build | grep -v grep | egrep 'AM|PM|Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec' | awk '{print $2}' | xargs kill -9) 2> /dev/null
509 # this is a special fn that allows us to add a "special" hook to the build
510 # farm that we want to do to the build farm. never leave it empty. instead,
511 # use ":" as the fn body.
513 # kill old processes on systems with a known problem
516 echo "just a placeholder";
522 ######################################################
523 # main code that is run on each call to the build code
524 rsync --timeout=200 -q -az samba.org::build_farm/*.c .
527 # build.log can grow to an excessive size, trim it beyond 50M
528 if [ -f build.log ]; then
529 find build.log -size +100000 -exec /bin/rm '{}' \;