build: allow samba process to run more longer
[amitay/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=25200 # 7 hours
11 SMBD_MAXTIME=18000 # 5 hours for a samba process ..
12 # default maximum memory size (100M) for any command
13 MAXMEM=100000
14 RUN_FROM_BUILD_FARM=yes
15 export RUN_FROM_BUILD_FARM
16
17 deptrees="";
18
19 build_test_fns_id='$Id$'
20
21 copy_dir() {
22         Tsrc=$1
23         Tdst=$2
24         pwd
25         echo rsync -a --delete $Tsrc/ $Tdst
26         rsync -a --delete $Tsrc/ $Tdst || return 1
27         return 0
28 }
29
30 #############################
31 # build a signature of a tree, used to see if we
32 # need to rebuild 
33 #############################
34
35 sum_tree() {
36         sum_tree_test_root=$1
37         sum_tree_tree=$2
38         sum_tree_sum=$3
39         sum_tree_scm=$4
40         find $sum_tree_test_root/$sum_tree_tree -type f -print | grep -v version.h | sort | xargs sum > $sum_tree_sum
41         sum build_test build_test.fns >> $sum_tree_sum
42
43         if [ -f "$host.fns" ]; then
44                 sum $host.fns >> $sum_tree_sum
45         else
46                 sum generic.fns >> $sum_tree_sum
47         fi
48
49         if [ -f "$test_root/$tree.$scm" ]; then
50                 sum "$test_root/$tree.$scm" >> $sum_tree_sum
51         fi
52
53         for d in $deptrees; do
54                 dscm=`choose_scm "$d"`
55                 if [ -f "$test_root/$d.$dscm" ]; then
56                 sum "$test_root/$d.$dscm" >> $sum_tree_sum
57                 fi
58         done
59 }
60
61 #############################
62 # send the logs to the master site
63 #############################
64
65 send_logs() {
66         if [ "$nologreturn" = "yes" ]; then
67                 echo "skipping log transfer"
68         else
69                 log="$1"
70                 err="$2"
71                 shift
72                 shift
73                 chmod 0644 "$log" "$err"
74
75                 # xargs -i is implemented differently or not at all.
76                 # GNU xargs did not implement "-I" until 4.2.9:
77                 xargs --version 2>&1 | grep "^GNU xargs" > /dev/null
78                 status=$?
79                 if [ x"$status" = x"0" ]; then
80                         XARGS_IS_GNU=yes
81                 fi
82
83                 if [ x"$XARGS_IS_GNU" = x"yes" ]; then
84                         XARGS_I="xargs -i"
85                 else
86                         XARGS_I="xargs -I '{}'"
87                 fi
88
89                 find $log -size +40000 | $XARGS_I sh -c 'dd if={} bs=1024 count=20000 of={}.tmp && mv {}.tmp {} &&  echo "\n***LOG TRUNCATED***" >> {}'
90                 find $err -size +40000 | $XARGS_I sh -c 'dd if={} bs=1024 count=20000 of={}.tmp && mv {}.tmp {} &&  echo "\n***LOG TRUNCATED***" >> {}'
91
92                 rsync $* -c -q --password-file=.password -z --timeout=200 \
93                         "$log" "$err" $host@build.samba.org::build_farm_data/
94         fi
95 }
96
97 #############################
98 # send the logs when they haven't changed
99 # the aim is to just update the servers timestamp.
100 # sending with a very large rsync block size does this
101 # with minimal network traffic
102 #############################
103
104 send_logs_skip() {
105         touch "$1" "$2"
106         send_logs "$1" "$2" -B 10000000
107 }
108
109 ############################
110 # fetch the latest copy of the tree
111 ############################
112
113 fetch_tree() {
114         if [ "$norsync" = "yes" ]; then
115                 echo "skipping tree transfer"
116         else
117                 fetchtree=$1
118                 if rsync --exclude=autom4te.cache/ --exclude=.svn/ --exclude=.git/ \
119                         --delete-excluded -q --partial --timeout=200 -ctrlpz --delete --ignore-errors \
120                         samba.org::ftp/unpacked/$fetchtree/ $test_root/$fetchtree; then
121                         echo "transferred $fetchtree OK"
122                 else
123                         echo "transfer of $fetchtree failed code $?"
124                         return 1
125                 fi
126         fi
127         return 0
128 }
129
130 ############################
131 # fetch the latest copy of the rev meta info
132 ############################
133
134 fetch_revinfo() {
135         tree=$1
136         scm=$2
137
138         test -z "$scm" && return 1
139         test x"$scm" = x"unknown" && return 1
140         test x"$scm" = x"cvs" && return 1
141
142         if [ "$norsync" = "yes" ]; then
143                 echo "skipping .revinfo.$scm transfer"
144         else
145                 if [ -r $test_root/$tree.$scm ]; then
146                         [ -f $test_root/$tree.$scm.old ] && rm -f $test_root/$tree.$scm.old
147                         [ -f $test_root/$tree.$scm ] && mv $test_root/$tree.$scm $test_root/$tree.$scm.old
148                 fi
149                 rsync -q --timeout=200 -clz --ignore-errors \
150                         samba.org::ftp/unpacked/$tree/.revinfo.$scm $test_root/$tree.$scm
151         fi
152         if [ -r $test_root/$tree.$scm ]; then
153                 return 0;
154         fi
155         return 1
156 }
157
158 ############################
159 # choose the scm that is used for the given project
160 ############################
161
162 choose_scm() {
163         tree=$1
164
165         case "$tree" in
166                         samba* | rsync | libreplace | talloc | tdb | ldb | pidl | ccache*)
167                         echo "git"
168                                 return 0
169                         ;;
170         esac
171
172         echo "svn"
173         return 0
174 }
175
176 locknesting=0
177
178 ############################
179 # grab a lock file. Not atomic, but close :)
180 # tries to cope with NFS
181 ############################
182
183 lock_file() {
184                 if [ -z "$lock_root" ]; then
185                         lock_root=`pwd`;
186                 fi
187
188                 lckf="$lock_root/$1"
189                 machine=`cat "$lckf" 2> /dev/null | cut -d: -f1`
190                 pid=`cat "$lckf" 2> /dev/null | cut -d: -f2`
191
192                 if [ "$pid" = "$$" ]; then
193                         locknesting=`expr $locknesting + 1`
194                         echo "lock nesting now $locknesting"
195                         return 0
196                 fi
197
198                 if test -f "$lckf"; then
199                         test $machine = $host || {
200                                 echo "lock file $lckf is valid for other machine $machine"
201                                 return 1
202                         }
203
204                         kill -0 $pid && {
205                                 echo "lock file $lckf is valid for process $pid"
206                                 return 1
207                         }
208
209                         echo "stale lock file $lckf for $machine:$pid"
210                         cat "$lckf"
211                         /bin/rm -f "$lckf"
212                 fi
213                 echo "$host:$$" > "$lckf"
214                 return 0
215 }
216
217 ############################
218 # unlock a lock file
219 ############################
220
221 unlock_file() {
222         if [ -z "$lock_root" ]; then
223                 lock_root=`pwd`;
224         fi
225         if [ "$locknesting" != "0" ]; then
226                 locknesting=`expr $locknesting - 1`
227                 echo "lock nesting now $locknesting"
228         else 
229                 lckf="$lock_root/$1"
230                 /bin/rm -f "$lckf"
231         fi
232 }
233
234 ############################
235 # run make, and print trace
236 ############################
237
238 do_make() {
239         if [ x"$MAKE" = x ]; then
240                 MAKE=make
241         fi
242
243         MMTIME=$MAXTIME
244         # some trees don't need as much time
245         case "$tree" in
246                 rsync | tdb | talloc | libreplace | ccache*)
247                         if [ "$compiler" != "checker" ]; then
248                                 MMTIME=`expr $MMTIME / 5`
249                         fi
250                 ;;
251         esac
252
253
254         for t in $*; do
255                 if [ x"$BUILD_FARM_NUM_JOBS" = x ]; then
256                         echo "$MAKE $t"
257                         $builddir/timelimit $MMTIME "$MAKE" "$t"
258                         status=$?
259                 else
260                         # we can parallelize everything and all targets
261                         if [ x"$t" = xeverything ] || [ x"$t" = xall]; then
262                                 echo "$MAKE" "-j$BUILD_FARM_NUM_JOBS"  "$t"
263                                 $builddir/timelimit $MMTIME "$MAKE" "-j$BUILD_FARM_NUM_JOBS"  "$t"
264                                 status=$?
265                         else
266                                 echo "$MAKE $t"
267                                 $builddir/timelimit $MMTIME "$MAKE" "$t"
268                                 status=$?
269                         fi
270                 fi
271
272                 if [ $status != 0 ]; then
273                         case "$t" in
274                                 test|check|installcheck)
275                                         ;;
276                                 *)
277                                         #run again with V=1, so we see failed commands
278                                         $builddir/timelimit $MMTIME "$MAKE" "$t" V=1
279                                         status=$?
280                                         ;;
281                         esac
282                 fi
283
284                 if [ $status != 0 ]; then
285                         return $status;
286                 fi
287
288         done
289
290         return 0
291 }
292
293
294 ############################
295 # do the coverage report
296 ############################
297
298 action_lcovreport() {
299         if [ "$LCOV_REPORT" = "yes" ]; then
300                 case "$tree" in
301                 lorikeet-heimdal*)
302                         lcov --directory $builddir --capture --output-file $builddir/$tree.lcov.info
303                         ;;
304                 samba_3_master*)
305                         lcov --base-directory $builddir --directory $builddir/.. --capture --output-file $builddir/$tree.lcov.info
306                         ;;
307                 samba_4*)
308                         # rm -f heimdal/lib/*/{lex,parse,sel-lex}.{gcda,gcno}
309                         lcov --base-directory $builddir --directory $builddir/.. --capture --output-file $builddir/$tree.lcov.info
310                         ;;
311                 *)
312                         lcov --base-directory $builddir --directory $builddir --capture --output-file $builddir/$tree.lcov.info
313                         ;;
314                 esac
315                 genhtml -o $builddir/coverage $builddir/$tree.lcov.info
316                 rc=$?
317                 echo "return code: $rc"
318         else
319                 echo "LCOV_REPORT not set and lcovreport asked"
320                 echo "Most probably an error please fix !"
321                 return 1
322         fi
323 }
324
325
326 ############################
327 # configure the tree
328 ############################
329
330 action_configure() {
331
332         if [ ! -x $srcdir/configure -a -r $srcdir/Makefile.PL ]; then
333                 perl $srcdir/Makefile.PL PREFIX="$prefix"
334                 cstatus=$?
335                 echo "CONFIGURE STATUS: $cstatus"
336                 return $cstatus;
337         fi
338
339         if [ ! -x $srcdir/configure ]; then
340                 ls -l $srcdir/configure
341                 echo "$srcdir/configure is missing"
342                 cstatus=255
343                 echo "CONFIGURE STATUS: $cstatus"
344                 return $cstatus;
345         fi
346
347         echo "CFLAGS=$CFLAGS"
348         echo configure options: $config_and_prefix
349         echo CC="$CCACHE $compiler" $srcdir/configure $config_and_prefix
350
351         CC="$CCACHE $compiler"
352         export CC
353         $builddir/timelimit $MAXTIME $srcdir/configure $config_and_prefix
354         cstatus=$?
355
356         if [ x"$cstatus" != x"0" ]; then
357                 if [ -f config.log ]; then
358                         echo "contents of config.log:"
359                         cat config.log
360                 fi
361
362                 # Waf style
363                 if [ -f bin/config.log ]; then
364                         echo "contents of config.log:"
365                         cat bin/config.log
366                 fi
367         fi
368         echo "CONFIGURE STATUS: $cstatus"
369         return $cstatus
370 }
371
372 ############################
373 # show the configure log
374 ############################
375
376 action_config_log() {
377
378         log_files="config.log bin/config.log"
379         for f in $log_files; do
380                 if [ -f $f ]; then
381                         echo "contents of config.log:"
382                         cat $f
383                         return 0
384                 fi
385         done
386         return 0
387 }
388
389 ############################
390 # show the config.h
391 ############################
392
393 action_config_header() {
394         hdr_files="config.h include/config.h bin/default/config.h bin/default/source4/include/config.h bin/default/source3/include/config.h"
395         for h in $hdr_files; do
396                 if [ -f $h ]; then
397                         echo "contents of $h:"
398                         cat $h
399                         return 0
400                 fi
401         done
402
403         return 0
404 }
405
406
407
408 ############################
409 # build the tree
410 ############################
411 action_build() {
412         case "$tree" in
413         samba_4*)
414                 do_make everything
415                 bstatus=$?
416                 ;;
417         samba_3*)
418                 do_make everything torture
419                 bstatus=$?
420                 ;;
421         *)
422                 do_make all
423                 bstatus=$?
424                 ;;
425         esac
426
427         echo "BUILD STATUS: $bstatus"
428
429         return $bstatus
430 }
431
432 ############################
433 # show static analysis results
434 ############################
435
436 action_cc_checker() {
437
438         # default to passing the cc_checker
439         cccstatus=0
440
441         if [ -f ibm_checker.out ]; then
442                 cat ibm_checker.out
443                 cccstatus=`cat ibm_checker.out | grep '^\-\- ' | wc -l`
444         fi
445
446         echo "CC_CHECKER STATUS: $cccstatus"
447         return $cccstatus;      
448 }
449
450 ############################
451 # install the tree
452 ############################
453
454 action_install() {
455         if [ -d $prefix ]; then
456                 if [ "$noclean" != "yes" ]; then
457                         rm -rf $prefix
458                 fi
459         fi
460
461         do_make install
462         istatus=$?
463         echo "INSTALL STATUS: $istatus"
464         return $istatus;
465 }
466
467 ############################
468 # test the tree
469 action_test_samba() {
470         do_make test
471         totalstatus=$?
472
473         # if we produced a test summary then show it
474         [ -f st/summary ] && {
475                 echo "TEST SUMMARY"
476                 cat st/summary
477         }
478
479         return "$totalstatus"
480 }
481
482 action_test_generic() {
483         CC="$compiler"
484         export CC
485         do_make installcheck
486         totalstatus=$?
487         echo "TEST STATUS: $totalstatus"
488         return "$totalstatus"
489 }
490
491 action_test_lorikeet_heimdal() {
492         CC="$compiler"
493         export CC
494         SOCKET_WRAPPER_DIR=`pwd`/sw
495         mkdir $SOCKET_WRAPPER_DIR
496         export SOCKET_WRAPPER_DIR
497         do_make check
498         totalstatus=$?
499         SOCKET_WRAPPER_DIR=
500         export SOCKET_WRAPPER_DIR
501         echo "TEST STATUS: $totalstatus"
502         return "$totalstatus"
503 }
504
505
506 #############################
507 # attempt some basic tests of functionaility
508 # starting as basic as possible, and getting incresingly complex
509 #############################
510
511 action_test() {
512         # Samba needs crufty code of its own for backward
513         # compatiblity.  I think a better way to do this in the future
514         # is to just call 'make installcheck'.
515         case "$tree" in
516         samba*|smb-build|pidl)
517                 action_test_samba
518                 ;;
519         lorikeet-heimdal*)
520                 action_test_lorikeet_heimdal
521                 ;;
522         *)
523                 action_test_generic
524                 ;;
525         esac
526 }
527
528 ###########################
529 # do a test build of a particular tree
530 # This is the master function called by generic.fns or
531 # host.fns
532 ###########################
533
534 test_tree() {
535         tree=$1
536         source=$2
537         compiler="$3"
538         shift
539         shift
540         shift
541         echo "Starting to deal with tree $tree with compiler $compiler"
542         if [ "$compiler" = "gcc" ] && [ "$tree" != "ccache" ] && [ "$tree" != "ccache-maint" ] && ccache -V > /dev/null 2>/dev/null; then
543                 CCACHE="ccache"
544                 export CCACHE
545         else
546                 CCACHE=""
547         fi
548
549         # limit our resource usage
550         ulimit -t $MAXTIME 2> /dev/null
551
552         # max mem size 100M
553         ulimit -m $MAXMEM 2> /dev/null
554
555         # max file size 100M
556         # darn, this affects sparse files too! disable it
557         # ulimit -f 100000 2> /dev/null
558
559         # try and limit the number of open files to 250. That means we'll discover
560         # fd leaks faster
561         ulimit -n 250 2> /dev/null
562
563         # Keep stuff private
564         umask 077
565
566         if [ -z "$test_root" ]; then
567                 test_root=`pwd`
568         fi
569
570         log="build.$tree.$host.$compiler.log"
571         err="build.$tree.$host.$compiler.err"
572         sum="build.$tree.$host.$compiler.sum"
573         lck="build.$tree.lck"
574                 srcdir="$test_root/$tree/$source"
575
576         lock_file "$lck" || {
577                 return
578         }
579
580         # work out what other trees this package depends on
581         deptrees=""
582         case "$tree" in
583                 samba-gtk)
584                 deptrees="samba_4_0_test"
585                 ;;
586         esac
587
588         scm=`choose_scm "$tree"`
589
590         # pull the entries, if any
591         # Remove old .svn or .git files
592         # Move the current .svn org .git to .svn.old or
593         # .git.old then fetch the new from rsync
594         if fetch_revinfo "$tree" "$scm"; then
595                 for d in $deptrees; do
596                         # If there is dependency substree(s) we add info
597                         # from the dependency tree so that we
598                         # can rebuild in case one of them has changed
599                         dscm=`choose_scm "$d"`
600                         if [ -f "$test_root/$d.$dscm" ]; then
601                                 if [ "$d" != "$tree" ]; then
602                                         cat "$test_root/$d.$dscm" >> $test_root/$tree.$scm
603                                 fi
604                         fi
605                 done
606                 [ -f $test_root/$tree.$compiler.$scm.old ] && rm -f $test_root/$tree.$compiler.$scm.old
607                 [ -f $test_root/$tree.$compiler.$scm ] && mv $test_root/$tree.$compiler.$scm $test_root/$tree.$compiler.$scm.old
608                 [ -f $test_root/$tree.$scm ] && cp $test_root/$tree.$scm $test_root/$tree.$compiler.$scm
609
610                 if [ -f $test_root/$tree.$compiler.$scm.old ] && \
611                                 cmp $test_root/$tree.$compiler.$scm $test_root/$tree.$compiler.$scm.old > /dev/null; then
612
613                         echo "skip: $tree.$compiler nothing changed in $scm"
614                         cd $test_root
615                         send_logs_skip "$log" "$err"
616                         unlock_file "$lck"
617                         return
618                 fi
619         fi
620
621         # pull the tree
622         fetch_tree "$tree" || {
623                 cd $test_root
624                 unlock_file "$lck"
625                 return
626         }
627
628         if [ ! -x $srcdir/configure ] && [ "$tree" != "pidl" ]; then
629                 echo "skip: $tree.$compiler configure not present, try again next time!"
630                 cd $test_root
631                 unlock_file "$lck"
632                 return
633         fi
634
635         echo "Starting build of $tree.$compiler in process $$ at `date`"
636
637
638         # Parameters for the build depending on the tree
639         case "$tree" in
640                 libreplace)
641                         builddir="$test_root/tmp.$tree.$compiler"
642                         usingtmpbuild=1
643                         if [ -d $builddir ]; then
644                                 rm -rf $builddir
645                         fi
646                         mkdir -p $builddir
647                         export builddir
648                         ;;
649                 *)
650                         builddir=$srcdir
651                         usingtmpbuild=0
652                         export builddir
653                         ;;
654         esac
655
656         #Fix the user
657         if [ ! x$USER = x"" ]; then
658                 whoami=$USER
659         else 
660                 if [ ! x$LOGNAME = x"" ]; then
661                         whoami=$LOGNAME
662                 else
663                         whoami=build
664                 fi
665         fi
666
667         # build the timelimit utility
668         echo "Building timelimit"
669         mkdir -p $builddir
670         echo $compiler $TIMELIMIT_FLAGS -o $builddir/timelimit $test_root/timelimit.c
671         $compiler $TIMELIMIT_FLAGS -o $builddir/timelimit $test_root/timelimit.c || exit 1
672
673         # build the killbysubdir utility
674         echo "Building killbysubdir"
675         echo $compiler -o $builddir/killbysubdir $test_root/killbysubdir.c
676         $compiler -o $builddir/killbysubdir $test_root/killbysubdir.c
677
678         prefix="$test_root/prefix/$tree.$compiler"
679         mkdir -p "$prefix"
680
681         # This can be defined in <host>.fns files
682         sw_config=$config
683
684         case "$tree" in
685         lorikeet-heimdal)
686                 sw_config="$config --enable-socket-wrapper"
687                 ;;
688         samba_4*)
689                 sw_config="$config --enable-socket-wrapper"
690                 sw_config="$sw_config --enable-nss-wrapper"
691                 sw_config="$sw_config --enable-uid-wrapper"
692                 ;;
693         samba_3*)
694                 sw_config="$config --enable-socket-wrapper"
695                 sw_config="$sw_config --enable-nss-wrapper"
696                 ;;
697         samba-gtk)
698                 PKG_CONFIG_PATH="$test_root/prefix/samba_4_0_test.$compiler/lib/pkgconfig"
699                 export PKG_CONFIG_PATH
700                 ;;
701         *)
702                 testsuite=testsuite
703                 ;;
704         esac
705
706         if [ "$LCOV_REPORT" = "yes" ]; then
707                 GCOV_FLAGS="--coverage"
708                 CFLAGS="$CFLAGS $GCOV_FLAGS" 
709                 LDFLAGS="$LDFLAGS $GCOV_FLAGS" 
710                 export CFLAGS LDFLAGS
711         fi
712
713         config_and_prefix="$sw_config --prefix=$prefix"
714
715         # see if we need to rebuild
716         sum_tree $test_root $tree $sum $scm
717         echo "CFLAGS=$CFLAGS $config_and_prefix" >> $sum
718
719         if [ -f "$sum.old" ] && cmp "$sum" "$sum.old" > /dev/null; then
720                 echo "skip: $tree.$compiler nothing changed"
721                 cd $test_root
722                 send_logs_skip "$log" "$err"
723                 unlock_file "$lck"
724                 echo "Ending build of $tree.$compiler in process $$ at `date`"
725                 return
726         fi
727
728         # we do need to rebuild - save the old sum
729         [ -f $sum.old ] && /bin/rm -f $sum.old
730         mv $sum $sum.old
731
732         #Action == what to do ie. configure config_log ...
733         actions="$*"
734
735         if [ "$actions" = "" ]; then
736                 actions="configure config_log config_header build install test"
737         fi
738
739         # start the build
740         (
741         {
742                 # we all want to be able to read the output...
743                 LANG=C
744                 export LANG
745
746                 uname -a
747
748                 echo ""
749                 echo "build_test                  : $build_test_id"
750                 echo "build_test.fns      : $build_test_fns_id"
751                 echo "local settings file : $build_test_settings_local_file"
752                 echo "local functions file: $build_test_fns_local_file"
753                 echo "used .fns file      : $build_test_used_fns_file"
754                 echo ""
755
756                 # we need to be able to see if a build farm machine is accumulating
757                 # stuck processes. We do this in two ways, as we don't know what style
758                 # of ps it will have
759                 ps xfuw 2> /dev/null
760                 ps -fu $USER 2> /dev/null
761
762                 echo "building $tree with CC=$compiler on $host at "`date`
763                 echo "builddir=$builddir"
764                 echo "prefix=$prefix"
765
766                 echo "Showing limits"
767                 ulimit -a 2> /dev/null
768
769                 # the following is for non-samba builds only
770                 if [ "$scm" = "svn" -a -r $test_root/$tree.svn ]; then
771                         h_rev=`grep 'Revision: ' $test_root/$tree.svn | cut -d ':' -f2 | cut -d ' ' -f2 | sed 1q`
772                         if [ -n "$h_rev" ]; then
773                                 echo "HIGHEST SVN REVISION: $h_rev"
774                         fi
775                         rev=`grep 'Last Changed Rev: ' $test_root/$tree.svn | cut -d ':' -f2 | cut -d ' ' -f2 | sed 1q`
776                         if [ -n "$rev" ]; then
777                         echo "BUILD REVISION: $rev"
778                         fi
779                 elif [ "$scm" = "git" -a -r $test_root/$tree.git ]; then
780                         csha1=`cat $test_root/$tree.git |head -3 | tail -1`
781                         if [ -n "$csha1" ]; then
782                                 echo "BUILD COMMIT REVISION: $csha1"
783                         fi
784                         cdate=`cat $test_root/$tree.git |head -4 | tail -1`
785                         if [ -n "$cdate" ]; then
786                                 echo "BUILD COMMIT DATE: $cdate"
787                         fi
788                         ctime=`cat $test_root/$tree.git |head -2 | tail -1`
789                         if [ -n "$ctime" ]; then
790                                 echo "BUILD COMMIT TIME: $ctime"
791                   fi
792                 fi
793
794                 if [ -x $builddir/killbysubdir ]; then
795                         echo "$builddir/killbysubdir $builddir in `pwd`"
796                         $builddir/killbysubdir $builddir
797                 fi
798
799                 for action in $actions; do
800
801                         echo Running action $action
802
803                         date
804
805                         cd $builddir || exit 1
806                         export srcdir
807                         df .
808                         mount
809                         vmstat
810
811                         if [ "x$PREHOOKS" != "x" ]; then
812                                 for hooks in $PREHOOKS; do
813                                         if [ "x$hooks" = "x$action" ]; then
814                                                 ( prehook_$action )
815                                         fi
816                                 done
817                         fi
818
819                         ( action_$action )
820                         action_status=$?
821
822                         if [ "x$POSTHOOKS" != "x" ]; then
823                                 for hooks in $POSTHOOKS; do
824                                         if [ "x$hooks" = "x$action" ]; then
825                                                 ( posthook_$action )
826                                         fi
827                                 done
828                         fi
829
830                         df .
831
832                         if [ $action_status != 0 ]; then
833                                 echo "ACTION FAILED: $action";
834                                 echo " return code $action_status $action";
835                         else
836                                 echo "ACTION PASSED: $action";
837                         fi
838
839                         if [ $action_status != 0 ]; then 
840                                 break;
841                         fi
842                 done
843
844
845                 if [ "$noclean" = "yes" ]; then
846                         echo cleanup skipped!
847                 else
848                         echo cleaning up
849                         do_make clean
850                 fi
851                 date
852         } 3>&2 2>&1 1>&3 | tee "$err"
853         ) > "$log" 2>&1
854         # be aware the above channel swap may sometimes result in unordered
855         # stdout/stderr merge
856
857         if [ "$LCOV_REPORT" = "yes" ]; then
858                 chmod u=rwX,g=rX,o=rX -R $builddir/coverage
859                 rsync -rct -q --password-file=.password -z --timeout=200 \
860                         $builddir/coverage/ $host@build.samba.org::lcov_data/$host/$tree/
861         fi
862
863         cd $test_root
864
865         /bin/rm -rf $prefix
866         if [ "$usingtmpbuild" = "1" ]; then
867                 if [ "$noclean" = "yes" ]; then
868                         echo builddir cleanup skipped!
869                 else
870                         /bin/rm -rf $builddir
871                 fi
872         fi
873         # send the logs to the master site
874         send_logs "$log" "$err"
875
876         # cleanup
877         echo "Ending build of $tree.$compiler in process $$ at `date`"
878         unlock_file "$lck"
879 }
880
881 #########################################################
882 # if you want to build only one project at a time
883 # add 'global_lock' after 'per_run_hook' and
884 # 'global_unlock' to the end of the file
885 #########################################################
886
887 global_lock() {
888         lock_file "global.lck" || {
889                 exit 0
890         }
891 }
892
893 global_unlock() {
894         unlock_file "global.lck"
895 }
896
897 delete_old_tree() {
898         otree=$1
899         test -z "$otree" && return 0;
900
901         rm -rf $otree
902         rm -rf $otree.svn
903         rm -rf $otree.*.svn
904         rm -rf $otree.git
905         rm -rf $otree.*.git
906         rm -rf build.$otree.*
907 }
908
909 # this is a special fn that allows us to add a "special" hook to the build
910 # farm that we want to do to the build farm. never leave it empty. instead,
911 # use ":" as the fn body.
912 per_run_hook() {
913         # kill old processes on systems with a known problem
914         case $host in
915         nohost)
916                 echo "just a placeholder";
917                 ;;
918         deckchair)
919                 rm -f deckchair.fns
920                 ;;
921         esac
922
923         # trim the log if too large
924         if [ "`wc -c < build.log`" -gt 2000000 ]; then
925         rm -f build.log
926         fi
927
928         old_trees="web popt distcc samba-gtk smb-build lorikeet-heimdal samba_3_2"
929         old_trees="$old_tree samba_3_2_test samba4 samba_4_0_waf samba_4_0_waf.metze"
930         old_trees="$old_tree samba_3_X_test samba_3_X_devel samba_3_X_devel"
931         for d in $old_trees; do
932                 delete_old_tree $d
933         done
934 }
935
936
937 ######################################################
938 # main code that is run on each call to the build code
939 ######################################################
940 rsync --timeout=200 -q -az build.samba.org::build_farm/*.c .
941
942
943 # build.log can grow to an excessive size, trim it beyond 50M
944 if [ -f build.log ]; then
945         find build.log -size +100000 -exec /bin/rm '{}' \;
946 fi