forked from PGBuildFarm/client-code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_build.pl
executable file
·2546 lines (2133 loc) · 60.9 KB
/
run_build.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl
=comment
Copyright (c) 2003-2017, Andrew Dunstan
See accompanying License file for license details
=cut
####################################################
=comment
NAME: run_build.pl - script to run postgresql buildfarm
SYNOPSIS:
run_build.pl [option ...] [branchname]
AUTHOR: Andrew Dunstan
DOCUMENTATION:
See https://wiki.postgresql.org/wiki/PostgreSQL_Buildfarm_Howto
REPOSITORY:
https://github.com/PGBuildFarm/client-code
=cut
###################################################
use strict;
use warnings;
use vars qw($VERSION); $VERSION = 'REL_8';
use Config;
use Fcntl qw(:flock :seek);
use File::Path;
use File::Copy;
use File::Basename;
use File::Temp;
use File::Spec;
use IO::Handle;
use POSIX qw(:signal_h strftime);
use Data::Dumper;
use Cwd qw(abs_path getcwd);
use File::Find ();
BEGIN
{
unshift(@INC, $ENV{BFLIB}) if $ENV{BFLIB};
use lib File::Spec->rel2abs(dirname(__FILE__));
}
# use High Resolution stat times if the module is available
# this helps make sure we sort logfiles correctly
BEGIN
{
eval { require Time::HiRes; Time::HiRes->import('stat'); };
}
# save a copy of the original enviroment for reporting
# save it early to reduce the risk of prior mangling
use vars qw($orig_env);
BEGIN
{
$orig_env = {};
while (my ($k, $v) = each %ENV)
{
# report all the keys but only values for whitelisted settings
# this is to stop leaking of things like passwords
$orig_env->{$k} = (
(
$k =~ /^PG(?!PASSWORD)|MAKE|CC|CPP|CXX|LD|LD_LIBRARY_PATH/
|| $k =~ /^(HOME|LOGNAME|USER|PATH|SHELL|LIBRAR|INCLUDE)$/
|| $k =~ /^BF_CONF_BRANCHES$/
)
? $v
: 'xxxxxx'
);
}
}
use PGBuild::SCM;
use PGBuild::Options;
use PGBuild::WebTxn;
use PGBuild::Utils qw(:DEFAULT $st_prefix $logdirname $branch_root
$steps_completed %skip_steps %only_steps $tmpdir
$temp_installs $devnull $send_result_routine);
$send_result_routine = \&send_res;
my $orig_dir = getcwd();
unshift @INC, $orig_dir;
# make sure we exit nicely on any normal interrupt
# so the cleanup handler gets called.
# that lets us stop the db if it's running and
# remove the inst and pgsql directories
# so the next run can start clean.
foreach my $sig (qw(INT TERM HUP QUIT))
{
$SIG{$sig} = \&interrupt_exit;
}
# copy command line before processing - so we can later report it
# unmunged
my @invocation_args = (@ARGV);
# process the command line
PGBuild::Options::fetch_options();
die "only one of --from-source and --from-source-clean allowed"
if ($from_source && $from_source_clean);
die "only one of --skip-steps and --only-steps allowed"
if ($skip_steps && $only_steps);
if ($testmode)
{
$verbose = 1 unless $verbose;
$forcerun = 1;
$nostatus = 1;
$nosend = 1;
}
$skip_steps ||= "";
if ($skip_steps =~ /\S/)
{
%skip_steps = map { $_ => 1 } split(/\s+/, $skip_steps);
}
$only_steps ||= "";
if ($only_steps =~ /\S/)
{
%only_steps = map { $_ => 1 } split(/\s+/, $only_steps);
}
use vars qw($branch);
my $explicit_branch = shift;
$branch = $explicit_branch || 'HEAD';
print_help() if ($help);
#
# process config file
#
require $buildconf;
# get this here before we change directories
my @conf_stat = stat $buildconf;
my $buildconf_mod = $conf_stat[9];
PGBuild::Options::fixup_conf(\%PGBuild::conf, \@config_set);
# default buildroot
$PGBuild::conf{build_root} ||= abs_path(dirname(__FILE__)) . "/buildroot";
# get the config data into some local variables
my (
$buildroot, $target,
$animal, $aux_path,
$trigger_exclude, $trigger_include,
$secret, $keep_errs,
$force_every, $make,
$optional_steps, $use_vpath,
$tar_log_cmd, $using_msvc,
$extra_config, $make_jobs,
$core_file_glob, $ccache_failure_remove,
$wait_timeout, $use_accache,
$use_valgrind, $valgrind_options,
$use_installcheck_parallel
)
= @PGBuild::conf{
qw(build_root target animal aux_path trigger_exclude
trigger_include secret keep_error_builds force_every make optional_steps
use_vpath tar_log_cmd using_msvc extra_config make_jobs core_file_glob
ccache_failure_remove wait_timeout use_accache
use_valgrind valgrind_options use_installcheck_parallel)
};
# default use_accache to on
$use_accache = 1 unless exists $PGBuild::conf{use_accache};
#default is no parallel build
$make_jobs ||= 1;
# default core file pattern is Linux, which used to be hardcoded
$core_file_glob ||= 'core*';
$PGBuild::Utils::core_file_glob = $core_file_glob;
# get check_warning from config if not on command line
$check_warnings = $PGBuild::conf{check_warnings}
unless defined $check_warnings;
# legacy name
if (defined($PGBuild::conf{trigger_filter}))
{
$trigger_exclude = $PGBuild::conf{trigger_filter};
}
my $scm_timeout_secs = $PGBuild::conf{scm_timeout_secs}
|| $PGBuild::conf{cvs_timeout_secs};
print scalar(localtime()), ": buildfarm run for $animal:$branch starting\n"
if $verbose;
die "cannot use vpath with MSVC"
if ($using_msvc and $use_vpath);
if (ref($force_every) eq 'HASH')
{
$force_every = $force_every->{$branch} || $force_every->{default};
}
my $config_opts = $PGBuild::conf{config_opts};
use vars qw($buildport);
if (exists $PGBuild::conf{base_port})
{
$buildport = $PGBuild::conf{base_port};
if ($branch =~ /REL(\d+)_(\d+)/)
{
$buildport += (10 * ($1 - 7)) + $2;
}
elsif ($branch =~ /REL_(\d+)/) # pattern used from REL_10_STABLE on
{
$buildport += 10 * ($1 - 7);
}
}
else
{
# support for legacy config style
$buildport = $PGBuild::conf{branch_ports}->{$branch} || 5999;
}
$ENV{EXTRA_REGRESS_OPTS} = "--port=$buildport";
$tar_log_cmd ||= "tar -z -cf runlogs.tgz *.log";
$logdirname = "lastrun-logs";
if ($from_source || $from_source_clean)
{
$from_source ||= $from_source_clean;
$from_source = abs_path($from_source)
unless File::Spec->file_name_is_absolute($from_source);
# we need to know where the lock should go, so unless the path
# contains HEAD or they have explicitly said the branch let
# them know where things are going.
print
"branch not specified, locks, logs, ",
"build artefacts etc will go in HEAD\n"
unless ($explicit_branch || $from_source =~ m!/HEAD/!);
$verbose ||= 1;
$nosend = 1;
$nostatus = 1;
$logdirname = "fromsource-logs";
if (!$from_source_clean && $use_vpath)
{
my $ofiles = 0;
File::Find::find(sub { /\.o$/ && $ofiles++; }, "$from_source/src");
if ($ofiles)
{
die "from source directory has object files. vpath build will fail";
}
}
}
my @locales;
@locales = @{ $PGBuild::conf{locales} } if exists $PGBuild::conf{locales};
unshift(@locales, 'C') unless grep { $_ eq "C" } @locales;
# sanity checks
# several people have run into these
if (`uname -s 2>&1 ` =~ /CYGWIN/i)
{
my @procs = `ps -ef`;
die "cygserver not running" unless (grep { /cygserver/ } @procs);
}
my $ccachedir = $PGBuild::conf{build_env}->{CCACHE_DIR};
if (!$ccachedir && $PGBuild::conf{use_default_ccache_dir})
{
$ccachedir = "$buildroot/ccache-$animal";
$ENV{CCACHE_DIR} = $ccachedir;
}
if ($ccachedir)
{
# ccache is smart enough to create what you tell it is the cache dir, but
# not smart enough to build the whole path. mkpath croaks on error, so
# we just let it.
mkpath $ccachedir;
$ccachedir = abs_path($ccachedir);
}
# this should now only apply to older Msys installs. All others should
# be running with perl >= 5.8 since that's required to build postgres
# anyway. However, the Msys DTK perl doesn't handle https, but Msys2 perl
# does, so detect if it's there. If we're not sending this is all moot anyway.
my $use_auxpath = undef;
unless ($nosend)
{
## no critic (ValuesAndExpressions::ProhibitMismatchedOperators)
# perlcritic gets confused by version comparisons - this usage is
# sanctioned by perldoc perlvar
if (!$^V || $^V lt v5.8.0)
{
$aux_path ||= find_in_path('run_web_txn.pl');
die "no aux_path in config file" unless $aux_path;
$use_auxpath = 1;
}
elsif ($Config{osname} eq 'msys' && $target =~ /^https/)
{
eval { require LWP::Protocol::https; };
if ($@)
{
$aux_path ||= find_in_path('run_web_txn.pl');
die "no aux_path in config file" unless $aux_path;
$use_auxpath = 1;
}
}
}
die "cannot run as root/Administrator" unless ($using_msvc or $> > 0);
$devnull = $using_msvc ? "nul" : "/dev/null";
$st_prefix = "$animal.";
# set environment from config
while (my ($envkey, $envval) = each %{ $PGBuild::conf{build_env} })
{
$ENV{$envkey} = $envval;
}
# default value - supply unless set via the config file
# or calling environment
$ENV{PGCTLTIMEOUT} = 120 unless exists $ENV{PGCTLTIMEOUT};
# change to buildroot for this branch or die
die "no buildroot" unless $buildroot;
unless ($buildroot =~ m!^/!
or ($using_msvc and $buildroot =~ m![a-z]:[/\\]!i))
{
die "buildroot $buildroot not absolute";
}
mkpath $buildroot unless -d $buildroot;
die "$buildroot does not exist or is not a directory" unless -d $buildroot;
chdir $buildroot || die "chdir to $buildroot: $!";
# set up a temporary directory for extra configs, sockets etc
my $oldmask = umask;
umask 0077 unless $using_msvc;
$tmpdir = File::Temp::tempdir(
"buildfarm-XXXXXX",
DIR => File::Spec->tmpdir,
CLEANUP => 1
);
umask $oldmask unless $using_msvc;
my $scm = PGBuild::SCM->new(\%PGBuild::conf);
if (!$from_source)
{
$scm->check_access($using_msvc);
}
mkdir $branch unless -d $branch;
chdir $branch || die "chdir to $buildroot/$branch";
# rename legacy status files/directories
foreach my $oldfile (glob("last*"))
{
move $oldfile, "$st_prefix$oldfile";
}
$branch_root = getcwd();
my $pgsql;
if ($from_source)
{
$pgsql = $use_vpath ? "$branch_root/pgsql.build" : $from_source;
}
else
{
$pgsql = $scm->get_build_path($use_vpath);
}
# make sure we are using GNU make (except for MSVC)
unless ($using_msvc)
{
die "$make is not GNU Make - please fix config file"
unless check_make();
}
# set up modules
foreach my $module (@{ $PGBuild::conf{modules} })
{
# fill in the name of the module here, so use double quotes
# so everything BUT the module name needs to be escaped
my $str = qq!
require PGBuild::Modules::$module;
PGBuild::Modules::${module}::setup(
\$buildroot,
\$branch,
\\\%PGBuild::conf,
\$pgsql);
!;
# the string is built at runtime so there is no option but
# to use stringy eval
eval $str; ## no critic (ProhibitStringyEval)
# make errors fatal
die $@ if $@;
}
# acquire the lock
my $lockfile;
my $have_lock;
open($lockfile, ">", "builder.LCK") || die "opening lockfile: $!";
# only one builder at a time allowed per branch
# having another build running is not a failure, and so we do not output
# a failure message under this condition.
if ($from_source)
{
die "acquiring lock in $buildroot/$branch/builder.LCK"
unless flock($lockfile, LOCK_EX | LOCK_NB);
}
elsif (!flock($lockfile, LOCK_EX | LOCK_NB))
{
print "Another process holds the lock on "
. "$buildroot/$branch/builder.LCK. Exiting.\n"
if ($verbose);
exit(0);
}
rmtree("inst");
rmtree("$pgsql") unless ($from_source && !$use_vpath);
# we are OK to run if we get here
$have_lock = 1;
# check if file present for forced run
my $forcefile = $st_prefix . "force-one-run";
if (-e $forcefile)
{
$forcerun = 1;
unlink $forcefile;
}
# try to allow core files to be produced.
# another way would be for the calling environment
# to call ulimit. We do this in an eval so failure is
# not fatal.
unless ($using_msvc)
{
eval {
require BSD::Resource;
BSD::Resource->import();
# explicit sub calls here. using & keeps compiler happy
my $coreok = setrlimit(&RLIMIT_CORE, &RLIM_INFINITY, &RLIM_INFINITY);
die "setrlimit" unless $coreok;
};
warn "failed to unlimit core size: $@" if $@ && $verbose > 1;
}
# the time we take the snapshot
use vars qw($now);
$now = time;
my $installdir = "$buildroot/$branch/inst";
my $dbstarted;
my $extraconf;
my $main_pid = $$;
my $waiter_pid;
# cleanup handler for all exits
END
{
# only do this block in the main process
return unless (defined($main_pid) && $main_pid == $$);
kill('TERM', $waiter_pid) if $waiter_pid;
# save the exit status in case $? is mangled by system() calls below
my $exit_status = $?;
# if we have the lock we must already be in the build root, so
# removing things there should be safe.
# there should only be anything to cleanup if we didn't have
# success.
if ( $have_lock
&& !-d "$pgsql"
&& $PGBuild::conf{rm_worktrees}
&& !$from_source)
{
# remove work tree on success, if configured
$scm->rm_worktree();
}
if ($have_lock && -d "$pgsql")
{
if ($dbstarted)
{
chdir $installdir;
system(qq{"bin/pg_ctl" -D data stop >$devnull 2>&1});
foreach my $loc (@locales)
{
next unless -d "data-$loc";
system(qq{"bin/pg_ctl" -D "data-$loc" stop >$devnull 2>&1});
}
chdir $branch_root;
}
if (!$from_source && $keep_errs)
{
print "moving kept error trees\n" if $verbose;
my $timestr = strftime "%Y-%m-%d_%H-%M-%S", localtime($now);
unless (move("$pgsql", "pgsqlkeep.$timestr"))
{
print "error renaming '$pgsql' to 'pgsqlkeep.$timestr': $!";
}
if (-d "inst")
{
unless (move("inst", "instkeep.$timestr"))
{
print "error renaming 'inst' to 'instkeep.$timestr': $!";
}
}
}
else
{
rmtree("inst") unless $keepall;
rmtree("$pgsql") unless (($from_source && !$use_vpath) || $keepall);
}
# only keep the cache in cases of success, if config flag is set
if ($ccache_failure_remove)
{
rmtree("$ccachedir") if $ccachedir;
}
}
# get the modules to clean up after themselves
process_module_hooks('cleanup');
if ($have_lock)
{
if ($use_vpath && !$from_source)
{
# vpath builds leave some stuff lying around in the
# source dir, unfortunately. This should clean it up.
$scm->cleanup();
}
close($lockfile);
unlink("builder.LCK");
}
$? = $exit_status;
}
$waiter_pid = spawn(\&wait_timeout, $wait_timeout) if $wait_timeout;
# Prepend the DEFAULT settings (if any) to any settings for the
# branch. Since we're mangling this, deep clone $extra_config
# so the config object is kept as given. This is done using
# Dumper() because the MSys DTK perl doesn't have Storable. This
# is less efficient but it hardly matters here for this shallow
# structure.
{
## no critic (ProhibitStringyEval)
eval Data::Dumper->Dump([$extra_config], ['extra_config']);
}
if ($extra_config && $extra_config->{DEFAULT})
{
if (!exists $extra_config->{$branch})
{
$extra_config->{$branch} = $extra_config->{DEFAULT};
}
else
{
unshift(@{ $extra_config->{$branch} }, @{ $extra_config->{DEFAULT} });
}
}
if ($extra_config && $extra_config->{$branch})
{
my $tmpname = "$tmpdir/bfextra.conf";
open($extraconf, ">", "$tmpname") || die 'opening $tmpname $!';
$ENV{TEMP_CONFIG} = $tmpname;
foreach my $line (@{ $extra_config->{$branch} })
{
print $extraconf "$line\n";
}
autoflush $extraconf 1;
}
$steps_completed = "";
my @changed_files;
my @changed_since_success;
my $last_status;
my $last_run_snap;
my $last_success_snap;
my $current_snap;
my @filtered_files;
my $savescmlog = "";
$ENV{PGUSER} = 'buildfarm';
if ($from_source_clean)
{
die "configure step needed for --from-source-clean"
unless step_wanted('configure');
cleanlogs(); # do this here so we capture the "make dist" log
print time_str(), "cleaning source in $pgsql ...\n";
clean_from_source();
}
elsif (!$from_source)
{
# see if we need to run the tests (i.e. if either something has changed or
# we have gone over the force_every heartbeat time)
print time_str(), "checking out source ...\n" if $verbose;
my $timeout_pid;
$timeout_pid = spawn(\&scm_timeout, $scm_timeout_secs)
if $scm_timeout_secs;
$savescmlog = $scm->checkout($branch);
$steps_completed = "SCM-checkout";
process_module_hooks('checkout', $savescmlog);
if ($timeout_pid)
{
# don't kill me, I finished in time
if (kill(SIGTERM, $timeout_pid))
{
# reap the zombie
waitpid($timeout_pid, 0);
}
}
print time_str(), "checking if build run needed ...\n" if $verbose;
# transition to new time processing
unlink "last.success";
# get the timestamp data
$last_status = find_last('status') || 0;
$last_run_snap = find_last('run.snap');
$last_success_snap = find_last('success.snap');
my $last_stage = get_last_stage() || "";
if ($last_stage =~ /-Git|/ && $last_status < (time - (3 * 3600)))
{
# force a rerun 3 hours after a git failure
$forcerun = 1;
}
$forcerun = 1 unless (defined($last_run_snap));
# updated by find_changed to last mtime of any file in the repo
$current_snap = 0;
# see if we need to force a build
$last_status = 0
if ( $last_status
&& $force_every
&& $last_status + ($force_every * 3600) < $now);
$last_status = 0 if $forcerun;
# see what's changed since the last time we did work
$scm->find_changed(
\$current_snap, $last_run_snap, $last_success_snap,
\@changed_files, \@changed_since_success
);
#ignore changes to files specified by the trigger exclude filter, if any
if (defined($trigger_exclude))
{
@filtered_files = grep { !m[$trigger_exclude] } @changed_files;
}
else
{
@filtered_files = @changed_files;
}
#ignore changes to files NOT specified by the trigger include filter, if any
if (defined($trigger_include))
{
@filtered_files = grep { m[$trigger_include] } @filtered_files;
}
my $modules_need_run;
process_module_hooks('need-run', \$modules_need_run);
# if no build required do nothing
if ($last_status && !@filtered_files && !$modules_need_run)
{
print time_str(),
"No build required: last status = ", scalar(gmtime($last_status)),
" GMT, current snapshot = ", scalar(gmtime($current_snap)), " GMT,",
" changed files = ", scalar(@filtered_files), "\n"
if $verbose;
rmtree("$pgsql");
exit 0;
}
# get version info on both changed files sets
# XXX modules support?
$scm->get_versions(\@changed_files);
$scm->get_versions(\@changed_since_success);
} # end of unless ($from_source)
cleanlogs() unless ($from_source_clean || !step_wanted('configure'));
writelog('SCM-checkout', $savescmlog) unless $from_source;
$scm->log_id() unless $from_source;
# copy/create according to vpath/scm settings
if ($use_vpath)
{
print time_str(), "creating vpath build dir $pgsql ...\n" if $verbose;
mkdir $pgsql || die "making $pgsql: $!";
}
elsif (!$from_source && $scm->copy_source_required())
{
print time_str(), "copying source to $pgsql ...\n" if $verbose;
$scm->copy_source($using_msvc);
}
process_module_hooks('setup-target');
# start working
set_last('status', $now) unless $nostatus;
set_last('run.snap', $current_snap) unless $nostatus;
my $started_times = 0;
# counter for temp installs. if it gets high enough
# (currently 3) we can set NO_TEMP_INSTALL.
$temp_installs = 0;
# each of these routines will call send_result, which calls exit,
# on any error, so each step depends on success in the previous
# steps.
if (step_wanted('configure'))
{
print time_str(), "running configure ...\n" if $verbose;
configure();
}
# module configure has to wait until we have built and installed the base
# so see below
make();
make_check() unless $delay_check;
# contrib is built under the standard build step for msvc
make_contrib() unless ($using_msvc);
make_testmodules()
if (!$using_msvc && ($branch eq 'HEAD' || $branch ge 'REL9_5'));
make_doc() if (check_optional_step('build_docs'));
make_install();
# contrib is installed under standard install for msvc
make_contrib_install() unless ($using_msvc);
make_testmodules_install()
if (!$using_msvc && ($branch eq 'HEAD' || $branch ge 'REL9_5'));
make_check() if $delay_check;
process_module_hooks('configure');
process_module_hooks('build');
process_module_hooks("check") unless $delay_check;
process_module_hooks('install');
process_module_hooks("check") if $delay_check;
run_bin_tests();
run_misc_tests();
foreach my $locale (@locales)
{
last unless step_wanted('install');
print time_str(), "setting up db cluster ($locale)...\n" if $verbose;
initdb($locale);
do
{
local %ENV = %ENV;
if (!$using_msvc && $Config{osname} !~ /msys|MSWin/)
{
$ENV{PGHOST} = $tmpdir;
}
else
{
$ENV{PGHOST} = 'localhost';
}
print time_str(), "starting db ($locale)...\n" if $verbose;
start_db($locale);
make_install_check($locale);
process_module_hooks('installcheck', $locale);
if ( -d "$pgsql/src/test/isolation"
&& $locale eq 'C'
&& step_wanted('isolation-check'))
{
# restart the db to clear the log file
print time_str(), "restarting db ($locale)...\n" if $verbose;
stop_db($locale);
start_db($locale);
print time_str(), "running make isolation check ...\n" if $verbose;
make_isolation_check($locale);
}
if (
step_wanted('pl-install-check')
&& (
(
!$using_msvc
&& (grep { /--with-(perl|python|tcl)/ } @$config_opts)
)
|| (
$using_msvc
&& ( defined($config_opts->{perl})
|| defined($config_opts->{python})
|| defined($config_opts->{tcl}))
)
)
)
{
# restart the db to clear the log file
print time_str(), "restarting db ($locale)...\n" if $verbose;
stop_db($locale);
start_db($locale);
print time_str(), "running make PL installcheck ($locale)...\n"
if $verbose;
make_pl_install_check($locale);
}
if (step_wanted('contrib-install-check'))
{
# restart the db to clear the log file
print time_str(), "restarting db ($locale)...\n" if $verbose;
stop_db($locale);
start_db($locale);
print time_str(), "running make contrib installcheck ($locale)...\n"
if $verbose;
make_contrib_install_check($locale);
}
if (step_wanted('testmodules-install-check')
&& ($branch eq 'HEAD' || $branch ge 'REL9_5'))
{
print time_str(), "restarting db ($locale)...\n" if $verbose;
stop_db($locale);
start_db($locale);
print time_str(),
"running make test-modules installcheck ($locale)...\n"
if $verbose;
make_testmodules_install_check($locale);
}
print time_str(), "stopping db ($locale)...\n" if $verbose;
stop_db($locale);
}; # end of do block with local %ENV
process_module_hooks('locale-end', $locale);
rmtree("$installdir/data-$locale")
unless $keepall;
}
if (step_wanted('ecpg-check'))
{
print time_str(), "running make ecpg check ...\n" if $verbose;
make_ecpg_check();
}
if ((check_optional_step('find_typedefs') || $find_typedefs)
&& step_wanted('find-typedefs'))
{
print time_str(), "running find_typedefs ...\n" if $verbose;
find_typedefs();
}
# if we get here everything went fine ...
my $saved_config = get_config_summary();
# error out if there are non-empty valgrind logs
my @vglines = run_log("grep -l VALGRINDERROR- ${st_prefix}$logdirname/*.log");
do { $_ = basename $_; $_ =~ s/\.log$//; }
foreach @vglines;
if (@vglines)
{
unshift(@vglines,
"=== Valgrind errors were found at the following stage(s):\n");
send_result('Valgrind', 1, \@vglines);
}
rmtree("inst") unless $keepall; # only keep failures
rmtree("$pgsql") unless ($keepall || ($from_source && !$use_vpath));
print(time_str(), "OK\n") if $verbose;
send_result("OK");
exit;
############## end of main program ###########################
sub print_help
{
print qq!
usage: $0 [options] [branch]
where options are one or more of:
--nosend = don't send results
--nostatus = don't set status files
--force = force a build run (ignore status files)
--from-source=/path = use source in path, not from SCM
or