| 1 | # | ||||||||||||||||||||||||||||
| 2 | # This file is part of CPANPLUS-Dist-Mageia | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | # This software is copyright (c) 2011 by Jerome Quelin. | ||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||
| 6 | # This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 7 | # the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | package CPANPLUS::Dist::Mageia; | ||||||||||||||||||||||||||||
| 14 | # ABSTRACT: a cpanplus backend to build mageia rpms | ||||||||||||||||||||||||||||
| 15 | 1 | $CPANPLUS::Dist::Mageia::VERSION = '2.101'; | |||||||||||||||||||||||||||
| 16 | 1 | ▶ | use base 'CPANPLUS::Dist::Base'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use CPANPLUS::Error; # imported subs: error(), msg() | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use File::Basename qw{ basename dirname }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use File::Copy qw{ copy }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use File::ShareDir qw{ dist_dir }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 1 | ▶ | use File::Slurp qw{ slurp }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 1 | ▶ | use IPC::Cmd qw{ run can_run }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 1 | ▶ | use List::Util qw{ first }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 1 | ▶ | use List::MoreUtils qw{ uniq }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 1 | ▶ | use Pod::POM; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 1 | ▶ | use Pod::POM::View::Text; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 1 | ▶ | use POSIX (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 1 | ▶ | use Readonly; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | 1 | ▶ | use Text::Wrap; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 1 | my @RPMSUBDIRS = qw{ build rpm source spec srcrpm }; | |||||||||||||||||||||||||||
| 34 | 1 | my %RPMDIR = map {do { chomp(my $d=qx[ rpm --eval %_${_}dir ]); $_, $d; }} @RPMSUBDIRS ; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | # -- class methods | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | sub format_available { | ||||||||||||||||||||||||||||
| 40 | # check mageia release file | ||||||||||||||||||||||||||||
| 41 | 0 | ▶ | if ( ! -f '/etc/mageia-release' ) { | ||||||||||||||||||||||||||
|
Subroutine
format_available: not called CC=6 SCAR=37.4
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 0 | error( 'not on a mageia system' ); | |||||||||||||||||||||||||||
| 43 | 0 | return; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | my $flag; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | # check rpm tree structure | ||||||||||||||||||||||||||||
| 49 | 0 | foreach my $subdir ( keys %RPMDIR ) { | |||||||||||||||||||||||||||
| 50 | 0 | my $dir = "$RPMDIR{$subdir}"; | |||||||||||||||||||||||||||
| 51 | 0 | ▶ | next if -d $dir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 0 | error( "missing directory '$dir'" ); | |||||||||||||||||||||||||||
| 53 | 0 | $flag++; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | # check prereqs | ||||||||||||||||||||||||||||
| 57 | 0 | for my $prog ( qw[ rpm rpmbuild gcc ] ) { | |||||||||||||||||||||||||||
| 58 | 0 | ▶ | next if can_run($prog); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 0 | error( "'$prog' is a required program to build mageia packages" ); | |||||||||||||||||||||||||||
| 60 | 0 | $flag++; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | return not $flag; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | # -- public methods | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | sub init { | ||||||||||||||||||||||||||||
| 71 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
init: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 72 | 0 | my $status = $self->status; # an Object::Accessor | |||||||||||||||||||||||||||
| 73 | # distname: Foo-Bar | ||||||||||||||||||||||||||||
| 74 | # distvers: 1.23 | ||||||||||||||||||||||||||||
| 75 | # extra_files: qw[ /bin/foo /usr/bin/bar ] | ||||||||||||||||||||||||||||
| 76 | # rpmname: perl-Foo-Bar | ||||||||||||||||||||||||||||
| 77 | # rpmpath: $RPMDIR/RPMS/noarch/perl-Foo-Bar-1.23-1mga2008.0.noarch.rpm | ||||||||||||||||||||||||||||
| 78 | # rpmvers: 1 | ||||||||||||||||||||||||||||
| 79 | # srpmpath: $RPMDIR/SRPMS/perl-Foo-Bar-1.23-1mga2008.0.src.rpm | ||||||||||||||||||||||||||||
| 80 | # specpath: $RPMDIR/SPECS/perl-Foo-Bar.spec | ||||||||||||||||||||||||||||
| 81 | 0 | $status->mk_accessors(qw[ distname distvers extra_files rpmname rpmpath | |||||||||||||||||||||||||||
| 82 | rpmvers srpmpath specpath ]); | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | return 1; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | sub prepare { | ||||||||||||||||||||||||||||
| 90 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
prepare: not called CC=14 SCAR=53.5
Pod
documented
| |||||||||||||||||||||||||||||
| 91 | 0 | my $status = $self->status; # private hash | |||||||||||||||||||||||||||
| 92 | 0 | my $module = $self->parent; # CPANPLUS::Module | |||||||||||||||||||||||||||
| 93 | 0 | my $intern = $module->parent; # CPANPLUS::Internals | |||||||||||||||||||||||||||
| 94 | 0 | my $conf = $intern->configure_object; # CPANPLUS::Configure | |||||||||||||||||||||||||||
| 95 | 0 | my $distmm = $module->status->dist_cpan; # CPANPLUS::Dist::MM | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | # parse args. | ||||||||||||||||||||||||||||
| 98 | 0 | my %opts = ( | |||||||||||||||||||||||||||
| 99 | force => $conf->get_conf('force'), # force rebuild | ||||||||||||||||||||||||||||
| 100 | perl => $^X, | ||||||||||||||||||||||||||||
| 101 | verbose => $conf->get_conf('verbose'), | ||||||||||||||||||||||||||||
| 102 | %args, | ||||||||||||||||||||||||||||
| 103 | ); | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | # dry-run with makemaker: find build prereqs. | ||||||||||||||||||||||||||||
| 106 | 0 | msg( "dry-run prepare with makemaker..." ); | |||||||||||||||||||||||||||
| 107 | 0 | $self->SUPER::prepare( %args ); | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | # compute & store package information | ||||||||||||||||||||||||||||
| 110 | 0 | my $distname = $module->package_name; | |||||||||||||||||||||||||||
| 111 | 0 | $status->distname( $distname ); | |||||||||||||||||||||||||||
| 112 | 0 | my $distvers = $module->package_version; | |||||||||||||||||||||||||||
| 113 | 0 | my $distext = $module->package_extension; | |||||||||||||||||||||||||||
| 114 | 0 | my $distsummary = _module_summary($module); | |||||||||||||||||||||||||||
| 115 | 0 | my $distdescr = _module_description($module); | |||||||||||||||||||||||||||
| 116 | #my $distlicense = | ||||||||||||||||||||||||||||
| 117 | 0 | my ($disttoplevel) = $module->name=~ /([^:]+)::/; | |||||||||||||||||||||||||||
| 118 | 0 | my @reqs = sort keys %{ $module->status->prereqs }; | |||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 0 | my ($distbuild, $distmaker, $distinstall); | |||||||||||||||||||||||||||
| 121 | 0 | ▶ | if (-e _path_to_makefile_pl($module)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | 0 | ▶ | push @reqs, 'Module::Build::Compat' if _is_module_build_compat($module); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 0 | $distbuild = "%{__perl} Makefile.PL INSTALLDIRS=vendor\n"; | |||||||||||||||||||||||||||
| 124 | 0 | $distmaker = "%make"; | |||||||||||||||||||||||||||
| 125 | 0 | $distinstall = "%makeinstall_std"; | |||||||||||||||||||||||||||
| 126 | } else { | ||||||||||||||||||||||||||||
| 127 | # module::build only distribution | ||||||||||||||||||||||||||||
| 128 | 0 | push @reqs, 'Module::Build'; | |||||||||||||||||||||||||||
| 129 | 0 | $distbuild = "%{__perl} Build.PL --installdirs=vendor\n"; | |||||||||||||||||||||||||||
| 130 | 0 | $distmaker = "./Build"; | |||||||||||||||||||||||||||
| 131 | 0 | $distinstall = "./Build install --destdir=%{buildroot}"; | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | 0 | my $distbreqs = join "\n", map { "BuildRequires: perl($_)" } | |||||||||||||||||||||||||||
| 134 | 0 | grep { $_ ne "perl" } @reqs; | |||||||||||||||||||||||||||
| 135 | my @docfiles = | ||||||||||||||||||||||||||||
| 136 | uniq | ||||||||||||||||||||||||||||
| 137 | grep { | ||||||||||||||||||||||||||||
| 138 | 0 | ▶ | ( /^[A-Z.]+$/ && !/^MANIFEST/ ) || | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
/^[A-Z.]+$/ and not /^MANIFEST/
MC/DC0%0/2
/^[A-Z.]+$/ and not /^MANIFEST/
/^[A-Z.]+$/
not /^MANIFEST/
Truth table0%0/3
A and not(B)
A= /^[A-Z.]+$/B= not /^MANIFEST/
| |||||||||||||||||||||||||||||
| 139 | m{^(Change(s|log)|META.(json|yml)|(ex|s)amples?|e[gx]|demos?)$}i | ||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | 0 | map { basename $_ } | |||||||||||||||||||||||||||
| 142 | 0 | grep { m!^[^/]+/[^/]+$! } # only interested in root files | |||||||||||||||||||||||||||
| 143 | 0 | @{ $module->status->files }; | |||||||||||||||||||||||||||
| 144 | my $distarch = | ||||||||||||||||||||||||||||
| 145 | 0 | ▶ | defined( first { /\.(c|xs)$/i } @{ $module->status->files } ) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | ? 'BuildRequires: perl-devel' | ||||||||||||||||||||||||||||
| 147 | : 'BuildArch: noarch'; | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 0 | my $rpmname = _mk_pkg_name($distname); | |||||||||||||||||||||||||||
| 150 | 0 | $status->rpmname( $rpmname ); | |||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | # check whether package has been build. | ||||||||||||||||||||||||||||
| 154 | 0 | ▶ | if ( my $pkg = $self->_has_been_build($rpmname, $distvers) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | 0 | my $modname = $module->module; | |||||||||||||||||||||||||||
| 156 | 0 | msg( "already created package for '$modname' at '$pkg'" ); | |||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 0 | ▶ | if ( not $opts{force} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | 0 | msg( "won't re-spec package since --force isn't in use" ); | |||||||||||||||||||||||||||
| 160 | # c::d::mga store | ||||||||||||||||||||||||||||
| 161 | 0 | $status->rpmpath($pkg); # store the path of rpm | |||||||||||||||||||||||||||
| 162 | # cpanplus api | ||||||||||||||||||||||||||||
| 163 | 0 | $status->prepared(1); | |||||||||||||||||||||||||||
| 164 | 0 | $status->created(1); | |||||||||||||||||||||||||||
| 165 | 0 | $status->dist($pkg); | |||||||||||||||||||||||||||
| 166 | 0 | return $pkg; | |||||||||||||||||||||||||||
| 167 | # XXX check if it works | ||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 0 | msg( '--force in use, re-specing anyway' ); | |||||||||||||||||||||||||||
| 171 | # FIXME: bump rpm version | ||||||||||||||||||||||||||||
| 172 | } else { | ||||||||||||||||||||||||||||
| 173 | 0 | msg( "writing specfile for '$distname'..." ); | |||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | # compute & store path of specfile. | ||||||||||||||||||||||||||||
| 177 | 0 | my $spec = "$RPMDIR{spec}/$rpmname.spec"; | |||||||||||||||||||||||||||
| 178 | 0 | $status->specpath($spec); | |||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 0 | my $vers = $module->version; | |||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | # writing the spec file. | ||||||||||||||||||||||||||||
| 183 | 0 | my $tmpl = _template_spec_file_path(); | |||||||||||||||||||||||||||
| 184 | 0 | ▶ | open my $tmplfh, '<', $tmpl or die "can't open '$tmpl': $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 0 | POSIX::setlocale(&POSIX::LC_ALL, 'C'); | |||||||||||||||||||||||||||
| 187 | 0 | my $specfh; | |||||||||||||||||||||||||||
| 188 | 0 | ▶ | if ( not open $specfh, '>', $spec ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 189 | 0 | error( "can't open '$spec': $!" ); | |||||||||||||||||||||||||||
| 190 | 0 | return; | |||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | 0 | ▶ | while ( defined( my $line = <$tmplfh> ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 193 | 0 | ▶ | last if $line =~ /^__END__$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | 0 | $line =~ s/DISTNAME/$distname/; | |||||||||||||||||||||||||||
| 196 | 0 | $line =~ s/DISTVERS/$distvers/g; | |||||||||||||||||||||||||||
| 197 | 0 | $line =~ s/DISTSUMMARY/$distsummary/; | |||||||||||||||||||||||||||
| 198 | 0 | $line =~ s/DISTEXTENSION/$distext/; | |||||||||||||||||||||||||||
| 199 | 0 | $line =~ s/DISTBUILDBUILDER/$distbuild/; | |||||||||||||||||||||||||||
| 200 | 0 | $line =~ s/DISTINSTALL/$distinstall/; | |||||||||||||||||||||||||||
| 201 | 0 | $line =~ s/DISTARCH/$distarch/; | |||||||||||||||||||||||||||
| 202 | 0 | $line =~ s/DISTMAKER/$distmaker/; | |||||||||||||||||||||||||||
| 203 | 0 | $line =~ s/DISTBUILDREQUIRES/$distbreqs/; | |||||||||||||||||||||||||||
| 204 | 0 | $line =~ s/DISTDESCR/$distdescr/; | |||||||||||||||||||||||||||
| 205 | 0 | ▶ | $line =~ s/DISTDOC/@docfiles ? "%doc @docfiles" : ''/e; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 206 | 0 | $line =~ s/DISTTOPLEVEL/$disttoplevel/; | |||||||||||||||||||||||||||
| 207 | 0 | ▶ | $line =~ s/DISTEXTRA/join( "\n", @{ $status->extra_files || [] })/e; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 208 | 0 | $line =~ s/DISTDATE/POSIX::strftime("%a %b %d %Y", localtime())/e; | |||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 0 | print $specfh $line; | |||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | 0 | close $specfh; | |||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | # copy package. | ||||||||||||||||||||||||||||
| 215 | 0 | my $basename = basename $module->status->fetch; | |||||||||||||||||||||||||||
| 216 | 0 | my $tarball = "$RPMDIR{source}/$basename"; | |||||||||||||||||||||||||||
| 217 | 0 | copy( $module->status->fetch, $tarball ); | |||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | 0 | msg( "specfile for '$distname' written" ); | |||||||||||||||||||||||||||
| 220 | # return success | ||||||||||||||||||||||||||||
| 221 | 0 | $status->prepared(1); | |||||||||||||||||||||||||||
| 222 | 0 | return 1; | |||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | sub create { | ||||||||||||||||||||||||||||
| 228 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
create: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 229 | 0 | my $status = $self->status; # private hash | |||||||||||||||||||||||||||
| 230 | 0 | my $module = $self->parent; # CPANPLUS::Module | |||||||||||||||||||||||||||
| 231 | 0 | my $intern = $module->parent; # CPANPLUS::Internals | |||||||||||||||||||||||||||
| 232 | 0 | my $conf = $intern->configure_object; # CPANPLUS::Configure | |||||||||||||||||||||||||||
| 233 | 0 | my $distmm = $module->status->dist_cpan; # CPANPLUS::Dist::MM | |||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | # parse args. | ||||||||||||||||||||||||||||
| 236 | 0 | my %opts = ( | |||||||||||||||||||||||||||
| 237 | force => $conf->get_conf('force'), # force rebuild | ||||||||||||||||||||||||||||
| 238 | perl => $^X, | ||||||||||||||||||||||||||||
| 239 | verbose => $conf->get_conf('verbose'), | ||||||||||||||||||||||||||||
| 240 | %args, | ||||||||||||||||||||||||||||
| 241 | ); | ||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | # check if we need to rebuild package. | ||||||||||||||||||||||||||||
| 244 | 0 | ▶ | if ( $status->created && defined $status->dist ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$status->created and defined $status->dist
MC/DC0%0/2
$status->created and defined $status->dist
$status->created
defined $status->dist
Truth table0%0/3
A and B
A= $status->createdB= defined $status->dist
| |||||||||||||||||||||||||||||
| 245 | 0 | ▶ | if ( not $opts{force} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 246 | 0 | msg( "won't re-build package since --force isn't in use" ); | |||||||||||||||||||||||||||
| 247 | 0 | return $status->dist; | |||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||
| 249 | 0 | msg( '--force in use, re-building anyway' ); | |||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | RPMBUILD: { | ||||||||||||||||||||||||||||
| 253 | # dry-run with makemaker: handle prereqs. | ||||||||||||||||||||||||||||
| 254 | 0 | msg( 'dry-run build with makemaker...' ); | |||||||||||||||||||||||||||
| 255 | 0 | $self->SUPER::create( %args ); | |||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | 0 | my $spec = $status->specpath; | |||||||||||||||||||||||||||
| 259 | 0 | my $distname = $status->distname; | |||||||||||||||||||||||||||
| 260 | 0 | my $rpmname = $status->rpmname; | |||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | 0 | msg( "building '$distname' from specfile..." ); | |||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | # dry-run, to see if we forgot some files | ||||||||||||||||||||||||||||
| 265 | 0 | my ($buffer, $success); | |||||||||||||||||||||||||||
| 266 | DRYRUN: { | ||||||||||||||||||||||||||||
| 267 | 0 | local $ENV{LC_ALL} = 'C'; | |||||||||||||||||||||||||||
| 268 | $success = run( | ||||||||||||||||||||||||||||
| 269 | command => "rpmbuild -ba --quiet $spec", | ||||||||||||||||||||||||||||
| 270 | verbose => $opts{verbose}, | ||||||||||||||||||||||||||||
| 271 | 0 | buffer => \$buffer, | |||||||||||||||||||||||||||
| 272 | ); | ||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||
| 275 | # check if the dry-run finished correctly | ||||||||||||||||||||||||||||
| 276 | 0 | ▶ | if ( $success ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 277 | 0 | my ($rpm) = (sort glob "$RPMDIR{rpm}/*/$rpmname-*.rpm")[0]; | |||||||||||||||||||||||||||
| 278 | 0 | my ($srpm) = (sort glob "$RPMDIR{srcrpm}/$rpmname-*.src.rpm")[-1]; | |||||||||||||||||||||||||||
| 279 | 0 | msg( "rpm created successfully: $rpm" ); | |||||||||||||||||||||||||||
| 280 | 0 | msg( "srpm available: $srpm" ); | |||||||||||||||||||||||||||
| 281 | # c::d::mga store | ||||||||||||||||||||||||||||
| 282 | 0 | $status->rpmpath($rpm); | |||||||||||||||||||||||||||
| 283 | 0 | $status->srpmpath($srpm); | |||||||||||||||||||||||||||
| 284 | # cpanplus api | ||||||||||||||||||||||||||||
| 285 | 0 | $status->created(1); | |||||||||||||||||||||||||||
| 286 | 0 | $status->dist($rpm); | |||||||||||||||||||||||||||
| 287 | 0 | return $rpm; | |||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | # unknown error, aborting. | ||||||||||||||||||||||||||||
| 291 | 0 | ▶ | if ( not $buffer =~ /^\s+Installed .but unpackaged. file.s. found:\n(.*)\z/ms ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 292 | 0 | error( "failed to create mageia package for '$distname': $buffer" ); | |||||||||||||||||||||||||||
| 293 | # cpanplus api | ||||||||||||||||||||||||||||
| 294 | 0 | $status->created(0); | |||||||||||||||||||||||||||
| 295 | 0 | return; | |||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | # additional files to be packaged | ||||||||||||||||||||||||||||
| 299 | 0 | msg( "extra files installed, fixing spec file" ); | |||||||||||||||||||||||||||
| 300 | 0 | my $files = $1; | |||||||||||||||||||||||||||
| 301 | 0 | $files =~ s/^\s+//mg; # remove spaces | |||||||||||||||||||||||||||
| 302 | 0 | my @files = split /\n/, $files; | |||||||||||||||||||||||||||
| 303 | 0 | $status->extra_files( \@files ); | |||||||||||||||||||||||||||
| 304 | 0 | $self->prepare( %opts, force => 0 ); | |||||||||||||||||||||||||||
| 305 | 0 | msg( 'restarting build phase' ); | |||||||||||||||||||||||||||
| 306 | 0 | redo RPMBUILD; | |||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | sub install { | ||||||||||||||||||||||||||||
| 313 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
install: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 314 | 0 | my $status = $self->status; # private hash | |||||||||||||||||||||||||||
| 315 | 0 | my $module = $self->parent; # CPANPLUS::Module | |||||||||||||||||||||||||||
| 316 | 0 | my $intern = $module->parent; # CPANPLUS::Internals | |||||||||||||||||||||||||||
| 317 | 0 | my $conf = $intern->configure_object; # CPANPLUS::Configure | |||||||||||||||||||||||||||
| 318 | 0 | my $distmm = $module->status->dist_cpan; # CPANPLUS::Dist::MM | |||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | # parse args. | ||||||||||||||||||||||||||||
| 321 | 0 | my %opts = ( | |||||||||||||||||||||||||||
| 322 | verbose => $conf->get_conf('verbose'), | ||||||||||||||||||||||||||||
| 323 | %args, | ||||||||||||||||||||||||||||
| 324 | ); | ||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | 0 | my $rpm = $self->status->rpmpath; | |||||||||||||||||||||||||||
| 328 | 0 | msg( "installing $rpm" ); | |||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||
| 330 | # install the rpm | ||||||||||||||||||||||||||||
| 331 | # sudo is used, which means sudoers should be properly configured. | ||||||||||||||||||||||||||||
| 332 | 0 | my ($buffer, $success); | |||||||||||||||||||||||||||
| 333 | INSTALL: { | ||||||||||||||||||||||||||||
| 334 | 0 | local $ENV{LC_ALL} = 'C'; | |||||||||||||||||||||||||||
| 335 | 0 | ▶ | my $sudo = $> == 0 ? '' : 'sudo'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 336 | $success = run( | ||||||||||||||||||||||||||||
| 337 | command => "$sudo rpm -Uv $rpm", | ||||||||||||||||||||||||||||
| 338 | verbose => $opts{verbose}, | ||||||||||||||||||||||||||||
| 339 | 0 | buffer => \$buffer, | |||||||||||||||||||||||||||
| 340 | ); | ||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||
| 343 | # check if the install finished correctly | ||||||||||||||||||||||||||||
| 344 | 0 | ▶ | if ( $success ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 345 | 0 | msg("successfully installed $rpm"); | |||||||||||||||||||||||||||
| 346 | 0 | $status->installed(1); | |||||||||||||||||||||||||||
| 347 | } else { | ||||||||||||||||||||||||||||
| 348 | 0 | error("error while installing $rpm"); | |||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||
| 353 | # -- private methods | ||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||
| 355 | # | ||||||||||||||||||||||||||||
| 356 | # my $bool = $self->_has_been_build; | ||||||||||||||||||||||||||||
| 357 | # | ||||||||||||||||||||||||||||
| 358 | # return true if there's already a package build for this module. | ||||||||||||||||||||||||||||
| 359 | # | ||||||||||||||||||||||||||||
| 360 | sub _has_been_build { | ||||||||||||||||||||||||||||
| 361 | 0 | ▶ | my ($self, $name, $vers) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_has_been_build: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 362 | 0 | my $pkg = ( sort glob "$RPMDIR{rpm}/*/$name-$vers-*.rpm" )[-1]; | |||||||||||||||||||||||||||
| 363 | 0 | return $pkg; | |||||||||||||||||||||||||||
| 364 | # FIXME: should we check cooker? | ||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||
| 368 | # -- private subs | ||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||
| 370 | # | ||||||||||||||||||||||||||||
| 371 | # my $path = _path_to_makefile_pl(); | ||||||||||||||||||||||||||||
| 372 | # | ||||||||||||||||||||||||||||
| 373 | # return the path to the extracted makefile.pl | ||||||||||||||||||||||||||||
| 374 | # | ||||||||||||||||||||||||||||
| 375 | sub _path_to_makefile_pl { | ||||||||||||||||||||||||||||
| 376 | 0 | ▶ | my $module = shift; | ||||||||||||||||||||||||||
|
Subroutine
_path_to_makefile_pl: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 377 | 0 | return $module->_status->extract . '/Makefile.PL'; | |||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||
| 381 | # | ||||||||||||||||||||||||||||
| 382 | # my $bool = _is_module_build_compat(); | ||||||||||||||||||||||||||||
| 383 | # | ||||||||||||||||||||||||||||
| 384 | # return true if shipped makefile.pl is auto-generated with | ||||||||||||||||||||||||||||
| 385 | # module::build::compat usage. | ||||||||||||||||||||||||||||
| 386 | # | ||||||||||||||||||||||||||||
| 387 | sub _is_module_build_compat { | ||||||||||||||||||||||||||||
| 388 | 0 | ▶ | my ($module) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_is_module_build_compat: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 389 | 0 | my $makefile = _path_to_makefile_pl($module); | |||||||||||||||||||||||||||
| 390 | 0 | my $content = slurp($makefile); | |||||||||||||||||||||||||||
| 391 | 0 | return $content =~ /Module::Build::Compat/; | |||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||
| 395 | # | ||||||||||||||||||||||||||||
| 396 | # my $path = _template_spec_file_path(); | ||||||||||||||||||||||||||||
| 397 | # | ||||||||||||||||||||||||||||
| 398 | # return the absolute path where the template spec will be located. | ||||||||||||||||||||||||||||
| 399 | # | ||||||||||||||||||||||||||||
| 400 | sub _template_spec_file_path { | ||||||||||||||||||||||||||||
| 401 | 0 | ▶ | my $path = dist_dir('CPANPLUS-Dist-Mageia'); | ||||||||||||||||||||||||||
|
Subroutine
_template_spec_file_path: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 402 | 0 | return "$path/template.spec"; | |||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||
| 406 | # | ||||||||||||||||||||||||||||
| 407 | # my $name = _mk_pkg_name($dist); | ||||||||||||||||||||||||||||
| 408 | # | ||||||||||||||||||||||||||||
| 409 | # given a distribution name, return the name of the mageia rpm | ||||||||||||||||||||||||||||
| 410 | # package. in most cases, it will be the same, but some pakcage name | ||||||||||||||||||||||||||||
| 411 | # will be too long as a rpm name: we'll have to cut it. | ||||||||||||||||||||||||||||
| 412 | # | ||||||||||||||||||||||||||||
| 413 | sub _mk_pkg_name { | ||||||||||||||||||||||||||||
| 414 | 0 | ▶ | my ($dist) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_mk_pkg_name: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 415 | 0 | my $name = 'perl-' . $dist; | |||||||||||||||||||||||||||
| 416 | 0 | return $name; | |||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||
| 421 | # | ||||||||||||||||||||||||||||
| 422 | # my $description = _module_description($module); | ||||||||||||||||||||||||||||
| 423 | # | ||||||||||||||||||||||||||||
| 424 | # given a cpanplus::module, try to extract its description from the | ||||||||||||||||||||||||||||
| 425 | # embedded pod in the extracted files. this would be the first paragraph | ||||||||||||||||||||||||||||
| 426 | # of the DESCRIPTION head1. | ||||||||||||||||||||||||||||
| 427 | # | ||||||||||||||||||||||||||||
| 428 | sub _module_description { | ||||||||||||||||||||||||||||
| 429 | 0 | ▶ | my ($module) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_module_description: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||
| 431 | 0 | my $path = dirname $module->_status->extract; # where tarball has been extracted | |||||||||||||||||||||||||||
| 432 | my @docfiles = | ||||||||||||||||||||||||||||
| 433 | 0 | map { "$path/$_" } # prepend extract directory | |||||||||||||||||||||||||||
| 434 | 0 | sort { length $a <=> length $b } # sort by length: we prefer top-level module description | |||||||||||||||||||||||||||
| 435 | 0 | grep { /\.(pod|pm)$/ } # filter out those that can contain pod | |||||||||||||||||||||||||||
| 436 | 0 | @{ $module->_status->files }; # list of embedded files | |||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||
| 438 | # parse file, trying to find a header | ||||||||||||||||||||||||||||
| 439 | 0 | my $parser = Pod::POM->new; | |||||||||||||||||||||||||||
| 440 | DOCFILE: | ||||||||||||||||||||||||||||
| 441 | 0 | foreach my $docfile ( @docfiles ) { | |||||||||||||||||||||||||||
| 442 | 0 | my $pom = $parser->parse_file($docfile); # try to find some pod | |||||||||||||||||||||||||||
| 443 | 0 | ▶ | next DOCFILE unless defined $pom; # the file may contain no pod, that's ok | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 444 | HEAD1: | ||||||||||||||||||||||||||||
| 445 | 0 | foreach my $head1 ($pom->head1) { | |||||||||||||||||||||||||||
| 446 | 0 | ▶ | next HEAD1 unless $head1->title eq 'DESCRIPTION'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 447 | 0 | my $pom = $head1->content; # get pod for DESCRIPTION paragraph | |||||||||||||||||||||||||||
| 448 | 0 | my $text = $pom->present('Pod::POM::View::Text'); # transform pod to text | |||||||||||||||||||||||||||
| 449 | 0 | my @paragraphs = split /\n\n/, $text; # split into paragraphs | |||||||||||||||||||||||||||
| 450 | 0 | ▶ | splice @paragraphs, 3 if @paragraphs > 3; # only the 3 first paragraphs | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 451 | 0 | return join "\n\n", @paragraphs; | |||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||
| 455 | 0 | return ''; | |||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||
| 459 | # | ||||||||||||||||||||||||||||
| 460 | # my $summary = _module_summary($module); | ||||||||||||||||||||||||||||
| 461 | # | ||||||||||||||||||||||||||||
| 462 | # given a cpanplus::module, return its registered description (if any) | ||||||||||||||||||||||||||||
| 463 | # or try to extract it from the embedded pod in the extracted files. | ||||||||||||||||||||||||||||
| 464 | # | ||||||||||||||||||||||||||||
| 465 | sub _module_summary { | ||||||||||||||||||||||||||||
| 466 | 0 | ▶ | my ($module) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_module_summary: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||
| 468 | # registered modules won't go farther... | ||||||||||||||||||||||||||||
| 469 | 0 | my $summary = $module->description; | |||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||
| 471 | 0 | ▶ | if (!$summary) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 472 | 0 | my $path = dirname $module->_status->extract; # where tarball has been extracted | |||||||||||||||||||||||||||
| 473 | my @docfiles = | ||||||||||||||||||||||||||||
| 474 | 0 | map { "$path/$_" } # prepend extract directory | |||||||||||||||||||||||||||
| 475 | 0 | sort { length $a <=> length $b } # sort by length: we prefer top-level module summary | |||||||||||||||||||||||||||
| 476 | 0 | grep { /\.(pod|pm)$/ } # filter out those that can contain pod | |||||||||||||||||||||||||||
| 477 | 0 | @{ $module->_status->files }; # list of files embedded | |||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||
| 479 | # parse file, trying to find a header | ||||||||||||||||||||||||||||
| 480 | 0 | my $parser = Pod::POM->new; | |||||||||||||||||||||||||||
| 481 | DOCFILE: | ||||||||||||||||||||||||||||
| 482 | 0 | foreach my $docfile ( @docfiles ) { | |||||||||||||||||||||||||||
| 483 | 0 | my $pom = $parser->parse_file($docfile); # try to find some pod | |||||||||||||||||||||||||||
| 484 | 0 | ▶ | next unless defined $pom; # the file may contain no pod, that's ok | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 485 | HEAD1: | ||||||||||||||||||||||||||||
| 486 | 0 | foreach my $head1 ($pom->head1) { | |||||||||||||||||||||||||||
| 487 | # continue till we find '=head1 NAME' | ||||||||||||||||||||||||||||
| 488 | 0 | my $title = $head1->title; | |||||||||||||||||||||||||||
| 489 | 0 | ▶ | next HEAD1 unless $title eq 'NAME'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 490 | # extract the description in NAME section | ||||||||||||||||||||||||||||
| 491 | 0 | my $content = $head1->content; | |||||||||||||||||||||||||||
| 492 | 0 | ▶ | next DOCFILE unless $content =~ /^[^-]+ - (.*)$/m; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 493 | 0 | ▶ | $summary = $1 if $content; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||
| 498 | 0 | ▶ | if (!$summary) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 499 | 0 | $summary = 'no summary found'; | |||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||
| 502 | # summary must begin with an uppercase, without any final dot | ||||||||||||||||||||||||||||
| 503 | # (this is a rpmlint policy) | ||||||||||||||||||||||||||||
| 504 | 0 | $summary =~ s/^(.)/\u$1/; | |||||||||||||||||||||||||||
| 505 | 0 | $summary =~ s/\.$//; | |||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||
| 507 | 0 | return $summary; | |||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||
| 510 | 1 | 1; | |||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||
| 512 | __END__ | ||||||||||||||||||||||||||||