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 [ x"$status" = x"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 $* -c -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 -ctrlpz --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
144 samba* | rsync | libreplace | talloc | tdb | ldb | pidl | ccache*)
156 ############################
157 # grab a lock file. Not atomic, but close :)
158 # tries to cope with NFS
160 if [ -z "$lock_root" ]; then
164 machine=`cat "$lckf" 2> /dev/null | cut -d: -f1`
165 pid=`cat "$lckf" 2> /dev/null | cut -d: -f2`
167 if [ "$pid" = "$$" ]; then
168 locknesting=`expr $locknesting + 1`
169 echo "lock nesting now $locknesting"
173 if test -f "$lckf"; then
174 test $machine = $host || {
175 echo "lock file $lckf is valid for other machine $machine"
179 echo "lock file $lckf is valid for process $pid"
182 echo "stale lock file $lckf for $machine:$pid"
186 echo "$host:$$" > "$lckf"
190 ############################
193 if [ -z "$lock_root" ]; then
196 if [ "$locknesting" != "0" ]; then
197 locknesting=`expr $locknesting - 1`
198 echo "lock nesting now $locknesting"
205 ############################
206 # run make, and print trace
215 # some trees don't need as much time
217 rsync | tdb | talloc | libreplace | ccache*)
218 if [ "$compiler" != "checker" ]; then
219 MMTIME=`expr $MMTIME / 5`
226 if [ x"$BUILD_FARM_NUM_JOBS" = x ]; then
228 $builddir/timelimit $MMTIME "$MAKE" "$t"
231 # we can parallelize everything and all targets
232 if [ x"$t" = xeverything ] || [ x"$t" = xall]; then
233 echo "$MAKE" "-j$BUILD_FARM_NUM_JOBS" "$t"
234 $builddir/timelimit $MMTIME "$MAKE" "-j$BUILD_FARM_NUM_JOBS" "$t"
238 $builddir/timelimit $MMTIME "$MAKE" "$t"
243 if [ $status != 0 ]; then
244 # run again with V=1, so we see failed commands
245 $builddir/timelimit $MMTIME "$MAKE" "$t" V=1
249 if [ $status != 0 ]; then
258 ############################
261 if [ ! -x $srcdir/configure -a -r $srcdir/Makefile.PL ]; then
262 perl $srcdir/Makefile.PL PREFIX="$prefix"
264 echo "CONFIGURE STATUS: $cstatus"
267 if [ ! -x $srcdir/configure ]; then
268 ls -l $srcdir/configure
269 echo "$srcdir/configure is missing"
271 echo "CONFIGURE STATUS: $cstatus"
274 echo "CFLAGS=$CFLAGS"
275 echo configure options: $config_and_prefix
276 echo CC="$CCACHE $compiler" $srcdir/configure $config_and_prefix
277 CC="$CCACHE $compiler"
279 $builddir/timelimit $MAXTIME $srcdir/configure $config_and_prefix
281 if [ x"$cstatus" != x"0" ]; then
282 if [ -f config.log ]; then
283 echo "contents of config.log:"
286 if [ -f bin/config.log ]; then
287 echo "contents of config.log:"
291 echo "CONFIGURE STATUS: $cstatus"
295 ############################
296 # show the configure log
297 action_config_log() {
298 log_files="config.log bin/config.log"
299 for f in $log_files; do
301 echo "contents of config.log:"
309 ############################
311 action_config_header() {
312 hdr_files="config.h include/config.h bin/default/config.h bin/default/source4/include/config.h bin/default/source3/include/config.h"
313 for h in $hdr_files; do
315 echo "contents of $h:"
327 echo rsync -a --delete $Tsrc/ $Tdst
328 rsync -a --delete $Tsrc/ $Tdst || return 1
333 ############################
342 do_make everything torture
351 echo "BUILD STATUS: $bstatus"
356 ############################
357 # show static analysis results
358 action_cc_checker() {
360 # default to passing the cc_checker
363 if [ -f ibm_checker.out ]; then
365 cccstatus=`cat ibm_checker.out | grep '^\-\- ' | wc -l`
368 echo "CC_CHECKER STATUS: $cccstatus"
372 ############################
375 if [ -d $prefix ]; then
376 if [ "$noclean" != "yes" ]; then
383 echo "INSTALL STATUS: $istatus"
387 ############################
389 action_test_samba() {
392 # if we produced a test summary then show it
393 [ -f st/summary ] && {
397 return "$totalstatus"
400 action_test_generic() {
405 echo "TEST STATUS: $totalstatus"
406 return "$totalstatus"
409 action_test_lorikeet_heimdal() {
412 SOCKET_WRAPPER_DIR=`pwd`/sw
413 mkdir $SOCKET_WRAPPER_DIR
414 export SOCKET_WRAPPER_DIR
418 export SOCKET_WRAPPER_DIR
419 echo "TEST STATUS: $totalstatus"
420 return "$totalstatus"
424 #############################
425 # attempt some basic tests of functionaility
426 # starting as basic as possible, and getting incresingly complex
429 # Samba needs crufty code of its own for backward
430 # compatiblity. I think a better way to do this in the future
431 # is to just call 'make installcheck'.
433 samba*|smb-build|pidl)
437 action_test_lorikeet_heimdal
445 ###########################
446 # do a test build of a particular tree
454 if [ "$compiler" = "gcc" ] && [ "$tree" != "ccache" ] && [ "$tree" != "ccache-maint" ] && ccache -V > /dev/null; then
461 # limit our resource usage
462 ulimit -t $MAXTIME 2> /dev/null
465 ulimit -m $MAXMEM 2> /dev/null
468 # darn, this affects sparse files too! disable it
469 # ulimit -f 100000 2> /dev/null
471 # try and limit the number of open files to 250. That means we'll discover
473 ulimit -n 250 2> /dev/null
478 if [ -z "$test_root" ]; then
482 log="build.$tree.$host.$compiler.log"
483 err="build.$tree.$host.$compiler.err"
484 sum="build.$tree.$host.$compiler.sum"
485 lck="build.$tree.lck"
486 srcdir="$test_root/$tree/$source"
488 lock_file "$lck" || {
492 # work out what other trees this package depends on
496 deptrees="samba_4_0_test"
500 scm=`choose_scm "$tree"`
502 # pull the entries, if any
503 if fetch_revinfo "$tree" "$scm"; then
504 for d in $deptrees; do
505 dscm=`choose_scm "$d"`
506 if [ -f "$test_root/$d.$dscm" ]; then
507 if [ "$d" != "$tree" ]; then
508 cat "$test_root/$d.$dscm" >> $test_root/$tree.$scm
512 rm -f $test_root/$tree.$compiler.$scm.old
513 mv $test_root/$tree.$compiler.$scm $test_root/$tree.$compiler.$scm.old
514 cp $test_root/$tree.$scm $test_root/$tree.$compiler.$scm
515 if cmp $test_root/$tree.$compiler.$scm $test_root/$tree.$compiler.$scm.old > /dev/null; then
516 echo "skip: $tree.$compiler nothing changed in $scm"
518 send_logs_skip "$log" "$err"
525 fetch_tree "$tree" || {
531 if [ ! -x $srcdir/configure ] && [ "$tree" != "pidl" ]; then
532 echo "skip: $tree.$compiler configure not present, try again next time!"
538 echo "Starting build of $tree.$compiler in process $$ at `date`"
542 builddir="$test_root/tmp.$tree.$compiler"
544 if [ -d $builddir ]; then
557 if [ ! x$USER = x"" ]; then
560 if [ ! x$LOGNAME = x"" ]; then
567 # build the timelimit utility
568 echo "Building timelimit"
570 echo $compiler $TIMELIMIT_FLAGS -o $builddir/timelimit $test_root/timelimit.c
571 $compiler $TIMELIMIT_FLAGS -o $builddir/timelimit $test_root/timelimit.c || exit 1
573 # build the killbysubdir utility
574 echo "Building killbysubdir"
575 echo $compiler -o $builddir/killbysubdir $test_root/killbysubdir.c
576 $compiler -o $builddir/killbysubdir $test_root/killbysubdir.c
578 prefix="$test_root/prefix/$tree.$compiler"
585 sw_config="$config --enable-socket-wrapper"
588 sw_config="$config --enable-socket-wrapper"
589 sw_config="$sw_config --enable-nss-wrapper"
590 sw_config="$sw_config --enable-uid-wrapper"
593 sw_config="$config --enable-socket-wrapper"
594 sw_config="$sw_config --enable-nss-wrapper"
597 PKG_CONFIG_PATH="$test_root/prefix/samba_4_0_test.$compiler/lib/pkgconfig"
598 export PKG_CONFIG_PATH
605 if [ "$LCOV_REPORT" = "yes" ]; then
606 GCOV_FLAGS="--coverage"
607 CFLAGS="$CFLAGS $GCOV_FLAGS"
608 LDFLAGS="$LDFLAGS $GCOV_FLAGS"
609 export CFLAGS LDFLAGS
612 config_and_prefix="$sw_config --prefix=$prefix"
614 # see if we need to rebuild
615 sum_tree $test_root $tree $sum $scm
616 echo "CFLAGS=$CFLAGS $config_and_prefix" >> $sum
618 if cmp "$sum" "$sum.old" > /dev/null; then
619 echo "skip: $tree.$compiler nothing changed"
621 send_logs_skip "$log" "$err"
623 echo "Ending build of $tree.$compiler in process $$ at `date`"
627 # we do need to rebuild - save the old sum
633 if [ "$actions" = "" ]; then
634 actions="configure config_log config_header build install test"
640 # we all want to be able to read the output...
647 echo "build_test : $build_test_id"
648 echo "build_test.fns : $build_test_fns_id"
649 echo "local settings file : $build_test_settings_local_file"
650 echo "local functions file: $build_test_fns_local_file"
651 echo "used .fns file : $build_test_used_fns_file"
654 # we need to be able to see if a build farm machine is accumulating
655 # stuck processes. We do this in two ways, as we don't know what style
658 ps -fu $USER 2> /dev/null
660 echo "building $tree with CC=$compiler on $host at "`date`
661 echo "builddir=$builddir"
662 echo "prefix=$prefix"
664 echo "Showing limits"
665 ulimit -a 2> /dev/null
667 # the following is for non-samba builds only
668 if [ "$scm" = "svn" -a -r $test_root/$tree.svn ]; then
669 h_rev=`grep 'Revision: ' $test_root/$tree.svn | cut -d ':' -f2 | cut -d ' ' -f2 | sed 1q`
670 if [ -n "$h_rev" ]; then
671 echo "HIGHEST SVN REVISION: $h_rev"
673 rev=`grep 'Last Changed Rev: ' $test_root/$tree.svn | cut -d ':' -f2 | cut -d ' ' -f2 | sed 1q`
674 if [ -n "$rev" ]; then
675 echo "BUILD REVISION: $rev"
677 elif [ "$scm" = "git" -a -r $test_root/$tree.git ]; then
678 csha1=`cat $test_root/$tree.git |head -3 | tail -1`
679 if [ -n "$csha1" ]; then
680 echo "BUILD COMMIT REVISION: $csha1"
682 cdate=`cat $test_root/$tree.git |head -4 | tail -1`
683 if [ -n "$cdate" ]; then
684 echo "BUILD COMMIT DATE: $cdate"
686 ctime=`cat $test_root/$tree.git |head -2 | tail -1`
687 if [ -n "$ctime" ]; then
688 echo "BUILD COMMIT TIME: $ctime"
692 if [ -x $builddir/killbysubdir ]; then
693 echo "$builddir/killbysubdir $builddir in `pwd`"
694 $builddir/killbysubdir $builddir
697 for action in $actions; do
699 echo Running action $action
703 cd $builddir || exit 1
714 if [ $action_status != 0 ]; then
715 echo "ACTION FAILED: $action";
717 echo "ACTION PASSED: $action";
720 if [ $action_status != 0 ]; then
726 if [ "$LCOV_REPORT" = "yes" ]; then
729 lcov --directory $builddir --capture --output-file $builddir/$tree.lcov.info
732 lcov --base-directory $builddir --directory $builddir/.. --capture --output-file $builddir/$tree.lcov.info
735 # ugly hack for s4, as lcov is otherwise not able to find
737 rm -f heimdal/lib/*/{lex,parse,sel-lex}.{gcda,gcno}
738 lcov --base-directory $builddir --directory $builddir/.. --capture --output-file $builddir/$tree.lcov.info
741 lcov --base-directory $builddir --directory $builddir --capture --output-file $builddir/$tree.lcov.info
744 genhtml -o $builddir/coverage $builddir/$tree.lcov.info
747 if [ "$noclean" = "yes" ]; then
748 echo cleanup skipped!
754 } 3>&2 2>&1 1>&3 | tee "$err"
756 # be aware the above channel swap may sometimes result in unordered
757 # stdout/stderr merge
759 if [ "$LCOV_REPORT" = "yes" ]; then
760 chmod u=rwX,g=rX,o=rX -R $builddir/coverage
761 rsync -rct -q --password-file=.password -z --timeout=200 \
762 $builddir/coverage/ $host@build.samba.org::lcov_data/$host/$tree/
768 if [ "$usingtmpbuild" = "1" ]; then
769 if [ "$noclean" = "yes" ]; then
770 echo builddir cleanup skipped!
772 /bin/rm -rf $builddir
775 # send the logs to the master site
776 send_logs "$log" "$err"
779 echo "Ending build of $tree.$compiler in process $$ at `date`"
783 #########################################################
784 # if you want to build only one project at a time
785 # add 'global_lock' after 'per_run_hook' and
786 # 'global_unlock' to the end of the file
788 lock_file "global.lck" || {
793 unlock_file "global.lck"
799 test -z "$otree" && return 0;
806 rm -rf build.$otree.*
809 # this is a special fn that allows us to add a "special" hook to the build
810 # farm that we want to do to the build farm. never leave it empty. instead,
811 # use ":" as the fn body.
813 # kill old processes on systems with a known problem
816 echo "just a placeholder";
822 # trim the log if too large
823 if [ "`wc -c < build.log`" -gt 2000000 ]; then
827 old_trees="samba_3_2 samba_3_2_test samba4 samba_4_0_waf samba_3_X_test samba_3_X_devel samba_3_X_devel"
828 for d in old_trees; do
834 ######################################################
835 # main code that is run on each call to the build code
836 rsync --timeout=200 -q -az build.samba.org::build_farm/*.c .
839 # build.log can grow to an excessive size, trim it beyond 50M
840 if [ -f build.log ]; then
841 find build.log -size +100000 -exec /bin/rm '{}' \;