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
16 #############################
17 # build a signature of a tree, used to see if we
23 find $sum_tree_test_root/$sum_tree_tree -type f -print | grep -v '.svn' | grep -v version.h | sort | xargs sum > $sum_tree_sum
24 sum build_test build_test.fns >> $sum_tree_sum
26 if [ -f "$host.fns" ]; then
27 sum $host.fns >> $sum_tree_sum
29 sum generic.fns >> $sum_tree_sum
31 if [ -f "$test_root/$tree.svn" ]; then
32 sum "$test_root/$tree.svn" >> $sum_tree_sum
34 for d in $deptrees; do
35 if [ -f "$test_root/$d.svn" ]; then
36 sum "$test_root/$d.svn" >> $sum_tree_sum
41 #############################
42 # send the logs to the master site
44 if [ "$nologreturn" = "yes" ]; then
45 echo "skipping log transfer"
51 chmod 0644 "$log" "$err"
54 if [ "`uname`" = "FreeBSD" ]; then
55 XARGS_I="xargs -I '{}' -R -1"
57 find $log -size +20000k | $XARGS_I sh -c 'dd if={} bs=1024 count=20000 of={}.tmp && mv {}.tmp {} && echo "\n***LOG TRUNCATED***" >> {}'
58 find $err -size +20000k | $XARGS_I sh -c 'dd if={} bs=1024 count=20000 of={}.tmp && mv {}.tmp {} && echo "\n***LOG TRUNCATED***" >> {}'
60 rsync $* -ct -q --password-file=.password -z --timeout=200 \
61 "$log" "$err" $host@samba.org::build_farm_data/
65 #############################
66 # send the logs when they haven't changed
67 # the aim is to just update the servers timestamp.
68 # sending with a very large rsync block size does this
69 # with minimal network traffic
72 send_logs "$1" "$2" -B 10000000
75 ############################
76 # fetch the latest copy of the tree
78 if [ "$norsync" = "yes" ]; then
79 echo "skipping tree transfer"
82 if rsync --exclude=autom4te.cache/ --exclude=.svn/ --delete-excluded -q --partial --timeout=200 -crlpz --delete --ignore-errors \
83 samba.org::ftp/unpacked/$fetchtree/ $test_root/$fetchtree; then
84 echo "transferred $fetchtree OK"
86 echo "transfer of $fetchtree failed code $?"
93 ############################
94 # fetch the latest copy of the svn entries file
97 # skip products still in CVS.
99 ccache | distcc | rsync)
105 if [ "$norsync" = "yes" ]; then
106 echo "skipping svn transfer"
108 if [ -r $test_root/$tree.svn ]; then
109 rm -f $test_root/$tree.svn.old
110 mv $test_root/$tree.svn $test_root/$tree.svn.old
112 rsync -q --timeout=200 -clz --ignore-errors \
113 samba.org::ftp/unpacked/$tree/.svn/entries $test_root/$tree.svn.tmp
114 chmod u+w $test_root/$tree.svn.tmp
115 sort -u < $test_root/$tree.svn.tmp > $test_root/$tree.svn
116 rm -f $test_root/$tree.svn.tmp
118 if [ -r $test_root/$tree.svn ]; then
126 ############################
127 # grab a lock file. Not atomic, but close :)
128 # tries to cope with NFS
130 if [ -z "$lock_root" ]; then
134 machine=`cat "$lckf" 2> /dev/null | cut -d: -f1`
135 pid=`cat "$lckf" 2> /dev/null | cut -d: -f2`
137 if [ "$pid" = "$$" ]; then
138 locknesting=`expr $locknesting + 1`
139 echo "lock nesting now $locknesting"
143 if test -f "$lckf"; then
144 test $machine = $host || {
145 echo "lock file $lckf is valid for other machine $machine"
149 echo "lock file $lckf is valid for process $pid"
152 echo "stale lock file $lckf for $machine:$pid"
156 echo "$host:$$" > "$lckf"
160 ############################
163 if [ -z "$lock_root" ]; then
166 if [ "$locknesting" != "0" ]; then
167 locknesting=`expr $locknesting - 1`
168 echo "lock nesting now $locknesting"
175 ############################
176 # run make, and print trace
185 # some trees don't need as much time
187 rsync | tdb | talloc | libreplace | ccache | distcc)
188 if [ "$compiler" != "checker" ]; then
189 MMTIME=`expr $MMTIME / 5`
196 if [ x"$BUILD_FARM_NUM_JOBS" = x ]; then
198 ./timelimit $MMTIME "$MAKE" "$t"
201 # we can parallelize everything and all targets
202 if [ x"$t" = xeverything ] || [ x"$t" = xall]; then
203 echo "$MAKE" "-j$BUILD_FARM_NUM_JOBS" "$t"
204 ./timelimit $MMTIME "$MAKE" "-j$BUILD_FARM_NUM_JOBS" "$t"
208 ./timelimit $MMTIME "$MAKE" "$t"
213 if [ $status != 0 ]; then
222 ############################
225 if [ ! -x configure ]; then
229 echo "CFLAGS=$CFLAGS"
230 echo configure options: $config_and_prefix
231 echo CC="$CCACHE $compiler" $srcdir/configure $config_and_prefix
232 CC="$CCACHE $compiler"
234 ./timelimit $MAXTIME $srcdir/configure $config_and_prefix
236 echo "CONFIGURE STATUS: $cstatus"
237 if [ -f config.h ]; then
238 echo "contents of config.h:"
241 if [ -f include/config.h ]; then
242 echo "contents of include/config.h:"
248 ############################
249 # show the configure log
250 action_config_log() {
251 if [ ! -f config.log ]; then
254 echo "contents of config.log:"
259 ############################
264 # the 2nd 'make everything' is to work around a bug
266 do_make proto showflags everything
268 do_make bin/smbtorture
271 do_make proto everything torture
279 echo "BUILD STATUS: $bstatus"
281 if [ "$tree" = "samba4" ] && [ -n "$smbtorture4" ] && [ -f bin/smbtorture ]; then
283 cp bin/smbtorture $smbtorture4
288 ############################
289 # show static analysis results
290 action_cc_checker() {
292 # default to passing the cc_checker
295 if [ -f ibm_checker.out ]; then
297 cccstatus=`cat ibm_checker.out | grep '^\-\- ' | wc -l`
300 echo "CC_CHECKER STATUS: $cccstatus"
304 ############################
307 if [ -d $prefix ]; then
308 if [ "$noclean" != "yes" ]; then
315 echo "INSTALL STATUS: $istatus"
319 ############################
321 action_test_samba() {
324 return "$totalstatus"
327 action_test_generic() {
332 echo "TEST STATUS: $totalstatus"
333 return "$totalstatus"
336 action_test_lorikeet_heimdal() {
339 SOCKET_WRAPPER_DIR=`pwd`/sw
340 mkdir $SOCKET_WRAPPER_DIR
341 export SOCKET_WRAPPER_DIR
345 export SOCKET_WRAPPER_DIR
346 echo "TEST STATUS: $totalstatus"
347 return "$totalstatus"
351 #############################
352 # attempt some basic tests of functionaility
353 # starting as basic as possible, and getting incresingly complex
356 # Samba needs crufty code of its own for backward
357 # compatiblity. I think a better way to do this in the future
358 # is to just call 'make installcheck'.
361 # echo "testing of samba_3_0 disabled until cause of runaway processes found (tridge - 7th sep 2006)"
363 samba*|smb-build|pidl)
367 action_test_lorikeet_heimdal
375 ###########################
376 # do a test build of a particular tree
384 if [ "$compiler" = "gcc" ] && [ "$tree" != "ccache" ] && ccache -V > /dev/null; then
391 # limit our resource usage
392 ulimit -t $MAXTIME 2> /dev/null
395 ulimit -m 100000 2> /dev/null
398 # darn, this affects sparse files too! disable it
399 # ulimit -f 100000 2> /dev/null
401 # try and limit the number of open files to 150. That means we'll discover
403 ulimit -n 150 2> /dev/null
408 if [ -z "$test_root" ]; then
412 log="build.$tree.$host.$compiler.log"
413 err="build.$tree.$host.$compiler.err"
414 sum="build.$tree.$host.$compiler.sum"
415 lck="build.$tree.lck"
416 srcdir="$test_root/$tree/$source"
418 lock_file "$lck" || {
422 # work out what other trees this package depends on
426 deptrees="libreplace";
429 deptrees="libreplace talloc tdb";
436 # pull the svn entries, if any
437 if fetch_svn "$tree"; then
438 for d in $deptrees; do
439 if [ -f "$test_root/$d.svn" ]; then
440 if [ "$d" != "$tree" ]; then
441 cat "$test_root/$d.svn" >> $test_root/$tree.svn
445 rm -f $test_root/$tree.$compiler.svn.old
446 mv $test_root/$tree.$compiler.svn $test_root/$tree.$compiler.svn.old
447 cp $test_root/$tree.svn $test_root/$tree.$compiler.svn
448 if cmp $test_root/$tree.$compiler.svn $test_root/$tree.$compiler.svn.old > /dev/null; then
449 echo "skip: $tree.$compiler nothing changed in svn"
451 send_logs_skip "$log" "$err"
458 fetch_tree "$tree" || {
464 if [ ! -x $srcdir/configure ] && [ "$tree" != "pidl" ]; then
465 echo "skip: $tree.$compiler configure not present, try again next time!"
471 echo "Starting build of $tree.$compiler in process $$ at `date`"
474 tdb | talloc | ldb | libreplace)
475 builddir="$test_root/tmp.$tree.$compiler"
477 if [ -d $builddir ]; then
490 if [ ! $USER = "" ]; then
493 if [ ! $LOGNAME = "" ]; then
500 prefix="$test_root/prefix/$tree.$compiler"
503 smbtorture4=$test_root/smbtorture4
509 samba4|lorikeet-heimdal)
510 sw_config="$config --enable-socket-wrapper"
513 sw_config="$config --enable-socket-wrapper"
514 if [ -f $smbtorture4 ]; then
515 # we create a local copy to make sure the same binary is used for all tests
516 cp $smbtorture4 $smbtorture4.$tree
517 sw_config="$sw_config --with-smbtorture4-path=$smbtorture4.$tree"
521 PKG_CONFIG_PATH="$test_root/prefix/samba4.$compiler/lib/pkgconfig"
522 export PKG_CONFIG_PATH
528 fetch_tree libreplace
535 if [ "$LCOV_REPORT" = "yes" ]; then
536 GCOV_FLAGS="-ftest-coverage -fprofile-arcs"
538 HOSTCC_CFLAGS="$HOSTCC_CFLAGS $GCOV_FLAGS"
539 CFLAGS="$CFLAGS $GCOV_FLAGS"
540 LDFLAGS="$LDFLAGS $GCOV_FLAGS $GCOV_LIBS"
541 SHLD_FLAGS="$SHLD_FLAGS $GCOV_FLAGS $GCOV_LIBS"
542 export HOSTCC_CFLAGS CFLAGS LDFLAGS SHLD_FLAGS
545 config_and_prefix="$sw_config --prefix=$prefix"
547 # see if we need to rebuild
548 sum_tree $test_root $tree $sum
549 echo "CFLAGS=$CFLAGS $config_and_prefix" >> $sum
551 if cmp "$sum" "$sum.old" > /dev/null; then
552 echo "skip: $tree.$compiler nothing changed"
554 send_logs_skip "$log" "$err"
556 echo "Ending build of $tree.$compiler in process $$ at `date`"
560 # we do need to rebuild - save the old sum
566 if [ "$actions" = "" ]; then
567 actions="configure config_log build install test"
574 # we need to be able to see if a build farm machine is accumulating
575 # stuck processes. We do this in two ways, as we don't know what style
578 ps -fu $USER 2> /dev/null
580 echo "building $tree with CC=$compiler on $host at "`date`
581 echo "builddir=$builddir"
582 echo "prefix=$prefix"
584 echo "Showing limits"
585 ulimit -a 2> /dev/null
587 # build the timelimit utility
588 echo "Building timelimit"
590 $compiler $TIMELIMIT_FLAGS -o $builddir/timelimit $test_root/timelimit.c || exit 1
592 if [ -r $test_root/$tree.svn ]; then
593 h_rev=`grep revision= $test_root/$tree.svn | cut -d'"' -f2 | sort -n | tail -1`
594 if [ -n "$h_rev" ]; then
595 echo "HIGHEST SVN REVISION: $h_rev"
597 rev=`grep committed-rev= $test_root/$tree.svn | cut -d'"' -f2 | sort -n | tail -1`
598 if [ -n "$rev" ]; then
599 echo "BUILD REVISION: $rev"
604 if [ "$tree" = "pidl" ]
607 perl ./Makefile.PL "$prefix"
610 for action in $actions; do
612 echo Running action $action
616 cd $builddir || exit 1
625 if [ $action_status != 0 ]; then
626 echo "ACTION FAILED: $action";
628 echo "ACTION PASSED: $action";
631 if [ $action_status != 0 ]; then
637 if [ "$LCOV_REPORT" = "yes" ]; then
640 lcov --directory $builddir --capture --output-file $builddir/$tree.lcov.info
643 # ugly hack for s4, as lcov is otherwise not able to find
645 rm -f heimdal/lib/*/{lex,parse}.{gcda,gcno}
646 lcov --base-directory $builddir --directory $builddir --capture --output-file $builddir/$tree.lcov.info
649 genhtml -o $builddir/coverage $builddir/$tree.lcov.info
652 if [ "$noclean" = "yes" ]; then
653 echo cleanup skipped!
661 if [ "$LCOV_REPORT" = "yes" ]; then
662 chmod u=rwX,g=rX,o=rX -R $builddir/coverage
663 rsync -rct -q --password-file=.password -z --timeout=200 \
664 $builddir/coverage/ $host@samba.org::lcov_data/$host/$tree/
670 if [ "$usingtmpbuild" = "1" ]; then
671 if [ "$noclean" = "yes" ]; then
672 echo builddir cleanup skipped!
674 /bin/rm -rf $builddir
677 # send the logs to the master site
678 send_logs "$log" "$err"
681 echo "Ending build of $tree.$compiler in process $$ at `date`"
685 #########################################################
686 # if you want to build only one project at a time
687 # add 'global_lock' after 'per_run_hook' and
688 # 'global_unlock' to the end of the file
690 lock_file "global.lck" || {
695 unlock_file "global.lck"
698 #########################################################
699 # enable this on a per host basis only when needed please
700 # (at least for the moment)
701 kill_old_processes() {
702 # this should work on systems with linux like ps
703 (ps uxfw | grep /build | grep -v grep | egrep 'Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec' | awk '{print $2}' | xargs kill -9) 2> /dev/null
704 # and this should work on sysv style ps
705 (ps -fu $USER | grep /build | grep -v grep | egrep 'Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec' | awk '{print $2}' | xargs kill -9) 2> /dev/null
709 # this is a special fn that allows us to add a "special" hook to the build
710 # farm that we want to do to the build farm. never leave it empty. instead,
711 # use ":" as the fn body.
713 # kill old processes on systems with a known problem
716 echo "just a placeholder";
725 # trim the log if too large
726 if [ "`wc -c < build.log`" -gt 2000000 ]; then
732 ######################################################
733 # main code that is run on each call to the build code
734 rsync --timeout=200 -q -az samba.org::build_farm/*.c .
737 # build.log can grow to an excessive size, trim it beyond 50M
738 if [ -f build.log ]; then
739 find build.log -size +100000 -exec /bin/rm '{}' \;