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