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 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;
79 if ($0 =~ /(.*)\.pl$/) {
80 die "$0: Please use `@{[join ' ' => $1, @ARGV]}' instead.\n"
87 my $orig_dir = getcwd();
90 # make sure we exit nicely on any normal interrupt
91 # so the cleanup handler gets called.
92 # that lets us stop the db if it's running and
93 # remove the inst and exim directories
94 # so the next run can start clean.
96 foreach my $sig (qw(INT TERM HUP QUIT))
98 $SIG{$sig}=\&interrupt_exit;
101 # copy command line before processing - so we can later report it
104 my @invocation_args = (@ARGV);
106 # process the command line
107 EximBuild::Options::fetch_options();
109 die "only one of --from-source and --from-source-clean allowed"
110 if ($from_source && $from_source_clean);
112 die "only one of --skip-steps and --only-steps allowed"
113 if ($skip_steps && $only_steps);
115 $verbose=1 if (defined($verbose) && $verbose==0);
116 $verbose ||= 0; # stop complaints about undefined var in numeric comparison
120 $verbose=1 unless $verbose;
127 use vars qw(%skip_steps %only_steps);
129 if ($skip_steps =~ /\S/)
131 %skip_steps = map {$_ => 1} split(/\s+/,$skip_steps);
134 if ($only_steps =~ /\S/)
136 %only_steps = map {$_ => 1} split(/(\s+|[:,])/,$only_steps);
139 # Currently only specifying a branch is actually used.
140 # Specifying a different repo is just a wishlist item .
141 use vars qw($branch $repo);
142 my ($arg1,$arg2) = (shift,shift);
143 $branch = $arg2 ? $arg2 :
146 $repo = $arg2 ? $arg1 : 'exim';
147 my $explicit_branch = $branch;
149 print_help() if ($help);
152 # process config file
156 # get the config data into some local variables
158 $buildroot,$target,$animal, $print_success,
159 $aux_path,$trigger_exclude,$trigger_include,$secret,
160 $keep_errs,$force_every, $make, $optional_steps,
161 $use_vpath,$tar_log_cmd, $using_msvc, $extra_config,
162 $make_jobs, $core_file_glob
165 qw(build_root target animal print_success aux_path trigger_exclude
166 trigger_include secret keep_error_builds force_every make optional_steps
167 use_vpath tar_log_cmd using_msvc extra_config make_jobs core_file_glob)
170 #default is no parallel build
173 # default core file pattern is Linux, which used to be hardcoded
174 $core_file_glob ||= 'core*';
177 if (defined($EximBuild::conf{trigger_filter}))
179 $trigger_exclude = $EximBuild::conf{trigger_filter};
182 my $scm_timeout_secs = $EximBuild::conf{scm_timeout_secs}
183 || $EximBuild::conf{cvs_timeout_secs};
185 print scalar(localtime()),": buildfarm run for $animal:$branch starting\n"
188 # Allow commandline overrides of conf variables
189 foreach my $arg ( @{$EximBuild::Options::overrides} )
191 if (my ($key,$val) = split '=', $arg)
193 $EximBuild::conf{$key} = $val;
194 printf "Commandline override: '$key' = '%s'\n", $EximBuild::conf{$key}
199 if (ref($force_every) eq 'HASH')
201 $force_every = $force_every->{$branch} || $force_every->{default};
204 my $scm = new EximBuild::SCM \%EximBuild::conf;
208 if (exists $EximBuild::conf{base_port})
210 $buildport = $EximBuild::conf{base_port};
211 if ($branch =~ /REL(\d+)_(\d+)/)
213 $buildport += (10 * ($1 - 7)) + $2;
219 # support for legacy config style
220 $buildport = $EximBuild::conf{branch_ports}->{$branch} || 5999;
223 $ENV{EXTRA_REGRESS_OPTS} = "--port=$buildport";
225 $tar_log_cmd ||= "tar -z -cf runlogs.tgz *.log";
227 my $logdirname = "lastrun-logs";
229 if ($from_source || $from_source_clean)
231 $from_source ||= $from_source_clean;
232 die "sourceroot $from_source not absolute"
233 unless $from_source =~ m!^/!;
235 # we need to know where the lock should go, so unless the path
236 # contains HEAD we require it to be specified.
237 die "must specify branch explicitly with from_source"
238 unless ($explicit_branch || $from_source =~ m!/HEAD/!);
243 $logdirname = "fromsource-logs";
247 if ($branch eq 'HEAD' || $branch ge 'REL8_4')
250 # non-C locales are not regression-safe before 8.4
251 @locales = @{$EximBuild::conf{locales}} if exists $EximBuild::conf{locales};
253 unshift(@locales,'C') unless grep {$_ eq "C"} @locales;
256 # several people have run into these
258 if ( `uname -s 2>&1 ` =~ /CYGWIN/i )
260 my @procs = `ps -ef`;
261 die "cygserver not running" unless(grep {/cygserver/} @procs);
264 if ( $ccachedir = $EximBuild::conf{build_env}->{CCACHE_DIR} )
267 # ccache is smart enough to create what you tell it is the cache dir, but
268 # not smart enough to build the whole path. mkpath croaks on error, so
272 $ccachedir = abs_path($ccachedir);
277 die "no aux_path in config file" unless $aux_path;
280 die "cannot run as root/Administrator" unless ($using_msvc or $> > 0);
282 my $devnull = $using_msvc ? "nul" : "/dev/null";
286 $scm->check_access($using_msvc);
289 my $st_prefix = "$animal.";
291 my $exim = $from_source || $scm->get_build_path($use_vpath);
293 # set environment from config
294 while (my ($envkey,$envval) = each %{$EximBuild::conf{build_env}})
296 $ENV{$envkey}=$envval;
299 # change to buildroot for this branch or die
300 die "no buildroot" unless $buildroot;
302 unless ($buildroot =~ m!^/!
303 or($using_msvc and $buildroot =~ m![a-z]:[/\\]!i ))
305 die "buildroot $buildroot not absolute";
308 die "$buildroot does not exist or is not a directory" unless -d $buildroot;
310 chdir $buildroot || die "chdir to $buildroot: $!";
312 mkdir $branch unless -d $branch;
313 chdir $branch || die "chdir to $buildroot/$branch";
315 # rename legacy status files/directories
316 foreach my $oldfile (glob("last*"))
318 move $oldfile, "$st_prefix$oldfile";
321 my $branch_root = getcwd();
323 # Normally we would require GNU Make, but allow farm
324 # configuration to override this
325 die "$make is not GNU Make - please fix config file"
329 foreach my $module (@{$EximBuild::conf{modules}})
332 # fill in the name of the module here, so use double quotes
333 # so everything BUT the module name needs to be escaped
335 require EximBuild::Modules::$module;
336 EximBuild::Modules::${module}::setup(
353 open($lockfile, ">builder.LCK") || die "opening lockfile: $!";
355 # only one builder at a time allowed per branch
356 # having another build running is not a failure, and so we do not output
357 # a failure message under this condition.
360 die "acquiring lock in $buildroot/$branch/builder.LCK"
361 unless flock($lockfile,LOCK_EX|LOCK_NB);
363 elsif ( !flock($lockfile,LOCK_EX|LOCK_NB) )
365 print "Another process holds the lock on "
366 ."$buildroot/$branch/builder.LCK. Exiting."
371 die "$buildroot/$branch has $exim or inst directories!"
372 if ((!$from_source && -d $exim) || -d "inst");
374 # we are OK to run if we get here
377 # check if file present for forced run
378 my $forcefile = $st_prefix . "force-one-run";
385 # try to allow core files to be produced.
386 # another way would be for the calling environment
387 # to call ulimit. We do this in an eval so failure is
390 require BSD::Resource;
391 BSD::Resource->import();
393 # explicit sub calls here. using & keeps compiler happy
394 my $coreok = setrlimit(&RLIMIT_CORE,&RLIM_INFINITY,&RLIM_INFINITY);
395 die "setrlimit" unless $coreok;
397 warn "failed to unlimit core size: $@" if $@ && $verbose > 1;
399 # the time we take the snapshot
401 my $installdir = "$buildroot/$branch/inst";
406 # cleanup handler for all exits
411 unlink $ENV{TEMP_CONFIG} if $extraconf;
413 # if we have the lock we must already be in the build root, so
414 # removing things there should be safe.
415 # there should only be anything to cleanup if we didn't have
417 if ( $have_lock && -d "$exim")
422 system(qq{"bin/pg_ctl" -D data stop >$devnull 2>&1});
423 foreach my $loc (@locales)
425 next unless -d "data-$loc";
426 system(qq{"bin/pg_ctl" -D "data-$loc" stop >$devnull 2>&1});
430 if ( !$from_source && $keep_errs)
432 print "moving kept error trees\n" if $verbose;
433 my $timestr = strftime "%Y-%m-%d_%H-%M-%S", localtime($now);
434 unless (move("$exim", "eximkeep.$timestr"))
436 print "error renaming '$exim' to 'eximkeep.$timestr': $!";
440 unless(move("inst", "instkeep.$timestr"))
442 print "error renaming 'inst' to 'instkeep.$timestr': $!";
448 rmtree("inst") unless $keepall;
449 rmtree("$exim") unless ($from_source || $keepall);
452 # only keep the cache in cases of success
453 rmtree("$ccachedir") if $ccachedir;
456 # get the modules to clean up after themselves
457 process_module_hooks('cleanup');
464 # vpath builds leave some stuff lying around in the
465 # source dir, unfortunately. This should clean it up.
469 unlink("builder.LCK");
473 # Prepend the DEFAULT settings (if any) to any settings for the
474 # branch. Since we're mangling this, deep clone $extra_config
475 # so the config object is kept as given. This is done using
476 # Dumper() because the MSys DTK perl doesn't have Storable. This
477 # is less efficient but it hardly matters here for this shallow
480 $extra_config = eval Dumper($extra_config);
482 if ($extra_config && $extra_config->{DEFAULT})
484 if (!exists $extra_config->{$branch})
486 $extra_config->{$branch} = $extra_config->{DEFAULT};
490 unshift(@{$extra_config->{$branch}}, @{$extra_config->{DEFAULT}});
494 if ($extra_config && $extra_config->{$branch})
497 ($extraconf,$tmpname) =File::Temp::tempfile(
499 DIR => File::Spec->tmpdir(),
502 die 'no $tmpname!' unless $tmpname;
503 $ENV{TEMP_CONFIG} = $tmpname;
504 foreach my $line (@{$extra_config->{$branch}})
506 print $extraconf "$line\n";
508 autoflush $extraconf 1;
511 use vars qw($steps_completed);
512 $steps_completed = "";
515 my @changed_since_success;
519 my $last_success_snap;
525 if ($from_source_clean)
527 print time_str(),"cleaning source in $exim ...\n";
530 elsif (!$from_source)
533 # see if we need to run the tests (i.e. if either something has changed or
534 # we have gone over the force_every heartbeat time)
536 print time_str(),"checking out source ...\n" if $verbose;
540 $timeout_pid = spawn(\&scm_timeout,$scm_timeout_secs)
541 if $scm_timeout_secs;
543 $savescmlog = $scm->checkout($branch);
544 $steps_completed = "SCM-checkout";
546 process_module_hooks('checkout',$savescmlog);
551 # don't kill me, I finished in time
552 if (kill(SIGTERM, $timeout_pid))
556 waitpid($timeout_pid,0);
560 print time_str(),"checking if build run needed ...\n" if $verbose;
562 # transition to new time processing
563 unlink "last.success";
565 # get the timestamp data
566 $last_config = find_last('config') || 0;
567 $last_status = find_last('status') || 0;
568 $last_run_snap = find_last('run.snap');
569 $last_success_snap = find_last('success.snap');
570 $forcerun = 1 unless (defined($last_run_snap));
572 # If config file changed, force a rebuild
573 ($current_config) = (stat $orig_dir.'/'.$buildconf)[9];
574 if (defined $current_config && $current_config > $last_config)
577 set_last('config',$current_config) unless $nostatus;
580 # updated by find_changed to last mtime of any file in the repo
583 # see if we need to force a build
587 &&$last_status+($force_every*3600) < $now);
588 $last_status = 0 if $forcerun;
590 # see what's changed since the last time we did work
591 $scm->find_changed(\$current_snap,$last_run_snap, $last_success_snap,
592 \@changed_files,\@changed_since_success);
594 #ignore changes to files specified by the trigger exclude filter, if any
595 if (defined($trigger_exclude))
597 @filtered_files = grep { !m[$trigger_exclude] } @changed_files;
601 @filtered_files = @changed_files;
604 #ignore changes to files NOT specified by the trigger include filter, if any
605 if (defined($trigger_include))
607 @filtered_files = grep { m[$trigger_include] } @filtered_files;
610 my $modules_need_run;
612 process_module_hooks('need-run',\$modules_need_run);
614 # if no build required do nothing
615 if ($last_status && !@filtered_files && !$modules_need_run)
618 "No build required: last status = ",scalar(gmtime($last_status)),
619 " GMT, current snapshot = ",scalar(gmtime($current_snap))," GMT,",
620 " changed files = ",scalar(@filtered_files),"\n"
626 # get version info on both changed files sets
627 # XXX modules support?
629 $scm->get_versions(\@changed_files);
630 $scm->get_versions(\@changed_since_success);
632 } # end of unless ($from_source)
636 writelog('SCM-checkout',$savescmlog) unless $from_source;
637 $scm->log_id() unless $from_source;
639 # copy/create according to vpath/scm settings
643 print time_str(),"creating vpath build dir $exim ...\n" if $verbose;
644 mkdir $exim || die "making $exim: $!";
646 elsif (!$from_source && $scm->copy_source_required())
648 print time_str(),"copying source to $exim ...\n" if $verbose;
650 $scm->copy_source($using_msvc);
653 process_module_hooks('setup-target');
657 set_last('status',$now) unless $nostatus;
658 set_last('run.snap',$current_snap) unless $nostatus;
660 my $started_times = 0;
661 print time_str(),"running configure ...\n" if $verbose;
663 # each of these routines will call send_result, which calls exit,
664 # on any error, so each step depends on success in the previous
672 make_test() if (check_optional_step('test'));
674 make_doc() if (check_optional_step('make-doc'));
676 ##check_port_is_ok($buildport,'Post');
678 # if we get here everything went fine ...
680 my $saved_config = get_config_summary();
682 rmtree("inst"); # only keep failures
683 rmtree("$exim") unless ($from_source || $keepall);
685 print(time_str(),"OK\n") if $verbose;
691 ############## end of main program ###########################
696 usage: $0 [options] [branch]
698 where options are one or more of:
700 --nosend = don't send results
701 --nostatus = don't set status files
702 --force = force a build run (ignore status files)
703 --from-source=/path = use source in path, not from SCM
705 --from-source-clean=/path = same as --from-source, run make distclean first
706 --config=/path/to/file = alternative location for config file
707 --keepall = keep directories if an error occurs
708 --verbose[=n] = verbosity (default 1) 2 or more = huge output.
709 --quiet = suppress normal error message
710 --test = short for --nosend --nostatus --verbose --force
711 --skip-steps=list = skip certain steps
712 --only-steps=list = only do certain steps, not allowed with skip-steps
713 lists can be comma, colon, or space separated
715 Default branch is HEAD. Usually only the --config option should be necessary.
723 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
724 return sprintf("[%.2d:%.2d:%.2d] ",$hour, $min, $sec);
730 return $only_steps{$step} if $only_steps;
731 return !$skip_steps{$step} if $skip_steps;
732 return 1; # default is everything is wanted
735 sub register_module_hooks
739 while (my ($hook,$func) = each %$what)
741 $module_hooks{$hook} ||= [];
742 push(@{$module_hooks{$hook}},[$func,$who]);
746 sub process_module_hooks
750 # pass remaining args (if any) to module func
751 foreach my $module (@{$module_hooks{$hook}})
753 my ($func,$module_instance) = @$module;
754 &$func($module_instance, @_);
758 sub check_optional_step
764 return undef unless ref($oconf = $optional_steps->{$step});
765 if ($oconf->{branches})
767 return undef unless grep {$_ eq $branch} @{$oconf->{branches}};
770 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =localtime(time);
771 return undef if (exists $oconf->{min_hour} && $hour < $oconf->{min_hour});
772 return undef if (exists $oconf->{max_hour} && $hour > $oconf->{max_hour});
773 return undef if (exists $oconf->{dow}
774 &&grep {$_ eq $wday} @{$oconf->{dow}});
776 my $last_step = $last_status = find_last("$step") || 0;
777 ## If made it *to* these optional steps, we just run them and reset last time
778 #return undef unless ($forcerun ||
779 # time >$last_step + (3600 * $oconf->{min_hours_since}));
780 set_last("$step") unless $nostatus;
785 sub clean_from_source
787 if (-e "$exim/GNUmakefile")
791 my @makeout = `cd $exim && $make distclean 2>&1`;
793 writelog('distclean',\@makeout);
794 print "======== distclean log ===========\n",@makeout if ($verbose > 1);
795 send_result('distclean',$status,\@makeout) if $status;
802 print "Exiting on signal $signame\n";
808 my $lrname = $st_prefix . $logdirname;
810 mkdir "$lrname" || die "can't make $lrname dir: $!";
816 my $loglines = shift;
818 my $lrname = $st_prefix . $logdirname;
819 open($handle,">$lrname/$stage.log") || die $!;
820 print $handle @$loglines;
826 return unless step_wanted('features');
828 src/build-*/exim -C test/confs/0000 -bV `;
830 writelog('features',\@out);
831 print "======== features log ===========\n",@out if ($verbose > 1);
832 send_result('Features',$status,\@out) if $status;
833 $steps_completed .= " Features";
838 # Allow farm member to configure non-GNU make
839 my $non_gnu_make = $EximBuild::conf{non_gnu_make};
840 if (!defined $non_gnu_make ||
841 (defined $non_gnu_make && $non_gnu_make == 1)) {
844 my @out = `$make -v 2>&1`;
845 return undef unless ($? == 0 && grep {/GNU Make/} @out);
851 return unless step_wanted('make');
852 print time_str(),"running make ...\n" if $verbose;
853 my $make_args = join(' ',$EximBuild::conf{make_args});
855 my $make_cmd = $make;
856 $make_cmd = "$make -j $make_jobs"
857 if ($make_jobs > 1 && ($branch eq 'HEAD' || $branch ge 'REL9_1'));
858 @makeout = `cd $exim/src && $make_cmd $make_args 2>&1`;
860 writelog('make',\@makeout);
861 print "======== make log ===========\n",@makeout if ($verbose > 1);
862 send_result('Make',$status,\@makeout) if $status;
863 $steps_completed .= " Make";
868 return unless step_wanted('make-doc');
869 print time_str(),"running make doc ...\n" if $verbose;
872 @makeout = `cd $exim/doc/doc-docbook/ && \
873 EXIM_VER="4.82" $make everything 2>&1`;
875 writelog('make-doc',\@makeout);
876 print "======== make doc log ===========\n",@makeout if ($verbose > 1);
877 send_result('Doc',$status,\@makeout) if $status;
878 $steps_completed .= " Doc";
886 # no core = no result
887 my @cores = glob("$pgdata/$core_file_glob");
888 return () unless @cores;
891 system "gdb --version > $devnull 2>&1";
893 return () if $status;
895 my $cmdfile = "./gdbcmd";
897 open($handle, ">$cmdfile");
898 print $handle "bt\n";
903 foreach my $core (@cores)
905 my @onetrace = `gdb -x $cmdfile --batch $bindir/exim $core 2>&1`;
907 "\n\n================== stack trace: $core ==================\n",
916 sub make_install_check
919 return unless step_wanted('install-check');
920 print time_str(),"running make installcheck ($locale)...\n" if $verbose;
925 @checklog = `cd $exim/src/test/regress && $make installcheck 2>&1`;
929 chdir "$exim/src/tools/msvc";
930 @checklog = `perl vcregress.pl installcheck 2>&1`;
935 ("$exim/src/test/regress/regression.diffs","$installdir/logfile");
936 foreach my $logfile(@logfiles)
938 next unless (-e $logfile );
939 push(@checklog,"\n\n================== $logfile ==================\n");
941 open($handle,$logfile);
951 get_stack_trace("$installdir/bin","$installdir/data-$locale");
952 push(@checklog,@trace);
954 writelog("install-check-$locale",\@checklog);
955 print "======== make installcheck log ===========\n",@checklog
957 send_result("InstallCheck-$locale",$status,\@checklog) if $status;
958 $steps_completed .= " InstallCheck-$locale";
961 sub make_isolation_check
964 return unless step_wanted('isolation-check');
969 "cd $exim/src/test/isolation && $make NO_LOCALE=1 installcheck";
970 @makeout = `$cmd 2>&1`;
974 chdir "$exim/src/tools/msvc";
975 @makeout = `perl vcregress.pl isolationcheck 2>&1`;
981 # get the log files and the regression diffs
982 my @logs = glob("$exim/src/test/isolation/log/*.log");
983 push(@logs,"$installdir/logfile");
984 unshift(@logs,"$exim/src/test/isolation/regression.diffs")
985 if (-e "$exim/src/test/isolation/regression.diffs");
986 foreach my $logfile (@logs)
988 push(@makeout,"\n\n================== $logfile ===================\n");
990 open($handle,$logfile);
1000 get_stack_trace("$installdir/bin","$installdir/data-$locale");
1001 push(@makeout,@trace);
1003 writelog('isolation-check',\@makeout);
1004 print "======== make isolation check logs ===========\n",@makeout
1007 send_result('IsolationCheck',$status,\@makeout) if $status;
1008 $steps_completed .= " IsolationCheck";
1013 return unless step_wanted('test');
1014 print time_str(),"running make test ...\n" if $verbose;
1015 my $tests_range = $EximBuild::conf{range_num_tests} || "1 4";
1017 @makeout =`(cd $exim/test
1018 autoconf && ./configure && $make )2>&1 `;
1019 my $status = $? >>8;
1022 my @tmp = `(WORKDIR=\$PWD
1024 ./runtest \$WORKDIR/$exim/src/build-*/exim -CONTINUE $tests_range )2>&1`;
1026 push @makeout, @tmp;
1027 # Prepend the failed summary log outputs for ease of reading
1028 my $fail_summary = "$exim/test/failed-summary.log";
1029 if (-f $fail_summary)
1031 @tmp = `cat $fail_summary`;
1033 unshift @makeout, @tmp;
1034 unshift @makeout, "Summary of failed tests:\n";
1037 writelog('test',\@makeout);
1038 print "======== make test logs ===========\n",@makeout
1041 send_result('Test',$status,\@makeout) if $status;
1042 $steps_completed .= " Test";
1047 return unless step_wanted('ecpg-check');
1049 my $ecpg_dir = "$exim/src/interfaces/ecpg";
1052 chdir "$exim/src/tools/msvc";
1053 @makeout = `perl vcregress.pl ecpgcheck 2>&1`;
1058 @makeout = `cd $ecpg_dir && $make NO_LOCALE=1 check 2>&1`;
1060 my $status = $? >>8;
1062 # get the log files and the regression diffs
1063 my @logs = glob("$ecpg_dir/test/log/*.log");
1064 unshift(@logs,"$ecpg_dir/test/regression.diffs")
1065 if (-e "$ecpg_dir/test/regression.diffs");
1066 foreach my $logfile (@logs)
1068 push(@makeout,"\n\n================== $logfile ===================\n");
1070 open($handle,$logfile);
1079 my $base = "$ecpg_dir/test/regress/tmp_check";
1081 get_stack_trace("$base/install$installdir/bin", "$base/data");
1082 push(@makeout,@trace);
1084 writelog('ecpg-check',\@makeout);
1085 print "======== make ecpg check logs ===========\n",@makeout
1088 send_result('ECPG-Check',$status,\@makeout) if $status;
1089 $steps_completed .= " ECPG-Check";
1094 return unless step_wanted('configure');
1095 print time_str(),"creating configuration ...\n" if $verbose;
1097 my $env = $EximBuild::conf{makefile_set};
1098 my $add = $EximBuild::conf{makefile_add};
1099 my $features = $EximBuild::conf{makefile_regex};
1102 while (my ($key,$val) = each %$env)
1104 $envstr .= "$key='$val'\n";
1106 while (my ($key,$val) = each %$add)
1108 $envstr .= "$key+='$val'\n";
1111 my $conf_path = "src/src/EDITME";
1112 my $local_conf = "src/Local/Makefile";
1113 my @confout = `cd $exim; mkdir -p src/Local 2>&1`;
1114 my @tmp = `cd $exim && cp $conf_path $local_conf 2>&1`;
1115 my $status = $? >> 8;
1116 push @confout, @tmp;
1119 # First, let's display some directory permissions in case
1120 # permissions are causing problems.
1121 my @dir = split('/',`pwd`);
1123 my $count = scalar @dir;
1126 while ($loop < $count)
1129 foreach my $i (0 .. $loop)
1131 $dir .= $dir[$i].'/';
1136 @tmp = `echo "Verify Directory Permissions"
1138 push @confout, @tmp;
1139 # Build the config file from the EDITME template
1140 @tmp = `cd $exim && echo '$envstr' >> $local_conf`;
1141 push @confout, @tmp;
1142 my $exim_user = $EximBuild::conf{master_exim_user} || 'exim';
1143 @tmp = `echo "Hardcoded Exim user info:"; id $exim_user
1144 cd $exim && perl -pi -e 's/^EXIM_USER=.*/EXIM_USER=$exim_user/' $local_conf`;
1145 push @confout, @tmp;
1146 my $me = `whoami`; chomp $me;
1147 @tmp = `echo "Build Farm user info:"; id $me
1148 cd $exim && perl -pi -e 's/^# CONFIGURE_OWNER=\$/CONFIGURE_OWNER=$me/' $local_conf`;
1149 push @confout, @tmp;
1150 my $testdir = `cd $exim && /bin/pwd`; chomp $testdir; $testdir .= "/test";
1151 my $trcf = "$testdir/trusted-configs";
1152 my $tecf = "$testdir/test-config";
1153 @tmp = `cd $exim && perl -pi -e "s%^# TRUSTED_CONFIG_LIST=.*%TRUSTED_CONFIG_LIST=$trcf%" $local_conf`;
1154 push @confout, @tmp;
1155 @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`;
1156 push @confout, @tmp;
1157 @tmp = `cd $exim && perl -pi -e 's/^EXIM_MONITOR=(.*)/# EXIM_MONITOR=\$1/' $local_conf`;
1158 push @confout, @tmp;
1159 for my $regex ( @$features )
1162 perl -pi -e '$regex' $local_conf 2>&1
1163 echo "Used regex: $regex" `;
1164 push @confout, @tmp;
1166 # Add the final build file to the display output
1169 echo "Contents of Local/Makefile:"
1170 egrep '^[^#]' $local_conf `;
1171 push @confout, @tmp;
1172 # Build the config_opts array to send to the server
1174 my @config_opts = grep s/(?:LOOKUP_|EXPERIMENTAL_|USE_)(\S+)=.*/$1/,
1176 push @config_opts, grep s/^(?:EXIM_)(PERL|PYTHON)=.*/$1/,
1178 # OpenSSL doesn't have a specific USE flag
1179 push @config_opts, grep s/^(TLS_LIBS.*-l(ssl|crypto)).*/OPENSSL/,
1181 $EximBuild::conf{config_opts} = \@config_opts;
1183 # Does not matter what the Exim version is, as long as it is valid.
1184 my $exim_ver = $EximBuild::conf{exim_test_version} || '4.82';
1186 echo 'EXIM_RELEASE_VERSION="$exim_ver"' > src/src/version.sh
1187 echo 'EXIM_VARIANT_VERSION=""' >> src/src/version.sh
1188 echo 'EXIM_COMPILE_NUMBER="0"' >> src/src/version.sh`;
1190 # Create a trusted-configs list file
1191 @tmp = `cd $exim && echo "$tecf" > "$trcf"`;
1192 push @confout, @tmp;
1195 print "======== configure output ===========\n",@confout
1198 writelog('configure',\@confout);
1202 send_result('Configure',$status,\@confout);
1205 $steps_completed .= " Configure";
1211 my $stname = $st_prefix . "last.$which";
1213 open($handle,$stname) or return undef;
1214 my $time = <$handle>;
1223 my $stname = $st_prefix . "last.$which";
1224 my $st_now = shift || time;
1226 open($handle,">$stname") or die "opening $stname: $!";
1227 print $handle "$st_now\n";
1234 # clean up temp file
1239 my $ts = $now || time;
1240 my $status=shift || 0;
1241 my $log = shift || [];
1242 print "======== log passed to send_result ===========\n",@$log
1246 "Last file mtime in snapshot: ",
1247 scalar(gmtime($current_snap)),
1248 " GMT\n","===================================================\n")
1249 unless ($from_source || !$current_snap);
1251 my $log_data = join("",@$log);
1253 my $changed_this_run = "";
1254 my $changed_since_success = "";
1255 $changed_this_run = join("!",@changed_files)
1257 $changed_since_success = join("!",@changed_since_success)
1258 if ($stage ne 'OK' && @changed_since_success);
1262 $confsum= $saved_config;
1264 elsif ($stage !~ /CVS|Git|SCM/ )
1266 $confsum = get_config_summary();
1270 $confsum = get_script_config_dump();
1273 my $savedata = Data::Dumper->Dump(
1275 $changed_this_run, $changed_since_success, $branch, $status,$stage,
1276 $animal, $ts,$log_data, $confsum, $target, $verbose, $secret
1279 qw(changed_this_run changed_since_success branch status stage
1280 animal ts log_data confsum target verbose secret)
1284 my $lrname = $st_prefix . $logdirname;
1286 # might happen if there is a CVS failure and have never got further
1287 mkdir $lrname unless -d $lrname;
1289 my $txfname = "$lrname/web-txn.data";
1291 open($txdhandle,">$txfname");
1292 print $txdhandle $savedata;
1295 if ($nosend || $stage eq 'CVS' || $stage eq 'CVS-status' )
1297 print "Branch: $branch\n";
1300 print "All stages succeeded\n";
1301 set_last('success.snap',$current_snap) unless $nostatus;
1306 print "Stage $stage failed with status $status\n";
1311 if ($stage !~ /CVS|Git|SCM|Pre-run-port-check/ )
1314 my @logfiles = glob("$lrname/*.log");
1315 my %mtimes = map { $_ => (stat $_)[9] } @logfiles;
1317 map { basename $_ }( sort { $mtimes{$a} <=> $mtimes{$b} } @logfiles );
1318 my $logfiles = join(' ',@logfiles);
1319 $tar_log_cmd =~ s/\*\.log/$logfiles/;
1321 system("$tar_log_cmd 2>&1 ");
1322 chdir($branch_root);
1328 # these would be from an earlier run, since we
1329 # do cleanlogs() after the cvs stage
1330 # so don't send them.
1331 unlink "$lrname/runlogs.tgz";
1336 # this should now only apply to older Msys installs. All others should
1337 # be running with perl >= 5.8 since that's required to build exim
1339 if (!$^V or $^V lt v5.8.0)
1342 unless (-x "$aux_path/run_web_txn.pl")
1344 print "Could not locate $aux_path/run_web_txn.pl\n";
1348 system("$aux_path/run_web_txn.pl $lrname");
1349 $txstatus = $? >> 8;
1353 $txstatus = EximBuild::WebTxn::run_web_txn($lrname) ? 0 : 1;
1359 print "Web txn failed with status: $txstatus\n";
1361 # if the web txn fails, restore the timestamps
1362 # so we try again the next time.
1363 set_last('status',$last_status) unless $nostatus;
1364 set_last('run.snap',$last_run_snap) unless $nostatus;
1368 unless ($stage eq 'OK' || $quiet)
1370 print "BuildFarm member $animal failed on $branch stage $stage\n";
1373 # print "Success!\n",$response->content
1374 # if $print_success;
1376 set_last('success.snap',$current_snap) if ($stage eq 'OK' && !$nostatus);
1381 sub get_config_summary
1385 # unless ($using_msvc)
1387 # open($handle,"$exim/config.log") || return undef;
1388 # my $start = undef;
1391 # if (!$start && /created by PostgreSQL configure/)
1394 # s/It was/This file was/;
1396 # next unless $start;
1397 # last if /Core tests/;
1399 # next if /= <?unknown>?/;
1401 # # split up long configure line
1402 # if (m!\$.*configure.*--with! && length > 70)
1404 # my $pos = index($_," ",70);
1405 # substr($_,$pos+1,0,"\\\n ") if ($pos > 0);
1406 # $pos = index($_," ",140);
1407 # substr($_,$pos+1,0,"\\\n ") if ($pos > 0);
1408 # $pos = index($_," ",210);
1409 # substr($_,$pos+1,0,"\\\n ") if ($pos > 0);
1415 # "\n========================================================\n";
1417 $config .= get_script_config_dump();
1421 sub get_script_config_dump
1424 %EximBuild::conf, # shallow copy
1425 script_version => $VERSION,
1426 invocation_args => \@invocation_args,
1427 steps_completed => $steps_completed,
1428 orig_env => $orig_env,
1430 delete $conf->{secret};
1432 if ($conf->{scm} eq 'git') {
1433 chomp($conf->{farm}{revision} = `git describe --tags --always --dirty=+`);
1436 $Data::Dumper::Sortkeys = 1;
1437 return Data::Dumper->Dump([$conf],['Script_Config']);
1442 my $wait_time = shift;
1443 my $who_to_kill = getpgrp(0);
1446 print "waiting $wait_time secs to time out process $who_to_kill\n"
1448 foreach my $sig (qw(INT TERM HUP QUIT))
1450 $SIG{$sig}='DEFAULT';
1453 $SIG{TERM} = 'IGNORE'; # so we don't kill ourself, we're exiting anyway
1454 # kill the whole process group
1455 unless (kill $sig,$who_to_kill)
1457 print "scm timeout kill failed\n";
1463 my $coderef = shift;
1465 if (defined($pid) && $pid == 0)