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