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);
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"
88 my $orig_dir = getcwd();
91 # make sure we exit nicely on any normal interrupt
92 # so the cleanup handler gets called.
93 # that lets us stop the db if it's running and
94 # remove the inst and exim directories
95 # so the next run can start clean.
97 foreach my $sig (qw(INT TERM HUP QUIT))
99 $SIG{$sig}=\&interrupt_exit;
102 # copy command line before processing - so we can later report it
105 my @invocation_args = (@ARGV);
107 # process the command line
108 EximBuild::Options::fetch_options();
110 die "only one of --from-source and --from-source-clean allowed"
111 if ($from_source && $from_source_clean);
113 die "only one of --skip-steps and --only-steps allowed"
114 if ($skip_steps && $only_steps);
116 $verbose=1 if (defined($verbose) && $verbose==0);
117 $verbose ||= 0; # stop complaints about undefined var in numeric comparison
121 $verbose=1 unless $verbose;
128 use vars qw(%skip_steps %only_steps);
130 if ($skip_steps =~ /\S/)
132 %skip_steps = map {$_ => 1} split(/\s+/,$skip_steps);
135 if ($only_steps =~ /\S/)
137 %only_steps = map {$_ => 1} split(/(\s+|[:,])/,$only_steps);
140 # Currently only specifying a branch is actually used.
141 # Specifying a different repo is just a wishlist item .
142 use vars qw($branch $repo);
143 my ($arg1,$arg2) = (shift,shift);
144 $branch = $arg2 ? $arg2 :
147 $repo = $arg2 ? $arg1 : 'exim';
148 my $explicit_branch = $branch;
150 print_help() if ($help);
153 # process config file
157 # get the config data into some local variables
159 $buildroot,$target,$animal, $print_success,
160 $aux_path,$trigger_exclude,$trigger_include,$secret,
161 $keep_errs,$force_every, $make, $optional_steps,
162 $use_vpath,$tar_log_cmd, $using_msvc, $extra_config,
163 $make_jobs, $core_file_glob
166 qw(build_root target animal print_success aux_path trigger_exclude
167 trigger_include secret keep_error_builds force_every make optional_steps
168 use_vpath tar_log_cmd using_msvc extra_config make_jobs core_file_glob)
171 #default is no parallel build
174 # default core file pattern is Linux, which used to be hardcoded
175 $core_file_glob ||= 'core*';
178 if (defined($EximBuild::conf{trigger_filter}))
180 $trigger_exclude = $EximBuild::conf{trigger_filter};
183 my $scm_timeout_secs = $EximBuild::conf{scm_timeout_secs}
184 || $EximBuild::conf{cvs_timeout_secs};
186 print scalar(localtime()),": buildfarm run for $animal:$branch starting\n"
189 # Allow commandline overrides of conf variables
190 foreach my $arg ( @{$EximBuild::Options::overrides} )
192 if (my ($key,$val) = split '=', $arg)
194 $EximBuild::conf{$key} = $val;
195 printf "Commandline override: '$key' = '%s'\n", $EximBuild::conf{$key}
200 if (ref($force_every) eq 'HASH')
202 $force_every = $force_every->{$branch} || $force_every->{default};
205 my $scm = new EximBuild::SCM \%EximBuild::conf;
209 if (exists $EximBuild::conf{base_port})
211 $buildport = $EximBuild::conf{base_port};
212 if ($branch =~ /REL(\d+)_(\d+)/)
214 $buildport += (10 * ($1 - 7)) + $2;
220 # support for legacy config style
221 $buildport = $EximBuild::conf{branch_ports}->{$branch} || 5999;
224 $ENV{EXTRA_REGRESS_OPTS} = "--port=$buildport";
226 $tar_log_cmd ||= "tar -z -cf runlogs.tgz *.log";
228 my $logdirname = "lastrun-logs";
230 if ($from_source || $from_source_clean)
232 $from_source ||= $from_source_clean;
233 die "sourceroot $from_source not absolute"
234 unless $from_source =~ m!^/!;
236 # we need to know where the lock should go, so unless the path
237 # contains HEAD we require it to be specified.
238 die "must specify branch explicitly with from_source"
239 unless ($explicit_branch || $from_source =~ m!/HEAD/!);
244 $logdirname = "fromsource-logs";
248 if ($branch eq 'HEAD' || $branch ge 'REL8_4')
251 # non-C locales are not regression-safe before 8.4
252 @locales = @{$EximBuild::conf{locales}} if exists $EximBuild::conf{locales};
254 unshift(@locales,'C') unless grep {$_ eq "C"} @locales;
257 # several people have run into these
259 if ( `uname -s 2>&1 ` =~ /CYGWIN/i )
261 my @procs = `ps -ef`;
262 die "cygserver not running" unless(grep {/cygserver/} @procs);
265 if ( $ccachedir = $EximBuild::conf{build_env}->{CCACHE_DIR} )
268 # ccache is smart enough to create what you tell it is the cache dir, but
269 # not smart enough to build the whole path. mkpath croaks on error, so
273 $ccachedir = abs_path($ccachedir);
278 die "no aux_path in config file" unless $aux_path;
281 die "cannot run as root/Administrator" unless ($using_msvc or $> > 0);
283 my $devnull = $using_msvc ? "nul" : "/dev/null";
287 $scm->check_access($using_msvc);
290 my $st_prefix = "$animal.";
292 my $exim = $from_source || $scm->get_build_path($use_vpath);
294 # set environment from config
295 while (my ($envkey,$envval) = each %{$EximBuild::conf{build_env}})
297 $ENV{$envkey}=$envval;
300 # change to buildroot for this branch or die
301 die "no buildroot" unless $buildroot;
303 unless ($buildroot =~ m!^/!
304 or($using_msvc and $buildroot =~ m![a-z]:[/\\]!i ))
306 die "buildroot $buildroot not absolute";
309 die "$buildroot does not exist or is not a directory" unless -d $buildroot;
311 chdir $buildroot || die "chdir to $buildroot: $!";
313 mkdir $branch unless -d $branch;
314 chdir $branch || die "chdir to $buildroot/$branch";
316 # rename legacy status files/directories
317 foreach my $oldfile (glob("last*"))
319 move $oldfile, "$st_prefix$oldfile";
322 my $branch_root = getcwd();
324 # Normally we would require GNU Make, but allow farm
325 # configuration to override this
326 die "$make is not GNU Make - please fix config file"
330 foreach my $module (@{$EximBuild::conf{modules}})
333 # fill in the name of the module here, so use double quotes
334 # so everything BUT the module name needs to be escaped
336 require EximBuild::Modules::$module;
337 EximBuild::Modules::${module}::setup(
354 open($lockfile, ">builder.LCK") || die "opening lockfile: $!";
356 # only one builder at a time allowed per branch
357 # having another build running is not a failure, and so we do not output
358 # a failure message under this condition.
361 die "acquiring lock in $buildroot/$branch/builder.LCK"
362 unless flock($lockfile,LOCK_EX|LOCK_NB);
364 elsif ( !flock($lockfile,LOCK_EX|LOCK_NB) )
366 print "Another process holds the lock on "
367 ."$buildroot/$branch/builder.LCK. Exiting."
372 die "$buildroot/$branch has $exim or inst directories!"
373 if ((!$from_source && -d $exim) || -d "inst");
375 # we are OK to run if we get here
378 # check if file present for forced run
379 my $forcefile = $st_prefix . "force-one-run";
386 # try to allow core files to be produced.
387 # another way would be for the calling environment
388 # to call ulimit. We do this in an eval so failure is
391 require BSD::Resource;
392 BSD::Resource->import();
394 # explicit sub calls here. using & keeps compiler happy
395 my $coreok = setrlimit(&RLIMIT_CORE,&RLIM_INFINITY,&RLIM_INFINITY);
396 die "setrlimit" unless $coreok;
398 warn "failed to unlimit core size: $@" if $@ && $verbose > 1;
400 # the time we take the snapshot
402 my $installdir = "$buildroot/$branch/inst";
407 # cleanup handler for all exits
412 unlink $ENV{TEMP_CONFIG} if $extraconf;
414 # if we have the lock we must already be in the build root, so
415 # removing things there should be safe.
416 # there should only be anything to cleanup if we didn't have
418 if ( $have_lock && -d "$exim")
423 system(qq{"bin/pg_ctl" -D data stop >$devnull 2>&1});
424 foreach my $loc (@locales)
426 next unless -d "data-$loc";
427 system(qq{"bin/pg_ctl" -D "data-$loc" stop >$devnull 2>&1});
431 if ( !$from_source && $keep_errs)
433 print "moving kept error trees\n" if $verbose;
434 my $timestr = strftime "%Y-%m-%d_%H-%M-%S", localtime($now);
435 unless (move("$exim", "eximkeep.$timestr"))
437 print "error renaming '$exim' to 'eximkeep.$timestr': $!";
441 unless(move("inst", "instkeep.$timestr"))
443 print "error renaming 'inst' to 'instkeep.$timestr': $!";
449 rmtree("inst") unless $keepall;
450 rmtree("$exim") unless ($from_source || $keepall);
453 # only keep the cache in cases of success
454 rmtree("$ccachedir") if $ccachedir;
457 # get the modules to clean up after themselves
458 process_module_hooks('cleanup');
465 # vpath builds leave some stuff lying around in the
466 # source dir, unfortunately. This should clean it up.
470 unlink("builder.LCK");
474 # Prepend the DEFAULT settings (if any) to any settings for the
475 # branch. Since we're mangling this, deep clone $extra_config
476 # so the config object is kept as given. This is done using
477 # Dumper() because the MSys DTK perl doesn't have Storable. This
478 # is less efficient but it hardly matters here for this shallow
481 $extra_config = eval Dumper($extra_config);
483 if ($extra_config && $extra_config->{DEFAULT})
485 if (!exists $extra_config->{$branch})
487 $extra_config->{$branch} = $extra_config->{DEFAULT};
491 unshift(@{$extra_config->{$branch}}, @{$extra_config->{DEFAULT}});
495 if ($extra_config && $extra_config->{$branch})
498 ($extraconf,$tmpname) =File::Temp::tempfile(
500 DIR => File::Spec->tmpdir(),
503 die 'no $tmpname!' unless $tmpname;
504 $ENV{TEMP_CONFIG} = $tmpname;
505 foreach my $line (@{$extra_config->{$branch}})
507 print $extraconf "$line\n";
509 autoflush $extraconf 1;
512 use vars qw($steps_completed);
513 $steps_completed = "";
516 my @changed_since_success;
520 my $last_success_snap;
526 if ($from_source_clean)
528 print time_str(),"cleaning source in $exim ...\n";
531 elsif (!$from_source)
534 # see if we need to run the tests (i.e. if either something has changed or
535 # we have gone over the force_every heartbeat time)
537 print time_str(),"checking out source ...\n" if $verbose;
541 $timeout_pid = spawn(\&scm_timeout,$scm_timeout_secs)
542 if $scm_timeout_secs;
544 $savescmlog = $scm->checkout($branch);
545 $steps_completed = "SCM-checkout";
547 process_module_hooks('checkout',$savescmlog);
552 # don't kill me, I finished in time
553 if (kill(SIGTERM, $timeout_pid))
557 waitpid($timeout_pid,0);
561 print time_str(),"checking if build run needed ...\n" if $verbose;
563 # transition to new time processing
564 unlink "last.success";
566 # get the timestamp data
567 $last_config = find_last('config') || 0;
568 $last_status = find_last('status') || 0;
569 $last_run_snap = find_last('run.snap');
570 $last_success_snap = find_last('success.snap');
571 $forcerun = 1 unless (defined($last_run_snap));
573 # If config file changed, force a rebuild
574 ($current_config) = (stat $orig_dir.'/'.$buildconf)[9];
575 if (defined $current_config && $current_config > $last_config)
578 set_last('config',$current_config) unless $nostatus;
581 # updated by find_changed to last mtime of any file in the repo
584 # see if we need to force a build
588 &&$last_status+($force_every*3600) < $now);
589 $last_status = 0 if $forcerun;
591 # see what's changed since the last time we did work
592 $scm->find_changed(\$current_snap,$last_run_snap, $last_success_snap,
593 \@changed_files,\@changed_since_success);
595 #ignore changes to files specified by the trigger exclude filter, if any
596 if (defined($trigger_exclude))
598 @filtered_files = grep { !m[$trigger_exclude] } @changed_files;
602 @filtered_files = @changed_files;
605 #ignore changes to files NOT specified by the trigger include filter, if any
606 if (defined($trigger_include))
608 @filtered_files = grep { m[$trigger_include] } @filtered_files;
611 my $modules_need_run;
613 process_module_hooks('need-run',\$modules_need_run);
615 # if no build required do nothing
616 if ($last_status && !@filtered_files && !$modules_need_run)
619 "No build required: last status = ",scalar(gmtime($last_status)),
620 " GMT, current snapshot = ",scalar(gmtime($current_snap))," GMT,",
621 " changed files = ",scalar(@filtered_files),"\n"
627 # get version info on both changed files sets
628 # XXX modules support?
630 $scm->get_versions(\@changed_files);
631 $scm->get_versions(\@changed_since_success);
633 } # end of unless ($from_source)
637 writelog('SCM-checkout',$savescmlog) unless $from_source;
638 $scm->log_id() unless $from_source;
640 # copy/create according to vpath/scm settings
644 print time_str(),"creating vpath build dir $exim ...\n" if $verbose;
645 mkdir $exim || die "making $exim: $!";
647 elsif (!$from_source && $scm->copy_source_required())
649 print time_str(),"copying source to $exim ...\n" if $verbose;
651 $scm->copy_source($using_msvc);
654 process_module_hooks('setup-target');
658 set_last('status',$now) unless $nostatus;
659 set_last('run.snap',$current_snap) unless $nostatus;
661 my $started_times = 0;
662 print time_str(),"running configure ...\n" if $verbose;
664 # each of these routines will call send_result, which calls exit,
665 # on any error, so each step depends on success in the previous
673 make_test() if (check_optional_step('test'));
675 make_doc() if (check_optional_step('make-doc'));
677 ##check_port_is_ok($buildport,'Post');
679 # if we get here everything went fine ...
681 my $saved_config = get_config_summary();
683 rmtree("inst"); # only keep failures
684 rmtree("$exim") unless ($from_source || $keepall);
686 print(time_str(),"OK\n") if $verbose;
692 ############## end of main program ###########################
697 usage: $0 [options] [branch]
699 where options are one or more of:
701 --nosend = don't send results
702 --nostatus = don't set status files
703 --force = force a build run (ignore status files)
704 --from-source=/path = use source in path, not from SCM
706 --from-source-clean=/path = same as --from-source, run make distclean first
707 --config=/path/to/file = alternative location for config file
708 --keepall = keep directories if an error occurs
709 --verbose[=n] = verbosity (default 1) 2 or more = huge output.
710 --quiet = suppress normal error message
711 --test = short for --nosend --nostatus --verbose --force
712 --skip-steps=list = skip certain steps
713 --only-steps=list = only do certain steps, not allowed with skip-steps
714 lists can be comma, colon, or space separated
716 Default branch is HEAD. Usually only the --config option should be necessary.
724 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
725 return sprintf("[%.2d:%.2d:%.2d] ",$hour, $min, $sec);
731 return $only_steps{$step} if $only_steps;
732 return !$skip_steps{$step} if $skip_steps;
733 return 1; # default is everything is wanted
736 sub register_module_hooks
740 while (my ($hook,$func) = each %$what)
742 $module_hooks{$hook} ||= [];
743 push(@{$module_hooks{$hook}},[$func,$who]);
747 sub process_module_hooks
751 # pass remaining args (if any) to module func
752 foreach my $module (@{$module_hooks{$hook}})
754 my ($func,$module_instance) = @$module;
755 &$func($module_instance, @_);
759 sub check_optional_step
765 return undef unless ref($oconf = $optional_steps->{$step});
766 if ($oconf->{branches})
768 return undef unless grep {$_ eq $branch} @{$oconf->{branches}};
771 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =localtime(time);
772 return undef if (exists $oconf->{min_hour} && $hour < $oconf->{min_hour});
773 return undef if (exists $oconf->{max_hour} && $hour > $oconf->{max_hour});
774 return undef if (exists $oconf->{dow}
775 &&grep {$_ eq $wday} @{$oconf->{dow}});
777 my $last_step = $last_status = find_last("$step") || 0;
778 ## If made it *to* these optional steps, we just run them and reset last time
779 #return undef unless ($forcerun ||
780 # time >$last_step + (3600 * $oconf->{min_hours_since}));
781 set_last("$step") unless $nostatus;
786 sub clean_from_source
788 if (-e "$exim/GNUmakefile")
792 my @makeout = `cd $exim && $make distclean 2>&1`;
794 writelog('distclean',\@makeout);
795 print "======== distclean log ===========\n",@makeout if ($verbose > 1);
796 send_result('distclean',$status,\@makeout) if $status;
803 print "Exiting on signal $signame\n";
809 my $lrname = $st_prefix . $logdirname;
811 mkdir "$lrname" || die "can't make $lrname dir: $!";
817 my $loglines = shift;
819 my $lrname = $st_prefix . $logdirname;
820 open($handle,">$lrname/$stage.log") || die $!;
821 print $handle @$loglines;
827 return unless step_wanted('features');
829 src/build-*/exim -C test/confs/0000 -bV `;
831 writelog('features',\@out);
832 print "======== features log ===========\n",@out if ($verbose > 1);
833 send_result('Features',$status,\@out) if $status;
834 $steps_completed .= " Features";
839 # Allow farm member to configure non-GNU make
840 my $non_gnu_make = $EximBuild::conf{non_gnu_make};
841 if (!defined $non_gnu_make ||
842 (defined $non_gnu_make && $non_gnu_make == 1)) {
845 my @out = `$make -v 2>&1`;
846 return undef unless ($? == 0 && grep {/GNU Make/} @out);
852 return unless step_wanted('make');
853 print time_str(),"running make ...\n" if $verbose;
854 my $make_args = join(' ',$EximBuild::conf{make_args});
856 my $make_cmd = $make;
857 $make_cmd = "$make -j $make_jobs"
858 if ($make_jobs > 1 && ($branch eq 'HEAD' || $branch ge 'REL9_1'));
859 @makeout = `cd $exim/src && $make_cmd $make_args 2>&1`;
861 writelog('make',\@makeout);
862 print "======== make log ===========\n",@makeout if ($verbose > 1);
863 send_result('Make',$status,\@makeout) if $status;
864 $steps_completed .= " Make";
869 return unless step_wanted('make-doc');
870 print time_str(),"running make doc ...\n" if $verbose;
873 @makeout = `cd $exim/doc/doc-docbook/ && \
874 EXIM_VER="4.82" $make everything 2>&1`;
876 writelog('make-doc',\@makeout);
877 print "======== make doc log ===========\n",@makeout if ($verbose > 1);
878 send_result('Doc',$status,\@makeout) if $status;
879 $steps_completed .= " Doc";
887 # no core = no result
888 my @cores = glob("$pgdata/$core_file_glob");
889 return () unless @cores;
892 system "gdb --version > $devnull 2>&1";
894 return () if $status;
896 my $cmdfile = "./gdbcmd";
898 open($handle, ">$cmdfile");
899 print $handle "bt\n";
904 foreach my $core (@cores)
906 my @onetrace = `gdb -x $cmdfile --batch $bindir/exim $core 2>&1`;
908 "\n\n================== stack trace: $core ==================\n",
917 sub make_install_check
920 return unless step_wanted('install-check');
921 print time_str(),"running make installcheck ($locale)...\n" if $verbose;
926 @checklog = `cd $exim/src/test/regress && $make installcheck 2>&1`;
930 chdir "$exim/src/tools/msvc";
931 @checklog = `perl vcregress.pl installcheck 2>&1`;
936 ("$exim/src/test/regress/regression.diffs","$installdir/logfile");
937 foreach my $logfile(@logfiles)
939 next unless (-e $logfile );
940 push(@checklog,"\n\n================== $logfile ==================\n");
942 open($handle,$logfile);
952 get_stack_trace("$installdir/bin","$installdir/data-$locale");
953 push(@checklog,@trace);
955 writelog("install-check-$locale",\@checklog);
956 print "======== make installcheck log ===========\n",@checklog
958 send_result("InstallCheck-$locale",$status,\@checklog) if $status;
959 $steps_completed .= " InstallCheck-$locale";
962 sub make_isolation_check
965 return unless step_wanted('isolation-check');
970 "cd $exim/src/test/isolation && $make NO_LOCALE=1 installcheck";
971 @makeout = `$cmd 2>&1`;
975 chdir "$exim/src/tools/msvc";
976 @makeout = `perl vcregress.pl isolationcheck 2>&1`;
982 # get the log files and the regression diffs
983 my @logs = glob("$exim/src/test/isolation/log/*.log");
984 push(@logs,"$installdir/logfile");
985 unshift(@logs,"$exim/src/test/isolation/regression.diffs")
986 if (-e "$exim/src/test/isolation/regression.diffs");
987 foreach my $logfile (@logs)
989 push(@makeout,"\n\n================== $logfile ===================\n");
991 open($handle,$logfile);
1001 get_stack_trace("$installdir/bin","$installdir/data-$locale");
1002 push(@makeout,@trace);
1004 writelog('isolation-check',\@makeout);
1005 print "======== make isolation check logs ===========\n",@makeout
1008 send_result('IsolationCheck',$status,\@makeout) if $status;
1009 $steps_completed .= " IsolationCheck";
1014 return unless step_wanted('test');
1015 print time_str(),"running make test ...\n" if $verbose;
1016 my $tests_range = $EximBuild::conf{range_num_tests} || "1 4";
1018 @makeout =`(cd $exim/test
1019 autoconf && ./configure && $make )2>&1 `;
1020 my $status = $? >>8;
1023 my @tmp = `(WORKDIR=\$PWD
1025 ./runtest \$WORKDIR/$exim/src/build-*/exim -CONTINUE $tests_range )2>&1`;
1027 push @makeout, @tmp;
1028 # Prepend the failed summary log outputs for ease of reading
1029 my $fail_summary = "$exim/test/failed-summary.log";
1030 if (-f $fail_summary)
1032 @tmp = `cat $fail_summary`;
1034 unshift @makeout, @tmp;
1035 unshift @makeout, "Summary of failed tests:\n";
1038 writelog('test',\@makeout);
1039 print "======== make test logs ===========\n",@makeout
1042 send_result('Test',$status,\@makeout) if $status;
1043 $steps_completed .= " Test";
1048 return unless step_wanted('ecpg-check');
1050 my $ecpg_dir = "$exim/src/interfaces/ecpg";
1053 chdir "$exim/src/tools/msvc";
1054 @makeout = `perl vcregress.pl ecpgcheck 2>&1`;
1059 @makeout = `cd $ecpg_dir && $make NO_LOCALE=1 check 2>&1`;
1061 my $status = $? >>8;
1063 # get the log files and the regression diffs
1064 my @logs = glob("$ecpg_dir/test/log/*.log");
1065 unshift(@logs,"$ecpg_dir/test/regression.diffs")
1066 if (-e "$ecpg_dir/test/regression.diffs");
1067 foreach my $logfile (@logs)
1069 push(@makeout,"\n\n================== $logfile ===================\n");
1071 open($handle,$logfile);
1080 my $base = "$ecpg_dir/test/regress/tmp_check";
1082 get_stack_trace("$base/install$installdir/bin", "$base/data");
1083 push(@makeout,@trace);
1085 writelog('ecpg-check',\@makeout);
1086 print "======== make ecpg check logs ===========\n",@makeout
1089 send_result('ECPG-Check',$status,\@makeout) if $status;
1090 $steps_completed .= " ECPG-Check";
1095 return unless step_wanted('configure');
1096 print time_str(),"creating configuration ...\n" if $verbose;
1098 my $env = $EximBuild::conf{makefile_set};
1099 my $add = $EximBuild::conf{makefile_add};
1100 my $features = $EximBuild::conf{makefile_regex};
1103 while (my ($key,$val) = each %$env)
1105 $envstr .= "$key='$val'\n";
1107 while (my ($key,$val) = each %$add)
1109 $envstr .= "$key+='$val'\n";
1112 my $conf_path = "src/src/EDITME";
1113 my $local_conf = "src/Local/Makefile";
1114 my @confout = `cd $exim; mkdir -p src/Local 2>&1`;
1115 my @tmp = `cd $exim && cp $conf_path $local_conf 2>&1`;
1116 my $status = $? >> 8;
1117 push @confout, @tmp;
1120 # First, let's display some directory permissions in case
1121 # permissions are causing problems.
1122 my @dir = split('/',`pwd`);
1124 my $count = scalar @dir;
1127 while ($loop < $count)
1130 foreach my $i (0 .. $loop)
1132 $dir .= $dir[$i].'/';
1137 @tmp = `echo "Verify Directory Permissions"
1139 push @confout, @tmp;
1140 # Build the config file from the EDITME template
1141 @tmp = `cd $exim && echo '$envstr' >> $local_conf`;
1142 push @confout, @tmp;
1143 my $exim_user = $EximBuild::conf{master_exim_user} || 'exim';
1144 @tmp = `echo "Hardcoded Exim user info:"; id $exim_user
1145 cd $exim && perl -pi -e 's/^EXIM_USER=.*/EXIM_USER=$exim_user/' $local_conf`;
1146 push @confout, @tmp;
1147 my $me = `whoami`; chomp $me;
1148 @tmp = `echo "Build Farm user info:"; id $me
1149 cd $exim && perl -pi -e 's/^# CONFIGURE_OWNER=\$/CONFIGURE_OWNER=$me/' $local_conf`;
1150 push @confout, @tmp;
1151 my $testdir = `cd $exim && /bin/pwd`; chomp $testdir; $testdir .= "/test";
1152 my $trcf = "$testdir/trusted-configs";
1153 my $tecf = "$testdir/test-config";
1154 @tmp = `cd $exim && perl -pi -e "s%^# TRUSTED_CONFIG_LIST=.*%TRUSTED_CONFIG_LIST=$trcf%" $local_conf`;
1155 push @confout, @tmp;
1156 @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`;
1157 push @confout, @tmp;
1158 @tmp = `cd $exim && perl -pi -e 's/^EXIM_MONITOR=(.*)/# EXIM_MONITOR=\$1/' $local_conf`;
1159 push @confout, @tmp;
1160 for my $regex ( @$features )
1163 perl -pi -e '$regex' $local_conf 2>&1
1164 echo "Used regex: $regex" `;
1165 push @confout, @tmp;
1167 # Add the final build file to the display output
1170 echo "Contents of Local/Makefile:"
1171 egrep '^[^#]' $local_conf `;
1172 push @confout, @tmp;
1173 # Build the config_opts array to send to the server
1175 my @config_opts = grep s/(?:LOOKUP_|EXPERIMENTAL_|USE_)(\S+)=.*/$1/,
1177 push @config_opts, grep s/^(?:EXIM_)(PERL|PYTHON)=.*/$1/,
1179 # OpenSSL doesn't have a specific USE flag
1180 push @config_opts, grep s/^(TLS_LIBS.*-l(ssl|crypto)).*/OPENSSL/,
1182 $EximBuild::conf{config_opts} = \@config_opts;
1184 # Does not matter what the Exim version is, as long as it is valid.
1185 my $exim_ver = $EximBuild::conf{exim_test_version} || '4.82';
1187 echo 'EXIM_RELEASE_VERSION="$exim_ver"' > src/src/version.sh
1188 echo 'EXIM_VARIANT_VERSION=""' >> src/src/version.sh
1189 echo 'EXIM_COMPILE_NUMBER="0"' >> src/src/version.sh`;
1191 # Create a trusted-configs list file
1192 @tmp = `cd $exim && echo "$tecf" > "$trcf"`;
1193 push @confout, @tmp;
1196 print "======== configure output ===========\n",@confout
1199 writelog('configure',\@confout);
1203 send_result('Configure',$status,\@confout);
1206 $steps_completed .= " Configure";
1212 my $stname = $st_prefix . "last.$which";
1214 open($handle,$stname) or return undef;
1215 my $time = <$handle>;
1224 my $stname = $st_prefix . "last.$which";
1225 my $st_now = shift || time;
1227 open($handle,">$stname") or die "opening $stname: $!";
1228 print $handle "$st_now\n";
1235 # clean up temp file
1240 my $ts = $now || time;
1241 my $status=shift || 0;
1242 my $log = shift || [];
1243 print "======== log passed to send_result ===========\n",@$log
1247 "Last file mtime in snapshot: ",
1248 scalar(gmtime($current_snap)),
1249 " GMT\n","===================================================\n")
1250 unless ($from_source || !$current_snap);
1252 my $log_data = join("",@$log);
1254 my $changed_this_run = "";
1255 my $changed_since_success = "";
1256 $changed_this_run = join("!",@changed_files)
1258 $changed_since_success = join("!",@changed_since_success)
1259 if ($stage ne 'OK' && @changed_since_success);
1263 $confsum= $saved_config;
1265 elsif ($stage !~ /CVS|Git|SCM/ )
1267 $confsum = get_config_summary();
1271 $confsum = get_script_config_dump();
1274 my $savedata = Data::Dumper->Dump(
1276 $changed_this_run, $changed_since_success, $branch, $status,$stage,
1277 $animal, $ts,$log_data, $confsum, $target, $verbose, $secret
1280 qw(changed_this_run changed_since_success branch status stage
1281 animal ts log_data confsum target verbose secret)
1285 my $lrname = $st_prefix . $logdirname;
1287 # might happen if there is a CVS failure and have never got further
1288 mkdir $lrname unless -d $lrname;
1290 my $txfname = "$lrname/web-txn.data";
1292 open($txdhandle,">$txfname");
1293 print $txdhandle $savedata;
1296 if ($nosend || $stage eq 'CVS' || $stage eq 'CVS-status' )
1298 print "Branch: $branch\n";
1301 print "All stages succeeded\n";
1302 set_last('success.snap',$current_snap) unless $nostatus;
1307 print "Stage $stage failed with status $status\n";
1312 if ($stage !~ /CVS|Git|SCM|Pre-run-port-check/ )
1315 my @logfiles = glob("$lrname/*.log");
1316 my %mtimes = map { $_ => (stat $_)[9] } @logfiles;
1318 map { basename $_ }( sort { $mtimes{$a} <=> $mtimes{$b} } @logfiles );
1319 my $logfiles = join(' ',@logfiles);
1320 $tar_log_cmd =~ s/\*\.log/$logfiles/;
1322 system("$tar_log_cmd 2>&1 ");
1323 chdir($branch_root);
1329 # these would be from an earlier run, since we
1330 # do cleanlogs() after the cvs stage
1331 # so don't send them.
1332 unlink "$lrname/runlogs.tgz";
1337 # this should now only apply to older Msys installs. All others should
1338 # be running with perl >= 5.8 since that's required to build exim
1340 if (!$^V or $^V lt v5.8.0)
1343 unless (-x "$aux_path/run_web_txn.pl")
1345 print "Could not locate $aux_path/run_web_txn.pl\n";
1349 system("$aux_path/run_web_txn.pl $lrname");
1350 $txstatus = $? >> 8;
1354 $txstatus = EximBuild::WebTxn::run_web_txn($lrname) ? 0 : 1;
1360 print "Web txn failed with status: $txstatus\n";
1362 # if the web txn fails, restore the timestamps
1363 # so we try again the next time.
1364 set_last('status',$last_status) unless $nostatus;
1365 set_last('run.snap',$last_run_snap) unless $nostatus;
1369 unless ($stage eq 'OK' || $quiet)
1371 print "BuildFarm member $animal failed on $branch stage $stage\n";
1374 # print "Success!\n",$response->content
1375 # if $print_success;
1377 set_last('success.snap',$current_snap) if ($stage eq 'OK' && !$nostatus);
1382 sub get_config_summary
1386 # unless ($using_msvc)
1388 # open($handle,"$exim/config.log") || return undef;
1389 # my $start = undef;
1392 # if (!$start && /created by PostgreSQL configure/)
1395 # s/It was/This file was/;
1397 # next unless $start;
1398 # last if /Core tests/;
1400 # next if /= <?unknown>?/;
1402 # # split up long configure line
1403 # if (m!\$.*configure.*--with! && length > 70)
1405 # my $pos = index($_," ",70);
1406 # substr($_,$pos+1,0,"\\\n ") if ($pos > 0);
1407 # $pos = index($_," ",140);
1408 # substr($_,$pos+1,0,"\\\n ") if ($pos > 0);
1409 # $pos = index($_," ",210);
1410 # substr($_,$pos+1,0,"\\\n ") if ($pos > 0);
1416 # "\n========================================================\n";
1418 $config .= get_script_config_dump();
1422 sub get_script_config_dump
1425 %EximBuild::conf, # shallow copy
1426 script_version => $VERSION,
1427 invocation_args => \@invocation_args,
1428 steps_completed => $steps_completed,
1429 orig_env => $orig_env,
1431 delete $conf->{secret};
1433 if ($conf->{scm} eq 'git') {
1434 chomp($conf->{farm}{revision} = `git describe --tags --always --dirty=+`);
1435 $conf->{farm}{cwd} = getcwd();
1436 $conf->{farm}{bindir} = $Bin;
1439 $Data::Dumper::Sortkeys = 1;
1440 return Data::Dumper->Dump([$conf],['Script_Config']);
1445 my $wait_time = shift;
1446 my $who_to_kill = getpgrp(0);
1449 print "waiting $wait_time secs to time out process $who_to_kill\n"
1451 foreach my $sig (qw(INT TERM HUP QUIT))
1453 $SIG{$sig}='DEFAULT';
1456 $SIG{TERM} = 'IGNORE'; # so we don't kill ourself, we're exiting anyway
1457 # kill the whole process group
1458 unless (kill $sig,$who_to_kill)
1460 print "scm timeout kill failed\n";
1466 my $coderef = shift;
1468 if (defined($pid) && $pid == 0)