don't rerun test commands
[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         case "$t" in
245             test | check | installcheck)
246                 ;;
247             *)
248                 # run again with V=1, so we see failed commands
249                 $builddir/timelimit $MMTIME "$MAKE" "$t" V=1
250                 status=$?
251                 ;;
252         esac
253     fi
254
255     if [ $status != 0 ]; then
256       return $status;
257     fi
258
259   done
260
261   return 0
262 }      
263
264 ############################
265 # configure the tree
266 action_configure() {
267         if [ ! -x $srcdir/configure -a -r $srcdir/Makefile.PL ]; then
268                 perl $srcdir/Makefile.PL PREFIX="$prefix"
269                 cstatus=$?
270                 echo "CONFIGURE STATUS: $cstatus"
271                 return $cstatus;
272         fi
273         if [ ! -x $srcdir/configure ]; then
274             ls -l $srcdir/configure
275             echo "$srcdir/configure is missing"
276             cstatus=255
277             echo "CONFIGURE STATUS: $cstatus"
278             return $cstatus;
279         fi
280         echo "CFLAGS=$CFLAGS"
281         echo configure options: $config_and_prefix
282         echo CC="$CCACHE $compiler" $srcdir/configure $config_and_prefix
283         CC="$CCACHE $compiler"
284         export CC
285         $builddir/timelimit $MAXTIME $srcdir/configure $config_and_prefix
286         cstatus=$?
287         if [ x"$cstatus" != x"0" ]; then
288                 if [ -f config.log ]; then
289                         echo "contents of config.log:"
290                         cat config.log
291                 fi
292                 if [ -f bin/config.log ]; then
293                         echo "contents of config.log:"
294                         cat bin/config.log
295                 fi
296         fi
297         echo "CONFIGURE STATUS: $cstatus"
298         return $cstatus;
299 }
300
301 ############################
302 # show the configure log
303 action_config_log() {
304     log_files="config.log bin/config.log"
305     for f in $log_files; do
306         if [ -f $f ]; then
307             echo "contents of config.log:"
308             cat $f
309             return 0;
310         fi
311     done
312     return 0
313 }
314
315 ############################
316 # show the config.h
317 action_config_header() {
318     hdr_files="config.h include/config.h bin/default/config.h bin/default/source4/include/config.h bin/default/source3/include/config.h"
319     for h in $hdr_files; do
320         if [ -f $h ]; then
321             echo "contents of $h:"
322             cat $h
323             return 0;
324         fi
325     done
326     return 0;
327 }
328
329 copy_dir() {
330         Tsrc=$1
331         Tdst=$2
332         pwd
333         echo rsync -a --delete $Tsrc/ $Tdst
334         rsync -a --delete $Tsrc/ $Tdst || return 1
335         return 0
336 }
337
338
339 ############################
340 # build the tree
341 action_build() {
342         case "$tree" in
343         samba_4*)
344                 do_make everything
345                 bstatus=$?
346                 ;;
347         samba_3*)
348                 do_make everything torture
349                 bstatus=$?
350                 ;;
351         *)
352                 do_make all
353                 bstatus=$?
354                 ;;
355         esac
356
357         echo "BUILD STATUS: $bstatus"
358
359         return $bstatus
360 }
361
362 ############################
363 # show static analysis results
364 action_cc_checker() {
365
366         # default to passing the cc_checker
367         cccstatus=0
368
369         if [ -f ibm_checker.out ]; then
370                 cat ibm_checker.out
371                 cccstatus=`cat ibm_checker.out | grep '^\-\- ' | wc -l`
372         fi
373
374         echo "CC_CHECKER STATUS: $cccstatus"
375         return $cccstatus;      
376 }
377
378 ############################
379 # install the tree
380 action_install() {
381         if [ -d $prefix ]; then
382                 if [ "$noclean" != "yes" ]; then
383                     rm -rf $prefix
384                 fi
385         fi
386
387         do_make install
388         istatus=$?
389         echo "INSTALL STATUS: $istatus"
390         return $istatus;
391 }
392
393 ############################
394 # test the tree
395 action_test_samba() {
396         do_make test
397         totalstatus=$?
398         # if we produced a test summary then show it
399         [ -f st/summary ] && {
400             echo "TEST SUMMARY"
401             cat st/summary
402         }
403         return "$totalstatus"
404 }
405
406 action_test_generic() {
407         CC="$compiler"
408         export CC
409         do_make installcheck
410         totalstatus=$?
411         echo "TEST STATUS: $totalstatus"
412         return "$totalstatus"
413 }
414
415 action_test_lorikeet_heimdal() {
416         CC="$compiler"
417         export CC
418         SOCKET_WRAPPER_DIR=`pwd`/sw
419         mkdir $SOCKET_WRAPPER_DIR
420         export SOCKET_WRAPPER_DIR
421         do_make check
422         totalstatus=$?
423         SOCKET_WRAPPER_DIR=
424         export SOCKET_WRAPPER_DIR
425         echo "TEST STATUS: $totalstatus"
426         return "$totalstatus"
427 }
428
429
430 #############################
431 # attempt some basic tests of functionaility
432 # starting as basic as possible, and getting incresingly complex
433
434 action_test() {
435         # Samba needs crufty code of its own for backward
436         # compatiblity.  I think a better way to do this in the future
437         # is to just call 'make installcheck'.
438         case "$tree" in
439         samba*|smb-build|pidl)
440             action_test_samba
441             ;;
442         lorikeet-heimdal*)
443             action_test_lorikeet_heimdal
444             ;;
445         *)
446             action_test_generic
447             ;;
448         esac
449 }
450
451 ###########################
452 # do a test build of a particular tree
453 test_tree() {
454         tree=$1
455         source=$2
456         compiler="$3"
457         shift
458         shift
459         shift
460         if [ "$compiler" = "gcc" ] && [ "$tree" != "ccache" ] && [ "$tree" != "ccache-maint" ] && ccache -V > /dev/null; then
461             CCACHE="ccache"
462             export CCACHE
463         else
464             CCACHE=""
465         fi
466
467         # limit our resource usage
468         ulimit -t $MAXTIME 2> /dev/null
469
470         # max mem size 100M
471         ulimit -m $MAXMEM 2> /dev/null
472
473         # max file size 100M
474         # darn, this affects sparse files too! disable it
475         # ulimit -f 100000 2> /dev/null
476
477         # try and limit the number of open files to 250. That means we'll discover
478         # fd leaks faster
479         ulimit -n 250 2> /dev/null
480
481         # Keep stuff private
482         umask 077
483
484         if [ -z "$test_root" ]; then
485                 test_root=`pwd`
486         fi
487
488         log="build.$tree.$host.$compiler.log"
489         err="build.$tree.$host.$compiler.err"
490         sum="build.$tree.$host.$compiler.sum"
491         lck="build.$tree.lck"
492         srcdir="$test_root/$tree/$source"
493
494         lock_file "$lck" || {
495                 return
496         }
497
498         # work out what other trees this package depends on
499         deptrees=""
500         case "$tree" in
501             samba-gtk)
502                 deptrees="samba_4_0_test"
503                 ;;
504         esac
505
506         scm=`choose_scm "$tree"`
507
508         # pull the entries, if any
509         if fetch_revinfo "$tree" "$scm"; then
510             for d in $deptrees; do
511                 dscm=`choose_scm "$d"`
512                 if [ -f "$test_root/$d.$dscm" ]; then
513                     if [ "$d" != "$tree" ]; then
514                         cat "$test_root/$d.$dscm" >> $test_root/$tree.$scm
515                     fi
516                 fi
517             done
518             rm -f $test_root/$tree.$compiler.$scm.old
519             mv $test_root/$tree.$compiler.$scm $test_root/$tree.$compiler.$scm.old
520             cp $test_root/$tree.$scm $test_root/$tree.$compiler.$scm
521             if cmp $test_root/$tree.$compiler.$scm $test_root/$tree.$compiler.$scm.old > /dev/null; then
522                 echo "skip: $tree.$compiler nothing changed in $scm"
523                 cd $test_root
524                 send_logs_skip "$log" "$err"
525                 unlock_file "$lck"
526                 return
527             fi
528         fi
529
530         # pull the tree
531         fetch_tree "$tree" || {
532             cd $test_root
533             unlock_file "$lck"
534             return
535         }
536
537         if [ ! -x $srcdir/configure ] && [ "$tree" != "pidl" ]; then
538                 echo "skip: $tree.$compiler configure not present, try again next time!"
539                 cd $test_root
540                 unlock_file "$lck"
541                 return
542         fi
543
544         echo "Starting build of $tree.$compiler in process $$ at `date`"
545
546         case "$tree" in
547             libreplace)
548                 builddir="$test_root/tmp.$tree.$compiler"
549                 usingtmpbuild=1
550                 if [ -d $builddir ]; then
551                     rm -rf $builddir
552                 fi
553                 mkdir -p $builddir
554                 export builddir
555             ;;
556             *)
557                 builddir=$srcdir
558                 usingtmpbuild=0
559                 export builddir
560             ;;
561         esac
562         
563         if [ ! x$USER = x"" ]; then
564             whoami=$USER
565         else 
566             if [ ! x$LOGNAME = x"" ]; then
567                 whoami=$LOGNAME
568             else
569                 whoami=build
570             fi
571         fi
572
573         # build the timelimit utility
574         echo "Building timelimit"
575         mkdir -p $builddir
576         echo $compiler $TIMELIMIT_FLAGS -o $builddir/timelimit $test_root/timelimit.c
577         $compiler $TIMELIMIT_FLAGS -o $builddir/timelimit $test_root/timelimit.c || exit 1
578
579         # build the killbysubdir utility
580         echo "Building killbysubdir"
581         echo $compiler -o $builddir/killbysubdir $test_root/killbysubdir.c
582         $compiler -o $builddir/killbysubdir $test_root/killbysubdir.c
583
584         prefix="$test_root/prefix/$tree.$compiler"
585         mkdir -p "$prefix"
586
587         sw_config=$config
588
589         case "$tree" in
590         lorikeet-heimdal)
591                 sw_config="$config --enable-socket-wrapper"
592                 ;;
593         samba_4*)
594                 sw_config="$config --enable-socket-wrapper"
595                 sw_config="$sw_config --enable-nss-wrapper"
596                 sw_config="$sw_config --enable-uid-wrapper"
597                 ;;
598         samba_3*)
599                 sw_config="$config --enable-socket-wrapper"
600                 sw_config="$sw_config --enable-nss-wrapper"
601                 ;;
602         samba-gtk)
603                 PKG_CONFIG_PATH="$test_root/prefix/samba_4_0_test.$compiler/lib/pkgconfig"
604                 export PKG_CONFIG_PATH
605                 ;;
606         *)
607                 testsuite=testsuite
608                 ;;
609         esac
610
611         if [ "$LCOV_REPORT" = "yes" ]; then
612             GCOV_FLAGS="--coverage"
613             CFLAGS="$CFLAGS $GCOV_FLAGS" 
614             LDFLAGS="$LDFLAGS $GCOV_FLAGS" 
615             export CFLAGS LDFLAGS
616         fi
617
618         config_and_prefix="$sw_config --prefix=$prefix"
619
620         # see if we need to rebuild
621         sum_tree $test_root $tree $sum $scm
622         echo "CFLAGS=$CFLAGS $config_and_prefix" >> $sum
623
624         if cmp "$sum" "$sum.old" > /dev/null; then
625                 echo "skip: $tree.$compiler nothing changed"
626                 cd $test_root
627                 send_logs_skip "$log" "$err"
628                 unlock_file "$lck"
629                 echo "Ending build of $tree.$compiler in process $$ at `date`"
630                 return
631         fi
632
633         # we do need to rebuild - save the old sum
634         /bin/rm -f $sum.old
635         mv $sum $sum.old
636
637         actions="$*"
638         
639         if [ "$actions" = "" ]; then
640             actions="configure config_log config_header build install test"
641         fi
642
643         # start the build
644         (
645         {
646                 # we all want to be able to read the output...
647                 LANG=C
648                 export LANG
649
650                 uname -a
651
652                 echo ""
653                 echo "build_test          : $build_test_id"
654                 echo "build_test.fns      : $build_test_fns_id"
655                 echo "local settings file : $build_test_settings_local_file"
656                 echo "local functions file: $build_test_fns_local_file"
657                 echo "used .fns file      : $build_test_used_fns_file"
658                 echo ""
659
660                 # we need to be able to see if a build farm machine is accumulating
661                 # stuck processes. We do this in two ways, as we don't know what style
662                 # of ps it will have
663                 ps xfuw 2> /dev/null
664                 ps -fu $USER 2> /dev/null
665
666                 echo "building $tree with CC=$compiler on $host at "`date`
667                 echo "builddir=$builddir"
668                 echo "prefix=$prefix"
669
670                 echo "Showing limits"
671                 ulimit -a 2> /dev/null
672
673                 # the following is for non-samba builds only
674                 if [ "$scm" = "svn" -a -r $test_root/$tree.svn ]; then
675                   h_rev=`grep 'Revision: ' $test_root/$tree.svn | cut -d ':' -f2 | cut -d ' ' -f2 | sed 1q`
676                   if [ -n "$h_rev" ]; then
677                         echo "HIGHEST SVN REVISION: $h_rev"
678                   fi
679                   rev=`grep 'Last Changed Rev: ' $test_root/$tree.svn | cut -d ':' -f2 | cut -d ' ' -f2 | sed 1q`
680                   if [ -n "$rev" ]; then
681                         echo "BUILD REVISION: $rev"
682                   fi
683                 elif [ "$scm" = "git" -a -r $test_root/$tree.git ]; then
684                   csha1=`cat $test_root/$tree.git |head -3 | tail -1`
685                   if [ -n "$csha1" ]; then
686                     echo "BUILD COMMIT REVISION: $csha1"
687                   fi
688                   cdate=`cat $test_root/$tree.git |head -4 | tail -1`
689                   if [ -n "$cdate" ]; then
690                     echo "BUILD COMMIT DATE: $cdate"
691                   fi
692                   ctime=`cat $test_root/$tree.git |head -2 | tail -1`
693                   if [ -n "$ctime" ]; then
694                     echo "BUILD COMMIT TIME: $ctime"
695                   fi
696                 fi
697
698                 if [ -x $builddir/killbysubdir ]; then
699                     echo "$builddir/killbysubdir $builddir in `pwd`"
700                     $builddir/killbysubdir $builddir
701                 fi
702
703                 for action in $actions; do
704
705                     echo Running action $action
706
707                     date
708
709                     cd $builddir || exit 1
710                     export srcdir
711                     df .
712                     mount
713                     vmstat
714
715                     ( action_$action )
716                     action_status=$?
717
718                     df .
719
720                     if [ $action_status != 0 ]; then
721                         echo "ACTION FAILED: $action";
722                     else
723                         echo "ACTION PASSED: $action";
724                     fi
725                     
726                     if [ $action_status != 0 ]; then 
727                         break;
728                     fi
729
730                 done
731
732                 if [ "$LCOV_REPORT" = "yes" ]; then
733                     case "$tree" in
734                         lorikeet-heimdal*)
735                             lcov --directory $builddir --capture --output-file $builddir/$tree.lcov.info
736                             ;;
737                         samba_3_master*)
738                             lcov --base-directory $builddir --directory $builddir/.. --capture --output-file $builddir/$tree.lcov.info
739                             ;;
740                         samba_4*)
741                             # ugly hack for s4, as lcov is otherwise not able to find 
742                             # these files
743                             rm -f heimdal/lib/*/{lex,parse,sel-lex}.{gcda,gcno}
744                             lcov --base-directory $builddir --directory $builddir/.. --capture --output-file $builddir/$tree.lcov.info
745                             ;;
746                         *)
747                             lcov --base-directory $builddir --directory $builddir --capture --output-file $builddir/$tree.lcov.info
748                             ;;
749                     esac
750                     genhtml -o $builddir/coverage $builddir/$tree.lcov.info
751                 fi
752
753                 if [ "$noclean" = "yes" ]; then
754                     echo cleanup skipped!
755                 else
756                     echo cleaning up
757                     do_make clean
758                 fi
759                 date
760         } 3>&2 2>&1 1>&3 | tee "$err"
761         ) > "$log" 2>&1
762         # be aware the above channel swap may sometimes result in unordered
763         # stdout/stderr merge
764
765         if [ "$LCOV_REPORT" = "yes" ]; then
766             chmod u=rwX,g=rX,o=rX -R $builddir/coverage
767             rsync -rct -q --password-file=.password -z --timeout=200 \
768                 $builddir/coverage/ $host@build.samba.org::lcov_data/$host/$tree/
769         fi
770
771         cd $test_root
772
773         /bin/rm -rf $prefix
774         if [ "$usingtmpbuild" = "1" ]; then
775             if [ "$noclean" = "yes" ]; then
776                 echo builddir cleanup skipped!
777             else
778                 /bin/rm -rf $builddir
779             fi
780         fi
781         # send the logs to the master site
782         send_logs "$log" "$err"
783
784         # cleanup
785         echo "Ending build of $tree.$compiler in process $$ at `date`"
786         unlock_file "$lck"
787 }
788
789 #########################################################
790 # if you want to build only one project at a time
791 # add 'global_lock' after 'per_run_hook' and
792 # 'global_unlock' to the end of the file
793 global_lock() {
794     lock_file "global.lck" || {
795         exit 0
796     }
797 }
798 global_unlock() {
799     unlock_file "global.lck"
800 }
801
802 delete_old_tree() {
803         otree=$1
804
805         test -z "$otree" && return 0;
806
807         rm -rf $otree
808         rm -rf $otree.svn
809         rm -rf $otree.*.svn
810         rm -rf $otree.git
811         rm -rf $otree.*.git
812         rm -rf build.$otree.*
813 }
814
815 # this is a special fn that allows us to add a "special" hook to the build
816 # farm that we want to do to the build farm. never leave it empty. instead,
817 # use ":" as the fn body.
818 per_run_hook() {
819     # kill old processes on systems with a known problem
820     case $host in
821         nohost)
822             echo "just a placeholder";
823             ;;
824         deckchair)
825             rm -f deckchair.fns
826             ;;
827     esac
828     # trim the log if too large
829     if [ "`wc -c < build.log`" -gt 2000000 ]; then
830         rm -f build.log
831     fi
832
833     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"
834     for d in old_trees; do
835         delete_old_tree $d
836     done
837 }
838
839
840 ######################################################
841 # main code that is run on each call to the build code
842 rsync --timeout=200 -q -az build.samba.org::build_farm/*.c .
843
844
845 # build.log can grow to an excessive size, trim it beyond 50M
846 if [ -f build.log ]; then
847   find build.log -size +100000 -exec /bin/rm '{}' \;
848 fi
849