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
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$'
24 echo rsync -a --delete $Tsrc/ $Tdst
25 rsync -a --delete $Tsrc/ $Tdst || return 1
29 #############################
30 # build a signature of a tree, used to see if we
32 #############################
39 find $sum_tree_test_root/$sum_tree_tree -type f -print | grep -v version.h | sort | xargs sum > $sum_tree_sum
40 sum build_test build_test.fns >> $sum_tree_sum
42 if [ -f "$host.fns" ]; then
43 sum $host.fns >> $sum_tree_sum
45 sum generic.fns >> $sum_tree_sum
48 if [ -f "$test_root/$tree.$scm" ]; then
49 sum "$test_root/$tree.$scm" >> $sum_tree_sum
52 for d in $deptrees; do
53 dscm=`choose_scm "$d"`
54 if [ -f "$test_root/$d.$dscm" ]; then
55 sum "$test_root/$d.$dscm" >> $sum_tree_sum
60 #############################
61 # send the logs to the master site
62 #############################
65 if [ "$nologreturn" = "yes" ]; then
66 echo "skipping log transfer"
72 chmod 0644 "$log" "$err"
74 # xargs -i is implemented differently or not at all.
75 # GNU xargs did not implement "-I" until 4.2.9:
76 xargs --version 2>&1 | grep "^GNU xargs" > /dev/null
78 if [ x"$status" = x"0" ]; then
82 if [ x"$XARGS_IS_GNU" = x"yes" ]; then
85 XARGS_I="xargs -I '{}'"
88 find $log -size +40000 | $XARGS_I sh -c 'dd if={} bs=1024 count=20000 of={}.tmp && mv {}.tmp {} && echo "\n***LOG TRUNCATED***" >> {}'
89 find $err -size +40000 | $XARGS_I sh -c 'dd if={} bs=1024 count=20000 of={}.tmp && mv {}.tmp {} && echo "\n***LOG TRUNCATED***" >> {}'
91 rsync $* -c -q --password-file=.password -z --timeout=200 \
92 "$log" "$err" $host@build.samba.org::build_farm_data/
96 #############################
97 # send the logs when they haven't changed
98 # the aim is to just update the servers timestamp.
99 # sending with a very large rsync block size does this
100 # with minimal network traffic
101 #############################
105 send_logs "$1" "$2" -B 10000000
108 ############################
109 # fetch the latest copy of the tree
110 ############################
113 if [ "$norsync" = "yes" ]; then
114 echo "skipping tree transfer"
117 if rsync --exclude=autom4te.cache/ --exclude=.svn/ --exclude=.git/ \
118 --delete-excluded -q --partial --timeout=200 -ctrlpz --delete --ignore-errors \
119 samba.org::ftp/unpacked/$fetchtree/ $test_root/$fetchtree; then
120 echo "transferred $fetchtree OK"
122 echo "transfer of $fetchtree failed code $?"
129 ############################
130 # fetch the latest copy of the rev meta info
131 ############################
137 test -z "$scm" && return 1
138 test x"$scm" = x"unknown" && return 1
139 test x"$scm" = x"cvs" && return 1
141 if [ "$norsync" = "yes" ]; then
142 echo "skipping .revinfo.$scm transfer"
144 if [ -r $test_root/$tree.$scm ]; then
145 [ -f $test_root/$tree.$scm.old ] && rm -f $test_root/$tree.$scm.old
146 [ -f $test_root/$tree.$scm ] && mv $test_root/$tree.$scm $test_root/$tree.$scm.old
148 rsync -q --timeout=200 -clz --ignore-errors \
149 samba.org::ftp/unpacked/$tree/.revinfo.$scm $test_root/$tree.$scm
151 if [ -r $test_root/$tree.$scm ]; then
157 ############################
158 # choose the scm that is used for the given project
159 ############################
165 samba* | rsync | libreplace | talloc | tdb | ldb | pidl | ccache*)
177 ############################
178 # grab a lock file. Not atomic, but close :)
179 # tries to cope with NFS
180 ############################
183 if [ -z "$lock_root" ]; then
188 machine=`cat "$lckf" 2> /dev/null | cut -d: -f1`
189 pid=`cat "$lckf" 2> /dev/null | cut -d: -f2`
191 if [ "$pid" = "$$" ]; then
192 locknesting=`expr $locknesting + 1`
193 echo "lock nesting now $locknesting"
197 if test -f "$lckf"; then
198 test $machine = $host || {
199 echo "lock file $lckf is valid for other machine $machine"
204 echo "lock file $lckf is valid for process $pid"
208 echo "stale lock file $lckf for $machine:$pid"
212 echo "$host:$$" > "$lckf"
216 ############################
218 ############################
221 if [ -z "$lock_root" ]; then
224 if [ "$locknesting" != "0" ]; then
225 locknesting=`expr $locknesting - 1`
226 echo "lock nesting now $locknesting"
233 ############################
234 # run make, and print trace
235 ############################
238 if [ x"$MAKE" = x ]; then
243 # some trees don't need as much time
245 rsync | tdb | talloc | libreplace | ccache*)
246 if [ "$compiler" != "checker" ]; then
247 MMTIME=`expr $MMTIME / 5`
254 if [ x"$BUILD_FARM_NUM_JOBS" = x ]; then
256 $builddir/timelimit $MMTIME "$MAKE" "$t"
259 # we can parallelize everything and all targets
260 if [ x"$t" = xeverything ] || [ x"$t" = xall]; then
261 echo "$MAKE" "-j$BUILD_FARM_NUM_JOBS" "$t"
262 $builddir/timelimit $MMTIME "$MAKE" "-j$BUILD_FARM_NUM_JOBS" "$t"
266 $builddir/timelimit $MMTIME "$MAKE" "$t"
271 if [ $status != 0 ]; then
273 test|check|installcheck)
276 #run again with V=1, so we see failed commands
277 $builddir/timelimit $MMTIME "$MAKE" "$t" V=1
283 if [ $status != 0 ]; then
293 ############################
294 # do the coverage report
295 ############################
297 action_lcovreport() {
298 if [ "$LCOV_REPORT" = "yes" ]; then
301 lcov --directory $builddir --capture --output-file $builddir/$tree.lcov.info
304 lcov --base-directory $builddir --directory $builddir/.. --capture --output-file $builddir/$tree.lcov.info
307 # rm -f heimdal/lib/*/{lex,parse,sel-lex}.{gcda,gcno}
308 lcov --base-directory $builddir --directory $builddir/.. --capture --output-file $builddir/$tree.lcov.info
311 lcov --base-directory $builddir --directory $builddir --capture --output-file $builddir/$tree.lcov.info
314 genhtml -o $builddir/coverage $builddir/$tree.lcov.info
316 echo "return code: $rc"
318 echo "LCOV_REPORT not set and lcovreport asked"
319 echo "Most probably an error please fix !"
325 ############################
327 ############################
331 if [ ! -x $srcdir/configure -a -r $srcdir/Makefile.PL ]; then
332 perl $srcdir/Makefile.PL PREFIX="$prefix"
334 echo "CONFIGURE STATUS: $cstatus"
338 if [ ! -x $srcdir/configure ]; then
339 ls -l $srcdir/configure
340 echo "$srcdir/configure is missing"
342 echo "CONFIGURE STATUS: $cstatus"
346 echo "CFLAGS=$CFLAGS"
347 echo configure options: $config_and_prefix
348 echo CC="$CCACHE $compiler" $srcdir/configure $config_and_prefix
350 CC="$CCACHE $compiler"
352 $builddir/timelimit $MAXTIME $srcdir/configure $config_and_prefix
355 if [ x"$cstatus" != x"0" ]; then
356 if [ -f config.log ]; then
357 echo "contents of config.log:"
362 if [ -f bin/config.log ]; then
363 echo "contents of config.log:"
367 echo "CONFIGURE STATUS: $cstatus"
371 ############################
372 # show the configure log
373 ############################
375 action_config_log() {
377 log_files="config.log bin/config.log"
378 for f in $log_files; do
380 echo "contents of config.log:"
388 ############################
390 ############################
392 action_config_header() {
393 hdr_files="config.h include/config.h bin/default/config.h bin/default/source4/include/config.h bin/default/source3/include/config.h"
394 for h in $hdr_files; do
396 echo "contents of $h:"
407 ############################
409 ############################
417 do_make everything torture
426 echo "BUILD STATUS: $bstatus"
431 ############################
432 # show static analysis results
433 ############################
435 action_cc_checker() {
437 # default to passing the cc_checker
440 if [ -f ibm_checker.out ]; then
442 cccstatus=`cat ibm_checker.out | grep '^\-\- ' | wc -l`
445 echo "CC_CHECKER STATUS: $cccstatus"
449 ############################
451 ############################
454 if [ -d $prefix ]; then
455 if [ "$noclean" != "yes" ]; then
462 echo "INSTALL STATUS: $istatus"
466 ############################
468 action_test_samba() {
472 # if we produced a test summary then show it
473 [ -f st/summary ] && {
478 return "$totalstatus"
481 action_test_generic() {
486 echo "TEST STATUS: $totalstatus"
487 return "$totalstatus"
490 action_test_lorikeet_heimdal() {
493 SOCKET_WRAPPER_DIR=`pwd`/sw
494 mkdir $SOCKET_WRAPPER_DIR
495 export SOCKET_WRAPPER_DIR
499 export SOCKET_WRAPPER_DIR
500 echo "TEST STATUS: $totalstatus"
501 return "$totalstatus"
505 #############################
506 # attempt some basic tests of functionaility
507 # starting as basic as possible, and getting incresingly complex
508 #############################
511 # Samba needs crufty code of its own for backward
512 # compatiblity. I think a better way to do this in the future
513 # is to just call 'make installcheck'.
515 samba*|smb-build|pidl)
519 action_test_lorikeet_heimdal
527 ###########################
528 # do a test build of a particular tree
529 # This is the master function called by generic.fns or
531 ###########################
540 echo "Starting to deal with tree $tree with compiler $compiler"
541 if [ "$compiler" = "gcc" ] && [ "$tree" != "ccache" ] && [ "$tree" != "ccache-maint" ] && ccache -V > /dev/null 2>/dev/null; then
548 # limit our resource usage
549 ulimit -t $MAXTIME 2> /dev/null
552 ulimit -m $MAXMEM 2> /dev/null
555 # darn, this affects sparse files too! disable it
556 # ulimit -f 100000 2> /dev/null
558 # try and limit the number of open files to 250. That means we'll discover
560 ulimit -n 250 2> /dev/null
565 if [ -z "$test_root" ]; then
569 log="build.$tree.$host.$compiler.log"
570 err="build.$tree.$host.$compiler.err"
571 sum="build.$tree.$host.$compiler.sum"
572 lck="build.$tree.lck"
573 srcdir="$test_root/$tree/$source"
575 lock_file "$lck" || {
579 # work out what other trees this package depends on
583 deptrees="samba_4_0_test"
587 scm=`choose_scm "$tree"`
589 # pull the entries, if any
590 # Remove old .svn or .git files
591 # Move the current .svn org .git to .svn.old or
592 # .git.old then fetch the new from rsync
593 if fetch_revinfo "$tree" "$scm"; then
594 for d in $deptrees; do
595 # If there is dependency substree(s) we add info
596 # from the dependency tree so that we
597 # can rebuild in case one of them has changed
598 dscm=`choose_scm "$d"`
599 if [ -f "$test_root/$d.$dscm" ]; then
600 if [ "$d" != "$tree" ]; then
601 cat "$test_root/$d.$dscm" >> $test_root/$tree.$scm
605 [ -f $test_root/$tree.$compiler.$scm.old ] && rm -f $test_root/$tree.$compiler.$scm.old
606 [ -f $test_root/$tree.$compiler.$scm ] && mv $test_root/$tree.$compiler.$scm $test_root/$tree.$compiler.$scm.old
607 [ -f $test_root/$tree.$scm ] && cp $test_root/$tree.$scm $test_root/$tree.$compiler.$scm
609 if [ -f $test_root/$tree.$compiler.$scm.old ] && \
610 cmp $test_root/$tree.$compiler.$scm $test_root/$tree.$compiler.$scm.old > /dev/null; then
612 echo "skip: $tree.$compiler nothing changed in $scm"
614 send_logs_skip "$log" "$err"
621 fetch_tree "$tree" || {
627 if [ ! -x $srcdir/configure ] && [ "$tree" != "pidl" ]; then
628 echo "skip: $tree.$compiler configure not present, try again next time!"
634 echo "Starting build of $tree.$compiler in process $$ at `date`"
637 # Parameters for the build depending on the tree
640 builddir="$test_root/tmp.$tree.$compiler"
642 if [ -d $builddir ]; then
656 if [ ! x$USER = x"" ]; then
659 if [ ! x$LOGNAME = x"" ]; then
666 # build the timelimit utility
667 echo "Building timelimit"
669 echo $compiler $TIMELIMIT_FLAGS -o $builddir/timelimit $test_root/timelimit.c
670 $compiler $TIMELIMIT_FLAGS -o $builddir/timelimit $test_root/timelimit.c || exit 1
672 # build the killbysubdir utility
673 echo "Building killbysubdir"
674 echo $compiler -o $builddir/killbysubdir $test_root/killbysubdir.c
675 $compiler -o $builddir/killbysubdir $test_root/killbysubdir.c
677 prefix="$test_root/prefix/$tree.$compiler"
680 # This can be defined in <host>.fns files
685 sw_config="$config --enable-socket-wrapper"
688 sw_config="$config --enable-socket-wrapper"
689 sw_config="$sw_config --enable-nss-wrapper"
690 sw_config="$sw_config --enable-uid-wrapper"
693 sw_config="$config --enable-socket-wrapper"
694 sw_config="$sw_config --enable-nss-wrapper"
697 PKG_CONFIG_PATH="$test_root/prefix/samba_4_0_test.$compiler/lib/pkgconfig"
698 export PKG_CONFIG_PATH
705 if [ "$LCOV_REPORT" = "yes" ]; then
706 GCOV_FLAGS="--coverage"
707 CFLAGS="$CFLAGS $GCOV_FLAGS"
708 LDFLAGS="$LDFLAGS $GCOV_FLAGS"
709 export CFLAGS LDFLAGS
712 config_and_prefix="$sw_config --prefix=$prefix"
714 # see if we need to rebuild
715 sum_tree $test_root $tree $sum $scm
716 echo "CFLAGS=$CFLAGS $config_and_prefix" >> $sum
718 if [ -f "$sum.old" ] && cmp "$sum" "$sum.old" > /dev/null; then
719 echo "skip: $tree.$compiler nothing changed"
721 send_logs_skip "$log" "$err"
723 echo "Ending build of $tree.$compiler in process $$ at `date`"
727 # we do need to rebuild - save the old sum
728 [ -f $sum.old ] && /bin/rm -f $sum.old
731 #Action == what to do ie. configure config_log ...
734 if [ "$actions" = "" ]; then
735 actions="configure config_log config_header build install test"
741 # we all want to be able to read the output...
748 echo "build_test : $build_test_id"
749 echo "build_test.fns : $build_test_fns_id"
750 echo "local settings file : $build_test_settings_local_file"
751 echo "local functions file: $build_test_fns_local_file"
752 echo "used .fns file : $build_test_used_fns_file"
755 # we need to be able to see if a build farm machine is accumulating
756 # stuck processes. We do this in two ways, as we don't know what style
759 ps -fu $USER 2> /dev/null
761 echo "building $tree with CC=$compiler on $host at "`date`
762 echo "builddir=$builddir"
763 echo "prefix=$prefix"
765 echo "Showing limits"
766 ulimit -a 2> /dev/null
768 # the following is for non-samba builds only
769 if [ "$scm" = "svn" -a -r $test_root/$tree.svn ]; then
770 h_rev=`grep 'Revision: ' $test_root/$tree.svn | cut -d ':' -f2 | cut -d ' ' -f2 | sed 1q`
771 if [ -n "$h_rev" ]; then
772 echo "HIGHEST SVN REVISION: $h_rev"
774 rev=`grep 'Last Changed Rev: ' $test_root/$tree.svn | cut -d ':' -f2 | cut -d ' ' -f2 | sed 1q`
775 if [ -n "$rev" ]; then
776 echo "BUILD REVISION: $rev"
778 elif [ "$scm" = "git" -a -r $test_root/$tree.git ]; then
779 csha1=`cat $test_root/$tree.git |head -3 | tail -1`
780 if [ -n "$csha1" ]; then
781 echo "BUILD COMMIT REVISION: $csha1"
783 cdate=`cat $test_root/$tree.git |head -4 | tail -1`
784 if [ -n "$cdate" ]; then
785 echo "BUILD COMMIT DATE: $cdate"
787 ctime=`cat $test_root/$tree.git |head -2 | tail -1`
788 if [ -n "$ctime" ]; then
789 echo "BUILD COMMIT TIME: $ctime"
793 if [ -x $builddir/killbysubdir ]; then
794 echo "$builddir/killbysubdir $builddir in `pwd`"
795 $builddir/killbysubdir $builddir
798 for action in $actions; do
800 echo Running action $action
804 cd $builddir || exit 1
810 if [ "x$PREHOOKS" != "x" ]; then
811 for hooks in $PREHOOKS; do
812 if [ "x$hooks" = "x$action" ]; then
821 if [ "x$POSTHOOKS" != "x" ]; then
822 for hooks in $POSTHOOKS; do
823 if [ "x$hooks" = "x$action" ]; then
831 if [ $action_status != 0 ]; then
832 echo "ACTION FAILED: $action";
833 echo " return code $action_status $action";
835 echo "ACTION PASSED: $action";
838 if [ $action_status != 0 ]; then
844 if [ "$noclean" = "yes" ]; then
845 echo cleanup skipped!
851 } 3>&2 2>&1 1>&3 | tee "$err"
853 # be aware the above channel swap may sometimes result in unordered
854 # stdout/stderr merge
856 if [ "$LCOV_REPORT" = "yes" ]; then
857 chmod u=rwX,g=rX,o=rX -R $builddir/coverage
858 rsync -rct -q --password-file=.password -z --timeout=200 \
859 $builddir/coverage/ $host@build.samba.org::lcov_data/$host/$tree/
865 if [ "$usingtmpbuild" = "1" ]; then
866 if [ "$noclean" = "yes" ]; then
867 echo builddir cleanup skipped!
869 /bin/rm -rf $builddir
872 # send the logs to the master site
873 send_logs "$log" "$err"
876 echo "Ending build of $tree.$compiler in process $$ at `date`"
880 #########################################################
881 # if you want to build only one project at a time
882 # add 'global_lock' after 'per_run_hook' and
883 # 'global_unlock' to the end of the file
884 #########################################################
887 lock_file "global.lck" || {
893 unlock_file "global.lck"
898 test -z "$otree" && return 0;
905 rm -rf build.$otree.*
908 # this is a special fn that allows us to add a "special" hook to the build
909 # farm that we want to do to the build farm. never leave it empty. instead,
910 # use ":" as the fn body.
912 # kill old processes on systems with a known problem
915 echo "just a placeholder";
922 # trim the log if too large
923 if [ "`wc -c < build.log`" -gt 2000000 ]; then
927 old_trees="web popt distcc samba-gtk smb-build lorikeet-heimdal samba_3_2"
928 old_trees="$old_tree samba_3_2_test samba4 samba_4_0_waf samba_4_0_waf.metze"
929 old_trees="$old_tree samba_3_X_test samba_3_X_devel samba_3_X_devel"
930 for d in $old_trees; do
936 ######################################################
937 # main code that is run on each call to the build code
938 ######################################################
939 rsync --timeout=200 -q -az build.samba.org::build_farm/*.c .
942 # build.log can grow to an excessive size, trim it beyond 50M
943 if [ -f build.log ]; then
944 find build.log -size +100000 -exec /bin/rm '{}' \;