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 is implemented differently or not at all.
62 # GNU xargs did not implement "-I" until 4.2.9:
63 xargs --version 2>&1 | grep "^GNU xargs" > /dev/null
65 if [ $status == 0 ]; then
69 if [ x"$XARGS_IS_GNU" = x"yes" ]; then
72 XARGS_I="xargs -I '{}'"
75 find $log -size +40000 | $XARGS_I sh -c 'dd if={} bs=1024 count=20000 of={}.tmp && mv {}.tmp {} && echo "\n***LOG TRUNCATED***" >> {}'
76 find $err -size +40000 | $XARGS_I sh -c 'dd if={} bs=1024 count=20000 of={}.tmp && mv {}.tmp {} && echo "\n***LOG TRUNCATED***" >> {}'
78 rsync $* -ct -q --password-file=.password -z --timeout=200 \
79 "$log" "$err" $host@build.samba.org::build_farm_data/
83 #############################
84 # send the logs when they haven't changed
85 # the aim is to just update the servers timestamp.
86 # sending with a very large rsync block size does this
87 # with minimal network traffic
90 send_logs "$1" "$2" -B 10000000
93 ############################
94 # fetch the latest copy of the tree
96 if [ "$norsync" = "yes" ]; then
97 echo "skipping tree transfer"
100 if rsync --exclude=autom4te.cache/ --exclude=.svn/ --exclude=.git/ \
101 --delete-excluded -q --partial --timeout=200 -crlpz --delete --ignore-errors \
102 samba.org::ftp/unpacked/$fetchtree/ $test_root/$fetchtree; then
103 echo "transferred $fetchtree OK"
105 echo "transfer of $fetchtree failed code $?"
112 ############################
113 # fetch the latest copy of the rev meta info
118 test -z "$scm" && return 1
119 test x"$scm" = x"unknown" && return 1
120 test x"$scm" = x"cvs" && return 1
122 if [ "$norsync" = "yes" ]; then
123 echo "skipping .revinfo.$scm transfer"
125 if [ -r $test_root/$tree.$scm ]; then
126 rm -f $test_root/$tree.$scm.old
127 mv $test_root/$tree.$scm $test_root/$tree.$scm.old
129 rsync -q --timeout=200 -clz --ignore-errors \
130 samba.org::ftp/unpacked/$tree/.revinfo.$scm $test_root/$tree.$scm
132 if [ -r $test_root/$tree.$scm ]; then
138 ############################
139 # choose the scm that is used for the given project
148 samba_3* | rsync | talloc)
160 ############################
161 # grab a lock file. Not atomic, but close :)
162 # tries to cope with NFS
164 if [ -z "$lock_root" ]; then
168 machine=`cat "$lckf" 2> /dev/null | cut -d: -f1`
169 pid=`cat "$lckf" 2> /dev/null | cut -d: -f2`
171 if [ "$pid" = "$$" ]; then
172 locknesting=`expr $locknesting + 1`
173 echo "lock nesting now $locknesting"
177 if test -f "$lckf"; then
178 test $machine = $host || {
179 echo "lock file $lckf is valid for other machine $machine"
183 echo "lock file $lckf is valid for process $pid"
186 echo "stale lock file $lckf for $machine:$pid"
190 echo "$host:$$" > "$lckf"
194 ############################
197 if [ -z "$lock_root" ]; then
200 if [ "$locknesting" != "0" ]; then
201 locknesting=`expr $locknesting - 1`
202 echo "lock nesting now $locknesting"
209 ############################
210 # run make, and print trace
219 # some trees don't need as much time
221 rsync | tdb | talloc | libreplace | ccache | distcc)
222 if [ "$compiler" != "checker" ]; then
223 MMTIME=`expr $MMTIME / 5`
230 if [ x"$BUILD_FARM_NUM_JOBS" = x ]; then
232 ./timelimit $MMTIME "$MAKE" "$t"
235 # we can parallelize everything and all targets
236 if [ x"$t" = xeverything ] || [ x"$t" = xall]; then
237 echo "$MAKE" "-j$BUILD_FARM_NUM_JOBS" "$t"
238 ./timelimit $MMTIME "$MAKE" "-j$BUILD_FARM_NUM_JOBS" "$t"
242 ./timelimit $MMTIME "$MAKE" "$t"
247 if [ $status != 0 ]; then
256 ############################
259 if [ ! -x $srcdir/configure ]; then
260 ls -l $srcdir/configure
261 echo "$srcdir/configure is missing"
263 echo "CONFIGURE STATUS: $cstatus"
266 echo "CFLAGS=$CFLAGS"
267 echo configure options: $config_and_prefix
268 echo CC="$CCACHE $compiler" $srcdir/configure $config_and_prefix
269 CC="$CCACHE $compiler"
271 ./timelimit $MAXTIME $srcdir/configure $config_and_prefix
273 echo "CONFIGURE STATUS: $cstatus"
274 if [ -f config.h ]; then
275 echo "contents of config.h:"
278 if [ -f include/config.h ]; then
279 echo "contents of include/config.h:"
285 ############################
286 # show the configure log
287 action_config_log() {
288 if [ ! -f config.log ]; then
291 echo "contents of config.log:"
299 rsync -a --delete $Tsrc/ $Tdst
302 s4selftest_create() {
303 lock_file "s4selftest.lck" || {
308 mkdir -p $s4selftest/source
310 copy_dir $builddir/bin $s4selftest/source/bin || {
312 unlock_file "s4selftest.lck";
316 copy_dir $srcdir/setup $s4selftest/source/setup || {
318 unlock_file "s4selftest.lck";
322 copy_dir $srcdir/../testprogs $s4selftest/testprogs || {
324 unlock_file "s4selftest.lck";
328 copy_dir $srcdir/selftest $s4selftest/source/selftest || {
330 unlock_file "s4selftest.lck";
334 copy_dir $srcdir/script $s4selftest/source/script || {
336 unlock_file "s4selftest.lck";
340 mkdir -p $s4selftest/source/scripting || {
342 unlock_file "s4selftest.lck";
346 copy_dir $srcdir/scripting/libjs $s4selftest/source/scripting/libjs || {
348 unlock_file "s4selftest.lck";
352 unlock_file "s4selftest.lck"
355 s4selftest_update() {
356 lock_file "s4selftest.lck" || {
360 copy_dir $s4selftest $s4selftest.$tree.$compiler.$$ || {
361 rm -rf $s4selftest.$tree.$compiler.$$;
362 unlock_file "s4selftest.lck";
366 rm -rf $s4selftest.$tree.$compiler
367 mv $s4selftest.$tree.$compiler.$$ $s4selftest.$tree.$compiler
369 unlock_file "s4selftest.lck"
372 ############################
379 if test x"$bstatus" != x"0"; then
380 # the 2nd 'make everything' is to work around a bug
386 if test x"$bstatus" != x"0"; then
391 if test x"$bstatus" = x"0"; then
397 do_make proto everything torture
406 echo "BUILD STATUS: $bstatus"
411 ############################
412 # show static analysis results
413 action_cc_checker() {
415 # default to passing the cc_checker
418 if [ -f ibm_checker.out ]; then
420 cccstatus=`cat ibm_checker.out | grep '^\-\- ' | wc -l`
423 echo "CC_CHECKER STATUS: $cccstatus"
427 ############################
430 if [ -d $prefix ]; then
431 if [ "$noclean" != "yes" ]; then
438 echo "INSTALL STATUS: $istatus"
442 ############################
444 action_test_samba() {
447 return "$totalstatus"
450 action_test_generic() {
455 echo "TEST STATUS: $totalstatus"
456 return "$totalstatus"
459 action_test_lorikeet_heimdal() {
462 SOCKET_WRAPPER_DIR=`pwd`/sw
463 mkdir $SOCKET_WRAPPER_DIR
464 export SOCKET_WRAPPER_DIR
468 export SOCKET_WRAPPER_DIR
469 echo "TEST STATUS: $totalstatus"
470 return "$totalstatus"
474 #############################
475 # attempt some basic tests of functionaility
476 # starting as basic as possible, and getting incresingly complex
479 # Samba needs crufty code of its own for backward
480 # compatiblity. I think a better way to do this in the future
481 # is to just call 'make installcheck'.
483 samba*|smb-build|pidl)
487 action_test_lorikeet_heimdal
495 ###########################
496 # do a test build of a particular tree
504 if [ "$compiler" = "gcc" ] && [ "$tree" != "ccache" ] && ccache -V > /dev/null; then
511 # limit our resource usage
512 ulimit -t $MAXTIME 2> /dev/null
515 ulimit -m $MAXMEM 2> /dev/null
518 # darn, this affects sparse files too! disable it
519 # ulimit -f 100000 2> /dev/null
521 # try and limit the number of open files to 150. That means we'll discover
523 ulimit -n 150 2> /dev/null
528 if [ -z "$test_root" ]; then
532 log="build.$tree.$host.$compiler.log"
533 err="build.$tree.$host.$compiler.err"
534 sum="build.$tree.$host.$compiler.sum"
535 lck="build.$tree.lck"
536 srcdir="$test_root/$tree/$source"
538 lock_file "$lck" || {
542 # work out what other trees this package depends on
546 deptrees="libreplace";
549 deptrees="libreplace talloc tdb";
556 scm=`choose_scm "$tree"`
558 # pull the entries, if any
559 if fetch_revinfo "$tree" "$scm"; then
560 for d in $deptrees; do
561 dscm=`choose_scm "$d"`
562 if [ -f "$test_root/$d.$dscm" ]; then
563 if [ "$d" != "$tree" ]; then
564 cat "$test_root/$d.$dscm" >> $test_root/$tree.$scm
568 rm -f $test_root/$tree.$compiler.$scm.old
569 mv $test_root/$tree.$compiler.$scm $test_root/$tree.$compiler.$scm.old
570 cp $test_root/$tree.$scm $test_root/$tree.$compiler.$scm
571 if cmp $test_root/$tree.$compiler.$scm $test_root/$tree.$compiler.$scm.old > /dev/null; then
572 echo "skip: $tree.$compiler nothing changed in $scm"
574 send_logs_skip "$log" "$err"
581 fetch_tree "$tree" || {
587 if [ ! -x $srcdir/configure ] && [ "$tree" != "pidl" ]; then
588 echo "skip: $tree.$compiler configure not present, try again next time!"
594 echo "Starting build of $tree.$compiler in process $$ at `date`"
597 tdb | talloc | ldb | libreplace)
598 builddir="$test_root/tmp.$tree.$compiler"
600 if [ -d $builddir ]; then
613 if [ ! x$USER = x"" ]; then
616 if [ ! x$LOGNAME = x"" ]; then
623 prefix="$test_root/prefix/$tree.$compiler"
626 s4selftest=$test_root/s4selftest
633 sw_config="$config --enable-socket-wrapper"
636 sw_config="$config --enable-socket-wrapper"
637 sw_config="$sw_config --enable-nss-wrapper"
640 sw_config="$config --enable-socket-wrapper"
641 sw_config="$sw_config --enable-nss-wrapper"
642 s4selftest_update "$tree" "$compiler" && {
643 t="$s4selftest.$tree.$compiler/source"
644 #sw_config="$sw_config --with-samba4srcdir=$t"
645 t="$t/bin/smbtorture"
646 sw_config="$sw_config --with-smbtorture4-path=$t"
650 PKG_CONFIG_PATH="$test_root/prefix/samba4.$compiler/lib/pkgconfig"
651 export PKG_CONFIG_PATH
657 fetch_tree libreplace
664 if [ "$LCOV_REPORT" = "yes" ]; then
665 GCOV_FLAGS="-ftest-coverage -fprofile-arcs"
667 HOSTCC_CFLAGS="$HOSTCC_CFLAGS $GCOV_FLAGS"
668 CFLAGS="$CFLAGS $GCOV_FLAGS"
669 LDFLAGS="$LDFLAGS $GCOV_FLAGS $GCOV_LIBS"
670 SHLD_FLAGS="$SHLD_FLAGS $GCOV_FLAGS $GCOV_LIBS"
671 BNLD_FLAGS="$BNLD_FLAGS $GCOV_FLAGS $GCOV_LIBS"
672 MDLD_FLAGS="$MDLD_FLAGS $GCOV_FLAGS $GCOV_LIBS"
673 HOSTLD_FLAGS="$HOSTLD_FLAGS $GCOV_FLAGS $GCOV_LIBS"
674 export HOSTCC_CFLAGS CFLAGS LDFLAGS SHLD_FLAGS MDLD_FLAGS BNLD_FLAGS HOSTLD_FLAGS
677 config_and_prefix="$sw_config --prefix=$prefix"
679 # see if we need to rebuild
680 sum_tree $test_root $tree $sum $scm
681 echo "CFLAGS=$CFLAGS $config_and_prefix" >> $sum
683 if cmp "$sum" "$sum.old" > /dev/null; then
684 echo "skip: $tree.$compiler nothing changed"
686 send_logs_skip "$log" "$err"
688 echo "Ending build of $tree.$compiler in process $$ at `date`"
692 # we do need to rebuild - save the old sum
698 if [ "$actions" = "" ]; then
699 actions="configure config_log build install test"
704 # we all want to be able to read the output...
711 echo "build_test : $build_test_id"
712 echo "build_test.fns : $build_test_fns_id"
713 echo "local settings file : $build_test_settings_local_file"
714 echo "local functions file: $build_test_fns_local_file"
715 echo "used .fns file : $build_test_used_fns_file"
718 # we need to be able to see if a build farm machine is accumulating
719 # stuck processes. We do this in two ways, as we don't know what style
722 ps -fu $USER 2> /dev/null
724 echo "building $tree with CC=$compiler on $host at "`date`
725 echo "builddir=$builddir"
726 echo "prefix=$prefix"
728 echo "Showing limits"
729 ulimit -a 2> /dev/null
731 # build the timelimit utility
732 echo "Building timelimit"
734 $compiler $TIMELIMIT_FLAGS -o $builddir/timelimit $test_root/timelimit.c || exit 1
736 # the following is for non-samba builds only
737 if [ -r $test_root/$tree.svn ]; then
738 h_rev=`grep 'Revision: ' $test_root/$tree.svn | cut -d ':' -f2 | cut -d ' ' -f2 | sed 1q`
739 if [ -n "$h_rev" ]; then
740 echo "HIGHEST SVN REVISION: $h_rev"
742 rev=`grep 'Last Changed Rev: ' $test_root/$tree.svn | cut -d ':' -f2 | cut -d ' ' -f2 | sed 1q`
743 if [ -n "$rev" ]; then
744 echo "BUILD REVISION: $rev"
746 elif [ -r $test_root/$tree.git ]; then
747 csha1=`cat $test_root/$tree.git |head -3 | tail -1`
748 if [ -n "$csha1" ]; then
749 echo "BUILD COMMIT REVISION: $csha1"
751 cdate=`cat $test_root/$tree.git |head -4 | tail -1`
752 if [ -n "$cdate" ]; then
753 echo "BUILD COMMIT DATE: $cdate"
755 ctime=`cat $test_root/$tree.git |head -2 | tail -1`
756 if [ -n "$ctime" ]; then
757 echo "BUILD COMMIT TIME: $ctime"
761 if [ "$tree" = "pidl" ]
764 perl ./Makefile.PL "$prefix"
767 for action in $actions; do
769 echo Running action $action
773 cd $builddir || exit 1
782 if [ $action_status != 0 ]; then
783 echo "ACTION FAILED: $action";
785 echo "ACTION PASSED: $action";
788 if [ $action_status != 0 ]; then
794 if [ "$LCOV_REPORT" = "yes" ]; then
797 lcov --directory $builddir --capture --output-file $builddir/$tree.lcov.info
800 # ugly hack for s4, as lcov is otherwise not able to find
802 rm -f heimdal/lib/*/{lex,parse}.{gcda,gcno}
803 lcov --base-directory $builddir --directory $builddir --capture --output-file $builddir/$tree.lcov.info
806 genhtml -o $builddir/coverage $builddir/$tree.lcov.info
809 if [ "$noclean" = "yes" ]; then
810 echo cleanup skipped!
818 if [ "$LCOV_REPORT" = "yes" ]; then
819 chmod u=rwX,g=rX,o=rX -R $builddir/coverage
820 rsync -rct -q --password-file=.password -z --timeout=200 \
821 $builddir/coverage/ $host@build.samba.org::lcov_data/$host/$tree/
827 if [ "$usingtmpbuild" = "1" ]; then
828 if [ "$noclean" = "yes" ]; then
829 echo builddir cleanup skipped!
831 /bin/rm -rf $builddir
834 # send the logs to the master site
835 send_logs "$log" "$err"
838 echo "Ending build of $tree.$compiler in process $$ at `date`"
842 #########################################################
843 # if you want to build only one project at a time
844 # add 'global_lock' after 'per_run_hook' and
845 # 'global_unlock' to the end of the file
847 lock_file "global.lck" || {
852 unlock_file "global.lck"
855 #########################################################
856 # enable this on a per host basis only when needed please
857 # (at least for the moment)
858 kill_old_processes() {
859 # this should work on systems with linux like ps
860 (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
861 # and this should work on sysv style ps
862 (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
865 delete_old_svn_tree() {
868 test -z "$otree" && return 0;
873 rm -rf s4selftest.$otree.*
874 rm -rf build.$otree.*
877 # this is a special fn that allows us to add a "special" hook to the build
878 # farm that we want to do to the build farm. never leave it empty. instead,
879 # use ":" as the fn body.
881 # kill old processes on systems with a known problem
884 echo "just a placeholder";
893 # trim the log if too large
894 if [ "`wc -c < build.log`" -gt 2000000 ]; then
898 delete_old_svn_tree "samba_3_2"
902 ######################################################
903 # main code that is run on each call to the build code
904 rsync --timeout=200 -q -az build.samba.org::build_farm/*.c .
907 # build.log can grow to an excessive size, trim it beyond 50M
908 if [ -f build.log ]; then
909 find build.log -size +100000 -exec /bin/rm '{}' \;