| 1 | package PkgForge::BuildInfo; | ||
| 2 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | 1 | ▶ | use File::Spec (); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 1 | ▶ | use Sys::Hostname (); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 1 | ▶ | use Moose; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 1 | ▶ | use MooseX::Types::Moose qw(Bool Int Str); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | 0 | ▶ | use PkgForge::Types qw(SourcePackageList); |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 11 | use PkgForge::SourceUtils (); | ||
| 12 | |||
| 13 | with 'PkgForge::YAMLStorage'; | ||
| 14 | |||
| 15 | has '+yamlfile' => ( default => 'buildinfo.yml' ); | ||
| 16 | |||
| 17 | has 'builder' => ( | ||
| 18 | traits => ['PkgForge::Serialise'], | ||
| 19 | is => 'rw', | ||
| 20 | isa => Str, | ||
| 21 | ); | ||
| 22 | |||
| 23 | has 'platform' => ( | ||
| 24 | traits => ['PkgForge::Serialise'], | ||
| 25 | is => 'rw', | ||
| 26 | isa => Str, | ||
| 27 | ); | ||
| 28 | |||
| 29 | has 'architecture' => ( | ||
| 30 | traits => ['PkgForge::Serialise'], | ||
| 31 | is => 'rw', | ||
| 32 | isa => Str, | ||
| 33 | ); | ||
| 34 | |||
| 35 | has 'hostname' => ( | ||
| 36 | traits => ['PkgForge::Serialise'], | ||
| 37 | is => 'rw', | ||
| 38 | isa => Str, | ||
| 39 | required => 1, | ||
| 40 | default => sub { Sys::Hostname::hostname } | ||
| 41 | ); | ||
| 42 | |||
| 43 | has 'starttime' => ( | ||
| 44 | traits => ['PkgForge::Serialise'], | ||
| 45 | is => 'rw', | ||
| 46 | isa => Int, | ||
| 47 | required => 1, | ||
| 48 | default => sub { time }, | ||
| 49 | ); | ||
| 50 | |||
| 51 | has 'endtime' => ( | ||
| 52 | traits => ['PkgForge::Serialise'], | ||
| 53 | is => 'rw', | ||
| 54 | isa => Int, | ||
| 55 | required => 1, | ||
| 56 | lazy => 1, | ||
| 57 | default => sub { time }, | ||
| 58 | ); | ||
| 59 | |||
| 60 | has 'jobid' => ( | ||
| 61 | traits => ['PkgForge::Serialise'], | ||
| 62 | is => 'rw', | ||
| 63 | isa => Str, | ||
| 64 | ); | ||
| 65 | |||
| 66 | has 'sources' => ( | ||
| 67 | traits => ['Array','PkgForge::Serialise'], | ||
| 68 | is => 'rw', | ||
| 69 | isa => SourcePackageList, | ||
| 70 | default => sub { [] }, | ||
| 71 | handles => { | ||
| 72 | sources_list => 'elements', | ||
| 73 | sources_count => 'count', | ||
| 74 | }, | ||
| 75 | pack => sub { PkgForge::SourceUtils::pack_packages($_[0]) }, | ||
| 76 | unpack => sub { PkgForge::SourceUtils::unpack_packages($_[0]) }, | ||
| 77 | documentation => 'The set of source packages to be built', | ||
| 78 | ); | ||
| 79 | |||
| 80 | has 'success' => ( | ||
| 81 | traits => [ 'Array', 'PkgForge::Serialise' ], | ||
| 82 | is => 'rw', | ||
| 83 | isa => SourcePackageList, | ||
| 84 | default => sub { [] }, | ||
| 85 | handles => { | ||
| 86 | has_success => 'count', | ||
| 87 | success_count => 'count', | ||
| 88 | }, | ||
| 89 | pack => sub { PkgForge::SourceUtils::pack_packages($_[0]) }, | ||
| 90 | unpack => sub { PkgForge::SourceUtils::unpack_packages($_[0]) }, | ||
| 91 | documentation => 'The set of source packages successfully built', | ||
| 92 | ); | ||
| 93 | |||
| 94 | has 'failures' => ( | ||
| 95 | traits => [ 'Array', 'PkgForge::Serialise' ], | ||
| 96 | is => 'rw', | ||
| 97 | isa => SourcePackageList, | ||
| 98 | default => sub { [] }, | ||
| 99 | handles => { | ||
| 100 | has_failures => 'count', | ||
| 101 | failure_count => 'count', | ||
| 102 | }, | ||
| 103 | pack => sub { PkgForge::SourceUtils::pack_packages($_[0]) }, | ||
| 104 | unpack => sub { PkgForge::SourceUtils::unpack_packages($_[0]) }, | ||
| 105 | documentation => 'The set of source packages which failed to build', | ||
| 106 | ); | ||
| 107 | |||
| 108 | has 'products' => ( | ||
| 109 | traits => [ 'Array', 'PkgForge::Serialise' ], | ||
| 110 | is => 'rw', | ||
| 111 | isa => 'ArrayRef[Str]', | ||
| 112 | default => sub { [] }, | ||
| 113 | handles => { | ||
| 114 | products_list => 'elements', | ||
| 115 | add_products => 'push', | ||
| 116 | }, | ||
| 117 | pack => sub { basename_only($_[0]) }, | ||
| 118 | documentation => 'The products of building the job', | ||
| 119 | ); | ||
| 120 | |||
| 121 | has 'logs' => ( | ||
| 122 | traits => [ 'Array', 'PkgForge::Serialise' ], | ||
| 123 | is => 'rw', | ||
| 124 | isa => 'ArrayRef[Str]', | ||
| 125 | default => sub { [] }, | ||
| 126 | handles => { | ||
| 127 | logs_list => 'elements', | ||
| 128 | add_logs => 'push', | ||
| 129 | }, | ||
| 130 | pack => sub { basename_only($_[0]) }, | ||
| 131 | documentation => 'The log files from building the job', | ||
| 132 | ); | ||
| 133 | |||
| 134 | has 'phases' => ( | ||
| 135 | traits => ['Array','PkgForge::Serialise' ], | ||
| 136 | is => 'rw', | ||
| 137 | isa => 'ArrayRef[Str]', | ||
| 138 | default => sub { ['init'] }, | ||
| 139 | handles => { | ||
| 140 | phases_list => 'elements', | ||
| 141 | phase_reached => 'push', | ||
| 142 | }, | ||
| 143 | documentation => 'Which phase in the build process has been reached', | ||
| 144 | ); | ||
| 145 | |||
| 146 | has 'completed' => ( | ||
| 147 | traits => ['PkgForge::Serialise'], | ||
| 148 | is => 'rw', | ||
| 149 | isa => Bool, | ||
| 150 | default => 0, | ||
| 151 | documentation => 'A boolean which indicates whether the job completed', | ||
| 152 | ); | ||
| 153 | |||
| 154 | no Moose; | ||
| 155 | __PACKAGE__->meta->make_immutable; | ||
| 156 | |||
| 157 | sub basename_only { [ map { (File::Spec->splitpath($_))[2] } @{$_[0]} ] } | ||
| 158 | |||
| 159 | sub built_successfully { | ||
| 160 | my ($self) = @_; | ||
| 161 | |||
| 162 | return ( $self->has_success && !$self->has_failures ); | ||
| 163 | } | ||
| 164 | |||
| 165 | sub last_phase { | ||
| 166 | my ($self) = @_; | ||
| 167 | |||
| 168 | my $last_phase = ($self->phases_list)[-1]; | ||
| 169 | |||
| 170 | return $last_phase; | ||
| 171 | } | ||
| 172 | |||
| 173 | sub source_files { | ||
| 174 | my ($self) = @_; | ||
| 175 | |||
| 176 | # We are only interested in the file names (i.e. the basename part) | ||
| 177 | # not the full path. | ||
| 178 | |||
| 179 | # There is a chance that the same filename may be in more than one | ||
| 180 | # source object so uniqueify using a hash. | ||
| 181 | |||
| 182 | my %files; | ||
| 183 | for my $source ($self->sources_list) { | ||
| 184 | my $file = $source->file; | ||
| 185 | $files{$file} = 1; | ||
| 186 | } | ||
| 187 | |||
| 188 | # Sort so that we always return the same list of strings for the | ||
| 189 | # same sources list. | ||
| 190 | |||
| 191 | my @files = sort keys %files; | ||
| 192 | |||
| 193 | return @files; | ||
| 194 | } | ||
| 195 | |||
| 196 | 1; | ||
| 197 | __END__ | ||