| 1 | package LCFG::Build::VCS; # -*-perl-*- | ||||||||||||||||||||||||||||||||||
| 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 v5.10; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||
| 7 | # $Id: VCS.pm.in 35396 2019-01-17 12:01:51Z squinney@INF.ED.AC.UK $ | ||||||||||||||||||||||||||||||||||
| 8 | # $Source: /var/cvs/dice/LCFG-Build-VCS/lib/LCFG/Build/VCS.pm.in,v $ | ||||||||||||||||||||||||||||||||||
| 9 | # $Revision: 35396 $ | ||||||||||||||||||||||||||||||||||
| 10 | # $HeadURL: https://svn.lcfg.org/svn/source/tags/LCFG-Build-VCS/LCFG_Build_VCS_0_3_9/lib/LCFG/Build/VCS.pm.in $ | ||||||||||||||||||||||||||||||||||
| 11 | # $Date: 2019-01-17 12:01:51 +0000 (Thu, 17 Jan 2019) $ | ||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||
| 13 | 1 | our $VERSION = '0.3.9'; | |||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use DateTime (); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use File::Copy (); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use File::Path (); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use File::Spec (); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use File::Temp (); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use IO::File (); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use IPC::Run qw(run); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 22 | 1 | ▶ | use Template v2.14 (); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||
| 24 | 1 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | use Moose::Util::TypeConstraints; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||
| 27 | subtype 'AbsPath' | ||||||||||||||||||||||||||||||||||
| 28 | => as 'Str' | ||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | => where { File::Spec->file_name_is_absolute($_) } | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | => message { 'Directory must be an absolute path.' }; | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||
| 32 | # coerce the input string (which is possibly a relative path) into an | ||||||||||||||||||||||||||||||||||
| 33 | # absolute path which does not have a trailing / | ||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||
| 35 | coerce 'AbsPath' | ||||||||||||||||||||||||||||||||||
| 36 | => from 'Str' | ||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | => via { my $path = File::Spec->file_name_is_absolute($_) ? $_ : File::Spec->rel2abs($_); $path =~ s{/$}{}; $path }; | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=14.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||
| 39 | 1 | requires qw/checkcommitted genchangelog tagversion export export_devel import_project checkout_project/; | |||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||
| 41 | 1 | has 'id' => ( | |||||||||||||||||||||||||||||||||
| 42 | is => 'ro', | ||||||||||||||||||||||||||||||||||
| 43 | isa => 'Str', | ||||||||||||||||||||||||||||||||||
| 44 | required => 1, | ||||||||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||
| 47 | 1 | has 'module' => ( | |||||||||||||||||||||||||||||||||
| 48 | is => 'rw', | ||||||||||||||||||||||||||||||||||
| 49 | isa => 'Str', | ||||||||||||||||||||||||||||||||||
| 50 | required => 1, | ||||||||||||||||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||
| 53 | 1 | has 'workdir' => ( | |||||||||||||||||||||||||||||||||
| 54 | is => 'rw', | ||||||||||||||||||||||||||||||||||
| 55 | isa => 'AbsPath', | ||||||||||||||||||||||||||||||||||
| 56 | required => 1, | ||||||||||||||||||||||||||||||||||
| 57 | coerce => 1, | ||||||||||||||||||||||||||||||||||
| 58 | default => q{.}, | ||||||||||||||||||||||||||||||||||
| 59 | ); | ||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||
| 61 | 1 | has 'binpath' => ( | |||||||||||||||||||||||||||||||||
| 62 | is => 'rw', | ||||||||||||||||||||||||||||||||||
| 63 | isa => 'Str', | ||||||||||||||||||||||||||||||||||
| 64 | required => 0, | ||||||||||||||||||||||||||||||||||
| 65 | ); | ||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||
| 67 | 1 | has 'quiet' => ( | |||||||||||||||||||||||||||||||||
| 68 | is => 'rw', | ||||||||||||||||||||||||||||||||||
| 69 | isa => 'Bool', | ||||||||||||||||||||||||||||||||||
| 70 | default => 0, | ||||||||||||||||||||||||||||||||||
| 71 | required => 0, | ||||||||||||||||||||||||||||||||||
| 72 | ); | ||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||
| 74 | 1 | has 'dryrun' => ( | |||||||||||||||||||||||||||||||||
| 75 | is => 'rw', | ||||||||||||||||||||||||||||||||||
| 76 | isa => 'Bool', | ||||||||||||||||||||||||||||||||||
| 77 | default => 0, | ||||||||||||||||||||||||||||||||||
| 78 | required => 0, | ||||||||||||||||||||||||||||||||||
| 79 | ); | ||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||
| 81 | 1 | has 'logname' => ( | |||||||||||||||||||||||||||||||||
| 82 | is => 'rw', | ||||||||||||||||||||||||||||||||||
| 83 | isa => 'Str', | ||||||||||||||||||||||||||||||||||
| 84 | default => 'ChangeLog', | ||||||||||||||||||||||||||||||||||
| 85 | required => 1, | ||||||||||||||||||||||||||||||||||
| 86 | ); | ||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | sub build_cmd { | ||||||||||||||||||||||||||||||||
|
Subroutine
build_cmd: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 89 | 0 | my ( $self, @args ) = @_; | |||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||
| 91 | 0 | my @cmd = ( $self->binpath, @args ); | |||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||
| 93 | 0 | return @cmd; | |||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | sub run_cmd { | ||||||||||||||||||||||||||||||||
|
Subroutine
run_cmd: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 97 | 0 | my ( $self, @args ) = @_; | |||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||
| 99 | 0 | my @cmd = $self->build_cmd(@args); | |||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||
| 101 | 0 | my @out; | |||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | if ( $self->dryrun ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 103 | 0 | my $cmd = join q( ), @cmd; | |||||||||||||||||||||||||||||||||
| 104 | 0 | print "Dry-run: $cmd\n"; | |||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||
| 106 | else { | ||||||||||||||||||||||||||||||||||
| 107 | 0 | my ( $in, $out, $err ); | |||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||
| 109 | 0 | my $success = run \@cmd, \$in, \$out, \$err; | |||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | if ( !$success ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 111 | 0 | die "Error whilst running @cmd: $err\n"; | |||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | if ($err) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 114 | 0 | warn "$err\n"; | |||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||
| 117 | 0 | @out = split /[\r\n]+/, $out; | |||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||
| 120 | 0 | return @out; | |||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | sub logfile { | ||||||||||||||||||||||||||||||||
|
Subroutine
logfile: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 124 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||
| 126 | 0 | return File::Spec->catfile( $self->workdir, $self->logname ); | |||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | sub gen_tag { | ||||||||||||||||||||||||||||||||
|
Subroutine
gen_tag: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 130 | 0 | my ( $self, $version ) = @_; | |||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||
| 132 | # Build a tag from the name and version (if specified) and then | ||||||||||||||||||||||||||||||||||
| 133 | # replace any period or hyphen characters. | ||||||||||||||||||||||||||||||||||
| 134 | # | ||||||||||||||||||||||||||||||||||
| 135 | # name: lcfg-foo, version: 1.0.1, gives: lcfg_foo_1_0_1 | ||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||
| 137 | 0 | my $tag; | |||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | if ( !defined $version ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 139 | 0 | $tag = $self->module; | |||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||
| 141 | else { | ||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | if ( $version eq 'latest' ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 144 | 0 | $tag = 'latest'; | |||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||
| 146 | else { | ||||||||||||||||||||||||||||||||||
| 147 | 0 | $tag = join q{_}, $self->module, $version; | |||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||
| 152 | 0 | $tag =~ s/\./_/g; | |||||||||||||||||||||||||||||||||
| 153 | 0 | $tag =~ s/\-/_/g; | |||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||
| 155 | 0 | return $tag; | |||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | sub update_changelog { | ||||||||||||||||||||||||||||||||
|
Subroutine
update_changelog: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 159 | 0 | my ( $self, $version, $options ) = @_; | |||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | $options //= {}; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$options //= {}
MC/DC0%0/1
$options //= {}
$options
Truth table0%0/2
A
A= $options
| |||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||
| 162 | 0 | $options->{dryrun} = $self->dryrun; | |||||||||||||||||||||||||||||||||
| 163 | 0 | $options->{id} = $self->id; | |||||||||||||||||||||||||||||||||
| 164 | 0 | $options->{version} = $version; | |||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | $options->{style} ||= 'default'; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$options->{"style"} ||= "default"
MC/DC0%0/1
$options->{"style"} ||= "default"
$options->{"style"}
Truth table0%0/2
A
A= $options->{"style"}
| |||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||
| 167 | 0 | my $dir = $self->workdir; | |||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||
| 169 | 0 | my ( $logfile, $needs_add ); | |||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | if ( $options->{style} eq 'debian' ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 171 | 0 | $logfile = File::Spec->catfile( $dir, 'debian', 'changelog' ); | |||||||||||||||||||||||||||||||||
| 172 | 0 | $needs_add = !-e $logfile; | |||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | if ( !$options->{pkgname} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||
| 176 | # Cook up something sensible which looks like a Debian package | ||||||||||||||||||||||||||||||||||
| 177 | # name | ||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||
| 179 | 0 | $options->{pkgname} = lc $self->module; | |||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||
| 181 | # underscores are not permitted, helpfully replace with dashes | ||||||||||||||||||||||||||||||||||
| 182 | 0 | $options->{pkgname} =~ s/_/-/g; | |||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||
| 184 | # For safety remove any other invalid characters | ||||||||||||||||||||||||||||||||||
| 185 | 0 | $options->{pkgname} =~ s/[^a-z0-9-]//; | |||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||
| 188 | 0 | update_debian_changelog( $logfile, $options ); | |||||||||||||||||||||||||||||||||
| 189 | } else { | ||||||||||||||||||||||||||||||||||
| 190 | 0 | $logfile = $self->logfile; | |||||||||||||||||||||||||||||||||
| 191 | 0 | $needs_add = !-e $logfile; | |||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||
| 193 | 0 | update_lcfg_changelog( $logfile, $options ); | |||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | if ( !$self->dryrun ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | if ($needs_add) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 198 | 0 | $self->run_cmd( 'add', $logfile ); | |||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||
| 202 | 0 | return; | |||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | sub update_lcfg_changelog { | ||||||||||||||||||||||||||||||||
|
Subroutine
update_lcfg_changelog: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 206 | 0 | my ( $logfile, $options ) = @_; | |||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | $options //= {}; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$options //= {}
MC/DC0%0/1
$options //= {}
$options
Truth table0%0/2
A
A= $options
| |||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | $options->{date} ||= DateTime->now->ymd; | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$options->{"date"} ||= "DateTime"->now->ymd
MC/DC0%0/2
$options->{"date"} ||= "DateTime"->now->ymd
$options->{"date"}
"DateTime"->now->ymd
Truth table0%0/3
A ||= B
A= $options->{"date"}B= "DateTime"->now->ymd
| |||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||
| 211 | 0 | my $dir = (File::Spec->splitpath($logfile))[1]; | |||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||
| 213 | 0 | my $tmplog = File::Temp->new( | |||||||||||||||||||||||||||||||||
| 214 | TEMPLATE => 'lcfgXXXXXX', | ||||||||||||||||||||||||||||||||||
| 215 | UNLINK => 1, | ||||||||||||||||||||||||||||||||||
| 216 | DIR => $dir, | ||||||||||||||||||||||||||||||||||
| 217 | ); | ||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||
| 219 | 0 | my $tmpname = $tmplog->filename; | |||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||
| 221 | 0 | $tmplog->print(<<"EOT"); | |||||||||||||||||||||||||||||||||
| 222 | $options->{date} $options->{id}: new release | ||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||
| 224 | \t* Release: $options->{version} | ||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||
| 226 | EOT | ||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | if ( -f $logfile ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | my $log = IO::File->new( $logfile, 'r' ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 230 | or die "Could not open $logfile: $!\n"; | ||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||
| 232 | 0 | ▶ | while ( defined( my $line = <$log> ) ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 233 | 0 | $tmplog->print($line); | |||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||
| 236 | 0 | $log->close; | |||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||
| 239 | $tmplog->close | ||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | or die "Could not close temporary file, $tmpname: $!\n"; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||
| 242 | 0 | ▶ | if ( !$options->{dryrun} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | rename $tmpname, $logfile | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 244 | or die "Could not rename $tmpname as $logfile: $!\n"; | ||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||
| 247 | 0 | return; | |||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||
| 250 | # These update_*_changelog subroutines are also used externally from | ||||||||||||||||||||||||||||||||||
| 251 | # places which do not have access to the VCS object so they are not | ||||||||||||||||||||||||||||||||||
| 252 | # class methods. | ||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | sub update_debian_changelog { | ||||||||||||||||||||||||||||||||
|
Subroutine
update_debian_changelog: not called CC=18 SCAR=58.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 255 | 0 | my ( $logfile, $options ) = @_; | |||||||||||||||||||||||||||||||||
| 256 | 0 | ▶ | $options //= {}; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$options //= {}
MC/DC0%0/1
$options //= {}
$options
Truth table0%0/2
A
A= $options
| |||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | $options->{urgency} ||= 'low'; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$options->{"urgency"} ||= "low"
MC/DC0%0/1
$options->{"urgency"} ||= "low"
$options->{"urgency"}
Truth table0%0/2
A
A= $options->{"urgency"}
| |||||||||||||||||||||||||||||||||||
| 259 | 0 | ▶ | $options->{distribution} ||= 'unstable'; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$options->{"distribution"} ||= "unstable"
MC/DC0%0/1
$options->{"distribution"} ||= "unstable"
$options->{"distribution"}
Truth table0%0/2
A
A= $options->{"distribution"}
| |||||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | $options->{release} //= 1; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$options->{"release"} //= 1
MC/DC0%0/1
$options->{"release"} //= 1
$options->{"release"}
Truth table0%0/2
A
A= $options->{"release"}
| |||||||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | $options->{message} ||= 'New upstream release'; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$options->{"message"} ||= "New upstream release"
MC/DC0%0/1
$options->{"message"} ||= "New upstream release"
$options->{"message"}
Truth table0%0/2
A
A= $options->{"message"}
| |||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||
| 263 | # RFC822 date | ||||||||||||||||||||||||||||||||||
| 264 | 0 | $options->{date} = DateTime->now->strftime('%a, %d %b %Y %H:%M:%S %z'); | |||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | if ( !$options->{email} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 267 | 0 | my $user_name = (getpwuid($<))[0]; | |||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||
| 269 | 0 | ▶ | my $email_addr = $ENV{DEBEMAIL} || $ENV{EMAIL}; | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$ENV{'DEBEMAIL'} || $ENV{'EMAIL'}
MC/DC0%0/2
$ENV{'DEBEMAIL'} || $ENV{'EMAIL'}
$ENV{'DEBEMAIL'}
$ENV{'EMAIL'}
Truth table0%0/3
A || B
A= $ENV{'DEBEMAIL'}B= $ENV{'EMAIL'}
| |||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||
| 271 | 0 | ▶ | if ( !$email_addr ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 272 | 0 | require Net::Domain; | |||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||
| 274 | 0 | my $domain = Net::Domain::hostdomain(); | |||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||
| 276 | 0 | $email_addr = join '@', $user_name, $domain; | |||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||
| 279 | # trim any leading or trailing whitespace | ||||||||||||||||||||||||||||||||||
| 280 | 0 | $email_addr =~ s/^\s+//; $email_addr =~ s/\s+$//; | |||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||
| 282 | 0 | ▶ | if ( $email_addr !~ m/<.+>/ ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | my $email_name = $ENV{DEBFULLNAME} || $ENV{NAME} || $user_name; | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
$ENV{'DEBFULLNAME'} || $ENV{'NAME'} || $user_name
$ENV{"DEBFULLNAME"} or $ENV{"NAME"}
MC/DC0%0/3
$ENV{'DEBFULLNAME'} || $ENV{'NAME'} || $user_name
$ENV{"DEBFULLNAME"}
$ENV{"NAME"}
$user_name
Truth table0%0/4
A or B || C
A= $ENV{"DEBFULLNAME"}B= $ENV{"NAME"}C= $user_name
| |||||||||||||||||||||||||||||||||||
| 284 | 0 | $email_name =~ s/^\s+//; $email_name =~ s/\s+$//; | |||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||
| 286 | 0 | $email_addr = "$email_name <$email_addr>"; | |||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||
| 289 | 0 | $options->{email} = $email_addr; | |||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||
| 292 | 0 | my ( $dir, $basename ) = (File::Spec->splitpath($logfile))[1,2]; | |||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||
| 294 | 0 | my $tmplog = File::Temp->new( | |||||||||||||||||||||||||||||||||
| 295 | TEMPLATE => 'lcfgXXXXXX', | ||||||||||||||||||||||||||||||||||
| 296 | UNLINK => 1, | ||||||||||||||||||||||||||||||||||
| 297 | DIR => $dir, | ||||||||||||||||||||||||||||||||||
| 298 | ); | ||||||||||||||||||||||||||||||||||
| 299 | 0 | my $tmpname = $tmplog->filename; | |||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | my $tt = Template->new( | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 302 | { | ||||||||||||||||||||||||||||||||||
| 303 | INCLUDE_PATH => $dir, | ||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||
| 305 | ) or die $Template::ERROR . "\n"; | ||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||
| 307 | 0 | my $template = q{ | |||||||||||||||||||||||||||||||||
| 308 | [%- FOREACH entry IN entries -%] | ||||||||||||||||||||||||||||||||||
| 309 | [% entry.item('pkgname') %] ([% entry.item('version') %]-[% entry.item('release') %]) [% entry.item('distribution') %]; urgency=[% entry.item('urgency') %] | ||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||
| 311 | * [% entry.item('message') %] | ||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||
| 313 | -- [% entry.item('email') %] [% entry.item('date') %] | ||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||
| 315 | [% END -%] | ||||||||||||||||||||||||||||||||||
| 316 | [% IF current_logfile %][% INSERT $current_logfile %][% END -%] | ||||||||||||||||||||||||||||||||||
| 317 | }; | ||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||
| 319 | 0 | my %args = ( | |||||||||||||||||||||||||||||||||
| 320 | entries => [$options], | ||||||||||||||||||||||||||||||||||
| 321 | ); | ||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | if ( -e $logfile ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 324 | 0 | $args{current_logfile} = $basename; | |||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||
| 327 | 0 | ▶ | $tt->process( \$template, \%args, $tmplog ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 328 | or die $tt->error() . "\n"; | ||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | $tmplog->close | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 331 | or die "Could not close temporary file, $tmpname: $!\n"; | ||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||
| 333 | 0 | ▶ | if ( !$options->{dryrun} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | rename $tmpname, $logfile | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 335 | or die "Could not rename $tmpname as $logfile: $!\n"; | ||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||
| 338 | 0 | return; | |||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||
| 342 | 0 | ▶ | sub mirror_file { | ||||||||||||||||||||||||||||||||
|
Subroutine
mirror_file: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 343 | 0 | my ( $self, $workdir, $exportdir, $dirname, $fname ) = @_; | |||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||
| 345 | 0 | my $from_dir = File::Spec->catdir( $workdir, $dirname ); | |||||||||||||||||||||||||||||||||
| 346 | 0 | my $to_dir = File::Spec->catdir( $exportdir, $dirname ); | |||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||
| 348 | 0 | ▶ | if ( !$self->dryrun && !-d $to_dir ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->dryrun or -d $to_dir
MC/DC0%0/2
$self->dryrun or -d $to_dir
$self->dryrun
-d $to_dir
Truth table0%0/3
A or B
A= $self->dryrunB= -d $to_dir
| |||||||||||||||||||||||||||||||||||
| 349 | 0 | eval { File::Path::mkpath($to_dir) }; | |||||||||||||||||||||||||||||||||
| 350 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 351 | 0 | die "Could not create $to_dir: $@\n"; | |||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||
| 354 | 0 | my ($dev, $ino, $mode, $nlink, $uid, | |||||||||||||||||||||||||||||||||
| 355 | $gid, $rdev, $size, $atime, $mtime, | ||||||||||||||||||||||||||||||||||
| 356 | $ctime, $blksize, $blocks | ||||||||||||||||||||||||||||||||||
| 357 | ) = stat $from_dir; | ||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||
| 359 | 0 | ▶ | chmod $mode, $to_dir or die "chmod on $to_dir failed: $!\n"; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||
| 361 | # We don't care about atime/mtime for directories | ||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||
| 364 | 0 | my $from = File::Spec->catfile( $workdir, $dirname, $fname ); | |||||||||||||||||||||||||||||||||
| 365 | 0 | my $to = File::Spec->catfile( $exportdir, $dirname, $fname ); | |||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||
| 367 | 0 | my ($dev, $ino, $mode, $nlink, $uid, | |||||||||||||||||||||||||||||||||
| 368 | $gid, $rdev, $size, $atime, $mtime, | ||||||||||||||||||||||||||||||||||
| 369 | $ctime, $blksize, $blocks | ||||||||||||||||||||||||||||||||||
| 370 | ) = stat $from; | ||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||
| 372 | 0 | ▶ | if ( $self->dryrun ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 373 | 0 | print "Dry-run: $from -> $to\n"; | |||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||
| 375 | else { | ||||||||||||||||||||||||||||||||||
| 376 | 0 | ▶ | File::Copy::syscopy( $from, $to ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 377 | or die "Copy $from to $to failed: $!\n"; | ||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||
| 379 | 0 | ▶ | chmod $mode, $to or die "chmod on $to to ($mode) failed: $!\n"; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 380 | 0 | ▶ | utime $atime, $mtime, $to or die "utime on $to to ($atime, $mtime) failed: $!\n"; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||
| 384 | 0 | return; | |||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||
| 387 | 0 | ▶ | sub store_version { | ||||||||||||||||||||||||||||||||
|
Subroutine
store_version: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 388 | 0 | my ( $self, $version ) = @_; | |||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||
| 390 | 0 | warn "Updating build ID file\n"; | |||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||
| 392 | 0 | my $dir = $self->workdir; | |||||||||||||||||||||||||||||||||
| 393 | 0 | my $version_file = 'lcfg-build-id.txt'; | |||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||
| 395 | 0 | my $tmpfh = File::Temp->new( | |||||||||||||||||||||||||||||||||
| 396 | UNLINK => 1, | ||||||||||||||||||||||||||||||||||
| 397 | DIR => $dir, | ||||||||||||||||||||||||||||||||||
| 398 | SUFFIX => '.tmp', | ||||||||||||||||||||||||||||||||||
| 399 | ); | ||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||
| 401 | 0 | my $tmpname = $tmpfh->filename; | |||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||
| 403 | 0 | $tmpfh->say($version); | |||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||
| 405 | 0 | ▶ | $tmpfh->close | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 406 | or die "Could not close temporary file, $tmpname: $!\n"; | ||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||
| 408 | 0 | ▶ | if ( !$self->dryrun ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 409 | 0 | ▶ | rename $tmpname, $version_file | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 410 | or die "Could not rename $tmpname as $version_file: $!\n"; | ||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||
| 413 | 0 | return; | |||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||
| 416 | 1 | 1; | |||||||||||||||||||||||||||||||||
| 417 | __END__ | ||||||||||||||||||||||||||||||||||