5 Copyright (c) 2003-2010, Andrew Dunstan
7 See accompanying License file for license details
11 ####################################################
15 NAME: run_build - script to run exim buildfarm
19 run_build [option ...] [branchname]
21 AUTHOR: Andrew Dunstan
25 See http://wiki.exim.org/wiki/PostgreSQL_Buildfarm_Howto
29 https://github.com/EximBuildFarm/client-code
33 ###################################################
35 our $VERSION = 'REL_0.1';
40 use Fcntl qw(:flock :seek);
48 use POSIX qw(:signal_h strftime);
50 use Cwd qw(abs_path getcwd);
53 # save a copy of the original enviroment for reporting
54 # save it early to reduce the risk of prior mangling
55 use vars qw($orig_env);
60 while (my ($k,$v) = each %ENV)
63 # report all the keys but only values for whitelisted settings
64 # this is to stop leaking of things like passwords
67 $k =~ /^PG(?!PASSWORD)|MAKE|CC|CPP|FLAG|LIBRAR|INCLUDE/
68 ||$k =~/^(HOME|LOGNAME|USER|PATH|SHELL)$/
77 use EximBuild::Options;
78 use EximBuild::WebTxn;
80 if ($0 =~ /(.*)\.pl$/) {
81 die "$0: Please use `@{[join ' ' => $1, @ARGV]}' instead.\n"
86 die "$0: please use an umask of 022\n"
90 my $orig_dir = getcwd();
93 # make sure we exit nicely on any normal interrupt
94 # so the cleanup handler gets called.
95 # that lets us stop the db if it's running and
96 # remove the inst and exim directories
97 # so the next run can start clean.
99 foreach my $sig (qw(INT TERM HUP QUIT))
101 $SIG{$sig}=\&interrupt_exit;
104 # copy command line before processing - so we can later report it
107 my @invocation_args = (@ARGV);
109 # process the command line
110 EximBuild::Options::fetch_options();
112 die "only one of --from-source and --from-source-clean allowed"
113 if ($from_source && $from_source_clean);
115 die "only one of --skip-steps and --only-steps allowed"
116 if ($skip_steps && $only_steps);
118 $verbose=1 if (defined($verbose) && $verbose==0);
119 $verbose ||= 0; # stop complaints about undefined var in numeric comparison
123 $verbose=1 unless $verbose;
130 use vars qw(%skip_steps %only_steps);
132 if ($skip_steps =~ /\S/)
134 %skip_steps = map {$_ => 1} split(/\s+/,$skip_steps);
137 if ($only_steps =~ /\S/)
139 %only_steps = map {$_ => 1} split(/(\s+|[:,])/,$only_steps);
142 # Currently only specifying a branch is actually used.
143 # Specifying a different repo is just a wishlist item .
144 use vars qw($branch $repo);
145 my ($arg1,$arg2) = (shift,shift);
146 $branch = $arg2 ? $arg2 :
149 $repo = $arg2 ? $arg1 : 'exim';
150 my $explicit_branch = $branch;
152 print_help() if ($help);
155 # process config file
159 #die Dumper \%EximBuild::conf;
162 die "$0: need read/write permissions on '$EximBuild::conf{global_lock_dir}': $!\n"
163 if not -r -w $EximBuild::conf{global_lock_dir};
165 # Does not seem to be necessary
166 #die "$0: permissions on '$EximBuild::conf{build_root}' should be >= 0775\n"
167 # if -d $EximBuild::conf{build_root}
168 # and ((stat $EximBuild::conf{build_root})[2] & 0775) != 0775;
171 # get the config data into some local variables
173 $buildroot,$target,$animal, $print_success,
174 $aux_path,$trigger_exclude,$trigger_include,$secret,
175 $keep_errs,$force_every, $make, $optional_steps,
176 $use_vpath,$tar_log_cmd, $using_msvc, $extra_config,
177 $make_jobs, $core_file_glob
180 qw(build_root target animal print_success aux_path trigger_exclude
181 trigger_include secret keep_error_builds force_every make optional_steps
182 use_vpath tar_log_cmd using_msvc extra_config make_jobs core_file_glob)
185 #default is no parallel build
188 # default core file pattern is Linux, which used to be hardcoded
189 $core_file_glob ||= 'core*';
192 if (defined($EximBuild::conf{trigger_filter}))
194 $trigger_exclude = $EximBuild::conf{trigger_filter};
197 my $scm_timeout_secs = $EximBuild::conf{scm_timeout_secs}
198 || $EximBuild::conf{cvs_timeout_secs};
200 print scalar(localtime()),": buildfarm run for $animal:$branch starting\n"
203 # Allow commandline overrides of conf variables
204 foreach my $arg ( @{$EximBuild::Options::overrides} )
206 if (my ($key,$val) = split '=', $arg)
208 $EximBuild::conf{$key} = $val;
209 printf "Commandline override: '$key' = '%s'\n", $EximBuild::conf{$key}
214 if (ref($force_every) eq 'HASH')
216 $force_every = $force_every->{$branch} || $force_every->{default};
219 my $scm = new EximBuild::SCM \%EximBuild::conf;
223 if (exists $EximBuild::conf{base_port})
225 $buildport = $EximBuild::conf{base_port};
226 if ($branch =~ /REL(\d+)_(\d+)/)
228 $buildport += (10 * ($1 - 7)) + $2;
234 # support for legacy config style
235 $buildport = $EximBuild::conf{branch_ports}->{$branch} || 5999;
238 $ENV{EXTRA_REGRESS_OPTS} = "--port=$buildport";
240 $tar_log_cmd ||= "tar -z -cf runlogs.tgz *.log";
242 my $logdirname = "lastrun-logs";
244 if ($from_source || $from_source_clean)
246 $from_source ||= $from_source_clean;
247 die "sourceroot $from_source not absolute"
248 unless $from_source =~ m!^/!;
250 # we need to know where the lock should go, so unless the path
251 # contains HEAD we require it to be specified.
252 die "must specify branch explicitly with from_source"
253 unless ($explicit_branch || $from_source =~ m!/HEAD/!);
258 $logdirname = "fromsource-logs";
262 if ($branch eq 'HEAD' || $branch ge 'REL8_4')
265 # non-C locales are not regression-safe before 8.4
266 @locales = @{$EximBuild::conf{locales}} if exists $EximBuild::conf{locales};
268 unshift(@locales,'C') unless grep {$_ eq "C"} @locales;
271 # several people have run into these
273 if ( `uname -s 2>&1 ` =~ /CYGWIN/i )
275 my @procs = `ps -ef`;
276 die "cygserver not running" unless(grep {/cygserver/} @procs);
279 if ( $ccachedir = $EximBuild::conf{build_env}->{CCACHE_DIR} )
282 # ccache is smart enough to create what you tell it is the cache dir, but
283 # not smart enough to build the whole path. mkpath croaks on error, so
287 $ccachedir = abs_path($ccachedir);
292 die "no aux_path in config file" unless $aux_path;
295 die "cannot run as root/Administrator" unless ($using_msvc or $> > 0);
297 my $devnull = $using_msvc ? "nul" : "/dev/null";
301 $scm->check_access($using_msvc);
304 my $st_prefix = "$animal.";
306 my $exim = $from_source || $scm->get_build_path($use_vpath);
308 # set environment from config
309 while (my ($envkey,$envval) = each %{$EximBuild::conf{build_env}})
311 $ENV{$envkey}=$envval;
314 # change to buildroot for this branch or die
315 die "no buildroot" unless $buildroot;
317 unless ($buildroot =~ m!^/!
318 or($using_msvc and $buildroot =~ m![a-z]:[/\\]!i ))
320 die "buildroot $buildroot not absolute";
323 die "$buildroot does not exist or is not a directory" unless -d $buildroot;
325 chdir $buildroot || die "chdir to $buildroot: $!";
327 mkdir $branch unless -d $branch;
328 chdir $branch || die "chdir to $buildroot/$branch";
330 # rename legacy status files/directories
331 foreach my $oldfile (glob("last*"))
333 move $oldfile, "$st_prefix$oldfile";
336 my $branch_root = getcwd();
338 # Normally we would require GNU Make, but allow farm
339 # configuration to override this
340 die "$make is not GNU Make - please fix config file"
344 foreach my $module (@{$EximBuild::conf{modules}})
347 # fill in the name of the module here, so use double quotes
348 # so everything BUT the module name needs to be escaped
350 require EximBuild::Modules::$module;
351 EximBuild::Modules::${module}::setup(
368 open($lockfile, ">builder.LCK") || die "opening lockfile: $!";
370 # only one builder at a time allowed per branch
371 # having another build running is not a failure, and so we do not output
372 # a failure message under this condition.
375 die "acquiring lock in $buildroot/$branch/builder.LCK"
376 unless flock($lockfile,LOCK_EX|LOCK_NB);
378 elsif ( !flock($lockfile,LOCK_EX|LOCK_NB) )
380 print "Another process holds the lock on "
381 ."$buildroot/$branch/builder.LCK. Exiting."
386 die "$buildroot/$branch has $exim or inst directories!"
387 if ((!$from_source && -d $exim) || -d "inst");
389 # we are OK to run if we get here
392 # check if file present for forced run
393 my $forcefile = $st_prefix . "force-one-run";
400 # try to allow core files to be produced.
401 # another way would be for the calling environment
402 # to call ulimit. We do this in an eval so failure is
405 require BSD::Resource;
406 BSD::Resource->import();
408 # explicit sub calls here. using & keeps compiler happy
409 my $coreok = setrlimit(&RLIMIT_CORE,&RLIM_INFINITY,&RLIM_INFINITY);
410 die "setrlimit" unless $coreok;
412 warn "failed to unlimit core size: $@" if $@ && $verbose > 1;
414 # the time we take the snapshot
416 my $installdir = "$buildroot/$branch/inst";
421 # cleanup handler for all exits
426 unlink $ENV{TEMP_CONFIG} if $extraconf;
428 # if we have the lock we must already be in the build root, so
429 # removing things there should be safe.
430 # there should only be anything to cleanup if we didn't have
432 if ( $have_lock && -d "$exim")
437 system(qq{"bin/pg_ctl" -D data stop >$devnull 2>&1});
438 foreach my $loc (@locales)
440 next unless -d "data-$loc";
441 system(qq{"bin/pg_ctl" -D "data-$loc" stop >$devnull 2>&1});
445 if ( !$from_source && $keep_errs)
447 print "moving kept error trees\n" if $verbose;
448 my $timestr = strftime "%Y-%m-%d_%H-%M-%S", localtime($now);
449 unless (move("$exim", "eximkeep.$timestr"))
451 print "error renaming '$exim' to 'eximkeep.$timestr': $!";
455 unless(move("inst", "instkeep.$timestr"))
457 print "error renaming 'inst' to 'instkeep.$timestr': $!";
463 rmtree("inst") unless $keepall;
464 rmtree("$exim") unless ($from_source || $keepall);
467 # only keep the cache in cases of success
468 rmtree("$ccachedir") if $ccachedir;
471 # get the modules to clean up after themselves
472 process_module_hooks('cleanup');
479 # vpath builds leave some stuff lying around in the
480 # source dir, unfortunately. This should clean it up.
484 unlink("builder.LCK");
488 # Prepend the DEFAULT settings (if any) to any settings for the
489 # branch. Since we're mangling this, deep clone $extra_config
490 # so the config object is kept as given. This is done using
491 # Dumper() because the MSys DTK perl doesn't have Storable. This
492 # is less efficient but it hardly matters here for this shallow
495 $extra_config = eval Dumper($extra_config);
497 if ($extra_config && $extra_config->{DEFAULT})
499 if (!exists $extra_config->{$branch})
501 $extra_config->{$branch} = $extra_config->{DEFAULT};
505 unshift(@{$extra_config->{$branch}}, @{$extra_config->{DEFAULT}});
509 if ($extra_config && $extra_config->{$branch})
512 ($extraconf,$tmpname) =File::Temp::tempfile(
514 DIR => File::Spec->tmpdir(),
517 die 'no $tmpname!' unless $tmpname;
518 $ENV{TEMP_CONFIG} = $tmpname;
519 foreach my $line (@{$extra_config->{$branch}})
521 print $extraconf "$line\n";
523 autoflush $extraconf 1;
526 use vars qw($steps_completed);
527 $steps_completed = "";
530 my @changed_since_success;
534 my $last_success_snap;
540 if ($from_source_clean)
542 print time_str(),"cleaning source in $exim ...\n";
545 elsif (!$from_source)
548 # see if we need to run the tests (i.e. if either something has changed or
549 # we have gone over the force_every heartbeat time)
551 print time_str(),"checking out source ...\n" if $verbose;
555 $timeout_pid = spawn(\&scm_timeout,$scm_timeout_secs)
556 if $scm_timeout_secs;
558 $savescmlog = $scm->checkout($branch);
559 $steps_completed = "SCM-checkout";
561 process_module_hooks('checkout',$savescmlog);
566 # don't kill me, I finished in time
567 if (kill(SIGTERM, $timeout_pid))
571 waitpid($timeout_pid,0);
575 print time_str(),"checking if build run needed ...\n" if $verbose;
577 # transition to new time processing
578 unlink "last.success";
580 # get the timestamp data
581 $last_config = find_last('config') || 0;
582 $last_status = find_last('status') || 0;
583 $last_run_snap = find_last('run.snap');
584 $last_success_snap = find_last('success.snap');
585 $forcerun = 1 unless (defined($last_run_snap));
587 # If config file changed, force a rebuild
588 ($current_config) = (stat $orig_dir.'/'.$buildconf)[9];
589 if (defined $current_config && $current_config > $last_config)
592 set_last('config',$current_config) unless $nostatus;
595 # updated by find_changed to last mtime of any file in the repo
598 # see if we need to force a build
602 &&$last_status+($force_every*3600) < $now);
603 $last_status = 0 if $forcerun;
605 # see what's changed since the last time we did work
606 $scm->find_changed(\$current_snap,$last_run_snap, $last_success_snap,
607 \@changed_files,\@changed_since_success);
609 #ignore changes to files specified by the trigger exclude filter, if any
610 if (defined($trigger_exclude))
612 @filtered_files = grep { !m[$trigger_exclude] } @changed_files;
616 @filtered_files = @changed_files;
619 #ignore changes to files NOT specified by the trigger include filter, if any
620 if (defined($trigger_include))
622 @filtered_files = grep { m[$trigger_include] } @filtered_files;
625 my $modules_need_run;
627 process_module_hooks('need-run',\$modules_need_run);
629 # if no build required do nothing
630 if ($last_status && !@filtered_files && !$modules_need_run)
633 "No build required: last status = ",scalar(gmtime($last_status)),
634 " GMT, current snapshot = ",scalar(gmtime($current_snap))," GMT,",
635 " changed files = ",scalar(@filtered_files),"\n"
641 # get version info on both changed files sets
642 # XXX modules support?
644 $scm->get_versions(\@changed_files);
645 $scm->get_versions(\@changed_since_success);
647 } # end of unless ($from_source)
651 writelog('SCM-checkout',$savescmlog) unless $from_source;
652 $scm->log_id() unless $from_source;
654 # copy/create according to vpath/scm settings
658 print time_str(),"creating vpath build dir $exim ...\n" if $verbose;
659 mkdir $exim || die "making $exim: $!";
661 elsif (!$from_source && $scm->copy_source_required())
663 print time_str(),"copying source to $exim ...\n" if $verbose;
665 $scm->copy_source($using_msvc);
668 process_module_hooks('setup-target');
672 set_last('status',$now) unless $nostatus;
673 set_last('run.snap',$current_snap) unless $nostatus;
675 my $started_times = 0;
676 print time_str(),"running configure ...\n" if $verbose;
678 # each of these routines will call send_result, which calls exit,
679 # on any error, so each step depends on success in the previous
687 make_test() if (check_optional_step('test'));
689 make_doc() if (check_optional_step('make-doc'));
691 ##check_port_is_ok($buildport,'Post');
693 # if we get here everything went fine ...
695 my $saved_config = get_config_summary();
697 rmtree("inst"); # only keep failures
698 rmtree("$exim") unless ($from_source || $keepall);
700 print(time_str(),"OK\n") if $verbose;
706 ############## end of main program ###########################
711 usage: $0 [options] [branch]
713 where options are one or more of:
715 --nosend = don't send results
716 --nostatus = don't set status files
717 --force = force a build run (ignore status files)
718 --from-source=/path = use source in path, not from SCM
720 --from-source-clean=/path = same as --from-source, run make distclean first
721 --config=/path/to/file = alternative location for config file
722 --keepall = keep directories if an error occurs
723 --verbose[=n] = verbosity (default 1) 2 or more = huge output.
724 --quiet = suppress normal error message
725 --test = short for --nosend --nostatus --verbose --force
726 --skip-steps=list = skip certain steps
727 --only-steps=list = only do certain steps, not allowed with skip-steps
728 lists can be comma, colon, or space separated
730 Default branch is HEAD. Usually only the --config option should be necessary.
738 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
739 return sprintf("[%.2d:%.2d:%.2d] ",$hour, $min, $sec);
745 return $only_steps{$step} if $only_steps;
746 return !$skip_steps{$step} if $skip_steps;
747 return 1; # default is everything is wanted
750 sub register_module_hooks
754 while (my ($hook,$func) = each %$what)
756 $module_hooks{$hook} ||= [];
757 push(@{$module_hooks{$hook}},[$func,$who]);
761 sub process_module_hooks
765 # pass remaining args (if any) to module func
766 foreach my $module (@{$module_hooks{$hook}})
768 my ($func,$module_instance) = @$module;
769 &$func($module_instance, @_);
773 sub check_optional_step
779 return undef unless ref($oconf = $optional_steps->{$step});
780 if ($oconf->{branches})
782 return undef unless grep {$_ eq $branch} @{$oconf->{branches}};
785 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =localtime(time);
786 return undef if (exists $oconf->{min_hour} && $hour < $oconf->{min_hour});
787 return undef if (exists $oconf->{max_hour} && $hour > $oconf->{max_hour});
788 return undef if (exists $oconf->{dow}
789 &&grep {$_ eq $wday} @{$oconf->{dow}});
791 my $last_step = $last_status = find_last("$step") || 0;
792 ## If made it *to* these optional steps, we just run them and reset last time
793 #return undef unless ($forcerun ||
794 # time >$last_step + (3600 * $oconf->{min_hours_since}));
795 set_last("$step") unless $nostatus;
800 sub clean_from_source
802 if (-e "$exim/GNUmakefile")
806 my @makeout = `cd $exim && $make distclean 2>&1`;
808 writelog('distclean',\@makeout);
809 print "======== distclean log ===========\n",@makeout if ($verbose > 1);
810 send_result('distclean',$status,\@makeout) if $status;
817 print "Exiting on signal $signame\n";
823 my $lrname = $st_prefix . $logdirname;
825 mkdir "$lrname" || die "can't make $lrname dir: $!";
831 my $loglines = shift;
833 my $lrname = $st_prefix . $logdirname;
834 open($handle,">$lrname/$stage.log") || die $!;
835 print $handle @$loglines;
841 return unless step_wanted('features');
843 src/build-*/exim -C test/confs/0000 -bV `;
845 writelog('features',\@out);
846 print "======== features log ===========\n",@out if ($verbose > 1);
847 send_result('Features',$status,\@out) if $status;
848 $steps_completed .= " Features";
853 # Allow farm member to configure non-GNU make
854 my $non_gnu_make = $EximBuild::conf{non_gnu_make};
855 if (!defined $non_gnu_make ||
856 (defined $non_gnu_make && $non_gnu_make == 1)) {
859 my @out = `$make -v 2>&1`;
860 return undef unless ($? == 0 && grep {/GNU Make/} @out);
866 return unless step_wanted('make');
867 print time_str(),"running make ...\n" if $verbose;
868 my $make_args = join(' ',$EximBuild::conf{make_args});
870 my $make_cmd = $make;
871 $make_cmd = "$make -j $make_jobs"
872 if ($make_jobs > 1 && ($branch eq 'HEAD' || $branch ge 'REL9_1'));
873 @makeout = `cd $exim/src && $make_cmd $make_args 2>&1`;
875 writelog('make',\@makeout);
876 print "======== make log ===========\n",@makeout if ($verbose > 1);
877 send_result('Make',$status,\@makeout) if $status;
878 $steps_completed .= " Make";
883 return unless step_wanted('make-doc');
884 print time_str(),"running make doc ...\n" if $verbose;
887 @makeout = `cd $exim/doc/doc-docbook/ && \
888 EXIM_VER="4.82" $make everything 2>&1`;
890 writelog('make-doc',\@makeout);
891 print "======== make doc log ===========\n",@makeout if ($verbose > 1);
892 send_result('Doc',$status,\@makeout) if $status;
893 $steps_completed .= " Doc";
901 # no core = no result
902 my @cores = glob("$pgdata/$core_file_glob");
903 return () unless @cores;
906 system "gdb --version > $devnull 2>&1";
908 return () if $status;
910 my $cmdfile = "./gdbcmd";
912 open($handle, ">$cmdfile");
913 print $handle "bt\n";
918 foreach my $core (@cores)
920 my @onetrace = `gdb -x $cmdfile --batch $bindir/exim $core 2>&1`;
922 "\n\n================== stack trace: $core ==================\n",
931 sub make_install_check
934 return unless step_wanted('install-check');
935 print time_str(),"running make installcheck ($locale)...\n" if $verbose;
940 @checklog = `cd $exim/src/test/regress && $make installcheck 2>&1`;
944 chdir "$exim/src/tools/msvc";
945 @checklog = `perl vcregress.pl installcheck 2>&1`;
950 ("$exim/src/test/regress/regression.diffs","$installdir/logfile");
951 foreach my $logfile(@logfiles)
953 next unless (-e $logfile );
954 push(@checklog,"\n\n================== $logfile ==================\n");
956 open($handle,$logfile);
966 get_stack_trace("$installdir/bin","$installdir/data-$locale");
967 push(@checklog,@trace);
969 writelog("install-check-$locale",\@checklog);
970 print "======== make installcheck log ===========\n",@checklog
972 send_result("InstallCheck-$locale",$status,\@checklog) if $status;
973 $steps_completed .= " InstallCheck-$locale";
976 sub make_isolation_check
979 return unless step_wanted('isolation-check');
984 "cd $exim/src/test/isolation && $make NO_LOCALE=1 installcheck";
985 @makeout = `$cmd 2>&1`;
989 chdir "$exim/src/tools/msvc";
990 @makeout = `perl vcregress.pl isolationcheck 2>&1`;
996 # get the log files and the regression diffs
997 my @logs = glob("$exim/src/test/isolation/log/*.log");
998 push(@logs,"$installdir/logfile");
999 unshift(@logs,"$exim/src/test/isolation/regression.diffs")
1000 if (-e "$exim/src/test/isolation/regression.diffs");
1001 foreach my $logfile (@logs)
1003 push(@makeout,"\n\n================== $logfile ===================\n");
1005 open($handle,$logfile);
1015 get_stack_trace("$installdir/bin","$installdir/data-$locale");
1016 push(@makeout,@trace);
1018 writelog('isolation-check',\@makeout);
1019 print "======== make isolation check logs ===========\n",@makeout
1022 send_result('IsolationCheck',$status,\@makeout) if $status;
1023 $steps_completed .= " IsolationCheck";
1028 return unless step_wanted('test');
1029 print time_str(),"running make test ...\n" if $verbose;
1030 my $tests_range = $EximBuild::conf{range_num_tests} || "1 4";
1032 @makeout =`(cd $exim/test
1033 autoconf && ./configure && $make )2>&1 `;
1034 my $status = $? >>8;
1037 my @tmp = `(WORKDIR=\$PWD
1039 ./runtest \$WORKDIR/$exim/src/build-*/exim -CONTINUE $tests_range )2>&1`;
1041 push @makeout, @tmp;
1042 # Prepend the failed summary log outputs for ease of reading
1043 my $fail_summary = "$exim/test/failed-summary.log";
1044 if (-f $fail_summary)
1046 @tmp = `cat $fail_summary`;
1048 unshift @makeout, @tmp;
1049 unshift @makeout, "Summary of failed tests:\n";
1052 writelog('test',\@makeout);
1053 print "======== make test logs ===========\n",@makeout
1056 send_result('Test',$status,\@makeout) if $status;
1057 $steps_completed .= " Test";
1062 return unless step_wanted('ecpg-check');
1064 my $ecpg_dir = "$exim/src/interfaces/ecpg";
1067 chdir "$exim/src/tools/msvc";
1068 @makeout = `perl vcregress.pl ecpgcheck 2>&1`;
1073 @makeout = `cd $ecpg_dir && $make NO_LOCALE=1 check 2>&1`;
1075 my $status = $? >>8;
1077 # get the log files and the regression diffs
1078 my @logs = glob("$ecpg_dir/test/log/*.log");
1079 unshift(@logs,"$ecpg_dir/test/regression.diffs")
1080 if (-e "$ecpg_dir/test/regression.diffs");
1081 foreach my $logfile (@logs)
1083 push(@makeout,"\n\n================== $logfile ===================\n");
1085 open($handle,$logfile);
1094 my $base = "$ecpg_dir/test/regress/tmp_check";
1096 get_stack_trace("$base/install$installdir/bin", "$base/data");
1097 push(@makeout,@trace);
1099 writelog('ecpg-check',\@makeout);
1100 print "======== make ecpg check logs ===========\n",@makeout
1103 send_result('ECPG-Check',$status,\@makeout) if $status;
1104 $steps_completed .= " ECPG-Check";
1109 return unless step_wanted('configure');
1110 print time_str(),"creating configuration ...\n" if $verbose;
1112 my $env = $EximBuild::conf{makefile_set};
1113 my $add = $EximBuild::conf{makefile_add};
1114 my $features = $EximBuild::conf{makefile_regex};
1117 while (my ($key,$val) = each %$env)
1119 $envstr .= "$key='$val'\n";
1121 while (my ($key,$val) = each %$add)
1123 $envstr .= "$key+='$val'\n";
1126 my $conf_path = "src/src/EDITME";
1127 my $local_conf = "src/Local/Makefile";
1128 my @confout = `cd $exim; mkdir -p src/Local 2>&1`;
1129 my @tmp = `cd $exim && cp $conf_path $local_conf 2>&1`;
1130 my $status = $? >> 8;
1131 push @confout, @tmp;
1134 # First, let's display some directory permissions in case
1135 # permissions are causing problems.
1136 my @dir = split('/',`pwd`);
1138 my $count = scalar @dir;
1141 while ($loop < $count)
1144 foreach my $i (0 .. $loop)
1146 $dir .= $dir[$i].'/';
1151 @tmp = `echo "Verify Directory Permissions"
1153 push @confout, @tmp;
1154 # Build the config file from the EDITME template
1155 @tmp = `cd $exim && echo '$envstr' >> $local_conf`;
1156 push @confout, @tmp;
1157 my $exim_user = $EximBuild::conf{master_exim_user} || 'exim';
1158 @tmp = `echo "Hardcoded Exim user info:"; id $exim_user
1159 cd $exim && perl -pi -e 's/^EXIM_USER=.*/EXIM_USER=$exim_user/' $local_conf`;
1160 push @confout, @tmp;
1161 my $me = `whoami`; chomp $me;
1162 @tmp = `echo "Build Farm user info:"; id $me
1163 cd $exim && perl -pi -e 's/^# CONFIGURE_OWNER=\$/CONFIGURE_OWNER=$me/' $local_conf`;
1164 push @confout, @tmp;
1165 my $testdir = `cd $exim && /bin/pwd`; chomp $testdir; $testdir .= "/test";
1166 my $trcf = "$testdir/trusted-configs";
1167 my $tecf = "$testdir/test-config";
1168 @tmp = `cd $exim && perl -pi -e "s%^# TRUSTED_CONFIG_LIST=.*%TRUSTED_CONFIG_LIST=$trcf%" $local_conf`;
1169 push @confout, @tmp;
1170 @tmp = `cd $exim && perl -pi -e 's/^# WHITELIST_D_MACROS=.*/WHITELIST_D_MACROS=DIR:EXIM_PATH:AA:ACL:ACLRCPT:ACL_MAIL:ACL_PREDATA:ACL_RCPT:AFFIX:ALLOW:ARG1:ARG2:AUTHF:AUTHS:AUTH_ID_DOMAIN:BAD:BANNER:BB:BR:BRB:CERT:COM:COMMAND_USER:CONNECTCOND:CONTROL:CREQCIP:CREQMAC:CRL:CSS:D6:DATA:DCF:DDF:DEFAULTDWC:DELAY:DETAILS:DRATELIMIT:DYNAMIC_OPTION:ELI:ERROR_DETAILS:ERT:FAKE:FALLBACK:FILTER:FILTER_PREPEND_HOME:FORBID:FORBID_SMTP_CODE:FUSER:HAI:HAP:HARDLIMIT:HEADER_LINE_MAXSIZE:HEADER_MAXSIZE:HELO_MSG:HL:HOSTS:HOSTS_AVOID_TLS:HOSTS_MAX_TRY:HVH:IFACE:IGNORE_QUOTA:INC:INSERT:IP1:IP2:LAST:LDAPSERVERS:LENCHECK:LIMIT:LIST:LOG_SELECTOR:LS:MAXNM:MESSAGE_LOGS:MSIZE:NOTDAEMON:ONCE:ONLY:OPT:OPTION:ORDER:PAH:PEX:PORT:PTBC:QDG:QOLL:QUOTA:QUOTA_FILECOUNT:QWM:RCPT_MSG:REMEMBER:REQUIRE:RETRY:RETRY1:RETRY2:RETURN:RETURN_ERROR_DETAILS:REWRITE:ROUTE_DATA:RRATELIMIT:RT:S:SELECTOR:SELF:SERVER:SERVERS:SREQCIP:SREQMAC:SRV:STD:STRICT:SUB:SUBMISSION_OPTIONS:TIMEOUTDEFER:TIMES:TRUSTED:TRYCLEAR:UL:USE_SENDER:UTF8:VALUE:WMF:X:Y/' $local_conf`;
1171 push @confout, @tmp;
1172 @tmp = `cd $exim && perl -pi -e 's/^EXIM_MONITOR=(.*)/# EXIM_MONITOR=\$1/' $local_conf`;
1173 push @confout, @tmp;
1174 for my $regex ( @$features )
1177 perl -pi -e '$regex' $local_conf 2>&1
1178 echo "Used regex: $regex" `;
1179 push @confout, @tmp;
1181 # Add the final build file to the display output
1184 echo "Contents of Local/Makefile:"
1185 egrep '^[^#]' $local_conf `;
1186 push @confout, @tmp;
1187 # Build the config_opts array to send to the server
1189 my @config_opts = grep s/(?:LOOKUP_|EXPERIMENTAL_|USE_)(\S+)=.*/$1/,
1191 push @config_opts, grep s/^(?:EXIM_)(PERL|PYTHON)=.*/$1/,
1193 # OpenSSL doesn't have a specific USE flag
1194 push @config_opts, grep s/^(TLS_LIBS.*-l(ssl|crypto)).*/OPENSSL/,
1196 $EximBuild::conf{config_opts} = \@config_opts;
1198 # Does not matter what the Exim version is, as long as it is valid.
1199 my $exim_ver = $EximBuild::conf{exim_test_version} || '4.82';
1201 echo 'EXIM_RELEASE_VERSION="$exim_ver"' > src/src/version.sh
1202 echo 'EXIM_VARIANT_VERSION=""' >> src/src/version.sh
1203 echo 'EXIM_COMPILE_NUMBER="0"' >> src/src/version.sh`;
1205 # Create a trusted-configs list file
1206 @tmp = `cd $exim && echo "$tecf" > "$trcf"`;
1207 push @confout, @tmp;
1210 print "======== configure output ===========\n",@confout
1213 writelog('configure',\@confout);
1217 send_result('Configure',$status,\@confout);
1220 $steps_completed .= " Configure";
1226 my $stname = $st_prefix . "last.$which";
1228 open($handle,$stname) or return undef;
1229 my $time = <$handle>;
1238 my $stname = $st_prefix . "last.$which";
1239 my $st_now = shift || time;
1241 open($handle,">$stname") or die "opening $stname: $!";
1242 print $handle "$st_now\n";
1249 # clean up temp file
1254 my $ts = $now || time;
1255 my $status=shift || 0;
1256 my $log = shift || [];
1257 print "======== log passed to send_result ===========\n",@$log
1261 "Last file mtime in snapshot: ",
1262 scalar(gmtime($current_snap)),
1263 " GMT\n","===================================================\n")
1264 unless ($from_source || !$current_snap);
1266 my $log_data = join("",@$log);
1268 my $changed_this_run = "";
1269 my $changed_since_success = "";
1270 $changed_this_run = join("!",@changed_files)
1272 $changed_since_success = join("!",@changed_since_success)
1273 if ($stage ne 'OK' && @changed_since_success);
1277 $confsum= $saved_config;
1279 elsif ($stage !~ /CVS|Git|SCM/ )
1281 $confsum = get_config_summary();
1285 $confsum = get_script_config_dump();
1288 my $savedata = Data::Dumper->Dump(
1290 $changed_this_run, $changed_since_success, $branch, $status,$stage,
1291 $animal, $ts,$log_data, $confsum, $target, $verbose, $secret
1294 qw(changed_this_run changed_since_success branch status stage
1295 animal ts log_data confsum target verbose secret)
1299 my $lrname = $st_prefix . $logdirname;
1301 # might happen if there is a CVS failure and have never got further
1302 mkdir $lrname unless -d $lrname;
1304 my $txfname = "$lrname/web-txn.data";
1306 open($txdhandle,">$txfname");
1307 print $txdhandle $savedata;
1310 if ($nosend || $stage eq 'CVS' || $stage eq 'CVS-status' )
1312 print "Branch: $branch\n";
1315 print "All stages succeeded\n";
1316 set_last('success.snap',$current_snap) unless $nostatus;
1321 print "Stage $stage failed with status $status\n";
1326 if ($stage !~ /CVS|Git|SCM|Pre-run-port-check/ )
1329 my @logfiles = glob("$lrname/*.log");
1330 my %mtimes = map { $_ => (stat $_)[9] } @logfiles;
1332 map { basename $_ }( sort { $mtimes{$a} <=> $mtimes{$b} } @logfiles );
1333 my $logfiles = join(' ',@logfiles);
1334 $tar_log_cmd =~ s/\*\.log/$logfiles/;
1336 system("$tar_log_cmd 2>&1 ");
1337 chdir($branch_root);
1343 # these would be from an earlier run, since we
1344 # do cleanlogs() after the cvs stage
1345 # so don't send them.
1346 unlink "$lrname/runlogs.tgz";
1351 # this should now only apply to older Msys installs. All others should
1352 # be running with perl >= 5.8 since that's required to build exim
1354 if (!$^V or $^V lt v5.8.0)
1357 unless (-x "$aux_path/run_web_txn.pl")
1359 print "Could not locate $aux_path/run_web_txn.pl\n";
1363 system("$aux_path/run_web_txn.pl $lrname");
1364 $txstatus = $? >> 8;
1368 $txstatus = EximBuild::WebTxn::run_web_txn($lrname) ? 0 : 1;
1374 print "Web txn failed with status: $txstatus\n";
1376 # if the web txn fails, restore the timestamps
1377 # so we try again the next time.
1378 set_last('status',$last_status) unless $nostatus;
1379 set_last('run.snap',$last_run_snap) unless $nostatus;
1383 unless ($stage eq 'OK' || $quiet)
1385 print "BuildFarm member $animal failed on $branch stage $stage\n";
1388 # print "Success!\n",$response->content
1389 # if $print_success;
1391 set_last('success.snap',$current_snap) if ($stage eq 'OK' && !$nostatus);
1396 sub get_config_summary
1400 # unless ($using_msvc)
1402 # open($handle,"$exim/config.log") || return undef;
1403 # my $start = undef;
1406 # if (!$start && /created by PostgreSQL configure/)
1409 # s/It was/This file was/;
1411 # next unless $start;
1412 # last if /Core tests/;
1414 # next if /= <?unknown>?/;
1416 # # split up long configure line
1417 # if (m!\$.*configure.*--with! && length > 70)
1419 # my $pos = index($_," ",70);
1420 # substr($_,$pos+1,0,"\\\n ") if ($pos > 0);
1421 # $pos = index($_," ",140);
1422 # substr($_,$pos+1,0,"\\\n ") if ($pos > 0);
1423 # $pos = index($_," ",210);
1424 # substr($_,$pos+1,0,"\\\n ") if ($pos > 0);
1430 # "\n========================================================\n";
1432 $config .= get_script_config_dump();
1436 sub get_script_config_dump
1439 %EximBuild::conf, # shallow copy
1440 script_version => $VERSION,
1441 invocation_args => \@invocation_args,
1442 steps_completed => $steps_completed,
1443 orig_env => $orig_env,
1445 delete $conf->{secret};
1447 if ($conf->{scm} eq 'git') {
1448 chomp($conf->{farm}{revision} = `git -C $Bin describe --tags --always --dirty=+`);
1449 $conf->{farm}{cwd} = getcwd();
1450 $conf->{farm}{bindir} = $Bin;
1453 $Data::Dumper::Sortkeys = 1;
1454 return Data::Dumper->Dump([$conf],['Script_Config']);
1459 my $wait_time = shift;
1460 my $who_to_kill = getpgrp(0);
1463 print "waiting $wait_time secs to time out process $who_to_kill\n"
1465 foreach my $sig (qw(INT TERM HUP QUIT))
1467 $SIG{$sig}='DEFAULT';
1470 $SIG{TERM} = 'IGNORE'; # so we don't kill ourself, we're exiting anyway
1471 # kill the whole process group
1472 unless (kill $sig,$who_to_kill)
1474 print "scm timeout kill failed\n";
1480 my $coderef = shift;
1482 if (defined($pid) && $pid == 0)