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
292 ############################
294 ############################
298 if [ ! -x $srcdir/configure -a -r $srcdir/Makefile.PL ]; then
299 perl $srcdir/Makefile.PL PREFIX="$prefix"
301 echo "CONFIGURE STATUS: $cstatus"
305 if [ ! -x $srcdir/configure ]; then
306 ls -l $srcdir/configure
307 echo "$srcdir/configure is missing"
309 echo "CONFIGURE STATUS: $cstatus"
313 echo "CFLAGS=$CFLAGS"
314 echo configure options: $config_and_prefix
315 echo CC="$CCACHE $compiler" $srcdir/configure $config_and_prefix
317 CC="$CCACHE $compiler"
319 $builddir/timelimit $MAXTIME $srcdir/configure $config_and_prefix
322 if [ x"$cstatus" != x"0" ]; then
323 if [ -f config.log ]; then
324 echo "contents of config.log:"
329 if [ -f bin/config.log ]; then
330 echo "contents of config.log:"
334 echo "CONFIGURE STATUS: $cstatus"
338 ############################
339 # show the configure log
340 ############################
342 action_config_log() {
344 log_files="config.log bin/config.log"
345 for f in $log_files; do
347 echo "contents of config.log:"
355 ############################
357 ############################
359 action_config_header() {
360 hdr_files="config.h include/config.h bin/default/config.h bin/default/source4/include/config.h bin/default/source3/include/config.h"
361 for h in $hdr_files; do
363 echo "contents of $h:"
374 ############################
376 ############################
384 do_make everything torture
393 echo "BUILD STATUS: $bstatus"
398 ############################
399 # show static analysis results
400 ############################
402 action_cc_checker() {
404 # default to passing the cc_checker
407 if [ -f ibm_checker.out ]; then
409 cccstatus=`cat ibm_checker.out | grep '^\-\- ' | wc -l`
412 echo "CC_CHECKER STATUS: $cccstatus"
416 ############################
418 ############################
421 if [ -d $prefix ]; then
422 if [ "$noclean" != "yes" ]; then
429 echo "INSTALL STATUS: $istatus"
433 ############################
435 action_test_samba() {
439 # if we produced a test summary then show it
440 [ -f st/summary ] && {
445 return "$totalstatus"
448 action_test_generic() {
453 echo "TEST STATUS: $totalstatus"
454 return "$totalstatus"
457 action_test_lorikeet_heimdal() {
460 SOCKET_WRAPPER_DIR=`pwd`/sw
461 mkdir $SOCKET_WRAPPER_DIR
462 export SOCKET_WRAPPER_DIR
466 export SOCKET_WRAPPER_DIR
467 echo "TEST STATUS: $totalstatus"
468 return "$totalstatus"
472 #############################
473 # attempt some basic tests of functionaility
474 # starting as basic as possible, and getting incresingly complex
475 #############################
478 # Samba needs crufty code of its own for backward
479 # compatiblity. I think a better way to do this in the future
480 # is to just call 'make installcheck'.
482 samba*|smb-build|pidl)
486 action_test_lorikeet_heimdal
494 ###########################
495 # do a test build of a particular tree
496 # This is the master function called by generic.fns or
498 ###########################
507 echo "Starting to deal with tree $tree with compiler $compiler"
508 if [ "$compiler" = "gcc" ] && [ "$tree" != "ccache" ] && [ "$tree" != "ccache-maint" ] && ccache -V > /dev/null 2>/dev/null; then
515 # limit our resource usage
516 ulimit -t $MAXTIME 2> /dev/null
519 ulimit -m $MAXMEM 2> /dev/null
522 # darn, this affects sparse files too! disable it
523 # ulimit -f 100000 2> /dev/null
525 # try and limit the number of open files to 250. That means we'll discover
527 ulimit -n 250 2> /dev/null
532 if [ -z "$test_root" ]; then
536 log="build.$tree.$host.$compiler.log"
537 err="build.$tree.$host.$compiler.err"
538 sum="build.$tree.$host.$compiler.sum"
539 lck="build.$tree.lck"
540 srcdir="$test_root/$tree/$source"
542 lock_file "$lck" || {
546 # work out what other trees this package depends on
550 deptrees="samba_4_0_test"
554 scm=`choose_scm "$tree"`
556 # pull the entries, if any
557 # Remove old .svn or .git files
558 # Move the current .svn org .git to .svn.old or
559 # .git.old then fetch the new from rsync
560 if fetch_revinfo "$tree" "$scm"; then
561 for d in $deptrees; do
562 # If there is dependency substree(s) we add info
563 # from the dependency tree so that we
564 # can rebuild in case one of them has changed
565 dscm=`choose_scm "$d"`
566 if [ -f "$test_root/$d.$dscm" ]; then
567 if [ "$d" != "$tree" ]; then
568 cat "$test_root/$d.$dscm" >> $test_root/$tree.$scm
572 [ -f $test_root/$tree.$compiler.$scm.old ] && rm -f $test_root/$tree.$compiler.$scm.old
573 [ -f $test_root/$tree.$compiler.$scm ] && mv $test_root/$tree.$compiler.$scm $test_root/$tree.$compiler.$scm.old
574 [ -f $test_root/$tree.$scm ] && cp $test_root/$tree.$scm $test_root/$tree.$compiler.$scm
576 if [ -f $test_root/$tree.$compiler.$scm.old ] && \
577 cmp $test_root/$tree.$compiler.$scm $test_root/$tree.$compiler.$scm.old > /dev/null; then
579 echo "skip: $tree.$compiler nothing changed in $scm"
581 send_logs_skip "$log" "$err"
588 fetch_tree "$tree" || {
594 if [ ! -x $srcdir/configure ] && [ "$tree" != "pidl" ]; then
595 echo "skip: $tree.$compiler configure not present, try again next time!"
601 echo "Starting build of $tree.$compiler in process $$ at `date`"
604 # Parameters for the build depending on the tree
607 builddir="$test_root/tmp.$tree.$compiler"
609 if [ -d $builddir ]; then
623 if [ ! x$USER = x"" ]; then
626 if [ ! x$LOGNAME = x"" ]; then
633 # build the timelimit utility
634 echo "Building timelimit"
636 echo $compiler $TIMELIMIT_FLAGS -o $builddir/timelimit $test_root/timelimit.c
637 $compiler $TIMELIMIT_FLAGS -o $builddir/timelimit $test_root/timelimit.c || exit 1
639 # build the killbysubdir utility
640 echo "Building killbysubdir"
641 echo $compiler -o $builddir/killbysubdir $test_root/killbysubdir.c
642 $compiler -o $builddir/killbysubdir $test_root/killbysubdir.c
644 prefix="$test_root/prefix/$tree.$compiler"
647 # This can be defined in <host>.fns files
652 sw_config="$config --enable-socket-wrapper"
655 sw_config="$config --enable-socket-wrapper"
656 sw_config="$sw_config --enable-nss-wrapper"
657 sw_config="$sw_config --enable-uid-wrapper"
660 sw_config="$config --enable-socket-wrapper"
661 sw_config="$sw_config --enable-nss-wrapper"
664 PKG_CONFIG_PATH="$test_root/prefix/samba_4_0_test.$compiler/lib/pkgconfig"
665 export PKG_CONFIG_PATH
672 if [ "$LCOV_REPORT" = "yes" ]; then
673 GCOV_FLAGS="--coverage"
674 CFLAGS="$CFLAGS $GCOV_FLAGS"
675 LDFLAGS="$LDFLAGS $GCOV_FLAGS"
676 export CFLAGS LDFLAGS
679 config_and_prefix="$sw_config --prefix=$prefix"
681 # see if we need to rebuild
682 sum_tree $test_root $tree $sum $scm
683 echo "CFLAGS=$CFLAGS $config_and_prefix" >> $sum
685 if [ -f "$sum.old" ] && cmp "$sum" "$sum.old" > /dev/null; then
686 echo "skip: $tree.$compiler nothing changed"
688 send_logs_skip "$log" "$err"
690 echo "Ending build of $tree.$compiler in process $$ at `date`"
694 # we do need to rebuild - save the old sum
695 [ -f $sum.old ] && /bin/rm -f $sum.old
698 #Action == what to do ie. configure config_log ...
701 if [ "$actions" = "" ]; then
702 actions="configure config_log config_header build install test"
708 # we all want to be able to read the output...
715 echo "build_test : $build_test_id"
716 echo "build_test.fns : $build_test_fns_id"
717 echo "local settings file : $build_test_settings_local_file"
718 echo "local functions file: $build_test_fns_local_file"
719 echo "used .fns file : $build_test_used_fns_file"
722 # we need to be able to see if a build farm machine is accumulating
723 # stuck processes. We do this in two ways, as we don't know what style
726 ps -fu $USER 2> /dev/null
728 echo "building $tree with CC=$compiler on $host at "`date`
729 echo "builddir=$builddir"
730 echo "prefix=$prefix"
732 echo "Showing limits"
733 ulimit -a 2> /dev/null
735 # the following is for non-samba builds only
736 if [ "$scm" = "svn" -a -r $test_root/$tree.svn ]; then
737 h_rev=`grep 'Revision: ' $test_root/$tree.svn | cut -d ':' -f2 | cut -d ' ' -f2 | sed 1q`
738 if [ -n "$h_rev" ]; then
739 echo "HIGHEST SVN REVISION: $h_rev"
741 rev=`grep 'Last Changed Rev: ' $test_root/$tree.svn | cut -d ':' -f2 | cut -d ' ' -f2 | sed 1q`
742 if [ -n "$rev" ]; then
743 echo "BUILD REVISION: $rev"
745 elif [ "$scm" = "git" -a -r $test_root/$tree.git ]; then
746 csha1=`cat $test_root/$tree.git |head -3 | tail -1`
747 if [ -n "$csha1" ]; then
748 echo "BUILD COMMIT REVISION: $csha1"
750 cdate=`cat $test_root/$tree.git |head -4 | tail -1`
751 if [ -n "$cdate" ]; then
752 echo "BUILD COMMIT DATE: $cdate"
754 ctime=`cat $test_root/$tree.git |head -2 | tail -1`
755 if [ -n "$ctime" ]; then
756 echo "BUILD COMMIT TIME: $ctime"
760 if [ -x $builddir/killbysubdir ]; then
761 echo "$builddir/killbysubdir $builddir in `pwd`"
762 $builddir/killbysubdir $builddir
765 for action in $actions; do
767 echo Running action $action
771 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
793 if [ "$LCOV_REPORT" = "yes" ]; then
796 lcov --directory $builddir --capture --output-file $builddir/$tree.lcov.info
799 lcov --base-directory $builddir --directory $builddir/.. --capture --output-file $builddir/$tree.lcov.info
802 # ugly hack for s4, as lcov is otherwise not able to find
804 rm -f heimdal/lib/*/{lex,parse,sel-lex}.{gcda,gcno}
805 lcov --base-directory $builddir --directory $builddir/.. --capture --output-file $builddir/$tree.lcov.info
808 lcov --base-directory $builddir --directory $builddir --capture --output-file $builddir/$tree.lcov.info
811 genhtml -o $builddir/coverage $builddir/$tree.lcov.info
814 if [ "$noclean" = "yes" ]; then
815 echo cleanup skipped!
821 } 3>&2 2>&1 1>&3 | tee "$err"
823 # be aware the above channel swap may sometimes result in unordered
824 # stdout/stderr merge
826 if [ "$LCOV_REPORT" = "yes" ]; then
827 chmod u=rwX,g=rX,o=rX -R $builddir/coverage
828 rsync -rct -q --password-file=.password -z --timeout=200 \
829 $builddir/coverage/ $host@build.samba.org::lcov_data/$host/$tree/
835 if [ "$usingtmpbuild" = "1" ]; then
836 if [ "$noclean" = "yes" ]; then
837 echo builddir cleanup skipped!
839 /bin/rm -rf $builddir
842 # send the logs to the master site
843 send_logs "$log" "$err"
846 echo "Ending build of $tree.$compiler in process $$ at `date`"
850 #########################################################
851 # if you want to build only one project at a time
852 # add 'global_lock' after 'per_run_hook' and
853 # 'global_unlock' to the end of the file
854 #########################################################
857 lock_file "global.lck" || {
863 unlock_file "global.lck"
868 test -z "$otree" && return 0;
875 rm -rf build.$otree.*
878 # this is a special fn that allows us to add a "special" hook to the build
879 # farm that we want to do to the build farm. never leave it empty. instead,
880 # use ":" as the fn body.
882 # kill old processes on systems with a known problem
885 echo "just a placeholder";
892 # trim the log if too large
893 if [ "`wc -c < build.log`" -gt 2000000 ]; then
897 old_trees="web popt distcc samba-gtk smb-build lorikeet-heimdal samba_3_2"
898 old_trees="$old_tree samba_3_2_test samba4 samba_4_0_waf samba_4_0_waf.metze"
899 old_trees="$old_tree samba_3_X_test samba_3_X_devel samba_3_X_devel"
900 for d in $old_trees; do
906 ######################################################
907 # main code that is run on each call to the build code
908 ######################################################
909 rsync --timeout=200 -q -az build.samba.org::build_farm/*.c .
912 # build.log can grow to an excessive size, trim it beyond 50M
913 if [ -f build.log ]; then
914 find build.log -size +100000 -exec /bin/rm '{}' \;