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