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/$tree/ $test_root/$tree; then
54 echo "transferred $tree OK"
56 echo "transfer of $tree 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 if [ -n "$smbtorture4" ]; then
184 if [ -f bin/smbtorture ]; then
185 if [ -f $smbtorture4 ]; then
188 cp bin/smbtorture $smbtorture4
193 do_make proto everything torture
201 echo "BUILD STATUS: $bstatus"
205 ############################
206 # show static analysis results
207 action_cc_checker() {
209 # default to passing the cc_checker
212 if [ -f ibm_checker.out ]; then
214 cccstatus=`cat ibm_checker.out | grep '^\-\- ' | wc -l`
217 echo "CC_CHECKER STATUS: $cccstatus"
221 ############################
224 if [ -d $prefix ]; then
225 if [ "$noclean" != "yes" ]; then
232 echo "INSTALL STATUS: $istatus"
236 ############################
238 action_test_samba() {
241 return "$totalstatus"
244 action_test_generic() {
249 echo "TEST STATUS: $totalstatus"
250 return "$totalstatus"
253 action_test_lorikeet_heimdal() {
258 echo "TEST STATUS: $totalstatus"
259 return "$totalstatus"
263 #############################
264 # attempt some basic tests of functionaility
265 # starting as basic as possible, and getting incresingly complex
268 # Samba needs crufty code of its own for backward
269 # compatiblity. I think a better way to do this in the future
270 # is to just call 'make installcheck'.
276 action_test_lorikeet_heimdal
284 ###########################
285 # do a test build of a particular tree
293 if [ "$compiler" = "gcc" ] && [ "$tree" != "ccache" ] && ccache -V > /dev/null; then
300 # limit our resource usage
307 if [ -z "$test_root" ]; then
311 log="build.$tree.$host.$compiler.log"
312 err="build.$tree.$host.$compiler.err"
313 sum="build.$tree.$host.$compiler.sum"
314 lck="$test_root/build.$tree.lck"
315 srcdir="$test_root/$tree/$source"
319 builddir=$srcdir/tmpbuild
328 if ! lock_file "$lck"; then
332 # pull the svn entries, if any
333 if fetch_svn "$tree"; then
334 rm -f $test_root/$tree.$compiler.svn.old
335 mv $test_root/$tree.$compiler.svn $test_root/$tree.$compiler.svn.old
336 cp $test_root/$tree.svn $test_root/$tree.$compiler.svn
337 if cmp $test_root/$tree.$compiler.svn $test_root/$tree.$compiler.svn.old > /dev/null; then
338 echo "skip: $tree.$compiler nothing changed in svn"
340 send_logs "$log" "$err"
347 if ! fetch_tree "$tree"; then
352 if [ ! -x $srcdir/configure ]; then
353 echo "skip: $tree.$compiler configure not present, try again next time!"
358 if [ ! $USER = "" ]; then
361 if [ ! $LOGNAME = "" ]; then
368 prefix="$test_root/prefix"
369 if [ ! -d $prefix ]; then
372 prefix="$prefix/$tree"
374 smbtorture4=$test_root/smbtorture4
379 config="$config --enable-socket-wrapper"
382 config="$config --enable-socket-wrapper"
383 if [ -f $smbtorture4 ]; then
384 # we create a local copy to make sure the same binary is used for all tests
385 cp $smbtorture4 $smbtorture4.$tree
386 config="$config --with-smbtorture4-path=$smbtorture4.$tree"
390 # try to avoid having extra copies of popt lying around, or
391 # depending on libpopt-dev on every system
392 config="$config --with-popt-src=../../samba4/source/lib/popt"
399 config_and_prefix="$config --prefix=$prefix"
401 # see if we need to rebuild
402 sum_tree $test_root $tree $sum
403 echo "CFLAGS=$CFLAGS $config_and_prefix" >> $sum
405 if cmp "$sum" "$sum.old" > /dev/null; then
406 echo "skip: $tree.$compiler nothing changed"
408 send_logs "$log" "$err"
413 # we do need to rebuild - save the old sum
419 if [ "$actions" = "" ]; then
420 actions="configure build install test"
427 # we need to be able to see if a build farm machine is accumulating
428 # stuck processes. We do this in two ways, as we don't know what style
431 ps -fu $USER 2> /dev/null
433 echo "building $tree with CC=$compiler on $host at "`date`
435 # build the timelimit utility
436 echo "Building timelimit"
438 $compiler $TIMELIMIT_FLAGS -o $builddir/timelimit $test_root/timelimit.c || exit 1
440 if [ -r $test_root/$tree.svn ]; then
441 h_rev=`grep revision= $test_root/$tree.svn | head -1 | cut -d'"' -f2`
442 if [ -n "$h_rev" ]; then
443 echo "HIGHEST SVN REVISION: $h_rev"
445 rev=`grep committed-rev= $test_root/$tree.svn | head -1 | cut -d'"' -f2`
446 if [ -n "$rev" ]; then
447 echo "BUILD REVISION: $rev"
451 for action in $actions; do
453 echo Running action $action
457 cd $builddir || exit 1
466 if [ $action_status != 0 ]; then
467 echo "ACTION FAILED: $action";
469 echo "ACTION PASSED: $action";
472 if [ $action_status != 0 ]; then
478 if [ "$noclean" = "yes" ]; then
479 echo cleanup skipped!
488 # send the logs to the master site
489 send_logs "$log" "$err"
496 #########################################################
497 # enable this on a per host basis only when needed please
498 # (at least for the moment)
499 kill_old_processes() {
500 # this should work on systems with linux like ps
501 (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
502 # and this should work on sysv style ps
503 (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
507 # this is a special fn that allows us to add a "special" hook to the build
508 # farm that we want to do to the build farm. never leave it empty. instead,
509 # use ":" as the fn body.
511 # kill old processes on systems with a known problem
514 echo "just a placeholder";
520 ######################################################
521 # main code that is run on each call to the build code
522 rsync --timeout=200 -q -az samba.org::build_farm/*.c .
525 # build.log can grow to an excessive size, trim it beyond 50M
526 if [ -f build.log ]; then
527 find build.log -size +100000 -exec /bin/rm '{}' \;