1 #!/bin/sh -*- 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 # default maximum memory size (100M) for any command
13 RUN_FROM_BUILD_FARM=yes
14 export RUN_FROM_BUILD_FARM
18 build_test_fns_id='$Id$'
20 #############################
21 # build a signature of a tree, used to see if we
28 find $sum_tree_test_root/$sum_tree_tree -type f -print | grep -v version.h | sort | xargs sum > $sum_tree_sum
29 sum build_test build_test.fns >> $sum_tree_sum
31 if [ -f "$host.fns" ]; then
32 sum $host.fns >> $sum_tree_sum
34 sum generic.fns >> $sum_tree_sum
37 if [ -f "$test_root/$tree.$scm" ]; then
38 sum "$test_root/$tree.$scm" >> $sum_tree_sum
41 for d in $deptrees; do
42 dscm=`choose_scm "$d"`
43 if [ -f "$test_root/$d.$dscm" ]; then
44 sum "$test_root/$d.$dscm" >> $sum_tree_sum
49 #############################
50 # send the logs to the master site
52 if [ "$nologreturn" = "yes" ]; then
53 echo "skipping log transfer"
59 chmod 0644 "$log" "$err"
61 XARGS_I="xargs -I '{}'"
62 find $log -size +40000 | $XARGS_I sh -c 'dd if={} bs=1024 count=20000 of={}.tmp && mv {}.tmp {} && echo "\n***LOG TRUNCATED***" >> {}'
63 find $err -size +40000 | $XARGS_I sh -c 'dd if={} bs=1024 count=20000 of={}.tmp && mv {}.tmp {} && echo "\n***LOG TRUNCATED***" >> {}'
65 rsync $* -ct -q --password-file=.password -z --timeout=200 \
66 "$log" "$err" $host@build.samba.org::build_farm_data/
70 #############################
71 # send the logs when they haven't changed
72 # the aim is to just update the servers timestamp.
73 # sending with a very large rsync block size does this
74 # with minimal network traffic
77 send_logs "$1" "$2" -B 10000000
80 ############################
81 # fetch the latest copy of the tree
83 if [ "$norsync" = "yes" ]; then
84 echo "skipping tree transfer"
87 if rsync --exclude=autom4te.cache/ --exclude=.svn/ --exclude=.git/ \
88 --delete-excluded -q --partial --timeout=200 -crlpz --delete --ignore-errors \
89 samba.org::ftp/unpacked/$fetchtree/ $test_root/$fetchtree; then
90 echo "transferred $fetchtree OK"
92 echo "transfer of $fetchtree failed code $?"
99 ############################
100 # fetch the latest copy of the rev meta info
105 test -z "$scm" && return 1
106 test x"$scm" = x"unknown" && return 1
107 test x"$scm" = x"cvs" && return 1
109 if [ "$norsync" = "yes" ]; then
110 echo "skipping .revinfo.$scm transfer"
112 if [ -r $test_root/$tree.$scm ]; then
113 rm -f $test_root/$tree.$scm.old
114 mv $test_root/$tree.$scm $test_root/$tree.$scm.old
116 rsync -q --timeout=200 -clz --ignore-errors \
117 samba.org::ftp/unpacked/$tree/.revinfo.$scm $test_root/$tree.$scm
119 if [ -r $test_root/$tree.$scm ]; then
125 ############################
126 # choose the scm that is used for the given project
147 ############################
148 # grab a lock file. Not atomic, but close :)
149 # tries to cope with NFS
151 if [ -z "$lock_root" ]; then
155 machine=`cat "$lckf" 2> /dev/null | cut -d: -f1`
156 pid=`cat "$lckf" 2> /dev/null | cut -d: -f2`
158 if [ "$pid" = "$$" ]; then
159 locknesting=`expr $locknesting + 1`
160 echo "lock nesting now $locknesting"
164 if test -f "$lckf"; then
165 test $machine = $host || {
166 echo "lock file $lckf is valid for other machine $machine"
170 echo "lock file $lckf is valid for process $pid"
173 echo "stale lock file $lckf for $machine:$pid"
177 echo "$host:$$" > "$lckf"
181 ############################
184 if [ -z "$lock_root" ]; then
187 if [ "$locknesting" != "0" ]; then
188 locknesting=`expr $locknesting - 1`
189 echo "lock nesting now $locknesting"
196 ############################
197 # run make, and print trace
206 # some trees don't need as much time
208 rsync | tdb | talloc | libreplace | ccache | distcc)
209 if [ "$compiler" != "checker" ]; then
210 MMTIME=`expr $MMTIME / 5`
217 if [ x"$BUILD_FARM_NUM_JOBS" = x ]; then
219 ./timelimit $MMTIME "$MAKE" "$t"
222 # we can parallelize everything and all targets
223 if [ x"$t" = xeverything ] || [ x"$t" = xall]; then
224 echo "$MAKE" "-j$BUILD_FARM_NUM_JOBS" "$t"
225 ./timelimit $MMTIME "$MAKE" "-j$BUILD_FARM_NUM_JOBS" "$t"
229 ./timelimit $MMTIME "$MAKE" "$t"
234 if [ $status != 0 ]; then
243 ############################
246 if [ ! -x $srcdir/configure ]; then
247 ls -l $srcdir/configure
248 echo "$srcdir/configure is missing"
250 echo "CONFIGURE STATUS: $cstatus"
253 echo "CFLAGS=$CFLAGS"
254 echo configure options: $config_and_prefix
255 echo CC="$CCACHE $compiler" $srcdir/configure $config_and_prefix
256 CC="$CCACHE $compiler"
258 ./timelimit $MAXTIME $srcdir/configure $config_and_prefix
260 echo "CONFIGURE STATUS: $cstatus"
261 if [ -f config.h ]; then
262 echo "contents of config.h:"
265 if [ -f include/config.h ]; then
266 echo "contents of include/config.h:"
272 ############################
273 # show the configure log
274 action_config_log() {
275 if [ ! -f config.log ]; then
278 echo "contents of config.log:"
286 rsync -a --delete $Tsrc/ $Tdst
289 s4selftest_create() {
290 lock_file "s4selftest.lck" || {
295 mkdir -p $s4selftest/source
297 copy_dir $builddir/bin $s4selftest/source/bin || {
299 unlock_file "s4selftest.lck";
303 copy_dir $srcdir/setup $s4selftest/source/setup || {
305 unlock_file "s4selftest.lck";
309 copy_dir $srcdir/../testprogs $s4selftest/testprogs || {
311 unlock_file "s4selftest.lck";
315 copy_dir $srcdir/selftest $s4selftest/source/selftest || {
317 unlock_file "s4selftest.lck";
321 copy_dir $srcdir/script $s4selftest/source/script || {
323 unlock_file "s4selftest.lck";
327 mkdir -p $s4selftest/source/scripting || {
329 unlock_file "s4selftest.lck";
333 copy_dir $srcdir/scripting/libjs $s4selftest/source/scripting/libjs || {
335 unlock_file "s4selftest.lck";
339 unlock_file "s4selftest.lck"
342 s4selftest_update() {
343 lock_file "s4selftest.lck" || {
347 copy_dir $s4selftest $s4selftest.$tree.$compiler.$$ || {
348 rm -rf $s4selftest.$tree.$compiler.$$;
349 unlock_file "s4selftest.lck";
353 rm -rf $s4selftest.$tree.$compiler
354 mv $s4selftest.$tree.$compiler.$$ $s4selftest.$tree.$compiler
356 unlock_file "s4selftest.lck"
359 ############################
366 if test x"$bstatus" != x"0"; then
367 # the 2nd 'make everything' is to work around a bug
373 if test x"$bstatus" != x"0"; then
378 if test x"$bstatus" = x"0"; then
384 do_make proto everything torture
393 echo "BUILD STATUS: $bstatus"
398 ############################
399 # show static analysis results
400 action_cc_checker() {
402 # default to passing the cc_checker
405 if [ -f ibm_checker.out ]; then
407 cccstatus=`cat ibm_checker.out | grep '^\-\- ' | wc -l`
410 echo "CC_CHECKER STATUS: $cccstatus"
414 ############################
417 if [ -d $prefix ]; then
418 if [ "$noclean" != "yes" ]; then
425 echo "INSTALL STATUS: $istatus"
429 ############################
431 action_test_samba() {
434 return "$totalstatus"
437 action_test_generic() {
442 echo "TEST STATUS: $totalstatus"
443 return "$totalstatus"
446 action_test_lorikeet_heimdal() {
449 SOCKET_WRAPPER_DIR=`pwd`/sw
450 mkdir $SOCKET_WRAPPER_DIR
451 export SOCKET_WRAPPER_DIR
455 export SOCKET_WRAPPER_DIR
456 echo "TEST STATUS: $totalstatus"
457 return "$totalstatus"
461 #############################
462 # attempt some basic tests of functionaility
463 # starting as basic as possible, and getting incresingly complex
466 # Samba needs crufty code of its own for backward
467 # compatiblity. I think a better way to do this in the future
468 # is to just call 'make installcheck'.
470 samba*|smb-build|pidl)
474 action_test_lorikeet_heimdal
482 ###########################
483 # do a test build of a particular tree
491 if [ "$compiler" = "gcc" ] && [ "$tree" != "ccache" ] && ccache -V > /dev/null; then
498 # limit our resource usage
499 ulimit -t $MAXTIME 2> /dev/null
502 ulimit -m $MAXMEM 2> /dev/null
505 # darn, this affects sparse files too! disable it
506 # ulimit -f 100000 2> /dev/null
508 # try and limit the number of open files to 150. That means we'll discover
510 ulimit -n 150 2> /dev/null
515 if [ -z "$test_root" ]; then
519 log="build.$tree.$host.$compiler.log"
520 err="build.$tree.$host.$compiler.err"
521 sum="build.$tree.$host.$compiler.sum"
522 lck="build.$tree.lck"
523 srcdir="$test_root/$tree/$source"
525 lock_file "$lck" || {
529 # work out what other trees this package depends on
533 deptrees="libreplace";
536 deptrees="libreplace talloc tdb";
543 scm=`choose_scm "$tree"`
545 # pull the entries, if any
546 if fetch_revinfo "$tree" "$scm"; then
547 for d in $deptrees; do
548 dscm=`choose_scm "$d"`
549 if [ -f "$test_root/$d.$dscm" ]; then
550 if [ "$d" != "$tree" ]; then
551 cat "$test_root/$d.$dscm" >> $test_root/$tree.$scm
555 rm -f $test_root/$tree.$compiler.$scm.old
556 mv $test_root/$tree.$compiler.$scm $test_root/$tree.$compiler.$scm.old
557 cp $test_root/$tree.$scm $test_root/$tree.$compiler.$scm
558 if cmp $test_root/$tree.$compiler.$scm $test_root/$tree.$compiler.$scm.old > /dev/null; then
559 echo "skip: $tree.$compiler nothing changed in $scm"
561 send_logs_skip "$log" "$err"
568 fetch_tree "$tree" || {
574 if [ ! -x $srcdir/configure ] && [ "$tree" != "pidl" ]; then
575 echo "skip: $tree.$compiler configure not present, try again next time!"
581 echo "Starting build of $tree.$compiler in process $$ at `date`"
584 tdb | talloc | ldb | libreplace)
585 builddir="$test_root/tmp.$tree.$compiler"
587 if [ -d $builddir ]; then
600 if [ ! x$USER = x"" ]; then
603 if [ ! x$LOGNAME = x"" ]; then
610 prefix="$test_root/prefix/$tree.$compiler"
613 s4selftest=$test_root/s4selftest
620 sw_config="$config --enable-socket-wrapper"
623 sw_config="$config --enable-socket-wrapper"
624 sw_config="$sw_config --enable-nss-wrapper"
627 sw_config="$config --enable-socket-wrapper"
628 sw_config="$sw_config --enable-nss-wrapper"
629 s4selftest_update "$tree" "$compiler" && {
630 t="$s4selftest.$tree.$compiler/source"
631 #sw_config="$sw_config --with-samba4srcdir=$t"
632 t="$t/bin/smbtorture"
633 sw_config="$sw_config --with-smbtorture4-path=$t"
637 PKG_CONFIG_PATH="$test_root/prefix/samba4.$compiler/lib/pkgconfig"
638 export PKG_CONFIG_PATH
644 fetch_tree libreplace
651 if [ "$LCOV_REPORT" = "yes" ]; then
652 GCOV_FLAGS="-ftest-coverage -fprofile-arcs"
654 HOSTCC_CFLAGS="$HOSTCC_CFLAGS $GCOV_FLAGS"
655 CFLAGS="$CFLAGS $GCOV_FLAGS"
656 LDFLAGS="$LDFLAGS $GCOV_FLAGS $GCOV_LIBS"
657 SHLD_FLAGS="$SHLD_FLAGS $GCOV_FLAGS $GCOV_LIBS"
658 export HOSTCC_CFLAGS CFLAGS LDFLAGS SHLD_FLAGS
661 config_and_prefix="$sw_config --prefix=$prefix"
663 # see if we need to rebuild
664 sum_tree $test_root $tree $sum $scm
665 echo "CFLAGS=$CFLAGS $config_and_prefix" >> $sum
667 if cmp "$sum" "$sum.old" > /dev/null; then
668 echo "skip: $tree.$compiler nothing changed"
670 send_logs_skip "$log" "$err"
672 echo "Ending build of $tree.$compiler in process $$ at `date`"
676 # we do need to rebuild - save the old sum
682 if [ "$actions" = "" ]; then
683 actions="configure config_log build install test"
688 # we all want to be able to read the output...
695 echo "build_test : $build_test_id"
696 echo "build_test.fns : $build_test_fns_id"
697 echo "local settings file : $build_test_settings_local_file"
698 echo "local functions file: $build_test_fns_local_file"
699 echo "used .fns file : $build_test_used_fns_file"
702 # we need to be able to see if a build farm machine is accumulating
703 # stuck processes. We do this in two ways, as we don't know what style
706 ps -fu $USER 2> /dev/null
708 echo "building $tree with CC=$compiler on $host at "`date`
709 echo "builddir=$builddir"
710 echo "prefix=$prefix"
712 echo "Showing limits"
713 ulimit -a 2> /dev/null
715 # build the timelimit utility
716 echo "Building timelimit"
718 $compiler $TIMELIMIT_FLAGS -o $builddir/timelimit $test_root/timelimit.c || exit 1
720 # the following is for non-samba builds only
721 if [ -r $test_root/$tree.svn ]; then
722 h_rev=`grep 'Revision: ' $test_root/$tree.svn | cut -d ':' -f2 | cut -d ' ' -f2 | sed 1q`
723 if [ -n "$h_rev" ]; then
724 echo "HIGHEST SVN REVISION: $h_rev"
726 rev=`grep 'Last Changed Rev: ' $test_root/$tree.svn | cut -d ':' -f2 | cut -d ' ' -f2 | sed 1q`
727 if [ -n "$rev" ]; then
728 echo "BUILD REVISION: $rev"
730 elif [ -r $test_root/$tree.git ]; then
731 csha1=`cat $test_root/$tree.git |head -3 | tail -1`
732 if [ -n "$csha1" ]; then
733 echo "BUILD COMMIT REVISION: $csha1"
735 cdate=`cat $test_root/$tree.git |head -4 | tail -1`
736 if [ -n "$cdate" ]; then
737 echo "BUILD COMMIT DATE: $cdate"
739 ctime=`cat $test_root/$tree.git |head -2 | tail -1`
740 if [ -n "$ctime" ]; then
741 echo "BUILD COMMIT TIME: $ctime"
745 if [ "$tree" = "pidl" ]
748 perl ./Makefile.PL "$prefix"
751 for action in $actions; do
753 echo Running action $action
757 cd $builddir || exit 1
766 if [ $action_status != 0 ]; then
767 echo "ACTION FAILED: $action";
769 echo "ACTION PASSED: $action";
772 if [ $action_status != 0 ]; then
778 if [ "$LCOV_REPORT" = "yes" ]; then
781 lcov --directory $builddir --capture --output-file $builddir/$tree.lcov.info
784 # ugly hack for s4, as lcov is otherwise not able to find
786 rm -f heimdal/lib/*/{lex,parse}.{gcda,gcno}
787 lcov --base-directory $builddir --directory $builddir --capture --output-file $builddir/$tree.lcov.info
790 genhtml -o $builddir/coverage $builddir/$tree.lcov.info
793 if [ "$noclean" = "yes" ]; then
794 echo cleanup skipped!
802 if [ "$LCOV_REPORT" = "yes" ]; then
803 chmod u=rwX,g=rX,o=rX -R $builddir/coverage
804 rsync -rct -q --password-file=.password -z --timeout=200 \
805 $builddir/coverage/ $host@build.samba.org::lcov_data/$host/$tree/
811 if [ "$usingtmpbuild" = "1" ]; then
812 if [ "$noclean" = "yes" ]; then
813 echo builddir cleanup skipped!
815 /bin/rm -rf $builddir
818 # send the logs to the master site
819 send_logs "$log" "$err"
822 echo "Ending build of $tree.$compiler in process $$ at `date`"
826 #########################################################
827 # if you want to build only one project at a time
828 # add 'global_lock' after 'per_run_hook' and
829 # 'global_unlock' to the end of the file
831 lock_file "global.lck" || {
836 unlock_file "global.lck"
839 #########################################################
840 # enable this on a per host basis only when needed please
841 # (at least for the moment)
842 kill_old_processes() {
843 # this should work on systems with linux like ps
844 (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
845 # and this should work on sysv style ps
846 (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
849 delete_old_svn_tree() {
852 test -z "$otree" && return 0;
857 rm -rf s4selftest.$otree.*
858 rm -rf build.$otree.*
861 # this is a special fn that allows us to add a "special" hook to the build
862 # farm that we want to do to the build farm. never leave it empty. instead,
863 # use ":" as the fn body.
865 # kill old processes on systems with a known problem
868 echo "just a placeholder";
877 # trim the log if too large
878 if [ "`wc -c < build.log`" -gt 2000000 ]; then
882 delete_old_svn_tree "samba_3_2"
886 ######################################################
887 # main code that is run on each call to the build code
888 rsync --timeout=200 -q -az build.samba.org::build_farm/*.c .
891 # build.log can grow to an excessive size, trim it beyond 50M
892 if [ -f build.log ]; then
893 find build.log -size +100000 -exec /bin/rm '{}' \;