1 #!/bin/sh -*- mode: shell-script; -*-
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
10 MAXTIME=25200 # 7 hours
11 SMBD_MAXTIME=18000 # 5 hours for a samba process ..
12 # default maximum memory size (100M) for any command
14 RUN_FROM_BUILD_FARM=yes
15 export RUN_FROM_BUILD_FARM
16 export MAXTIME SMBD_MAXTIME
20 build_test_fns_id='$Id$'
26 echo rsync -a --delete $Tsrc/ $Tdst
27 rsync -a --delete $Tsrc/ $Tdst || return 1
31 #############################
32 # build a signature of a tree, used to see if we
34 #############################
41 find $sum_tree_test_root/$sum_tree_tree -type f -print | grep -v version.h | sort | xargs sum > $sum_tree_sum
42 sum build_test build_test.fns >> $sum_tree_sum
44 if [ -f "$host.fns" ]; then
45 sum $host.fns >> $sum_tree_sum
47 sum generic.fns >> $sum_tree_sum
50 if [ -f "$test_root/$tree.$scm" ]; then
51 sum "$test_root/$tree.$scm" >> $sum_tree_sum
54 for d in $deptrees; do
55 dscm=`choose_scm "$d"`
56 if [ -f "$test_root/$d.$dscm" ]; then
57 sum "$test_root/$d.$dscm" >> $sum_tree_sum
62 #############################
63 # send the logs to the master site
64 #############################
67 if [ "$nologreturn" = "yes" ]; then
68 echo "skipping log transfer"
74 chmod 0644 "$log" "$err"
76 # xargs -i is implemented differently or not at all.
77 # GNU xargs did not implement "-I" until 4.2.9:
78 xargs --version 2>&1 | grep "^GNU xargs" > /dev/null
80 if [ x"$status" = x"0" ]; then
84 if [ x"$XARGS_IS_GNU" = x"yes" ]; then
87 XARGS_I="xargs -I '{}'"
90 find $log -size +40000 | $XARGS_I sh -c 'dd if={} bs=1024 count=20000 of={}.tmp && mv {}.tmp {} && echo "\n***LOG TRUNCATED***" >> {}'
91 find $err -size +40000 | $XARGS_I sh -c 'dd if={} bs=1024 count=20000 of={}.tmp && mv {}.tmp {} && echo "\n***LOG TRUNCATED***" >> {}'
93 rsync $* -c -q --password-file=.password -z --timeout=200 \
94 "$log" "$err" $host@build.samba.org::build_farm_data/
98 #############################
99 # send the logs when they haven't changed
100 # the aim is to just update the servers timestamp.
101 # sending with a very large rsync block size does this
102 # with minimal network traffic
103 #############################
107 send_logs "$1" "$2" -B 10000000
110 ############################
111 # fetch the latest copy of the tree
112 ############################
115 if [ "$norsync" = "yes" ]; then
116 echo "skipping tree transfer"
119 if rsync --exclude=autom4te.cache/ --exclude=.svn/ --exclude=.git/ \
120 --delete-excluded -q --partial --timeout=200 -ctrlpz --delete --ignore-errors \
121 samba.org::ftp/unpacked/$fetchtree/ $test_root/$fetchtree; then
122 echo "transferred $fetchtree OK"
124 echo "transfer of $fetchtree failed code $?"
131 ############################
132 # fetch the latest copy of the rev meta info
133 ############################
139 test -z "$scm" && return 1
140 test x"$scm" = x"unknown" && return 1
141 test x"$scm" = x"cvs" && return 1
143 if [ "$norsync" = "yes" ]; then
144 echo "skipping .revinfo.$scm transfer"
146 if [ -r $test_root/$tree.$scm ]; then
147 [ -f $test_root/$tree.$scm.old ] && rm -f $test_root/$tree.$scm.old
148 [ -f $test_root/$tree.$scm ] && mv $test_root/$tree.$scm $test_root/$tree.$scm.old
150 rsync -q --timeout=200 -clz --ignore-errors \
151 samba.org::ftp/unpacked/$tree/.revinfo.$scm $test_root/$tree.$scm
153 if [ -r $test_root/$tree.$scm ]; then
159 ############################
160 # choose the scm that is used for the given project
161 ############################
167 samba* | rsync | libreplace | talloc | tdb | ldb | pidl | ccache* | waf*)
179 ############################
180 # grab a lock file. Not atomic, but close :)
181 # tries to cope with NFS
182 ############################
185 if [ -z "$lock_root" ]; then
190 machine=`cat "$lckf" 2> /dev/null | cut -d: -f1`
191 pid=`cat "$lckf" 2> /dev/null | cut -d: -f2`
193 if [ "$pid" = "$$" ]; then
194 locknesting=`expr $locknesting + 1`
195 echo "lock nesting now $locknesting"
199 if test -f "$lckf"; then
200 test x$machine = x$host || {
201 echo "lock file $lckf is valid for other machine $machine"
206 echo "lock file $lckf is valid for process $pid"
210 echo "stale lock file $lckf for $machine:$pid"
214 echo "$host:$$" > "$lckf"
218 ############################
220 ############################
223 if [ -z "$lock_root" ]; then
226 if [ "$locknesting" != "0" ]; then
227 locknesting=`expr $locknesting - 1`
228 echo "lock nesting now $locknesting"
235 ############################
236 # run make, and print trace
237 ############################
240 # work out correct make command
247 if [ x"$MAKECOMMAND" = x ]; then
254 # some trees don't need as much time
256 rsync | tdb | talloc | libreplace | ccache* | waf*)
257 if [ "$compiler" != "checker" ]; then
258 MMTIME=`expr $MMTIME / 5`
263 # special build for some trees
266 ./waf distclean && ./waf configure build
272 if [ x"$BUILD_FARM_NUM_JOBS" = x ]; then
273 echo "$MAKECOMMAND $t"
274 $builddir/timelimit $MMTIME "$MAKECOMMAND" "$t"
277 # we can parallelize everything and all targets
278 if [ x"$t" = xeverything ] || [ x"$t" = xall]; then
279 echo "$MAKECOMMAND" "-j$BUILD_FARM_NUM_JOBS" "$t"
280 $builddir/timelimit $MMTIME "$MAKECOMMAND" "-j$BUILD_FARM_NUM_JOBS" "$t"
283 echo "$MAKECOMMAND $t"
284 $builddir/timelimit $MMTIME "$MAKECOMMAND" "$t"
289 if [ $status != 0 ]; then
291 test|check|installcheck)
294 #run again with V=1, so we see failed commands
295 $builddir/timelimit $MMTIME "$MAKECOMMAND" "$t" V=1
301 if [ $status != 0 ]; then
311 ############################
312 # do the coverage report
313 ############################
315 action_lcovreport() {
316 if [ "$LCOV_REPORT" = "yes" ]; then
319 lcov --directory $builddir --capture --output-file $builddir/$tree.lcov.info
322 lcov --base-directory $builddir --directory $builddir/.. --capture --output-file $builddir/$tree.lcov.info
325 # rm -f heimdal/lib/*/{lex,parse,sel-lex}.{gcda,gcno}
326 lcov --base-directory $builddir --directory $builddir/.. --capture --output-file $builddir/$tree.lcov.info
329 lcov --base-directory $builddir --directory $builddir --capture --output-file $builddir/$tree.lcov.info
332 genhtml -o $builddir/coverage $builddir/$tree.lcov.info
334 echo "return code: $rc"
336 echo "LCOV_REPORT not set and lcovreport asked"
337 echo "Most probably an error please fix !"
343 ############################
345 ############################
348 # special handling for some trees
351 $builddir/timelimit $MAXTIME ./waf configure
353 echo "CONFIGURE STATUS: $cstatus"
358 if [ ! -x $srcdir/configure -a -r $srcdir/Makefile.PL ]; then
359 perl $srcdir/Makefile.PL PREFIX="$prefix"
361 echo "CONFIGURE STATUS: $cstatus"
365 if [ ! -x $srcdir/configure ]; then
366 ls -l $srcdir/configure
367 echo "$srcdir/configure is missing"
369 echo "CONFIGURE STATUS: $cstatus"
373 echo "CFLAGS=$CFLAGS"
374 echo configure options: $config_and_prefix
375 echo CC="$CCACHE $compiler" $srcdir/configure $config_and_prefix
377 CC="$CCACHE $compiler"
379 $builddir/timelimit $MAXTIME $srcdir/configure $config_and_prefix
382 if [ x"$cstatus" != x"0" ]; then
383 if [ -f config.log ]; then
384 echo "contents of config.log:"
389 if [ -f bin/config.log ]; then
390 echo "contents of config.log:"
394 echo "CONFIGURE STATUS: $cstatus"
398 ############################
399 # show the configure log
400 ############################
402 action_config_log() {
404 log_files="config.log bin/config.log"
405 for f in $log_files; do
407 echo "contents of config.log:"
415 ############################
417 ############################
419 action_config_header() {
420 hdr_files="config.h include/config.h include/autoconf/config.h bin/default/config.h bin/default/include/config.h bin/default/source3/include/config.h"
421 for h in $hdr_files; do
423 echo "contents of $h:"
434 ############################
436 ############################
444 do_make everything torture
457 echo "BUILD STATUS: $bstatus"
462 ############################
463 # show static analysis results
464 ############################
466 action_cc_checker() {
468 # default to passing the cc_checker
471 if [ -f ibm_checker.out ]; then
473 cccstatus=`cat ibm_checker.out | grep '^\-\- ' | wc -l`
476 echo "CC_CHECKER STATUS: $cccstatus"
480 ############################
482 ############################
485 if [ -d $prefix ]; then
486 if [ "$noclean" != "yes" ]; then
493 echo "INSTALL STATUS: $istatus"
497 ############################
499 action_test_samba() {
503 # if we produced a test summary then show it
504 [ -f st/summary ] && {
509 return "$totalstatus"
512 action_test_generic() {
517 echo "TEST STATUS: $totalstatus"
518 return "$totalstatus"
521 action_test_lorikeet_heimdal() {
524 SOCKET_WRAPPER_DIR=`pwd`/sw
525 mkdir $SOCKET_WRAPPER_DIR
526 export SOCKET_WRAPPER_DIR
530 export SOCKET_WRAPPER_DIR
531 echo "TEST STATUS: $totalstatus"
532 return "$totalstatus"
536 #############################
537 # attempt some basic tests of functionaility
538 # starting as basic as possible, and getting incresingly complex
539 #############################
542 # Samba needs crufty code of its own for backward
543 # compatiblity. I think a better way to do this in the future
544 # is to just call 'make installcheck'.
546 samba*|smb-build|pidl)
550 action_test_lorikeet_heimdal
558 ###########################
559 # do a test build of a particular tree
560 # This is the master function called by generic.fns or
562 ###########################
571 echo "Starting to deal with tree $tree with compiler $compiler"
572 if [ "$compiler" = "gcc" ] && [ "$tree" != "ccache" ] && [ "$tree" != "ccache-maint" ] && ccache -V > /dev/null 2>/dev/null; then
579 # limit our resource usage
580 ulimit -t $MAXTIME 2> /dev/null
583 ulimit -m $MAXMEM 2> /dev/null
586 # darn, this affects sparse files too! disable it
587 # ulimit -f 100000 2> /dev/null
589 # try and limit the number of open files to 250. That means we'll discover
591 ulimit -n 250 2> /dev/null
596 if [ -z "$test_root" ]; then
600 log="build.$tree.$host.$compiler.log"
601 err="build.$tree.$host.$compiler.err"
602 sum="build.$tree.$host.$compiler.sum"
603 lck="build.$tree.lck"
604 srcdir="$test_root/$tree/$source"
606 lock_file "$lck" || {
610 # work out what other trees this package depends on
614 deptrees="samba_4_0_test"
618 scm=`choose_scm "$tree"`
620 # pull the entries, if any
621 # Remove old .svn or .git files
622 # Move the current .svn org .git to .svn.old or
623 # .git.old then fetch the new from rsync
624 if fetch_revinfo "$tree" "$scm"; then
625 for d in $deptrees; do
626 # If there is dependency substree(s) we add info
627 # from the dependency tree so that we
628 # can rebuild in case one of them has changed
629 dscm=`choose_scm "$d"`
630 if [ -f "$test_root/$d.$dscm" ]; then
631 if [ "$d" != "$tree" ]; then
632 cat "$test_root/$d.$dscm" >> $test_root/$tree.$scm
636 [ -f $test_root/$tree.$compiler.$scm.old ] && rm -f $test_root/$tree.$compiler.$scm.old
637 [ -f $test_root/$tree.$compiler.$scm ] && mv $test_root/$tree.$compiler.$scm $test_root/$tree.$compiler.$scm.old
638 [ -f $test_root/$tree.$scm ] && cp $test_root/$tree.$scm $test_root/$tree.$compiler.$scm
640 if [ -f $test_root/$tree.$compiler.$scm.old ] && \
641 cmp $test_root/$tree.$compiler.$scm $test_root/$tree.$compiler.$scm.old > /dev/null; then
643 echo "skip: $tree.$compiler nothing changed in $scm"
645 send_logs_skip "$log" "$err"
652 fetch_tree "$tree" || {
658 # check for essential files
664 if [ ! -x $srcdir/waf ]; then
665 echo "skip: $tree.$compiler waf not present, try again next time!"
672 if [ ! -x $srcdir/configure ]; then
673 echo "skip: $tree.$compiler configure not present, try again next time!"
681 echo "Starting build of $tree.$compiler in process $$ at `date`"
684 # Parameters for the build depending on the tree
693 if [ ! x$USER = x"" ]; then
696 if [ ! x$LOGNAME = x"" ]; then
703 # build the timelimit utility
704 echo "Building timelimit"
706 echo $compiler $TIMELIMIT_FLAGS -o $builddir/timelimit $test_root/timelimit.c
707 $compiler $TIMELIMIT_FLAGS -o $builddir/timelimit $test_root/timelimit.c || exit 1
709 # build the killbysubdir utility
710 echo "Building killbysubdir"
711 echo $compiler -o $builddir/killbysubdir $test_root/killbysubdir.c
712 $compiler -o $builddir/killbysubdir $test_root/killbysubdir.c
714 prefix="$test_root/prefix/$tree.$compiler"
717 # This can be defined in <host>.fns files
722 sw_config="$config --enable-socket-wrapper"
725 sw_config="$config --enable-socket-wrapper"
726 sw_config="$sw_config --enable-nss-wrapper"
727 sw_config="$sw_config --enable-uid-wrapper"
730 sw_config="$config --enable-socket-wrapper"
731 sw_config="$sw_config --enable-nss-wrapper"
734 PKG_CONFIG_PATH="$test_root/prefix/samba_4_0_test.$compiler/lib/pkgconfig"
735 export PKG_CONFIG_PATH
742 if [ "$LCOV_REPORT" = "yes" ]; then
743 GCOV_FLAGS="--coverage"
744 CFLAGS="$CFLAGS $GCOV_FLAGS"
745 LDFLAGS="$LDFLAGS $GCOV_FLAGS"
746 export CFLAGS LDFLAGS
749 config_and_prefix="$sw_config --prefix=$prefix"
751 # see if we need to rebuild
752 sum_tree $test_root $tree $sum $scm
753 echo "CFLAGS=$CFLAGS $config_and_prefix" >> $sum
755 if [ -f "$sum.old" ] && cmp "$sum" "$sum.old" > /dev/null; then
756 echo "skip: $tree.$compiler nothing changed"
758 send_logs_skip "$log" "$err"
760 echo "Ending build of $tree.$compiler in process $$ at `date`"
764 # we do need to rebuild - save the old sum
765 [ -f $sum.old ] && /bin/rm -f $sum.old
768 #Action == what to do ie. configure config_log ...
771 if [ "$actions" = "" ]; then
772 actions="configure config_log config_header build install test"
778 # we all want to be able to read the output...
785 echo "build_test : $build_test_id"
786 echo "build_test.fns : $build_test_fns_id"
787 echo "local settings file : $build_test_settings_local_file"
788 echo "local functions file: $build_test_fns_local_file"
789 echo "used .fns file : $build_test_used_fns_file"
792 # we need to be able to see if a build farm machine is accumulating
793 # stuck processes. We do this in two ways, as we don't know what style
796 ps -fu $USER 2> /dev/null
798 echo "building $tree with CC=$compiler on $host at "`date`
799 echo "builddir=$builddir"
800 echo "prefix=$prefix"
802 echo "Showing limits"
803 ulimit -a 2> /dev/null
805 # the following is for non-samba builds only
806 if [ "$scm" = "svn" -a -r $test_root/$tree.svn ]; then
807 h_rev=`grep 'Revision: ' $test_root/$tree.svn | cut -d ':' -f2 | cut -d ' ' -f2 | sed 1q`
808 if [ -n "$h_rev" ]; then
809 echo "HIGHEST SVN REVISION: $h_rev"
811 rev=`grep 'Last Changed Rev: ' $test_root/$tree.svn | cut -d ':' -f2 | cut -d ' ' -f2 | sed 1q`
812 if [ -n "$rev" ]; then
813 echo "BUILD REVISION: $rev"
815 elif [ "$scm" = "git" -a -r $test_root/$tree.git ]; then
816 csha1=`cat $test_root/$tree.git |head -3 | tail -1`
817 if [ -n "$csha1" ]; then
818 echo "BUILD COMMIT REVISION: $csha1"
820 cdate=`cat $test_root/$tree.git |head -4 | tail -1`
821 if [ -n "$cdate" ]; then
822 echo "BUILD COMMIT DATE: $cdate"
824 ctime=`cat $test_root/$tree.git |head -2 | tail -1`
825 if [ -n "$ctime" ]; then
826 echo "BUILD COMMIT TIME: $ctime"
830 if [ -x $builddir/killbysubdir ]; then
831 echo "$builddir/killbysubdir $builddir in `pwd`"
832 $builddir/killbysubdir $builddir
835 for action in $actions; do
837 echo Running action $action
841 cd $builddir || exit 1
847 if [ "x$PREHOOKS" != "x" ]; then
848 for hooks in $PREHOOKS; do
849 if [ "x$hooks" = "x$action" ]; then
858 if [ "x$POSTHOOKS" != "x" ]; then
859 for hooks in $POSTHOOKS; do
860 if [ "x$hooks" = "x$action" ]; then
868 if [ $action_status != 0 ]; then
869 echo "ACTION FAILED: $action";
870 echo " return code $action_status $action";
872 echo "ACTION PASSED: $action";
875 if [ $action_status != 0 ]; then
881 if [ "$noclean" = "yes" ]; then
882 echo cleanup skipped!
888 } 3>&2 2>&1 1>&3 | tee "$err"
890 # be aware the above channel swap may sometimes result in unordered
891 # stdout/stderr merge
893 if [ "$LCOV_REPORT" = "yes" ]; then
894 chmod u=rwX,g=rX,o=rX -R $builddir/coverage
895 rsync -rct -q --password-file=.password -z --timeout=200 \
896 $builddir/coverage/ $host@build.samba.org::lcov_data/$host/$tree/
902 # send the logs to the master site
903 send_logs "$log" "$err"
906 echo "Ending build of $tree.$compiler in process $$ at `date`"
910 #########################################################
911 # if you want to build only one project at a time
912 # add 'global_lock' after 'per_run_hook' and
913 # 'global_unlock' to the end of the file
914 #########################################################
917 lock_file "global.lck" || {
923 unlock_file "global.lck"
928 test -z "$otree" && return 0;
935 rm -rf build.$otree.*
938 # this is a special fn that allows us to add a "special" hook to the build
939 # farm that we want to do to the build farm. never leave it empty. instead,
940 # use ":" as the fn body.
942 # kill old processes on systems with a known problem
945 echo "just a placeholder";
952 # trim the log if too large
953 if [ "`wc -c < build.log`" -gt 2000000 ]; then
957 old_trees="web popt distcc samba-gtk smb-build lorikeet-heimdal samba_3_2"
958 old_trees="$old_tree samba_3_2_test samba4 samba_4_0_waf samba_4_0_waf.metze"
959 old_trees="$old_tree samba_3_X_test samba_3_X_devel samba_3_X_devel samba_3_waf"
960 for d in $old_trees; do
966 ######################################################
967 # main code that is run on each call to the build code
968 ######################################################
969 rsync --timeout=200 -q -az build.samba.org::build_farm/*.c .
972 # build.log can grow to an excessive size, trim it beyond 50M
973 if [ -f build.log ]; then
974 find build.log -size +100000 -exec /bin/rm '{}' \;