5 Copyright (c) 2003-2010, Andrew Dunstan
7 See accompanying License file for license details
11 ####################################################
15 NAME: run_build.pl - script to run exim buildfarm
19 run_build.pl [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 use vars qw($VERSION); $VERSION = 'REL_0.1';
40 use Fcntl qw(:flock :seek);
47 use POSIX qw(:signal_h strftime);
49 use Cwd qw(abs_path getcwd);
52 # save a copy of the original enviroment for reporting
53 # save it early to reduce the risk of prior mangling
54 use vars qw($orig_env);
59 while (my ($k,$v) = each %ENV)
62 # report all the keys but only values for whitelisted settings
63 # this is to stop leaking of things like passwords
66 $k =~ /^PG(?!PASSWORD)|MAKE|CC|CPP|FLAG|LIBRAR|INCLUDE/
67 ||$k =~/^(HOME|LOGNAME|USER|PATH|SHELL)$/
76 use EximBuild::Options;
77 use EximBuild::WebTxn;
80 my $orig_dir = getcwd();
83 # make sure we exit nicely on any normal interrupt
84 # so the cleanup handler gets called.
85 # that lets us stop the db if it's running and
86 # remove the inst and exim directories
87 # so the next run can start clean.
89 foreach my $sig (qw(INT TERM HUP QUIT))
91 $SIG{$sig}=\&interrupt_exit;
94 # copy command line before processing - so we can later report it
97 my @invocation_args = (@ARGV);
99 # process the command line
100 EximBuild::Options::fetch_options();
102 die "only one of --from-source and --from-source-clean allowed"
103 if ($from_source && $from_source_clean);
105 die "only one of --skip-steps and --only-steps allowed"
106 if ($skip_steps && $only_steps);
108 $verbose=1 if (defined($verbose) && $verbose==0);
109 $verbose ||= 0; # stop complaints about undefined var in numeric comparison
113 $verbose=1 unless $verbose;
120 use vars qw(%skip_steps %only_steps);
122 if ($skip_steps =~ /\S/)
124 %skip_steps = map {$_ => 1} split(/\s+/,$skip_steps);
127 if ($only_steps =~ /\S/)
129 %only_steps = map {$_ => 1} split(/(\s+|[:,])/,$only_steps);
132 # Currently only specifying a branch is actually used.
133 # Specifying a different repo is just a wishlist item .
134 use vars qw($branch $repo);
135 my ($arg1,$arg2) = (shift,shift);
136 $branch = $arg2 ? $arg2 :
139 $repo = $arg2 ? $arg1 : 'exim';
140 my $explicit_branch = $branch;
142 print_help() if ($help);
145 # process config file
149 # get the config data into some local variables
151 $buildroot,$target,$animal, $print_success,
152 $aux_path,$trigger_exclude,$trigger_include,$secret,
153 $keep_errs,$force_every, $make, $optional_steps,
154 $use_vpath,$tar_log_cmd, $using_msvc, $extra_config,
155 $make_jobs, $core_file_glob
158 qw(build_root target animal print_success aux_path trigger_exclude
159 trigger_include secret keep_error_builds force_every make optional_steps
160 use_vpath tar_log_cmd using_msvc extra_config make_jobs core_file_glob)
163 #default is no parallel build
166 # default core file pattern is Linux, which used to be hardcoded
167 $core_file_glob ||= 'core*';
170 if (defined($EximBuild::conf{trigger_filter}))
172 $trigger_exclude = $EximBuild::conf{trigger_filter};
175 my $scm_timeout_secs = $EximBuild::conf{scm_timeout_secs}
176 || $EximBuild::conf{cvs_timeout_secs};
178 print scalar(localtime()),": buildfarm run for $animal:$branch starting\n"
181 # Allow commandline overrides of conf variables
182 foreach my $arg ( @{$EximBuild::Options::overrides} )
184 if (my ($key,$val) = split '=', $arg)
186 $EximBuild::conf{$key} = $val;
187 printf "Commandline override: '$key' = '%s'\n", $EximBuild::conf{$key}
192 if (ref($force_every) eq 'HASH')
194 $force_every = $force_every->{$branch} || $force_every->{default};
197 my $scm = new EximBuild::SCM \%EximBuild::conf;
201 if (exists $EximBuild::conf{base_port})
203 $buildport = $EximBuild::conf{base_port};
204 if ($branch =~ /REL(\d+)_(\d+)/)
206 $buildport += (10 * ($1 - 7)) + $2;
212 # support for legacy config style
213 $buildport = $EximBuild::conf{branch_ports}->{$branch} || 5999;
216 $ENV{EXTRA_REGRESS_OPTS} = "--port=$buildport";
218 $tar_log_cmd ||= "tar -z -cf runlogs.tgz *.log";
220 my $logdirname = "lastrun-logs";
222 if ($from_source || $from_source_clean)
224 $from_source ||= $from_source_clean;
225 die "sourceroot $from_source not absolute"
226 unless $from_source =~ m!^/!;
228 # we need to know where the lock should go, so unless the path
229 # contains HEAD we require it to be specified.
230 die "must specify branch explicitly with from_source"
231 unless ($explicit_branch || $from_source =~ m!/HEAD/!);
236 $logdirname = "fromsource-logs";
240 if ($branch eq 'HEAD' || $branch ge 'REL8_4')
243 # non-C locales are not regression-safe before 8.4
244 @locales = @{$EximBuild::conf{locales}} if exists $EximBuild::conf{locales};
246 unshift(@locales,'C') unless grep {$_ eq "C"} @locales;
249 # several people have run into these
251 if ( `uname -s 2>&1 ` =~ /CYGWIN/i )
253 my @procs = `ps -ef`;
254 die "cygserver not running" unless(grep {/cygserver/} @procs);
257 if ( $ccachedir = $EximBuild::conf{build_env}->{CCACHE_DIR} )
260 # ccache is smart enough to create what you tell it is the cache dir, but
261 # not smart enough to build the whole path. mkpath croaks on error, so
265 $ccachedir = abs_path($ccachedir);
270 die "no aux_path in config file" unless $aux_path;
273 die "cannot run as root/Administrator" unless ($using_msvc or $> > 0);
275 my $devnull = $using_msvc ? "nul" : "/dev/null";
279 $scm->check_access($using_msvc);
282 my $st_prefix = "$animal.";
284 my $exim = $from_source || $scm->get_build_path($use_vpath);
286 # set environment from config
287 while (my ($envkey,$envval) = each %{$EximBuild::conf{build_env}})
289 $ENV{$envkey}=$envval;
292 # change to buildroot for this branch or die
293 die "no buildroot" unless $buildroot;
295 unless ($buildroot =~ m!^/!
296 or($using_msvc and $buildroot =~ m![a-z]:[/\\]!i ))
298 die "buildroot $buildroot not absolute";
301 die "$buildroot does not exist or is not a directory" unless -d $buildroot;
303 chdir $buildroot || die "chdir to $buildroot: $!";
305 mkdir $branch unless -d $branch;
306 chdir $branch || die "chdir to $buildroot/$branch";
308 # rename legacy status files/directories
309 foreach my $oldfile (glob("last*"))
311 move $oldfile, "$st_prefix$oldfile";
314 my $branch_root = getcwd();
316 # Normally we would require GNU Make, but allow farm
317 # configuration to override this
318 die "$make is not GNU Make - please fix config file"
322 foreach my $module (@{$EximBuild::conf{modules}})
325 # fill in the name of the module here, so use double quotes
326 # so everything BUT the module name needs to be escaped
328 require EximBuild::Modules::$module;
329 EximBuild::Modules::${module}::setup(
346 open($lockfile, ">builder.LCK") || die "opening lockfile: $!";
348 # only one builder at a time allowed per branch
349 # having another build running is not a failure, and so we do not output
350 # a failure message under this condition.
353 die "acquiring lock in $buildroot/$branch/builder.LCK"
354 unless flock($lockfile,LOCK_EX|LOCK_NB);
356 elsif ( !flock($lockfile,LOCK_EX|LOCK_NB) )
358 print "Another process holds the lock on "
359 ."$buildroot/$branch/builder.LCK. Exiting."
364 die "$buildroot/$branch has $exim or inst directories!"
365 if ((!$from_source && -d $exim) || -d "inst");
367 # we are OK to run if we get here
370 # check if file present for forced run
371 my $forcefile = $st_prefix . "force-one-run";
378 # try to allow core files to be produced.
379 # another way would be for the calling environment
380 # to call ulimit. We do this in an eval so failure is
383 require BSD::Resource;
384 BSD::Resource->import();
386 # explicit sub calls here. using & keeps compiler happy
387 my $coreok = setrlimit(&RLIMIT_CORE,&RLIM_INFINITY,&RLIM_INFINITY);
388 die "setrlimit" unless $coreok;
390 warn "failed to unlimit core size: $@" if $@ && $verbose > 1;
392 # the time we take the snapshot
394 my $installdir = "$buildroot/$branch/inst";
399 # cleanup handler for all exits
404 unlink $ENV{TEMP_CONFIG} if $extraconf;
406 # if we have the lock we must already be in the build root, so
407 # removing things there should be safe.
408 # there should only be anything to cleanup if we didn't have
410 if ( $have_lock && -d "$exim")
415 system(qq{"bin/pg_ctl" -D data stop >$devnull 2>&1});
416 foreach my $loc (@locales)
418 next unless -d "data-$loc";
419 system(qq{"bin/pg_ctl" -D "data-$loc" stop >$devnull 2>&1});
423 if ( !$from_source && $keep_errs)
425 print "moving kept error trees\n" if $verbose;
426 my $timestr = strftime "%Y-%m-%d_%H-%M-%S", localtime($now);
427 unless (move("$exim", "eximkeep.$timestr"))
429 print "error renaming '$exim' to 'eximkeep.$timestr': $!";
433 unless(move("inst", "instkeep.$timestr"))
435 print "error renaming 'inst' to 'instkeep.$timestr': $!";
441 rmtree("inst") unless $keepall;
442 rmtree("$exim") unless ($from_source || $keepall);
445 # only keep the cache in cases of success
446 rmtree("$ccachedir") if $ccachedir;
449 # get the modules to clean up after themselves
450 process_module_hooks('cleanup');
457 # vpath builds leave some stuff lying around in the
458 # source dir, unfortunately. This should clean it up.
462 unlink("builder.LCK");
466 # Prepend the DEFAULT settings (if any) to any settings for the
467 # branch. Since we're mangling this, deep clone $extra_config
468 # so the config object is kept as given. This is done using
469 # Dumper() because the MSys DTK perl doesn't have Storable. This
470 # is less efficient but it hardly matters here for this shallow
473 $extra_config = eval Dumper($extra_config);
475 if ($extra_config && $extra_config->{DEFAULT})
477 if (!exists $extra_config->{$branch})
479 $extra_config->{$branch} = $extra_config->{DEFAULT};
483 unshift(@{$extra_config->{$branch}}, @{$extra_config->{DEFAULT}});
487 if ($extra_config && $extra_config->{$branch})
490 ($extraconf,$tmpname) =File::Temp::tempfile(
492 DIR => File::Spec->tmpdir(),
495 die 'no $tmpname!' unless $tmpname;
496 $ENV{TEMP_CONFIG} = $tmpname;
497 foreach my $line (@{$extra_config->{$branch}})
499 print $extraconf "$line\n";
501 autoflush $extraconf 1;
504 use vars qw($steps_completed);
505 $steps_completed = "";
508 my @changed_since_success;
512 my $last_success_snap;
518 if ($from_source_clean)
520 print time_str(),"cleaning source in $exim ...\n";
523 elsif (!$from_source)
526 # see if we need to run the tests (i.e. if either something has changed or
527 # we have gone over the force_every heartbeat time)
529 print time_str(),"checking out source ...\n" if $verbose;
533 $timeout_pid = spawn(\&scm_timeout,$scm_timeout_secs)
534 if $scm_timeout_secs;
536 $savescmlog = $scm->checkout($branch);
537 $steps_completed = "SCM-checkout";
539 process_module_hooks('checkout',$savescmlog);
544 # don't kill me, I finished in time
545 if (kill(SIGTERM, $timeout_pid))
549 waitpid($timeout_pid,0);
553 print time_str(),"checking if build run needed ...\n" if $verbose;
555 # transition to new time processing
556 unlink "last.success";
558 # get the timestamp data
559 $last_config = find_last('config') || 0;
560 $last_status = find_last('status') || 0;
561 $last_run_snap = find_last('run.snap');
562 $last_success_snap = find_last('success.snap');
563 $forcerun = 1 unless (defined($last_run_snap));
565 # If config file changed, force a rebuild. This assumes that the config
566 # file is in the CWD, which may not always be true, so handle it by
567 # adding 1 to the value of last_config, which will force the rebuild.
568 ($current_config) = (stat $orig_dir.'/'.$buildconf)[9] || ($last_config+1);
569 if ($current_config > $last_config)
572 set_last('config',$current_config) unless $nostatus;
575 # updated by find_changed to last mtime of any file in the repo
578 # see if we need to force a build
582 &&$last_status+($force_every*3600) < $now);
583 $last_status = 0 if $forcerun;
585 # see what's changed since the last time we did work
586 $scm->find_changed(\$current_snap,$last_run_snap, $last_success_snap,
587 \@changed_files,\@changed_since_success);
589 #ignore changes to files specified by the trigger exclude filter, if any
590 if (defined($trigger_exclude))
592 @filtered_files = grep { !m[$trigger_exclude] } @changed_files;
596 @filtered_files = @changed_files;
599 #ignore changes to files NOT specified by the trigger include filter, if any
600 if (defined($trigger_include))
602 @filtered_files = grep { m[$trigger_include] } @filtered_files;
605 my $modules_need_run;
607 process_module_hooks('need-run',\$modules_need_run);
609 # if no build required do nothing
610 if ($last_status && !@filtered_files && !$modules_need_run)
613 "No build required: last status = ",scalar(gmtime($last_status)),
614 " GMT, current snapshot = ",scalar(gmtime($current_snap))," GMT,",
615 " changed files = ",scalar(@filtered_files),"\n"
621 # get version info on both changed files sets
622 # XXX modules support?
624 $scm->get_versions(\@changed_files);
625 $scm->get_versions(\@changed_since_success);
627 } # end of unless ($from_source)
631 writelog('SCM-checkout',$savescmlog) unless $from_source;
632 $scm->log_id() unless $from_source;
634 # copy/create according to vpath/scm settings
638 print time_str(),"creating vpath build dir $exim ...\n" if $verbose;
639 mkdir $exim || die "making $exim: $!";
641 elsif (!$from_source && $scm->copy_source_required())
643 print time_str(),"copying source to $exim ...\n" if $verbose;
645 $scm->copy_source($using_msvc);
648 process_module_hooks('setup-target');
652 set_last('status',$now) unless $nostatus;
653 set_last('run.snap',$current_snap) unless $nostatus;
655 my $started_times = 0;
656 print time_str(),"running configure ...\n" if $verbose;
658 # each of these routines will call send_result, which calls exit,
659 # on any error, so each step depends on success in the previous
667 make_test() if (check_optional_step('test'));
669 make_doc() if (check_optional_step('make-doc'));
671 ##check_port_is_ok($buildport,'Post');
673 # if we get here everything went fine ...
675 my $saved_config = get_config_summary();
677 rmtree("inst"); # only keep failures
678 rmtree("$exim") unless ($from_source || $keepall);
680 print(time_str(),"OK\n") if $verbose;
686 ############## end of main program ###########################
691 usage: $0 [options] [branch]
693 where options are one or more of:
695 --nosend = don't send results
696 --nostatus = don't set status files
697 --force = force a build run (ignore status files)
698 --from-source=/path = use source in path, not from SCM
700 --from-source-clean=/path = same as --from-source, run make distclean first
701 --config=/path/to/file = alternative location for config file
702 --keepall = keep directories if an error occurs
703 --verbose[=n] = verbosity (default 1) 2 or more = huge output.
704 --quiet = suppress normal error message
705 --test = short for --nosend --nostatus --verbose --force
706 --skip-steps=list = skip certain steps
707 --only-steps=list = only do certain steps, not allowed with skip-steps
708 lists can be comma, colon, or space separated
710 Default branch is HEAD. Usually only the --config option should be necessary.
718 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
719 return sprintf("[%.2d:%.2d:%.2d] ",$hour, $min, $sec);
725 return $only_steps{$step} if $only_steps;
726 return !$skip_steps{$step} if $skip_steps;
727 return 1; # default is everything is wanted
730 sub register_module_hooks
734 while (my ($hook,$func) = each %$what)
736 $module_hooks{$hook} ||= [];
737 push(@{$module_hooks{$hook}},[$func,$who]);
741 sub process_module_hooks
745 # pass remaining args (if any) to module func
746 foreach my $module (@{$module_hooks{$hook}})
748 my ($func,$module_instance) = @$module;
749 &$func($module_instance, @_);
753 sub check_optional_step
759 return undef unless ref($oconf = $optional_steps->{$step});
760 if ($oconf->{branches})
762 return undef unless grep {$_ eq $branch} @{$oconf->{branches}};
765 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =localtime(time);
766 return undef if (exists $oconf->{min_hour} && $hour < $oconf->{min_hour});
767 return undef if (exists $oconf->{max_hour} && $hour > $oconf->{max_hour});
768 return undef if (exists $oconf->{dow}
769 &&grep {$_ eq $wday} @{$oconf->{dow}});
771 my $last_step = $last_status = find_last("$step") || 0;
772 ## If made it *to* these optional steps, we just run them and reset last time
773 #return undef unless ($forcerun ||
774 # time >$last_step + (3600 * $oconf->{min_hours_since}));
775 set_last("$step") unless $nostatus;
780 sub clean_from_source
782 if (-e "$exim/GNUmakefile")
786 my @makeout = `cd $exim && $make distclean 2>&1`;
788 writelog('distclean',\@makeout);
789 print "======== distclean log ===========\n",@makeout if ($verbose > 1);
790 send_result('distclean',$status,\@makeout) if $status;
797 print "Exiting on signal $signame\n";
803 my $lrname = $st_prefix . $logdirname;
805 mkdir "$lrname" || die "can't make $lrname dir: $!";
811 my $loglines = shift;
813 my $lrname = $st_prefix . $logdirname;
814 open($handle,">$lrname/$stage.log") || die $!;
815 print $handle @$loglines;
821 return unless step_wanted('features');
823 src/build-*/exim -C test/confs/0000 -bV `;
825 writelog('features',\@out);
826 print "======== features log ===========\n",@out if ($verbose > 1);
827 send_result('Features',$status,\@out) if $status;
828 $steps_completed .= " Features";
833 # Allow farm member to configure non-GNU make
834 my $non_gnu_make = $EximBuild::conf{non_gnu_make};
835 if (!defined $non_gnu_make ||
836 (defined $non_gnu_make && $non_gnu_make == 1)) {
839 my @out = `$make -v 2>&1`;
840 return undef unless ($? == 0 && grep {/GNU Make/} @out);
846 return unless step_wanted('make');
847 print time_str(),"running make ...\n" if $verbose;
848 my $make_args = join(' ',$EximBuild::conf{make_args});
850 my $make_cmd = $make;
851 $make_cmd = "$make -j $make_jobs"
852 if ($make_jobs > 1 && ($branch eq 'HEAD' || $branch ge 'REL9_1'));
853 @makeout = `cd $exim/src && $make_cmd $make_args 2>&1`;
855 writelog('make',\@makeout);
856 print "======== make log ===========\n",@makeout if ($verbose > 1);
857 send_result('Make',$status,\@makeout) if $status;
858 $steps_completed .= " Make";
863 return unless step_wanted('make-doc');
864 print time_str(),"running make doc ...\n" if $verbose;
867 @makeout = `cd $exim/doc/doc-docbook/ && \
868 EXIM_VER="4.82" $make everything 2>&1`;
870 writelog('make-doc',\@makeout);
871 print "======== make doc log ===========\n",@makeout if ($verbose > 1);
872 send_result('Doc',$status,\@makeout) if $status;
873 $steps_completed .= " Doc";
881 # no core = no result
882 my @cores = glob("$pgdata/$core_file_glob");
883 return () unless @cores;
886 system "gdb --version > $devnull 2>&1";
888 return () if $status;
890 my $cmdfile = "./gdbcmd";
892 open($handle, ">$cmdfile");
893 print $handle "bt\n";
898 foreach my $core (@cores)
900 my @onetrace = `gdb -x $cmdfile --batch $bindir/exim $core 2>&1`;
902 "\n\n================== stack trace: $core ==================\n",
911 sub make_install_check
914 return unless step_wanted('install-check');
915 print time_str(),"running make installcheck ($locale)...\n" if $verbose;
920 @checklog = `cd $exim/src/test/regress && $make installcheck 2>&1`;
924 chdir "$exim/src/tools/msvc";
925 @checklog = `perl vcregress.pl installcheck 2>&1`;
930 ("$exim/src/test/regress/regression.diffs","$installdir/logfile");
931 foreach my $logfile(@logfiles)
933 next unless (-e $logfile );
934 push(@checklog,"\n\n================== $logfile ==================\n");
936 open($handle,$logfile);
946 get_stack_trace("$installdir/bin","$installdir/data-$locale");
947 push(@checklog,@trace);
949 writelog("install-check-$locale",\@checklog);
950 print "======== make installcheck log ===========\n",@checklog
952 send_result("InstallCheck-$locale",$status,\@checklog) if $status;
953 $steps_completed .= " InstallCheck-$locale";
956 sub make_isolation_check
959 return unless step_wanted('isolation-check');
964 "cd $exim/src/test/isolation && $make NO_LOCALE=1 installcheck";
965 @makeout = `$cmd 2>&1`;
969 chdir "$exim/src/tools/msvc";
970 @makeout = `perl vcregress.pl isolationcheck 2>&1`;
976 # get the log files and the regression diffs
977 my @logs = glob("$exim/src/test/isolation/log/*.log");
978 push(@logs,"$installdir/logfile");
979 unshift(@logs,"$exim/src/test/isolation/regression.diffs")
980 if (-e "$exim/src/test/isolation/regression.diffs");
981 foreach my $logfile (@logs)
983 push(@makeout,"\n\n================== $logfile ===================\n");
985 open($handle,$logfile);
995 get_stack_trace("$installdir/bin","$installdir/data-$locale");
996 push(@makeout,@trace);
998 writelog('isolation-check',\@makeout);
999 print "======== make isolation check logs ===========\n",@makeout
1002 send_result('IsolationCheck',$status,\@makeout) if $status;
1003 $steps_completed .= " IsolationCheck";
1008 return unless step_wanted('test');
1009 print time_str(),"running make test ...\n" if $verbose;
1010 my $tests_range = $EximBuild::conf{range_num_tests} || "1 4";
1012 @makeout =`(cd $exim/test
1013 autoconf && ./configure && $make )2>&1 `;
1014 my $status = $? >>8;
1017 my @tmp = `(WORKDIR=\$PWD
1019 ./runtest \$WORKDIR/$exim/src/build-*/exim -CONTINUE $tests_range )2>&1`;
1021 push @makeout, @tmp;
1022 # Prepend the failed summary log outputs for ease of reading
1023 my $fail_summary = "$exim/test/failed-summary.log";
1024 if (-f $fail_summary)
1026 @tmp = `cat $fail_summary`;
1028 unshift @makeout, @tmp;
1029 unshift @makeout, "Summary of failed tests:\n";
1032 writelog('test',\@makeout);
1033 print "======== make test logs ===========\n",@makeout
1036 send_result('Test',$status,\@makeout) if $status;
1037 $steps_completed .= " Test";
1042 return unless step_wanted('ecpg-check');
1044 my $ecpg_dir = "$exim/src/interfaces/ecpg";
1047 chdir "$exim/src/tools/msvc";
1048 @makeout = `perl vcregress.pl ecpgcheck 2>&1`;
1053 @makeout = `cd $ecpg_dir && $make NO_LOCALE=1 check 2>&1`;
1055 my $status = $? >>8;
1057 # get the log files and the regression diffs
1058 my @logs = glob("$ecpg_dir/test/log/*.log");
1059 unshift(@logs,"$ecpg_dir/test/regression.diffs")
1060 if (-e "$ecpg_dir/test/regression.diffs");
1061 foreach my $logfile (@logs)
1063 push(@makeout,"\n\n================== $logfile ===================\n");
1065 open($handle,$logfile);
1074 my $base = "$ecpg_dir/test/regress/tmp_check";
1076 get_stack_trace("$base/install$installdir/bin", "$base/data");
1077 push(@makeout,@trace);
1079 writelog('ecpg-check',\@makeout);
1080 print "======== make ecpg check logs ===========\n",@makeout
1083 send_result('ECPG-Check',$status,\@makeout) if $status;
1084 $steps_completed .= " ECPG-Check";
1089 return unless step_wanted('configure');
1090 print time_str(),"creating configuration ...\n" if $verbose;
1092 my $env = $EximBuild::conf{makefile_set};
1093 my $add = $EximBuild::conf{makefile_add};
1094 my $features = $EximBuild::conf{makefile_regex};
1097 while (my ($key,$val) = each %$env)
1099 $envstr .= "$key='$val'\n";
1101 while (my ($key,$val) = each %$add)
1103 $envstr .= "$key+='$val'\n";
1106 my $conf_path = "src/src/EDITME";
1107 my $local_conf = "src/Local/Makefile";
1108 my @confout = `cd $exim; mkdir -p src/Local 2>&1`;
1109 my @tmp = `cd $exim && cp $conf_path $local_conf 2>&1`;
1110 my $status = $? >> 8;
1111 push @confout, @tmp;
1114 # First, let's display some directory permissions in case
1115 # permissions are causing problems.
1116 my @dir = split('/',`pwd`);
1118 my $count = scalar @dir;
1121 while ($loop < $count)
1124 foreach my $i (0 .. $loop)
1126 $dir .= $dir[$i].'/';
1131 @tmp = `echo "Verify Directory Permissions"
1133 push @confout, @tmp;
1134 # Build the config file from the EDITME template
1135 @tmp = `cd $exim && echo '$envstr' >> $local_conf`;
1136 push @confout, @tmp;
1137 my $exim_user = $EximBuild::conf{master_exim_user} || 'exim';
1138 @tmp = `echo "Hardcoded Exim user info:"; id $exim_user
1139 cd $exim && perl -pi -e 's/^EXIM_USER=.*/EXIM_USER=$exim_user/' $local_conf`;
1140 push @confout, @tmp;
1141 my $me = `whoami`; chomp $me;
1142 @tmp = `echo "Build Farm user info:"; id $me
1143 cd $exim && perl -pi -e 's/^# CONFIGURE_OWNER=\$/CONFIGURE_OWNER=$me/' $local_conf`;
1144 push @confout, @tmp;
1145 @tmp = `cd $exim && perl -pi -e 's/^# TRUSTED_CONFIG_LIST=/TRUSTED_CONFIG_LIST=/' $local_conf`;
1146 push @confout, @tmp;
1147 @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`;
1148 push @confout, @tmp;
1149 @tmp = `cd $exim && perl -pi -e 's/^EXIM_MONITOR=(.*)/# EXIM_MONITOR=\$1/' $local_conf`;
1150 push @confout, @tmp;
1151 for my $regex ( @$features )
1154 perl -pi -e '$regex' $local_conf 2>&1
1155 echo "Used regex: $regex" `;
1156 push @confout, @tmp;
1158 # Add the final build file to the display output
1161 echo "Contents of Local/Makefile:"
1162 egrep '^[^#]' $local_conf `;
1163 push @confout, @tmp;
1164 # Build the config_opts array to send to the server
1166 my @config_opts = grep s/(?:LOOKUP_|EXPERIMENTAL_|USE_)(\S+)=.*/$1/,
1168 push @config_opts, grep s/^(?:EXIM_)(PERL|PYTHON)=.*/$1/,
1170 # OpenSSL doesn't have a specific USE flag
1171 push @config_opts, grep s/^(TLS_LIBS.*-l(ssl|crypto)).*/OPENSSL/,
1173 $EximBuild::conf{config_opts} = \@config_opts;
1175 # Does not matter what the Exim version is, as long as it is valid.
1176 my $exim_ver = $EximBuild::conf{exim_test_version} || '4.82';
1178 echo 'EXIM_RELEASE_VERSION="$exim_ver"' > src/src/version.sh
1179 echo 'EXIM_VARIANT_VERSION=""' >> src/src/version.sh
1180 echo 'EXIM_COMPILE_NUMBER="0"' >> src/src/version.sh`;
1183 print "======== configure output ===========\n",@confout
1186 writelog('configure',\@confout);
1190 send_result('Configure',$status,\@confout);
1193 $steps_completed .= " Configure";
1199 my $stname = $st_prefix . "last.$which";
1201 open($handle,$stname) or return undef;
1202 my $time = <$handle>;
1211 my $stname = $st_prefix . "last.$which";
1212 my $st_now = shift || time;
1214 open($handle,">$stname") or die "opening $stname: $!";
1215 print $handle "$st_now\n";
1222 # clean up temp file
1227 my $ts = $now || time;
1228 my $status=shift || 0;
1229 my $log = shift || [];
1230 print "======== log passed to send_result ===========\n",@$log
1234 "Last file mtime in snapshot: ",
1235 scalar(gmtime($current_snap)),
1236 " GMT\n","===================================================\n")
1237 unless ($from_source || !$current_snap);
1239 my $log_data = join("",@$log);
1241 my $changed_this_run = "";
1242 my $changed_since_success = "";
1243 $changed_this_run = join("!",@changed_files)
1245 $changed_since_success = join("!",@changed_since_success)
1246 if ($stage ne 'OK' && @changed_since_success);
1250 $confsum= $saved_config;
1252 elsif ($stage !~ /CVS|Git|SCM/ )
1254 $confsum = get_config_summary();
1258 $confsum = get_script_config_dump();
1261 my $savedata = Data::Dumper->Dump(
1263 $changed_this_run, $changed_since_success, $branch, $status,$stage,
1264 $animal, $ts,$log_data, $confsum, $target, $verbose, $secret
1267 qw(changed_this_run changed_since_success branch status stage
1268 animal ts log_data confsum target verbose secret)
1272 my $lrname = $st_prefix . $logdirname;
1274 # might happen if there is a CVS failure and have never got further
1275 mkdir $lrname unless -d $lrname;
1277 my $txfname = "$lrname/web-txn.data";
1279 open($txdhandle,">$txfname");
1280 print $txdhandle $savedata;
1283 if ($nosend || $stage eq 'CVS' || $stage eq 'CVS-status' )
1285 print "Branch: $branch\n";
1288 print "All stages succeeded\n";
1289 set_last('success.snap',$current_snap) unless $nostatus;
1294 print "Stage $stage failed with status $status\n";
1299 if ($stage !~ /CVS|Git|SCM|Pre-run-port-check/ )
1302 my @logfiles = glob("$lrname/*.log");
1303 my %mtimes = map { $_ => (stat $_)[9] } @logfiles;
1305 map { basename $_ }( sort { $mtimes{$a} <=> $mtimes{$b} } @logfiles );
1306 my $logfiles = join(' ',@logfiles);
1307 $tar_log_cmd =~ s/\*\.log/$logfiles/;
1309 system("$tar_log_cmd 2>&1 ");
1310 chdir($branch_root);
1316 # these would be from an earlier run, since we
1317 # do cleanlogs() after the cvs stage
1318 # so don't send them.
1319 unlink "$lrname/runlogs.tgz";
1324 # this should now only apply to older Msys installs. All others should
1325 # be running with perl >= 5.8 since that's required to build exim
1327 if (!$^V or $^V lt v5.8.0)
1330 unless (-x "$aux_path/run_web_txn.pl")
1332 print "Could not locate $aux_path/run_web_txn.pl\n";
1336 system("$aux_path/run_web_txn.pl $lrname");
1337 $txstatus = $? >> 8;
1341 $txstatus = EximBuild::WebTxn::run_web_txn($lrname) ? 0 : 1;
1347 print "Web txn failed with status: $txstatus\n";
1349 # if the web txn fails, restore the timestamps
1350 # so we try again the next time.
1351 set_last('status',$last_status) unless $nostatus;
1352 set_last('run.snap',$last_run_snap) unless $nostatus;
1356 unless ($stage eq 'OK' || $quiet)
1358 print "BuildFarm member $animal failed on $branch stage $stage\n";
1361 # print "Success!\n",$response->content
1362 # if $print_success;
1364 set_last('success.snap',$current_snap) if ($stage eq 'OK' && !$nostatus);
1369 sub get_config_summary
1373 # unless ($using_msvc)
1375 # open($handle,"$exim/config.log") || return undef;
1376 # my $start = undef;
1379 # if (!$start && /created by PostgreSQL configure/)
1382 # s/It was/This file was/;
1384 # next unless $start;
1385 # last if /Core tests/;
1387 # next if /= <?unknown>?/;
1389 # # split up long configure line
1390 # if (m!\$.*configure.*--with! && length > 70)
1392 # my $pos = index($_," ",70);
1393 # substr($_,$pos+1,0,"\\\n ") if ($pos > 0);
1394 # $pos = index($_," ",140);
1395 # substr($_,$pos+1,0,"\\\n ") if ($pos > 0);
1396 # $pos = index($_," ",210);
1397 # substr($_,$pos+1,0,"\\\n ") if ($pos > 0);
1403 # "\n========================================================\n";
1405 $config .= get_script_config_dump();
1409 sub get_script_config_dump
1412 %EximBuild::conf, # shallow copy
1413 script_version => $VERSION,
1414 invocation_args => \@invocation_args,
1415 steps_completed => $steps_completed,
1416 orig_env => $orig_env,
1418 delete $conf->{secret};
1419 $Data::Dumper::Sortkeys = 1;
1420 return Data::Dumper->Dump([$conf],['Script_Config']);
1425 my $wait_time = shift;
1426 my $who_to_kill = getpgrp(0);
1429 print "waiting $wait_time secs to time out process $who_to_kill\n"
1431 foreach my $sig (qw(INT TERM HUP QUIT))
1433 $SIG{$sig}='DEFAULT';
1436 $SIG{TERM} = 'IGNORE'; # so we don't kill ourself, we're exiting anyway
1437 # kill the whole process group
1438 unless (kill $sig,$who_to_kill)
1440 print "scm timeout kill failed\n";
1446 my $coderef = shift;
1448 if (defined($pid) && $pid == 0)