blib/lib/auto/share/dist/Alien-Alien/lib/perl5/Alien/Package/Rpm.pm

filter: Statementstmt 2.6% 7 / 262 Branchbran 0.0% 0 / 156 Conditioncond 0.0% 0 / 50 MC/DCmcdc 0.0% 0 / 30 Subroutinesub 12.5% 2 / 16 Podpod 100% 13 / 13 totaltotal 4.1% 22 / 527 CC 103 SCAR 61.3
CC
103
Cov
1%
unpack
1056.0
arch
462.0
scan
306.0
CRAP 458.2
↑ Summary blib/lib/auto/share/dist/Alien-Alien/lib/perl5/Alien/Package/Pkg.pm »
1 #!/usr/bin/perl -w
2  
3 =head1 NAME
4  
5 Alien::Package::Rpm - an object that represents a rpm package
6  
7 =cut
8  
9 package Alien::Package::Rpm;
10 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use base qw(Alien::Package);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 =head1 DESCRIPTION
14  
15 This is an object class that represents a rpm package. It is derived from
16 Alien::Package.
17  
18 =head1 FIELDS
19  
20 =over 4
21  
22 =item prefixes
23  
24 Relocatable rpm packages have a prefixes field.
25  
26 =back
27  
28 =head1 METHODS
29  
30 =over 4
31  
32 =item checkfile
33  
34 Detect rpm files by their extension.
35  
36 =cut
37  
38 0 ▶sub checkfile {
Subroutine checkfile: not called CC=1 SCAR=6.9
Pod documented
39 0 my $this=shift;
40 0 my $file=shift;
41  
42 0 return $file =~ m/.*\.rpm$/;
43 }
44  
45 =item install
46  
47 Install a rpm. If RPMINSTALLOPT is set in the environment, the options in
48 it are passed to rpm on its command line.
49  
50 =cut
51  
52 0 ▶sub install {
Subroutine install: not called CC=3 SCAR=24.8
Pod documented
53 0 my $this=shift;
54 0 my $rpm=shift;
55  
56 0 my $v=$Alien::Package::verbose;
57 0 $Alien::Package::verbose=2;
58 0 ▶ $this->do("rpm -ivh ".(exists $ENV{RPMINSTALLOPT} ? $ENV{RPMINSTALLOPT} : '').$rpm)
Branch: 2 branches
BranchTrueFalseTotal
$this->do('rpm -ivh ' . (exists $ENV{"RPMINSTALLOPT"} ? $ENV{"RPMINSTALLOPT"} : "") . $rpm) or die "Unable to install" 0 0 0
exists $ENV{'RPMINSTALLOPT'} ? : 0 0 0
59 or die "Unable to install";
60 0 $Alien::Package::verbose=$v;
61 }
62  
63 =item scan
64  
65 Implement the scan method to read a rpm file.
66  
67 =cut
68  
69 0 ▶sub scan {
Subroutine scan: not called CC=17 SCAR=57.2
Pod documented
70 0 my $this=shift;
71 0 $this->SUPER::scan(@_);
72 0 my $file=$this->filename;
73  
74 0 my %fieldtrans=(
75 PREIN => 'preinst',
76 POSTIN => 'postinst',
77 PREUN => 'prerm',
78 POSTUN => 'postrm',
79 LICENSE => 'copyright',
80 );
81  
82 # Use --queryformat to pull out all the fields we need.
83 0 foreach my $field (qw{NAME VERSION RELEASE ARCH CHANGELOGTEXT
84 SUMMARY DESCRIPTION PREFIXES},
85 keys(%fieldtrans)) {
86 0 my $value=$this->runpipe(0, "LANG=C rpm -qp --queryformat \%{$field} '$file'");
87 0 ▶ next if $? || $value eq '(none)';
Branch: 1 branch
BranchTrueFalseTotal
if $? or $value eq "(none)" 0 0 0
Condition0%0/3
$? or $value eq "(none)"
l!l&&r!l&&!r
000
MC/DC0%0/2
$? or $value eq "(none)"
$? $value eq "(none)"
Truth table0%0/3
A or B
A= $?B= $value eq "(none)"
ABresult
1X1
011
000
88 0 my $key;
89 0 ▶ if (exists $fieldtrans{$field}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $fieldtrans{$field}) { } 0 0 0
90 0 $key=$fieldtrans{$field};
91 }
92 else {
93 0 $key=lc($field);
94 }
95 0 $this->$key($value);
96 }
97  
98 # Get the conffiles list.
99 0 $this->conffiles([map { chomp; $_ } $this->runpipe(0, "LANG=C rpm -qcp '$file'")]);
100 0 ▶ if (defined $this->conffiles->[0] &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $this->conffiles->[0] and $this->conffiles->[0] eq "(contains no files)") 0 0 0
Condition0%0/3
defined $this->conffiles->[0] and $this->conffiles->[0] eq "(contains no files)"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $this->conffiles->[0] and $this->conffiles->[0] eq "(contains no files)"
defined $this->conffiles->[0] $this->conffiles->[0] eq "(contains no files)"
Truth table0%0/3
A and B
A= defined $this->conffiles->[0]B= $this->conffiles->[0] eq "(contains no files)"
ABresult
0X0
100
111
101 $this->conffiles->[0] eq '(contains no files)') {
102 0 $this->conffiles([]);
103 }
104  
105 0 $this->binary_info(scalar $this->runpipe(0, "rpm -qpi '$file'"));
106  
107 # Get the filelist.
108 0 $this->filelist([map { chomp; $_ } $this->runpipe(0, "LANG=C rpm -qpl '$file'")]);
109 0 ▶ if (defined $this->filelist->[0] &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $this->filelist->[0] and $this->filelist->[0] eq "(contains no files)") 0 0 0
Condition0%0/3
defined $this->filelist->[0] and $this->filelist->[0] eq "(contains no files)"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $this->filelist->[0] and $this->filelist->[0] eq "(contains no files)"
defined $this->filelist->[0] $this->filelist->[0] eq "(contains no files)"
Truth table0%0/3
A and B
A= defined $this->filelist->[0]B= $this->filelist->[0] eq "(contains no files)"
ABresult
0X0
100
111
110 $this->filelist->[0] eq '(contains no files)') {
111 0 $this->filelist([]);
112 }
113  
114 # Sanity check and sanitize fields.
115 0 ▶ unless (defined $this->summary) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $this->summary) 0 0 0
116 # Older rpms will have no summary, but will have a
117 # description. We'll take the 1st line out of the
118 # description, and use it for the summary.
119 0 $this->summary($this->description."\n")=~m/(.*?)\n/m;
120  
121 # Fallback.
122 0 ▶ if (! $this->summary) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($this->summary) 0 0 0
123 0 $this->summary('Converted RPM package');
124 }
125 }
126 0 ▶ unless (defined $this->description) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $this->description) 0 0 0
127 0 $this->description($this->summary);
128 }
129 0 ▶ unless (defined $this->copyright) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $this->copyright) 0 0 0
130 # Older rpms have no licence tag, but have a copyright.
131 0 $this->copyright($this->runpipe(0, "LANG=C rpm -qp --queryformat \%{COPYRIGHT} '$file'"));
132  
133 # Fallback.
134 0 ▶ if (! $this->copyright) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($this->copyright) 0 0 0
135 0 $this->copyright('unknown');
136 }
137 }
138 0 ▶ if (! defined $this->release || ! defined $this->version ||
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $this->release and defined $this->version and defined $this->name) 0 0 0
Condition0%0/6
defined $this->release and defined $this->version and defined $this->name
!ll&&!rl&&r
000
defined $this->release and defined $this->version
!ll&&!rl&&r
000
MC/DC0%0/3
defined $this->release and defined $this->version and defined $this->name
defined $this->release defined $this->version defined $this->name
Truth table0%0/4
A and B and C
A= defined $this->releaseB= defined $this->versionC= defined $this->name
ABCresult
0XX0
10X0
1100
1111
139 ! defined $this->name) {
140 0 die "Error querying rpm file";
141 }
142  
143 0 $this->distribution("Red Hat");
144 0 $this->origformat("rpm");
145  
146 0 return 1;
147 }
148  
149 =item unpack
150  
151 Implement the unpack method to unpack a rpm file. This is a little nasty
152 because it has to handle relocatable rpms and has to do a bit of
153 permissions fixing as well.
154  
155 =cut
156  
157 0 ▶sub unpack {
Subroutine unpack: not called CC=32 SCAR=69.6
Pod documented
158 0 my $this=shift;
159 0 $this->SUPER::unpack(@_);
160 0 my $workdir=$this->unpacked_tree;
161
162 # Check if we need to use lzma to uncompress the cpio archive
163 0 my $decomp='';
164 0 ▶ if ($this->do("rpm2cpio '".$this->filename."' | lzma -t -q > /dev/null 2>&1")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->do(q[rpm2cpio '] . $this->filename . q[' | lzma -t -q > /dev/null 2>&1])) 0 0 0
165 0 $decomp = 'lzma -d -q |';
166 }
167  
168 0 ▶ $this->do("rpm2cpio '".$this->filename."' | (cd $workdir; $decomp cpio --extract --make-directories --no-absolute-filenames --preserve-modification-time) 2>&1")
Branch: 1 branch
BranchTrueFalseTotal
$this->do(q[rpm2cpio '] . $this->filename . "' | (cd $workdir; $decomp cpio --extract --make-directories --no-absolute-filenames --preserve-modification-time) 2>&1") or die q[Unpacking of '] . $this->filename . q[' failed] 0 0 0
169 or die "Unpacking of '".$this->filename."' failed";
170
171 # cpio does not necessarily store all parent directories in an
172 # archive, and so some directories, if it has to make them and has
173 # no permission info, will come out with some random permissions.
174 # Find those directories and make them mode 755, which is more
175 # reasonable.
176 0 my %seenfiles;
177 0 ▶ open (RPMLIST, "rpm2cpio '".$this->filename."' | $decomp cpio -it --quiet |")
Branch: 1 branch
BranchTrueFalseTotal
open RPMLIST, q[rpm2cpio '] . $this->filename . "' | $decomp cpio -it --quiet |" or die q[File list of '] . $this->filename . q[' failed] 0 0 0
178 or die "File list of '".$this->filename."' failed";
179 0 ▶ while (<RPMLIST>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline RPMLIST)) 0 0 0
180 0 chomp;
181 0 $seenfiles{$_}=1;
182 }
183 0 close RPMLIST;
184 0 foreach my $file (`cd $workdir; find ./`) {
185 0 chomp $file;
186 0 ▶ if (! $seenfiles{$file} && -d "$workdir/$file" && ! -l "$workdir/$file") {
Branch: 1 branch
BranchTrueFalseTotal
if (not $seenfiles{$file} and -d "$workdir/$file" and not -l "$workdir/$file") 0 0 0
Condition0%0/6
not $seenfiles{$file} and -d "$workdir/$file" and not -l "$workdir/$file"
!ll&&!rl&&r
000
not $seenfiles{$file} and -d "$workdir/$file"
!ll&&!rl&&r
000
MC/DC0%0/3
not $seenfiles{$file} and -d "$workdir/$file" and not -l "$workdir/$file"
not $seenfiles{$file} -d "$workdir/$file" not -l "$workdir/$file"
Truth table0%0/4
not(A) and B and not(C)
A= not $seenfiles{$file}B= -d "$workdir/$file"C= not -l "$workdir/$file"
ABCresult
0XX0
10X0
1100
1111
187 0 $this->do("chmod 755 '$workdir/$file'");
188 }
189 }
190  
191 # If the package is relocatable. We'd like to move it to be under
192 # the $this->prefixes directory. However, it's possible that that
193 # directory is in the package - it seems some rpm's are marked as
194 # relocatable and unpack already in the directory they can relocate
195 # to, while some are marked relocatable and the directory they can
196 # relocate to is removed from all filenames in the package. I
197 # suppose this is due to some change between versions of rpm, but
198 # none of this is adequatly documented, so we'll just muddle
199 # through.
200 #
201 # Test to see if the package contains the prefix directory already.
202 0 ▶ if (defined $this->prefixes && ! -e "$workdir/".$this->prefixes) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $this->prefixes and not -e "$workdir/" . $this->prefixes) 0 0 0
Condition0%0/3
defined $this->prefixes and not -e "$workdir/" . $this->prefixes
!ll&&!rl&&r
000
MC/DC0%0/2
defined $this->prefixes and not -e "$workdir/" . $this->prefixes
defined $this->prefixes not -e "$workdir/" . $this->prefixes
Truth table0%0/3
A and not(B)
A= defined $this->prefixesB= not -e "$workdir/" . $this->prefixes
ABresult
0X0
100
111
203 0 my $relocate=1;
204  
205 # Get the files to move.
206 0 my @filelist=glob("$workdir/*");
207
208 # Now, make the destination directory.
209 0 my $collect=$workdir;
210 0 foreach (split m:/:, $this->prefixes) {
211 0 ▶ if ($_ ne '') { # this keeps us from using anything but relative paths.
Branch: 1 branch
BranchTrueFalseTotal
if ($_ ne "") 0 0 0
212 0 $collect.="/$_";
213 0 ▶ if (-d $collect) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $collect) 0 0 0
214 # The package contains a parent
215 # directory of the relocation
216 # directory. Since it's impossible
217 # to move a parent directory into
218 # its child, bail out and do
219 # nothing.
220 0 $relocate=0;
221 0 last;
222 }
223 0 ▶ $this->do("mkdir", $collect) || die "unable to mkdir $collect: $!";
Branch: 1 branch
BranchTrueFalseTotal
$this->do("mkdir", $collect) or die "unable to mkdir ${collect}: $!" 0 0 0
224 }
225 }
226  
227 0 ▶ if ($relocate) {
Branch: 1 branch
BranchTrueFalseTotal
if ($relocate) 0 0 0
228 # Now move all files in the package to the directory we made.
229 0 ▶ if (@filelist) {
Branch: 1 branch
BranchTrueFalseTotal
if (@filelist) 0 0 0
230 0 ▶ $this->do("mv", @filelist, "$workdir/".$this->prefixes)
Branch: 1 branch
BranchTrueFalseTotal
$this->do("mv", @filelist, "$workdir/" . $this->prefixes) or die "error moving unpacked files into the default prefix directory: $!" 0 0 0
231 or die "error moving unpacked files into the default prefix directory: $!";
232 }
233
234 # Deal with relocating conffiles.
235 0 my @cf;
236 0 foreach my $cf (@{$this->conffiles}) {
237 0 $cf=$this->prefixes.$cf;
238 0 push @cf, $cf;
239 }
240 0 $this->conffiles([@cf]);
241 }
242 }
243
244 # rpm files have two sets of permissions; the set in the cpio
245 # archive, and the set in the control data; which override them.
246 # The set in the control data are more correct, so let's use those.
247 # Some permissions setting may have to be postponed until the
248 # postinst.
249 0 my %owninfo = ();
250 0 my %modeinfo = ();
251 0 open (GETPERMS, 'rpm --queryformat \'[%{FILEMODES} %{FILEUSERNAME} %{FILEGROUPNAME} %{FILENAMES}\n]\' -qp \''.$this->filename.'\' |');
252 0 ▶ while (<GETPERMS>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline GETPERMS)) 0 0 0
253 0 chomp;
254 0 my ($mode, $owner, $group, $file) = split(/ /, $_, 4);
255  
256 0 ▶ next if -l "$workdir/$file";
Branch: 1 branch
BranchTrueFalseTotal
if -l "$workdir/$file" 0 0 0
257  
258 0 $mode = $mode & 07777; # remove filetype
259 0 my $uid = getpwnam($owner);
260 0 ▶ if (! defined $uid || $uid != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $uid or $uid != 0) 0 0 0
Condition0%0/3
not defined $uid or $uid != 0
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $uid or $uid != 0
not defined $uid $uid != 0
Truth table0%0/3
not(A) or B
A= not defined $uidB= $uid != 0
ABresult
1X1
011
000
261 0 $owninfo{$file}=$owner;
262 0 $uid=0;
263 }
264 0 my $gid = getgrnam($group);
265 0 ▶ if (! defined $gid || $gid != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $gid or $gid != 0) 0 0 0
Condition0%0/3
not defined $gid or $gid != 0
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $gid or $gid != 0
not defined $gid $gid != 0
Truth table0%0/3
not(A) or B
A= not defined $gidB= $gid != 0
ABresult
1X1
011
000
266 0 ▶ if (exists $owninfo{$file}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $owninfo{$file}) { } 0 0 0
267 0 $owninfo{$file}.=":$group";
268 }
269 else {
270 0 $owninfo{$file}=":$group";
271 }
272 0 $gid=0;
273 }
274 0 ▶ if (defined($owninfo{$file}) && (($mode & 07000) > 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $owninfo{$file} and ($mode & 3584) > 0) 0 0 0
Condition0%0/3
defined $owninfo{$file} and ($mode & 3584) > 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $owninfo{$file} and ($mode & 3584) > 0
defined $owninfo{$file} ($mode & 3584) > 0
Truth table0%0/3
A and B
A= defined $owninfo{$file}B= ($mode & 3584) > 0
ABresult
0X0
100
111
275 0 $modeinfo{$file} = sprintf "%lo", $mode;
276 }
277 # Note that ghost files exist in the metadata but not
278 # in the cpio archive, so check that the file exists
279 # before trying to access it
280 0 ▶ if (-e "$workdir/$file") {
Branch: 1 branch
BranchTrueFalseTotal
if (-e "$workdir/$file") 0 0 0
281 0 ▶ if ($> == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($> == 0) 0 0 0
282 0 ▶ $this->do("chown", "$uid:$gid", "$workdir/$file")
Branch: 1 branch
BranchTrueFalseTotal
$this->do("chown", "${uid}:$gid", "$workdir/$file") or die "failed chowning $file to ${uid}:${gid}: $!" 0 0 0
283 || die "failed chowning $file to $uid\:$gid\: $!";
284 }
285 0 ▶ $this->do("chmod", sprintf("%lo", $mode), "$workdir/$file")
Branch: 1 branch
BranchTrueFalseTotal
$this->do("chmod", sprintf("%lo", $mode), "$workdir/$file") or die "failed changing mode of $file to ${mode}: $!" 0 0 0
286 || die "failed changing mode of $file to $mode\: $!";
287 }
288 }
289 0 $this->owninfo(\%owninfo);
290 0 $this->modeinfo(\%modeinfo);
291  
292 0 return 1;
293 }
294  
295 =item prep
296  
297 Prepare for package building by generating the spec file.
298  
299 =cut
300  
301 0 ▶sub prep {
Subroutine prep: not called CC=15 SCAR=54.8
Pod documented
302 0 my $this=shift;
303 0 ▶ my $dir=$this->unpacked_tree || die "The package must be unpacked first!";
Condition0%0/2
$this->unpacked_tree || die('The package must be unpacked first!')
l!l
00
MC/DC0%0/1
$this->unpacked_tree || die('The package must be unpacked first!')
$this->unpacked_tree
Truth table0%0/2
A
A= $this->unpacked_tree
Aresult
11
00
304  
305 # Place %config in front of files that are conffiles.
306 0 my @conffiles = @{$this->conffiles};
307 0 my $filelist;
308 0 foreach my $fn (@{$this->filelist}) {
309 # Unquote any escaped characters in filenames - needed for
310 # non ascii characters. (eg. iso_8859-1 latin set)
311 0 ▶ if ($fn =~ /\\/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fn =~ /\\/) 0 0 0
312 0 $fn=eval qq{"$fn"};
313 }
314  
315 # Note all filenames are quoted in case they contain
316 # spaces.
317 0 ▶ if ($fn =~ m:/$:) {
Branch: 2 branches
BranchTrueFalseTotal
if ($fn =~ m[/$]) { } 0 0 0
elsif (grep /^\Q$fn\E$/, @conffiles) { } 0 0 0
318 0 $filelist.=qq{%dir "$fn"\n};
319 }
320 elsif (grep(m:^\Q$fn\E$:,@conffiles)) { # it's a conffile
321 0 $filelist.=qq{%config "$fn"\n};
322 }
323 else { # normal file
324 0 $filelist.=qq{"$fn"\n};
325 }
326 }
327  
328 # Write out the spec file.
329 0 my $spec="$dir/".$this->name."-".$this->version."-".$this->release.".spec";
330 0 ▶ open (OUT, ">$spec") || die "$spec: $!";
Branch: 1 branch
BranchTrueFalseTotal
open OUT, ">$spec" or die "${spec}: $!" 0 0 0
331 0 my $pwd=`pwd`;
332 0 chomp $pwd;
333 0 print OUT "Buildroot: $pwd/$dir\n"; # must be absolute dirname
334 0 print OUT "Name: ".$this->name."\n";
335 0 print OUT "Version: ".$this->version."\n";
336 0 print OUT "Release: ".$this->release."\n";
337 0 ▶ print OUT "Requires: ".$this->depends."\n"
Branch: 1 branch
BranchTrueFalseTotal
if defined $this->depends and length $this->depends 0 0 0
Condition0%0/3
defined $this->depends and length $this->depends
!ll&&!rl&&r
000
MC/DC0%0/2
defined $this->depends and length $this->depends
defined $this->depends length $this->depends
Truth table0%0/3
A and B
A= defined $this->dependsB= length $this->depends
ABresult
0X0
100
111
338 if defined $this->depends && length $this->depends;
339 0 print OUT "Summary: ".$this->summary."\n";
340 0 print OUT "License: ".$this->copyright."\n";
341 0 print OUT "Distribution: ".$this->distribution."\n";
342 0 print OUT "Group: Converted/".$this->group."\n";
343 0 print OUT "\n";
344 0 print OUT "\%define _rpmdir ../\n"; # write rpm to current directory
345 0 print OUT "\%define _rpmfilename %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm\n";
346 0 print OUT "\%define _unpackaged_files_terminate_build 0\n"; # work on SuSE
347 0 print OUT "\n";
348 0 ▶ if ($this->usescripts) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->usescripts) 0 0 0
349 0 ▶ if ($this->preinst) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->preinst) 0 0 0
350 0 print OUT "\%pre\n";
351 0 print OUT $this->preinst."\n";
352 0 print OUT "\n";
353 }
354 0 ▶ if ($this->postinst) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->postinst) 0 0 0
355 0 print OUT "\%post\n";
356 0 print OUT $this->postinst."\n";
357 0 print OUT "\n";
358 }
359 0 ▶ if ($this->prerm) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->prerm) 0 0 0
360 0 print OUT "\%preun\n";
361 0 print OUT $this->prerm."\n";
362 0 print OUT "\n";
363 }
364 0 ▶ if ($this->postrm) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->postrm) 0 0 0
365 0 print OUT "\%postun\n";
366 0 print OUT $this->postrm."\n";
367 0 print OUT "\n";
368 }
369 }
370 0 print OUT "\%description\n";
371 0 print OUT $this->description."\n";
372 0 print OUT "\n";
373 0 print OUT "(Converted from a ".$this->origformat." package by alien version $Alien::Version.)\n";
374 0 print OUT "\n";
375 0 print OUT "%files\n";
376 0 ▶ print OUT $filelist if defined $filelist;
Branch: 1 branch
BranchTrueFalseTotal
if defined $filelist 0 0 0
377 0 close OUT;
378 }
379  
380 =item cleantree
381  
382 Delete the spec file.
383  
384 =cut
385  
386 0 ▶sub cleantree {
Subroutine cleantree: not called CC=2 SCAR=17.9
Pod documented
387 0 my $this=shift;
388 0 ▶ my $dir=$this->unpacked_tree || die "The package must be unpacked first!";
Condition0%0/2
$this->unpacked_tree || die('The package must be unpacked first!')
l!l
00
MC/DC0%0/1
$this->unpacked_tree || die('The package must be unpacked first!')
$this->unpacked_tree
Truth table0%0/2
A
A= $this->unpacked_tree
Aresult
11
00
389
390 0 unlink "$dir/".$this->name."-".$this->version."-".$this->release.".spec";
391 }
392  
393 =item build
394  
395 Build a rpm. If RPMBUILDOPT is set in the environment, the options in
396 it are passed to rpm on its command line.
397  
398 An optional parameter, if passed, can be used to specify the program to use
399 to build the rpm. It defaults to rpmbuild.
400  
401 =cut
402  
403 0 ▶sub build {
Subroutine build: not called CC=8 SCAR=42.8
Pod documented
404 0 my $this=shift;
405 0 ▶ my $buildcmd=shift || 'rpmbuild';
Condition0%0/2
shift() || 'rpmbuild'
l!l
00
MC/DC0%0/1
shift() || 'rpmbuild'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
406 0 ▶ my $dir=$this->unpacked_tree || die "The package must be unpacked first!";
Condition0%0/2
$this->unpacked_tree || die('The package must be unpacked first!')
l!l
00
MC/DC0%0/1
$this->unpacked_tree || die('The package must be unpacked first!')
$this->unpacked_tree
Truth table0%0/2
A
A= $this->unpacked_tree
Aresult
11
00
407
408 # Ask rpm how it's set up. We want to know where it will place rpms.
409 0 my $rpmdir;
410 0 foreach ($this->runpipe(1, "rpm --showrc")) {
411 0 chomp;
412 0 ▶ if (/^rpmdir\s+:\s(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^rpmdir\s+:\s(.*)$/) 0 0 0
413 0 $rpmdir=$1;
414 }
415 }
416  
417 0 my $rpm=$this->name."-".$this->version."-".$this->release.".".$this->arch.".rpm";
418 0 my $opts='';
419 0 ▶ if ($rpmdir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rpmdir) { } 0 0 0
420 # Old versions of rpm toss it off in the middle of nowhere.
421 0 $rpm="$rpmdir/".$this->arch."/$rpm";
422  
423 # This is the old command line argument to set the arch.
424 0 $opts="--buildarch ".$this->arch;
425 }
426 else {
427 # Presumably we're dealing with rpm 3.0 or above, which
428 # doesn't output rpmdir in any format I'd care to try to
429 # parse. Instead, rpm is now of a late enough version to
430 # notice the %define's in the spec file, that will make the
431 # file end up in the directory we started in.
432 # Anyway, let's assume this is version 3 or above.
433
434 # This is the new command line arcgument to set the arch
435 # rpms. It appeared in rpm version 3.
436 0 $opts="--target ".$this->arch;
437 }
438  
439 0 ▶ $opts.=" $ENV{RPMBUILDOPT}" if exists $ENV{RPMBUILDOPT};
Branch: 1 branch
BranchTrueFalseTotal
if exists $ENV{"RPMBUILDOPT"} 0 0 0
440 0 my $pwd=`pwd`;
441 0 chomp $pwd;
442 0 my $command="cd $dir; $buildcmd --buildroot='$pwd/$dir' -bb $opts '".$this->name."-".$this->version."-".$this->release.".spec'";
443 0 my $log=$this->runpipe(1, "$command 2>&1");
444 0 ▶ if ($?) {
Branch: 1 branch
BranchTrueFalseTotal
if ($?) 0 0 0
445 0 die "Package build failed. Here's the log of the command ($command):\n", $log;
446 }
447  
448 0 return $rpm;
449 }
450  
451 =item version
452  
453 Set/get version.
454  
455 When retreiving the version, remove any dashes in it.
456  
457 =cut
458  
459 0 ▶sub version {
Subroutine version: not called CC=3 SCAR=24.8
Pod documented
460 0 my $this=shift;
461  
462 # set
463 0 ▶ $this->{version} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
464  
465 # get
466 0 ▶ return unless defined wantarray; # optimization
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray 0 0 0
467 0 $_=$this->{version};
468 0 tr/-/_/;
469 0 return $_;
470 }
471  
472 =item postinst
473  
474 =item postrm
475  
476 =item preinst
477  
478 =item prerm
479  
480 Set/get script fields.
481  
482 When retrieving a value, we have to do some truely sick mangling. Since
483 debian/slackware scripts can be anything -- perl programs or binary files
484 -- and rpm is limited to only shell scripts, we need to encode the files
485 and add a scrap of shell script to make it unextract and run on the fly.
486  
487 When setting a value, we do some mangling too. Rpm maintainer scripts
488 are typically shell scripts, but often lack the leading shebang line.
489 This can confuse dpkg, so add the shebang if it looks like there
490 is no shebang magic already in place.
491  
492 Additionally, it's not uncommon for rpm maintainer scripts to contain
493 bashisms, which can be triggered when they are ran on systems where /bin/sh
494 is not bash. To work around this, the shebang line of the scripts is
495 changed to use bash.
496  
497 Also, if the rpm is relocatable, the script could refer to
498 RPM_INSTALL_PREFIX, which is set by rpm at run time. Deal with this by
499 adding code to the script to set RPM_INSTALL_PREFIX.
500  
501 =cut
502  
503 # This helper function deals with all the scripts.
504 0 ▶sub _script_helper {
Subroutine _script_helper: not called CC=10 SCAR=47.0
505 0 my $this=shift;
506 0 my $script=shift;
507  
508 # set
509 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
510 0 my $prefixcode="";
511 0 ▶ if (defined $this->prefixes) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $this->prefixes) 0 0 0
512 0 $prefixcode="RPM_INSTALL_PREFIX=".$this->prefixes."\n";
513 0 $prefixcode.="export RPM_INSTALL_PREFIX\n";
514 }
515  
516 0 my $value=shift;
517 0 ▶ if (length $value and $value !~ m/^#!\s*\//) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $value and not $value =~ m[^#!\s*/]) { } 0 0 0
Condition0%0/3
length $value and not $value =~ m[^#!\s*/]
!ll&&!rl&&r
000
MC/DC0%0/2
length $value and not $value =~ m[^#!\s*/]
length $value not $value =~ m[^#!\s*/]
Truth table0%0/3
A and not(B)
A= length $valueB= not $value =~ m[^#!\s*/]
ABresult
0X0
100
111
518 0 $value="#!/bin/bash\n$prefixcode$value";
519 }
520 else {
521 0 $value=~s@^#!\s*/bin/sh(\s)@#!/bin/bash$1@;
522 0 $value=~s/\n/\n$prefixcode/s;
523 }
524 0 $this->{$script} = $value;
525 }
526 0 ▶ $this->{$script} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
527  
528 # get
529 0 ▶ return unless defined wantarray; # optimization
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray 0 0 0
530 0 $_=$this->{$script};
531 0 ▶ return '' unless defined $_;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 0 0 0
532 0 ▶ return $_ if m/^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^\s*$/ 0 0 0
533 0 ▶ return $_ if m/^#!\s*\/bin\/sh/; # looks like a shell script already
Branch: 1 branch
BranchTrueFalseTotal
if m[^#!\s*/bin/sh] 0 0 0
534 0 my $f = pack("u",$_);
535 0 $f =~ s/%/%%/g; # Rpm expands %S, so escape such things.
536 0 return "#!/bin/sh\n".
537 "set -e\n".
538 "mkdir /tmp/alien.\$\$\n".
539 qq{perl -pe '\$_=unpack("u",\$_)' << '__EOF__' > /tmp/alien.\$\$/script\n}.
540 $f."__EOF__\n".
541 "chmod 755 /tmp/alien.\$\$/script\n".
542 "/tmp/alien.\$\$/script \"\$@\"\n".
543 "rm -f /tmp/alien.\$\$/script\n".
544 "rmdir /tmp/alien.\$\$";
545 }
546 0 ▶sub postinst {
Subroutine postinst: not called CC=1 SCAR=6.9
Pod documented
547 0 my $this=shift;
548 0 $this->_script_helper('postinst', @_);
549 }
550 0 ▶sub postrm {
Subroutine postrm: not called CC=1 SCAR=6.9
Pod documented
551 0 my $this=shift;
552 0 $this->_script_helper('postrm', @_);
553 }
554 0 ▶sub preinst {
Subroutine preinst: not called CC=1 SCAR=6.9
Pod documented
555 0 my $this=shift;
556 0 $this->_script_helper('preinst', @_);
557 }
558 0 ▶sub prerm {
Subroutine prerm: not called CC=1 SCAR=6.9
Pod documented
559 0 my $this=shift;
560 0 $this->_script_helper('prerm', @_);
561 }
562  
563 =item arch
564  
565 Set/get arch field. When the arch field is set, some sanitizing is done
566 first to convert it to the debian format used internally. When it's
567 retrieved it's converted back to rpm form from the internal form.
568  
569 =cut
570  
571 0 ▶sub arch {
Subroutine arch: not called CC=21 SCAR=61.4
Pod documented
572 0 my $this=shift;
573  
574 0 my $arch;
575 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
576 0 $arch=shift;
577  
578 0 ▶ if ($arch eq 1) {
Branch: 13 branches
BranchTrueFalseTotal
if ($arch eq 1) { } 0 0 0
elsif ($arch eq 2) { } 0 0 0
elsif ($arch eq 3) { } 0 0 0
elsif ($arch eq 6) { } 0 0 0
elsif ($arch eq 'noarch') { } 0 0 0
elsif ($arch eq 'ppc') { } 0 0 0
elsif ($arch eq 'x86_64') { } 0 0 0
elsif ($arch eq 'em64t') { } 0 0 0
elsif ($arch =~ /i\d86/i or $arch =~ /pentium/i) { } 0 0 0
elsif ($arch eq 'armv4l') { } 0 0 0
elsif ($arch eq 'armv7l') { } 0 0 0
elsif ($arch eq 'parisc') { } 0 0 0
elsif ($arch eq 'ppc64le') { } 0 0 0
579 0 $arch='i386';
580 }
581 elsif ($arch eq 2) {
582 0 $arch='alpha';
583 }
584 elsif ($arch eq 3) {
585 0 $arch='sparc';
586 }
587 elsif ($arch eq 6) {
588 0 $arch='m68k';
589 }
590 elsif ($arch eq 'noarch') {
591 0 $arch='all';
592 }
593 elsif ($arch eq 'ppc') {
594 0 $arch='powerpc';
595 }
596 elsif ($arch eq 'x86_64') {
597 0 $arch='amd64';
598 }
599 elsif ($arch eq 'em64t') {
600 0 $arch='amd64';
601 }
602 ▶ elsif ($arch =~ m/i\d86/i || $arch =~ m/pentium/i) {
Condition0%0/3
$arch =~ /i\d86/i or $arch =~ /pentium/i
l!l&&r!l&&!r
000
MC/DC0%0/2
$arch =~ /i\d86/i or $arch =~ /pentium/i
$arch =~ /i\d86/i $arch =~ /pentium/i
Truth table0%0/3
A or B
A= $arch =~ /i\d86/iB= $arch =~ /pentium/i
ABresult
1X1
011
000
603 # Treat 486, 586, etc, as 386.
604 0 $arch='i386';
605 }
606 elsif ($arch eq 'armv4l') {
607 # Treat armv4l as arm.
608 0 $arch='arm';
609 }
610 elsif ($arch eq 'armv7l') {
611 # Treat armv7l as armel.
612 0 $arch='armel';
613 }
614 elsif ($arch eq 'parisc') {
615 0 $arch='hppa';
616 }
617 elsif ($arch eq 'ppc64le') {
618 0 $arch='ppc64el';
619 }
620
621 0 $this->{arch}=$arch;
622 }
623  
624 0 $arch=$this->{arch};
625 0 ▶ if ($arch eq 'amd64') {
Branch: 5 branches
BranchTrueFalseTotal
if ($arch eq 'amd64') { } 0 0 0
elsif ($arch eq 'powerpc') { } 0 0 0
elsif ($arch eq 'hppa') { } 0 0 0
elsif ($arch eq 'all') { } 0 0 0
elsif ($arch eq 'ppc64el') { } 0 0 0
626 0 $arch='x86_64';
627 }
628 elsif ($arch eq 'powerpc') {
629 # XXX is this the canonical name for powerpc on rpm
630 # systems?
631 0 $arch='ppc';
632 }
633 elsif ($arch eq 'hppa') {
634 0 $arch='parisc';
635 }
636 elsif ($arch eq 'all') {
637 0 $arch='noarch';
638 }
639 elsif ($arch eq 'ppc64el') {
640 0 $arch='ppc64le';
641 }
642  
643 0 return $arch
644 }
645  
646 =back
647  
648 =head1 AUTHOR
649  
650 Joey Hess <joey@kitenet.net>
651  
652 =cut
653  
654 1 1
↑ Summary blib/lib/auto/share/dist/Alien-Alien/lib/perl5/Alien/Package/Pkg.pm »