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