| 1 | package Dist::Zilla::Plugin::RPM; | ||||||||||||||||||||
| 2 | # ABSTRACT: Build an RPM from your Dist::Zilla release | ||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | 1 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | ▶ | use Moose::Autobox; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 1 | ▶ | use Moose::Util::TypeConstraints; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 1 | ▶ | use Path::Tiny; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 1 | ▶ | use namespace::autoclean; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 1 | our $VERSION = '0.016'; # VERSION | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 1 | with 'Dist::Zilla::Role::Releaser', | |||||||||||||||||||
| 13 | 'Dist::Zilla::Role::FilePruner'; | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 1 | has spec_file => ( | |||||||||||||||||||
| 16 | is => 'ro', | ||||||||||||||||||||
| 17 | isa => 'Str', | ||||||||||||||||||||
| 18 | default => 'build/dist.spec', | ||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 1 | has build => ( | |||||||||||||||||||
| 22 | is => 'ro', | ||||||||||||||||||||
| 23 | isa => enum([qw/source all/]), | ||||||||||||||||||||
| 24 | default => 'all', | ||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 1 | has sign => ( | |||||||||||||||||||
| 28 | is => 'ro', | ||||||||||||||||||||
| 29 | isa => 'Bool', | ||||||||||||||||||||
| 30 | default => 0, | ||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 1 | has ignore_build_deps => ( | |||||||||||||||||||
| 34 | is => 'ro', | ||||||||||||||||||||
| 35 | isa => 'Bool', | ||||||||||||||||||||
| 36 | default => 0, | ||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | 1 | has push_packages => ( is => 'ro', isa => 'Bool', default => 0 ); | |||||||||||||||||||
| 40 | 1 | has push_command => ( is => 'ro', isa => 'Str', default => 'rhnpush -s' ); | |||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 1 | ▶ | use constant _CoercedRegexp => do { | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 43 | 1 | my $tc = subtype as 'RegexpRef'; | |||||||||||||||||||
| 44 | 1 | ▶ | coerce $tc, from 'Str', via { qr/$_/ }; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 45 | 1 | $tc; | |||||||||||||||||||
| 46 | 1 | }; | |||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 1 | has push_ignore_packages => ( | |||||||||||||||||||
| 49 | is => 'ro', isa => _CoercedRegexp, coerce => 1, default => '.src.rpm$' ); | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 1 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 52 | 1 | ▶ | use File::Temp (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 53 | 1 | ▶ | use Path::Class qw(dir); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 54 | 1 | ▶ | use Text::Template (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 55 | 1 | ▶ | use IPC::Run; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 0 | ▶ | sub prune_files { | ||||||||||||||||||
|
Subroutine
prune_files: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||
| 58 | 0 | my($self) = @_; | |||||||||||||||||||
| 59 | 0 | my $spec = $self->spec_file; | |||||||||||||||||||
| 60 | 0 | for my $file ($self->zilla->files->flatten) { | |||||||||||||||||||
| 61 | 0 | ▶ | if ($file->name eq $self->spec_file) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 62 | 0 | $self->zilla->prune_file($file); | |||||||||||||||||||
| 63 | } | ||||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | 0 | return; | |||||||||||||||||||
| 66 | } | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | has '_rpmbuild_options' => ( | ||||||||||||||||||||
| 69 | is => 'ro', isa => 'ArrayRef[Str]', lazy => 1, | ||||||||||||||||||||
| 70 | 0 | ▶ | default => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 71 | 0 | my $self = shift; | |||||||||||||||||||
| 72 | return( [ | ||||||||||||||||||||
| 73 | 0 | ▶ | $self->sign ? '--sign' : (), | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 74 | $self->ignore_build_deps ? '--nodeps' : (), | ||||||||||||||||||||
| 75 | ] ); | ||||||||||||||||||||
| 76 | }, | ||||||||||||||||||||
| 77 | 1 | ); | |||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | has '_rpmbuild_stage' => ( | ||||||||||||||||||||
| 80 | is => 'ro', isa => 'Str', lazy => 1, | ||||||||||||||||||||
| 81 | 0 | ▶ | default => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 82 | 0 | my $self = shift; | |||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | 0 | ▶ | if ($self->build eq 'source') { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 85 | 0 | return('-bs'); | |||||||||||||||||||
| 86 | } elsif ($self->build eq 'all') { | ||||||||||||||||||||
| 87 | 0 | return('-ba'); | |||||||||||||||||||
| 88 | } | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | 0 | $self->log_fatal(q{invalid build type }.$self->build); | |||||||||||||||||||
| 91 | }, | ||||||||||||||||||||
| 92 | 1 | ); | |||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | has '_rpmbuild_command' => ( | ||||||||||||||||||||
| 95 | is => 'ro', | ||||||||||||||||||||
| 96 | isa => 'ArrayRef[Str]', | ||||||||||||||||||||
| 97 | lazy => 1, | ||||||||||||||||||||
| 98 | 0 | ▶ | default => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 99 | 0 | my $self = shift; | |||||||||||||||||||
| 100 | return( [ | ||||||||||||||||||||
| 101 | 'rpmbuild', | ||||||||||||||||||||
| 102 | $self->_rpmbuild_stage, | ||||||||||||||||||||
| 103 | 0 | @{$self->_rpmbuild_options}, | |||||||||||||||||||
| 104 | $self->_tmpspecfile->stringify, | ||||||||||||||||||||
| 105 | ] ); | ||||||||||||||||||||
| 106 | }, | ||||||||||||||||||||
| 107 | 1 | ); | |||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | has '_tmpdir' => ( | ||||||||||||||||||||
| 110 | is => 'ro', isa => 'File::Temp::Dir', lazy => 1, | ||||||||||||||||||||
| 111 | 0 | ▶ | default => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 112 | 0 | my $self = shift; | |||||||||||||||||||
| 113 | 0 | return File::Temp->newdir(); | |||||||||||||||||||
| 114 | }, | ||||||||||||||||||||
| 115 | 1 | ); | |||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | has '_tmpspecfile' => ( | ||||||||||||||||||||
| 118 | is => 'ro', isa => 'Path::Class::File', lazy => 1, | ||||||||||||||||||||
| 119 | 0 | ▶ | default => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 120 | 0 | my $self = shift; | |||||||||||||||||||
| 121 | 0 | return dir($self->_tmpdir)->file($self->zilla->name . '.spec'); | |||||||||||||||||||
| 122 | }, | ||||||||||||||||||||
| 123 | 1 | ); | |||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | 0 | ▶ | sub _write_spec { | ||||||||||||||||||
|
Subroutine
_write_spec: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 126 | 0 | my ($self, $archive) = @_; | |||||||||||||||||||
| 127 | 0 | my $fh = $self->_tmpspecfile->openw(); | |||||||||||||||||||
| 128 | 0 | $fh->print($self->mk_spec($archive)); | |||||||||||||||||||
| 129 | 0 | $fh->flush; | |||||||||||||||||||
| 130 | 0 | $fh->close; | |||||||||||||||||||
| 131 | 0 | return; | |||||||||||||||||||
| 132 | } | ||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | has '_sourcedir' => ( | ||||||||||||||||||||
| 135 | is => 'ro', isa => 'Str', lazy => 1, | ||||||||||||||||||||
| 136 | 0 | ▶ | default => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 137 | 0 | my $self = shift; | |||||||||||||||||||
| 138 | 0 | ▶ | my $sourcedir = qx/rpm --eval '%{_sourcedir}'/ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 139 | or $self->log_fatal(q{couldn't determine RPM sourcedir}); | ||||||||||||||||||||
| 140 | 0 | $sourcedir =~ s/[\r\n]+$//; | |||||||||||||||||||
| 141 | 0 | $sourcedir .= '/'; | |||||||||||||||||||
| 142 | |||||||||||||||||||||
| 143 | 0 | ▶ | unless( -d $sourcedir) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 144 | 0 | $sourcedir = "$self->_tmpdir"; | |||||||||||||||||||
| 145 | } | ||||||||||||||||||||
| 146 | |||||||||||||||||||||
| 147 | 0 | return($sourcedir); | |||||||||||||||||||
| 148 | }, | ||||||||||||||||||||
| 149 | 1 | ); | |||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | 0 | ▶ | sub release { | ||||||||||||||||||
|
Subroutine
release: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||
| 152 | 0 | my($self,$archive) = @_; | |||||||||||||||||||
| 153 | |||||||||||||||||||||
| 154 | 0 | $self->_write_spec($archive); | |||||||||||||||||||
| 155 | |||||||||||||||||||||
| 156 | 0 | ▶ | if(! -f $archive ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 157 | 0 | $self->log_fatal('archive '.$archive.' does not exist!'); | |||||||||||||||||||
| 158 | } | ||||||||||||||||||||
| 159 | |||||||||||||||||||||
| 160 | 0 | ▶ | system('cp',$archive,$self->_sourcedir) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 161 | && $self->log_fatal('cp failed'); | ||||||||||||||||||||
| 162 | |||||||||||||||||||||
| 163 | 0 | ▶ | if ($ENV{DZIL_PLUGIN_RPM_TEST}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 164 | 0 | $self->log("test: would have executed ".join(' ', @{$self->_rpmbuild_command})); | |||||||||||||||||||
| 165 | 0 | return; | |||||||||||||||||||
| 166 | } | ||||||||||||||||||||
| 167 | |||||||||||||||||||||
| 168 | 0 | $self->_execute_rpmbuild; | |||||||||||||||||||
| 169 | 0 | $self->log('RPMs build: '.join(', ', @{$self->_packages_build} )); | |||||||||||||||||||
| 170 | |||||||||||||||||||||
| 171 | 0 | ▶ | if( $self->push_packages ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 172 | 0 | $self->_execute_push_command; | |||||||||||||||||||
| 173 | } | ||||||||||||||||||||
| 174 | |||||||||||||||||||||
| 175 | 0 | return; | |||||||||||||||||||
| 176 | } | ||||||||||||||||||||
| 177 | |||||||||||||||||||||
| 178 | has '_packages_build' => ( is => 'ro', isa => 'ArrayRef[Str]', lazy => 1, | ||||||||||||||||||||
| 179 | 0 | ▶ | default => sub { [] } | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 180 | 1 | ); | |||||||||||||||||||
| 181 | |||||||||||||||||||||
| 182 | 0 | ▶ | sub _execute_rpmbuild { | ||||||||||||||||||
|
Subroutine
_execute_rpmbuild: not called CC=4 SCAR=30.0
| |||||||||||||||||||||
| 183 | 0 | my $self = shift; | |||||||||||||||||||
| 184 | 0 | my ($in, $out, $err); | |||||||||||||||||||
| 185 | 0 | my $lang = $ENV{'LANG'}; | |||||||||||||||||||
| 186 | 0 | $ENV{'LANG'} = 'C'; | |||||||||||||||||||
| 187 | 0 | $self->log('building RPM...'); | |||||||||||||||||||
| 188 | 0 | ▶ | IPC::Run::run( $self->_rpmbuild_command, \$in, \$out, \$err ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 189 | or $self->log_fatal('rpmbuild failed: '.$err); | ||||||||||||||||||||
| 190 | 0 | foreach my $line ( split(/\n/, $out ) ) { | |||||||||||||||||||
| 191 | 0 | ▶ | if( $line =~ m/^Wrote: (.*)$/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 192 | 0 | push(@{$self->_packages_build}, $1); | |||||||||||||||||||
| 193 | } | ||||||||||||||||||||
| 194 | } | ||||||||||||||||||||
| 195 | 0 | $ENV{'LANG'} = $lang; | |||||||||||||||||||
| 196 | 0 | return; | |||||||||||||||||||
| 197 | } | ||||||||||||||||||||
| 198 | |||||||||||||||||||||
| 199 | has _packages_to_push => ( | ||||||||||||||||||||
| 200 | is => 'ro', isa => 'ArrayRef[Str]', lazy => 1, | ||||||||||||||||||||
| 201 | 0 | ▶ | default => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 202 | 0 | my $self = shift; | |||||||||||||||||||
| 203 | 0 | my $regex = $self->push_ignore_packages; | |||||||||||||||||||
| 204 | 0 | return( [ grep { $_ !~ m/$regex/ } @{$self->_packages_build} ] ); | |||||||||||||||||||
| 205 | }, | ||||||||||||||||||||
| 206 | 1 | ); | |||||||||||||||||||
| 207 | |||||||||||||||||||||
| 208 | has _push_command => ( | ||||||||||||||||||||
| 209 | is => 'ro', isa => 'ArrayRef', lazy => 1, | ||||||||||||||||||||
| 210 | 0 | ▶ | default => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 211 | 0 | my $self = shift; | |||||||||||||||||||
| 212 | 0 | return( [ split(/ /, $self->push_command) ] ); | |||||||||||||||||||
| 213 | }, | ||||||||||||||||||||
| 214 | 1 | ); | |||||||||||||||||||
| 215 | |||||||||||||||||||||
| 216 | 0 | ▶ | sub _execute_push_command { | ||||||||||||||||||
|
Subroutine
_execute_push_command: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 217 | 0 | my $self = shift; | |||||||||||||||||||
| 218 | 0 | my ($in, $out, $err); | |||||||||||||||||||
| 219 | |||||||||||||||||||||
| 220 | 0 | $in = join("\n", @{$self->_packages_to_push}); | |||||||||||||||||||
| 221 | |||||||||||||||||||||
| 222 | 0 | $self->log('pushing packages: '.join(', ', @{$self->_packages_to_push})); | |||||||||||||||||||
| 223 | 0 | ▶ | IPC::Run::run( $self->_push_command, \$in, \$out, \$err ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 224 | or $self->log_fatal('push command failed: '.$err); | ||||||||||||||||||||
| 225 | |||||||||||||||||||||
| 226 | 0 | return; | |||||||||||||||||||
| 227 | } | ||||||||||||||||||||
| 228 | |||||||||||||||||||||
| 229 | 1 | ▶ | sub mk_spec { | ||||||||||||||||||
|
Subroutine
mk_spec: called CC=3 SCAR=13.3
Pod
undocumented
| |||||||||||||||||||||
| 230 | 1 | my($self,$archive) = @_; | |||||||||||||||||||
| 231 | 1 | ▶ | my $t = Text::Template->new( | ||||||||||||||||||
|
Condition33%1/3
'Text::Template'->new('TYPE', 'FILE', 'SOURCE', path($self->zilla->root)->child($self->spec_file), 'DELIMITERS', ['<%', '%>']) || $self->log_fatal($Text::Template::ERROR)
MC/DC0%0/2
'Text::Template'->new('TYPE', 'FILE', 'SOURCE', path($self->zilla->root)->child($self->spec_file), 'DELIMITERS', ['<%', '%>']) || $self->log_fatal($Text::Template::ERROR)
'Text::Template'->new('TYPE', 'FILE', 'SOURCE', path($self->zilla->root)->child($self->spec_file), 'DELIMITERS', ['<%', '%>'])
$self->log_fatal($Text::Template::ERROR)
Truth table33%1/3
A || B
A= 'Text::Template'->new('TYPE', 'FILE', 'SOURCE', path($self->zilla->root)->child($self->spec_file), 'DELIMITERS', ['<%', '%>'])B= $self->log_fatal($Text::Template::ERROR)
| |||||||||||||||||||||
| 232 | TYPE => 'FILE', | ||||||||||||||||||||
| 233 | SOURCE => path($self->zilla->root)->child($self->spec_file), | ||||||||||||||||||||
| 234 | DELIMITERS => [ '<%', '%>' ], | ||||||||||||||||||||
| 235 | ) || $self->log_fatal($Text::Template::ERROR); | ||||||||||||||||||||
| 236 | 1 | ▶ | return $t->fill_in( | ||||||||||||||||||
|
Condition33%1/3
$t->fill_in('HASH', {'zilla', \$self->zilla, 'archive', \$archive}) || $self->log_fatal($Text::Template::ERROR)
MC/DC0%0/2
$t->fill_in('HASH', {'zilla', \$self->zilla, 'archive', \$archive}) || $self->log_fatal($Text::Template::ERROR)
$t->fill_in('HASH', {'zilla', \$self->zilla, 'archive', \$archive})
$self->log_fatal($Text::Template::ERROR)
Truth table33%1/3
A || B
A= $t->fill_in('HASH', {'zilla', \$self->zilla, 'archive', \$archive})B= $self->log_fatal($Text::Template::ERROR)
| |||||||||||||||||||||
| 237 | HASH => { | ||||||||||||||||||||
| 238 | zilla => \($self->zilla), | ||||||||||||||||||||
| 239 | archive => \$archive, | ||||||||||||||||||||
| 240 | }, | ||||||||||||||||||||
| 241 | ) || $self->log_fatal($Text::Template::ERROR); | ||||||||||||||||||||
| 242 | } | ||||||||||||||||||||
| 243 | |||||||||||||||||||||
| 244 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||
| 245 | |||||||||||||||||||||
| 246 | |||||||||||||||||||||
| 247 | 1 | 1; | |||||||||||||||||||
| 248 | |||||||||||||||||||||
| 249 | __END__ | ||||||||||||||||||||