Merge branch 'master' of github.com:mrballcb/exim-build-farm-client
[buildfarm-client.git] / EximBuild / Modules / TestUpgrade.pm
1
2 # Package Namespace is hardcoded. Modules must live in
3 # EximBuild::Modules
4
5 package EximBuild::Modules::TestUpgrade;
6
7 use EximBuild::Options;
8 use EximBuild::SCM;
9
10 use File::Basename;
11
12 use strict;
13
14 use vars qw($VERSION); $VERSION = 'REL_0.1';
15
16 my $hooks = {
17
18     #    'checkout' => \&checkout,
19     #    'setup-target' => \&setup_target,
20     #    'need-run' => \&need_run,
21     #    'configure' => \&configure,
22     #    'build' => \&build,
23     #    'install' => \&install,
24     'check' => \&check,
25
26     #    'cleanup' => \&cleanup,
27 };
28
29 sub setup
30 {
31     my $class = __PACKAGE__;
32
33     my $buildroot = shift; # where we're building
34     my $branch = shift; # The branch of exim that's being built.
35     my $conf = shift;  # ref to the whole config object
36     my $exim = shift; # exim build dir
37
38     return unless ($branch eq 'HEAD' or $branch ge 'REL9_2');
39
40     die
41 "overly long build root $buildroot will cause upgrade problems - try something shorter than 46 chars"
42       if (length($buildroot) > 46);
43
44     # could even set up several of these (e.g. for different branches)
45     my $self  = {
46         buildroot => $buildroot,
47         eximbranch=> $branch,
48         bfconf => $conf,
49         exim => $exim
50     };
51     bless($self, $class);
52
53     # for each instance you create, do:
54     main::register_module_hooks($self,$hooks);
55
56 }
57
58 sub check
59 {
60     my $self = shift;
61
62     return unless main::step_wanted('pg_upgrade-check');
63
64     print main::time_str(), "checking pg_upgrade\n" if  $verbose;
65
66     my $make = $self->{bfconf}->{make};
67
68     local %ENV = %ENV;
69     delete $ENV{PGUSER};
70
71     (my $buildport = $ENV{EXTRA_REGRESS_OPTS}) =~ s/--port=//;
72     $ENV{PGPORT} = $buildport;
73
74     my @checklog;
75
76     if ($self->{bfconf}->{using_msvc})
77     {
78         chdir "$self->{exim}/src/tools/msvc";
79         @checklog = `perl vcregress.pl upgradecheck 2>&1`;
80         chdir "$self->{buildroot}/$self->{eximbranch}";
81     }
82     else
83     {
84         my $cmd = "cd $self->{exim}/contrib/pg_upgrade && $make check";
85         @checklog = `$cmd 2>&1`;
86     }
87
88     my @logfiles = glob("$self->{exim}/contrib/pg_upgrade/*.log");
89     foreach my $log (@logfiles)
90     {
91         my $fname = basename $log;
92         local $/ = undef;
93         my $handle;
94         open($handle,$log);
95         my $contents = <$handle>;
96         close($handle);
97         push(@checklog,
98             "=========================== $fname ================\n",$contents);
99     }
100
101     my $status = $? >>8;
102
103     main::writelog("check-pg_upgrade",\@checklog);
104     print "======== pg_upgrade check log ===========\n",@checklog
105       if ($verbose > 1);
106     main::send_result("pg_upgradeCheck",$status,\@checklog) if $status;
107     {
108         no warnings 'once';
109         $main::steps_completed .= " pg_upgradeCheck";
110     }
111
112 }
113
114 1;