-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathrun_build.pl
executable file
·3378 lines (2871 loc) · 83 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-2024, 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;
our ($VERSION); $VERSION = 'REL_18';
# minimum version supported
use v5.14; ## no critic (ProhibitVersionStrings)
use Config;
use Fcntl qw(:flock :seek);
use File::Path 'mkpath';
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 ();
use FindBin;
use lib $FindBin::RealBin;
BEGIN
{
unshift(@INC, $ENV{BFLIB}) if $ENV{BFLIB};
}
# 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
our ($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
$devnull $send_result_routine $ts_prefix);
use PGBuild::Log;
$send_result_routine = \&send_res;
# 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.
# can't rely on USR1 being present on Windows
my @usig = $Config{osname} !~ /msys|MSWin/ ? qw(USR1) : ();
foreach my $sig (qw(INT TERM HUP QUIT), @usig)
{
$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);
$skip_steps{make} = 1 if $skip_steps{build};
}
$only_steps ||= "";
if ($only_steps =~ /\S/)
{
%only_steps = map { $_ => 1 } split(/\s+/, $only_steps);
$only_steps{make} = 1 if $only_steps{build};
}
our %skip_suites;
$skip_suites ||= "";
if ($skip_suites =~ /\S/)
{
%skip_suites = map { $_ => 1 } split(/\s+/, $skip_suites);
}
our ($branch);
my $explicit_branch = shift;
my $from_source_branch = '';
if ($from_source || $from_source_clean)
{
my $parent = basename(dirname($from_source || $from_source_clean));
$from_source_branch = $parent if $parent =~ /^REL_?\d+(_\d+)_STABLE/;
}
$branch = $explicit_branch || $from_source_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, $max_load_avg,
$use_discard_caches, $archive_reports,
$using_meson, $meson_jobs,
$meson_test_timeout
)
= @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 max_load_avg
use_discard_caches archive_reports using_meson meson_jobs
meson_test_timeout)
};
$using_meson = undef unless $branch eq 'HEAD' || $branch ge 'REL_16_STABLE';
$meson_test_timeout //= 3;
# default is 4 hours, except on Windows, where it doesn't work
if ($Config{osname} !~ /msys|MSWin/)
{
$wait_timeout //= 4 * 60 * 60;
}
elsif ($wait_timeout || 0 > 0)
{
print "wait_timeout not supported on Windows, ignoring\n";
$wait_timeout = 0;
}
$ts_prefix = sprintf('%s:%-13s ', $animal, $branch);
if ($max_load_avg)
{
eval { require Unix::Uptime; };
if (!$@)
{
my ($load1, $load5, $load15) = Unix::Uptime->load();
if ($load1 > $max_load_avg || $load5 > $max_load_avg)
{
print time_str(),
"Load average is too high ($load1, $load5, $load15)... exiting\n";
exit 0;
}
}
else
{
print STDERR time_str(),
"could not determine load average - not available ... exiting\n";
exit 1;
}
}
# 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;
$use_vpath ||= $using_meson;
die "cannot use vpath with MSVC"
if ($using_msvc && $use_vpath && !$using_meson);
if (ref($force_every) eq 'HASH')
{
$force_every = $force_every->{$branch} || $force_every->{default};
}
my ($config_opts, $meson_opts);
if ($using_meson)
{
$meson_opts = $PGBuild::conf{meson_opts};
delete $PGBuild::conf{config_opts};
}
else
{
$config_opts = $PGBuild::conf{config_opts};
delete $PGBuild::conf{meson_opts};
}
our ($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;
die "source directory $from_source does not exist" unless -d $from_source;
$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
# 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 $branch\n"
unless ($explicit_branch);
$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);
}
# Msys perl doesn't always handle https so detect if it's there.
# If we're not sending this is all moot anyway.
my $use_auxpath = undef;
unless ($nosend)
{
if ($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;
}
}
}
# MSWin32 perl always says 0 for $>, and running as admin there should be ok
die "cannot run as root/Administrator"
unless ($^O eq 'MSWin32' or $> > 0);
$devnull = $using_msvc ? "nul" : "/dev/null";
$st_prefix = $testmode ? "$animal-test." : "$animal.";
# set environment from config
while (my ($envkey, $envval) = each %{ $PGBuild::conf{build_env} })
{
# ignore this setting for branches older than 13
next
if $envkey eq 'PG_TEST_USE_UNIX_SOCKETS'
&& $branch lt "REL_13_STABLE"
&& $branch ne 'HEAD';
$ENV{$envkey} = $envval;
}
# default directory for port locks in TAP tests
$ENV{PG_TEST_PORT_DIR} ||= $buildroot;
# default value - supply unless set via the config file
# or calling environment
$ENV{PGCTLTIMEOUT} = 180 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: $!";
my $oldmask = umask;
umask 0077 unless $using_msvc;
# try to keep temp files/directories on the same device ... this helps minimize
# cross-device issues with renaming etc.
unless (defined $ENV{TMPDIR})
{
my $temp = "$buildroot/tmp";
mkdir $temp unless -d $temp;
$ENV{TMPDIR} = $temp;
}
# set up a temporary directory for extra configs, sockets etc
$tmpdir = File::Temp::tempdir(
"buildfarm-XXXXXX",
DIR => File::Spec->tmpdir,
CLEANUP => 1
);
umask $oldmask unless $using_msvc;
my $vtmpdir = $tmpdir;
if ($Config{osname} =~ /msys/i)
{
$tmpdir = `cygpath -a -m $tmpdir`;
chomp $tmpdir;
}
my $scm = PGBuild::SCM->new(\%PGBuild::conf);
if (!$from_source)
{
$scm->check_access($using_msvc);
}
mkpath $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";
}
# cleanup old kept error directories. 10 days should be plenty
foreach my $kdir (glob("instkeep.* pgsqlkeep.*"))
{
next unless -d $kdir;
next unless -M _ > 10;
rmtree($kdir);
}
$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 || $using_meson);
}
# make sure we are using GNU make (except for MSVC)
unless ($using_msvc || $using_meson)
{
die "$make is not GNU Make - please fix config file"
unless check_make();
}
# set up modules
foreach my $module (@{ $PGBuild::conf{modules} })
{
# TestDecoding is now redundant.
next if $module eq 'TestDecoding';
# 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 > 1);
exit(0);
}
my $installdir = "$buildroot/$branch/inst";
# recursively fix any permissions that might stop us removing the directories
# then remove old run artefacts if any, die if not possible
my $fix_perms = sub { chmod 0700, $_ unless -l $_; };
if (step_wanted('install'))
{
File::Find::find($fix_perms, "inst") if -d "inst";
rmtree("inst");
die "$installdir exists!" if -e "inst";
}
unless ($from_source && !$use_vpath)
{
File::Find::find($fix_perms, "$pgsql") if -d $pgsql;
rmtree($pgsql);
die "$pgsql exists!" if -e $pgsql;
}
# 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, sorta, really the start of the run
# take this value as early as possible to lower the risk of
# conflicts with other parallel runs
our ($now);
BEGIN { $now = time; }
# unless --avoid-ts-collisions is in use
if ($avoid_ts_collisions)
{
# In this mode ensure that concurrent independent runs for the same animal
# on different branches get slightly different snapshot timestamps,
# to keep the server happy.
# Not needed if running with run_branches.pl, as it already does this
# for parallel runs.
open(my $tslock, ">", "$buildroot/$animal.ts.LCK")
|| die "opening tslock $!";
# this is a blocking lock, so only one run at a time can get past here.
die "acquiring lock on $buildroot/$animal.ts.LCK"
unless flock($tslock, LOCK_EX);
$now = time;
sleep 2;
# release the lock;
close($tslock);
}
my $dbstarted;
my $extraconf;
my $main_pid = $$;
my $waiter_pid;
my $exit_stage = "OK";
# 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
&& $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 && $exit_stage ne 'OK')
{
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; ## no critic (RequireLocalizedPunctuationVars)
}
$waiter_pid = spawn(\&wait_timeout, $wait_timeout) if $wait_timeout > 0;
# 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} });
}
}
# adjust to new config setting name
if ($branch eq 'HEAD' || $branch ge 'REL_16')
{
s/force_parallel_mode/debug_parallel_query/
foreach @{ $extra_config->{$branch} };
}
if ($use_discard_caches && ($branch eq 'HEAD' || $branch ge 'REL_14'))
{
if (!exists $extra_config->{$branch})
{
$extra_config->{$branch} = ["debug_discard_caches = 1"];
}
else
{
push(@{ $extra_config->{$branch} }, "debug_discard_caches = 1");
}
}
if ($extra_config && $extra_config->{$branch})
{
my $tmpname = "$vtmpdir/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';
my $idname = ($nosend || $nostatus) ? 'ns-githead' : 'githead';
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 && !($testmode || $from_source);
# 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|Git-mirror/ && $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)
{
$scm->log_id($idname); # update the githead.log for up-to-date checks
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($idname) unless $from_source;
# copy/create according to vpath/scm settings
if ($use_vpath)
{
my $str = $using_meson ? "meson" : "vpath";
print time_str(), "creating $str 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;
my $dblaststartstop = 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'))
{
my $str = $using_meson ? "meson setup" : "configure";
print time_str(), "running $str ...\n" if $verbose;
configure();
}
# force this on to avoid meson errors on build
local $ENV{MSYS} = $ENV{MSYS} || "";
$ENV{MSYS} .= " winjitdebug" if ($using_meson);
# module configure has to wait until we have built and installed the base
# so see below
make();
meson_test_setup() if $using_meson;
make_check() unless $delay_check;
# contrib is built under the standard build step for msvc
make_contrib() unless ($using_msvc || $using_meson);
make_testmodules()
unless ($using_msvc
|| $using_meson
|| ($branch ne 'HEAD' && $branch lt '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 || $using_meson);
make_testmodules_install()
unless ($branch ne 'HEAD' && $branch lt '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;
if ($using_meson)
{
run_meson_noninst_checks();
}
else