if a build fails, try again with V=1
[amitay/build-farm.git] / build_test.fns
1 #!/bin/sh -*- mode: shell-script; sh-indentation: 8; indent-tabs-mode: t; -*-
2
3 # build_farm -- distributed build/test architecture for samba, rsync, etc
4
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>
8
9 # default maximum runtime for any command
10 MAXTIME=12000
11 # default maximum memory size (100M) for any command
12 MAXMEM=100000
13 RUN_FROM_BUILD_FARM=yes
14 export RUN_FROM_BUILD_FARM
15
16 deptrees="";
17
18 build_test_fns_id='$Id$'
19
20 #############################
21 # build a signature of a tree, used to see if we
22 # need to rebuild 
23 sum_tree() {
24         sum_tree_test_root=$1
25         sum_tree_tree=$2
26         sum_tree_sum=$3
27         sum_tree_scm=$4
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
30
31         if [ -f "$host.fns" ]; then
32             sum $host.fns >> $sum_tree_sum
33         else
34             sum generic.fns >> $sum_tree_sum
35         fi
36
37         if [ -f "$test_root/$tree.$scm" ]; then
38             sum "$test_root/$tree.$scm" >> $sum_tree_sum
39         fi
40
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
45             fi
46         done
47 }
48
49 #############################
50 # send the logs to the master site
51 send_logs() {
52         if [ "$nologreturn" = "yes" ]; then
53                 echo "skipping log transfer"
54         else
55                 log="$1"
56                 err="$2"
57                 shift
58                 shift
59                 chmod 0644 "$log" "$err"
60
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
64                 status=$?
65                 if [ x"$status" = x"0" ]; then
66                         XARGS_IS_GNU=yes
67                 fi
68
69                 if [ x"$XARGS_IS_GNU" = x"yes" ]; then
70                         XARGS_I="xargs -i"
71                 else
72                         XARGS_I="xargs -I '{}'"
73                 fi
74
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***" >> {}'
77
78                 rsync $* -c -q --password-file=.password -z --timeout=200 \
79                     "$log" "$err" $host@build.samba.org::build_farm_data/
80         fi
81 }
82
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
88 send_logs_skip() {
89     touch "$1" "$2"
90     send_logs "$1" "$2" -B 10000000
91 }
92
93 ############################
94 # fetch the latest copy of the tree
95 fetch_tree() {
96         if [ "$norsync" = "yes" ]; then
97                 echo "skipping tree transfer"
98         else
99                 fetchtree=$1
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"
104                 else
105                         echo "transfer of $fetchtree failed code $?"
106                         return 1
107                 fi
108         fi
109         return 0
110 }
111
112 ############################
113 # fetch the latest copy of the rev meta info
114 fetch_revinfo() {
115     tree=$1
116     scm=$2
117
118     test -z "$scm" && return 1
119     test x"$scm" = x"unknown" && return 1
120     test x"$scm" = x"cvs" && return 1
121
122     if [ "$norsync" = "yes" ]; then
123         echo "skipping .revinfo.$scm transfer"
124     else
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
128         fi
129         rsync -q --timeout=200 -clz --ignore-errors \
130             samba.org::ftp/unpacked/$tree/.revinfo.$scm $test_root/$tree.$scm
131     fi
132     if [ -r $test_root/$tree.$scm ]; then
133         return 0;
134     fi
135     return 1
136 }
137
138 ############################
139 # choose the scm that is used for the given project
140 choose_scm() {
141         tree=$1
142
143         case "$tree" in
144                 samba* | rsync | libreplace | talloc | tdb | ldb | pidl | ccache*)
145                         echo "git"
146                         return 0
147                 ;;
148         esac
149
150         echo "svn"
151         return 0
152 }
153
154 locknesting=0
155
156 ############################
157 # grab a lock file. Not atomic, but close :)
158 # tries to cope with NFS
159 lock_file() {
160         if [ -z "$lock_root" ]; then
161           lock_root=`pwd`;
162         fi
163         lckf="$lock_root/$1"
164         machine=`cat "$lckf" 2> /dev/null | cut -d: -f1`
165         pid=`cat "$lckf" 2> /dev/null | cut -d: -f2`
166
167         if [ "$pid" = "$$" ]; then
168             locknesting=`expr $locknesting + 1`
169             echo "lock nesting now $locknesting"
170             return 0
171         fi
172
173         if test -f "$lckf"; then
174             test $machine = $host || {
175                 echo "lock file $lckf is valid for other machine $machine"
176                 return 1                 
177             }
178             kill -0 $pid && {
179                 echo "lock file $lckf is valid for process $pid"
180                 return 1
181             }
182             echo "stale lock file $lckf for $machine:$pid"
183             cat "$lckf"
184             /bin/rm -f "$lckf"
185         fi
186         echo "$host:$$" > "$lckf"
187         return 0
188 }
189
190 ############################
191 # unlock a lock file
192 unlock_file() {
193         if [ -z "$lock_root" ]; then
194           lock_root=`pwd`;
195         fi
196         if [ "$locknesting" != "0" ]; then
197             locknesting=`expr $locknesting - 1`
198             echo "lock nesting now $locknesting"
199         else 
200             lckf="$lock_root/$1"
201             /bin/rm -f "$lckf"
202         fi
203 }
204
205 ############################
206 # run make, and print trace
207 do_make() {
208
209   if [ x"$MAKE" = x ] 
210   then
211     MAKE=make
212   fi 
213
214   MMTIME=$MAXTIME
215   # some trees don't need as much time
216   case "$tree" in
217         rsync | tdb | talloc | libreplace | ccache*)
218           if [ "$compiler" != "checker" ]; then
219               MMTIME=`expr $MMTIME / 5`
220           fi
221           ;;
222   esac
223   
224     
225   for t in $*; do
226     if [ x"$BUILD_FARM_NUM_JOBS" = x ]; then
227       echo "$MAKE $t"
228       $builddir/timelimit $MMTIME "$MAKE" "$t"
229       status=$?
230     else
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"
235         status=$?
236       else
237         echo "$MAKE $t"
238         $builddir/timelimit $MMTIME "$MAKE" "$t"
239         status=$?
240       fi
241     fi
242
243     if [ $status != 0 ]; then
244       # run again with V=1, so we see failed commands
245       $builddir/timelimit $MMTIME "$MAKE" "$t" V=1
246       status=$?
247     fi
248
249     if [ $status != 0 ]; then
250       return $status;
251     fi
252
253   done
254
255   return 0
256 }      
257
258 ############################
259 # configure the tree
260 action_configure() {
261         if [ ! -x $srcdir/configure -a -r $srcdir/Makefile.PL ]; then
262                 perl $srcdir/Makefile.PL PREFIX="$prefix"
263                 cstatus=$?
264                 echo "CONFIGURE STATUS: $cstatus"
265                 return $cstatus;
266         fi
267         if [ ! -x $srcdir/configure ]; then
268             ls -l $srcdir/configure
269             echo "$srcdir/configure is missing"
270             cstatus=255
271             echo "CONFIGURE STATUS: $cstatus"
272             return $cstatus;
273         fi
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"
278         export CC
279         $builddir/timelimit $MAXTIME $srcdir/configure $config_and_prefix
280         cstatus=$?
281         if [ x"$cstatus" != x"0" ]; then
282                 if [ -f config.log ]; then
283                         echo "contents of config.log:"
284                         cat config.log
285                 fi
286                 if [ -f bin/config.log ]; then
287                         echo "contents of config.log:"
288                         cat bin/config.log
289                 fi
290         fi
291         echo "CONFIGURE STATUS: $cstatus"
292         return $cstatus;
293 }
294
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
300         if [ -f $f ]; then
301             echo "contents of config.log:"
302             cat $f
303             return 0;
304         fi
305     done
306     return 0
307 }
308
309 ############################
310 # show the config.h
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
314         if [ -f $h ]; then
315             echo "contents of $h:"
316             cat $h
317             return 0;
318         fi
319     done
320     return 0;
321 }
322
323 copy_dir() {
324         Tsrc=$1
325         Tdst=$2
326         pwd
327         echo rsync -a --delete $Tsrc/ $Tdst
328         rsync -a --delete $Tsrc/ $Tdst || return 1
329         return 0
330 }
331
332
333 ############################
334 # build the tree
335 action_build() {
336         case "$tree" in
337         samba_4*)
338                 do_make everything
339                 bstatus=$?
340                 ;;
341         samba_3*)
342                 do_make everything torture
343                 bstatus=$?
344                 ;;
345         *)
346                 do_make all
347                 bstatus=$?
348                 ;;
349         esac
350
351         echo "BUILD STATUS: $bstatus"
352
353         return $bstatus
354 }
355
356 ############################
357 # show static analysis results
358 action_cc_checker() {
359
360         # default to passing the cc_checker
361         cccstatus=0
362
363         if [ -f ibm_checker.out ]; then
364                 cat ibm_checker.out
365                 cccstatus=`cat ibm_checker.out | grep '^\-\- ' | wc -l`
366         fi
367
368         echo "CC_CHECKER STATUS: $cccstatus"
369         return $cccstatus;      
370 }
371
372 ############################
373 # install the tree
374 action_install() {
375         if [ -d $prefix ]; then
376                 if [ "$noclean" != "yes" ]; then
377                     rm -rf $prefix
378                 fi
379         fi
380
381         do_make install
382         istatus=$?
383         echo "INSTALL STATUS: $istatus"
384         return $istatus;
385 }
386
387 ############################
388 # test the tree
389 action_test_samba() {
390         do_make test
391         totalstatus=$?
392         # if we produced a test summary then show it
393         [ -f st/summary ] && {
394             echo "TEST SUMMARY"
395             cat st/summary
396         }
397         return "$totalstatus"
398 }
399
400 action_test_generic() {
401         CC="$compiler"
402         export CC
403         do_make installcheck
404         totalstatus=$?
405         echo "TEST STATUS: $totalstatus"
406         return "$totalstatus"
407 }
408
409 action_test_lorikeet_heimdal() {
410         CC="$compiler"
411         export CC
412         SOCKET_WRAPPER_DIR=`pwd`/sw
413         mkdir $SOCKET_WRAPPER_DIR
414         export SOCKET_WRAPPER_DIR
415         do_make check
416         totalstatus=$?
417         SOCKET_WRAPPER_DIR=
418         export SOCKET_WRAPPER_DIR
419         echo "TEST STATUS: $totalstatus"
420         return "$totalstatus"
421 }
422
423
424 #############################
425 # attempt some basic tests of functionaility
426 # starting as basic as possible, and getting incresingly complex
427
428 action_test() {
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'.
432         case "$tree" in
433         samba*|smb-build|pidl)
434             action_test_samba
435             ;;
436         lorikeet-heimdal*)
437             action_test_lorikeet_heimdal
438             ;;
439         *)
440             action_test_generic
441             ;;
442         esac
443 }
444
445 ###########################
446 # do a test build of a particular tree
447 test_tree() {
448         tree=$1
449         source=$2
450         compiler="$3"
451         shift
452         shift
453         shift
454         if [ "$compiler" = "gcc" ] && [ "$tree" != "ccache" ] && [ "$tree" != "ccache-maint" ] && ccache -V > /dev/null; then
455             CCACHE="ccache"
456             export CCACHE
457         else
458             CCACHE=""
459         fi
460
461         # limit our resource usage
462         ulimit -t $MAXTIME 2> /dev/null
463
464         # max mem size 100M
465         ulimit -m $MAXMEM 2> /dev/null
466
467         # max file size 100M
468         # darn, this affects sparse files too! disable it
469         # ulimit -f 100000 2> /dev/null
470
471         # try and limit the number of open files to 250. That means we'll discover
472         # fd leaks faster
473         ulimit -n 250 2> /dev/null
474
475         # Keep stuff private
476         umask 077
477
478         if [ -z "$test_root" ]; then
479                 test_root=`pwd`
480         fi
481
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"
487
488         lock_file "$lck" || {
489                 return
490         }
491
492         # work out what other trees this package depends on
493         deptrees=""
494         case "$tree" in
495             samba-gtk)
496                 deptrees="samba_4_0_test"
497                 ;;
498         esac
499
500         scm=`choose_scm "$tree"`
501
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
509                     fi
510                 fi
511             done
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"
517                 cd $test_root
518                 send_logs_skip "$log" "$err"
519                 unlock_file "$lck"
520                 return
521             fi
522         fi
523
524         # pull the tree
525         fetch_tree "$tree" || {
526             cd $test_root
527             unlock_file "$lck"
528             return
529         }
530
531         if [ ! -x $srcdir/configure ] && [ "$tree" != "pidl" ]; then
532                 echo "skip: $tree.$compiler configure not present, try again next time!"
533                 cd $test_root
534                 unlock_file "$lck"
535                 return
536         fi
537
538         echo "Starting build of $tree.$compiler in process $$ at `date`"
539
540         case "$tree" in
541             libreplace)
542                 builddir="$test_root/tmp.$tree.$compiler"
543                 usingtmpbuild=1
544                 if [ -d $builddir ]; then
545                     rm -rf $builddir
546                 fi
547                 mkdir -p $builddir
548                 export builddir
549             ;;
550             *)
551                 builddir=$srcdir
552                 usingtmpbuild=0
553                 export builddir
554             ;;
555         esac
556         
557         if [ ! x$USER = x"" ]; then
558             whoami=$USER
559         else 
560             if [ ! x$LOGNAME = x"" ]; then
561                 whoami=$LOGNAME
562             else
563                 whoami=build
564             fi
565         fi
566
567         # build the timelimit utility
568         echo "Building timelimit"
569         mkdir -p $builddir
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
572
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
577
578         prefix="$test_root/prefix/$tree.$compiler"
579         mkdir -p "$prefix"
580
581         sw_config=$config
582
583         case "$tree" in
584         lorikeet-heimdal)
585                 sw_config="$config --enable-socket-wrapper"
586                 ;;
587         samba_4*)
588                 sw_config="$config --enable-socket-wrapper"
589                 sw_config="$sw_config --enable-nss-wrapper"
590                 sw_config="$sw_config --enable-uid-wrapper"
591                 ;;
592         samba_3*)
593                 sw_config="$config --enable-socket-wrapper"
594                 sw_config="$sw_config --enable-nss-wrapper"
595                 ;;
596         samba-gtk)
597                 PKG_CONFIG_PATH="$test_root/prefix/samba_4_0_test.$compiler/lib/pkgconfig"
598                 export PKG_CONFIG_PATH
599                 ;;
600         *)
601                 testsuite=testsuite
602                 ;;
603         esac
604
605         if [ "$LCOV_REPORT" = "yes" ]; then
606             GCOV_FLAGS="--coverage"
607             CFLAGS="$CFLAGS $GCOV_FLAGS" 
608             LDFLAGS="$LDFLAGS $GCOV_FLAGS" 
609             export CFLAGS LDFLAGS
610         fi
611
612         config_and_prefix="$sw_config --prefix=$prefix"
613
614         # see if we need to rebuild
615         sum_tree $test_root $tree $sum $scm
616         echo "CFLAGS=$CFLAGS $config_and_prefix" >> $sum
617
618         if cmp "$sum" "$sum.old" > /dev/null; then
619                 echo "skip: $tree.$compiler nothing changed"
620                 cd $test_root
621                 send_logs_skip "$log" "$err"
622                 unlock_file "$lck"
623                 echo "Ending build of $tree.$compiler in process $$ at `date`"
624                 return
625         fi
626
627         # we do need to rebuild - save the old sum
628         /bin/rm -f $sum.old
629         mv $sum $sum.old
630
631         actions="$*"
632         
633         if [ "$actions" = "" ]; then
634             actions="configure config_log config_header build install test"
635         fi
636
637         # start the build
638         (
639         {
640                 # we all want to be able to read the output...
641                 LANG=C
642                 export LANG
643
644                 uname -a
645
646                 echo ""
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"
652                 echo ""
653
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
656                 # of ps it will have
657                 ps xfuw 2> /dev/null
658                 ps -fu $USER 2> /dev/null
659
660                 echo "building $tree with CC=$compiler on $host at "`date`
661                 echo "builddir=$builddir"
662                 echo "prefix=$prefix"
663
664                 echo "Showing limits"
665                 ulimit -a 2> /dev/null
666
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"
672                   fi
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"
676                   fi
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"
681                   fi
682                   cdate=`cat $test_root/$tree.git |head -4 | tail -1`
683                   if [ -n "$cdate" ]; then
684                     echo "BUILD COMMIT DATE: $cdate"
685                   fi
686                   ctime=`cat $test_root/$tree.git |head -2 | tail -1`
687                   if [ -n "$ctime" ]; then
688                     echo "BUILD COMMIT TIME: $ctime"
689                   fi
690                 fi
691
692                 if [ -x $builddir/killbysubdir ]; then
693                     echo "$builddir/killbysubdir $builddir in `pwd`"
694                     $builddir/killbysubdir $builddir
695                 fi
696
697                 for action in $actions; do
698
699                     echo Running action $action
700
701                     date
702
703                     cd $builddir || exit 1
704                     export srcdir
705                     df .
706                     mount
707                     vmstat
708
709                     ( action_$action )
710                     action_status=$?
711
712                     df .
713
714                     if [ $action_status != 0 ]; then
715                         echo "ACTION FAILED: $action";
716                     else
717                         echo "ACTION PASSED: $action";
718                     fi
719                     
720                     if [ $action_status != 0 ]; then 
721                         break;
722                     fi
723
724                 done
725
726                 if [ "$LCOV_REPORT" = "yes" ]; then
727                     case "$tree" in
728                         lorikeet-heimdal*)
729                             lcov --directory $builddir --capture --output-file $builddir/$tree.lcov.info
730                             ;;
731                         samba_3_master*)
732                             lcov --base-directory $builddir --directory $builddir/.. --capture --output-file $builddir/$tree.lcov.info
733                             ;;
734                         samba_4*)
735                             # ugly hack for s4, as lcov is otherwise not able to find 
736                             # these files
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
739                             ;;
740                         *)
741                             lcov --base-directory $builddir --directory $builddir --capture --output-file $builddir/$tree.lcov.info
742                             ;;
743                     esac
744                     genhtml -o $builddir/coverage $builddir/$tree.lcov.info
745                 fi
746
747                 if [ "$noclean" = "yes" ]; then
748                     echo cleanup skipped!
749                 else
750                     echo cleaning up
751                     do_make clean
752                 fi
753                 date
754         } 3>&2 2>&1 1>&3 | tee "$err"
755         ) > "$log" 2>&1
756         # be aware the above channel swap may sometimes result in unordered
757         # stdout/stderr merge
758
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/
763         fi
764
765         cd $test_root
766
767         /bin/rm -rf $prefix
768         if [ "$usingtmpbuild" = "1" ]; then
769             if [ "$noclean" = "yes" ]; then
770                 echo builddir cleanup skipped!
771             else
772                 /bin/rm -rf $builddir
773             fi
774         fi
775         # send the logs to the master site
776         send_logs "$log" "$err"
777
778         # cleanup
779         echo "Ending build of $tree.$compiler in process $$ at `date`"
780         unlock_file "$lck"
781 }
782
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
787 global_lock() {
788     lock_file "global.lck" || {
789         exit 0
790     }
791 }
792 global_unlock() {
793     unlock_file "global.lck"
794 }
795
796 delete_old_tree() {
797         otree=$1
798
799         test -z "$otree" && return 0;
800
801         rm -rf $otree
802         rm -rf $otree.svn
803         rm -rf $otree.*.svn
804         rm -rf $otree.git
805         rm -rf $otree.*.git
806         rm -rf build.$otree.*
807 }
808
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.
812 per_run_hook() {
813     # kill old processes on systems with a known problem
814     case $host in
815         nohost)
816             echo "just a placeholder";
817             ;;
818         deckchair)
819             rm -f deckchair.fns
820             ;;
821     esac
822     # trim the log if too large
823     if [ "`wc -c < build.log`" -gt 2000000 ]; then
824         rm -f build.log
825     fi
826
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
829         delete_old_tree $d
830     done
831 }
832
833
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 .
837
838
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 '{}' \;
842 fi
843