lib/ProjectBuilder/Distribution.pm

filter: Statementstmt 10.4% 37 / 353 Branchbran 0.0% 0 / 190 Conditioncond 0.0% 0 / 78 MC/DCmcdc 0.0% 0 / 49 Subroutinesub 40.7% 11 / 27 Podpod 87.5% 14 / 16 totaltotal 8.7% 62 / 713 SCAR 95.9
CC
132
Cov
6%
pb_distro_setuprepo_gen
506.0
pb_distro_only_deps_needed
272.0
pb_distro_get
240.0
CRAP 14623.4
↑ Summary blib/lib/ProjectBuilder/Base.pm »
1 #!/usr/bin/perl -w
2 #
3 # Creates common environment for distributions
4 #
5 # Copyright B. Cornec 2007-2016
6 # Eric Anderson's changes are (c) Copyright 2012 Hewlett Packard
7 # Provided under the GPL v2
8 #
9 # $Id$
10 #
11  
12 package ProjectBuilder::Distribution;
13  
14 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Carp 'confess';
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use ProjectBuilder::Version;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use ProjectBuilder::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use ProjectBuilder::Conf;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use File::Copy;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 # requires perl 5.004 minimum in VM/VE
23 1 ▶use File::Compare;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 # Global vars
26 # Inherit from the "Exporter" module which handles exporting functions.
27
28 1 ▶use vars qw($VERSION $REVISION @ISA @EXPORT);
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
30
31 # Export, by default, all the functions into the namespace of
32 # any code which uses this module.
33
34 1 our @ISA = qw(Exporter);
35 1 our @EXPORT = qw(pb_distro_init pb_distro_conffile pb_distro_get pb_distro_getlsb pb_distro_installdeps pb_distro_getdeps pb_distro_only_deps_needed pb_distro_setuprepo pb_distro_setuposrepo pb_distro_get_param pb_distro_get_context pb_distro_to_keylist pb_distro_conf_print pb_apply_conf_proxy);
36 1 ($VERSION,$REVISION) = pb_version_init();
37  
38 =pod
39  
40 =head1 NAME
41  
42 ProjectBuilder::Distribution, part of the project-builder.org - module dealing with distribution detection
43  
44 =head1 DESCRIPTION
45  
46 This modules provides functions to allow detection of Linux distributions, and giving back some attributes concerning them.
47  
48 =head1 SYNOPSIS
49  
50 use ProjectBuilder::Distribution;
51  
52 #
53 # Return information on the running distro
54 #
55 my $pbos = pb_distro_get_context();
56 print "distro tuple: ".Dumper($pbos->name, $pbos->ver, $pbos->fam, $pbos->type, $pbos->pbsuf, $pbos->pbupd, $pbos->pbins, $pbos->arch)."\n";
57 #
58 # Return information on the requested distro
59 #
60 my $pbos = pb_distro_get_context("ubuntu-7.10-x86_64");
61 print "distro tuple: ".Dumper($pbos->name, $pbos->ver, $pbos->fam, $pbos->type, $pbos->pbsuf, $pbos->pbupd, $pbos->pbins, $pbos->arch)."\n";
62 #
63 # Return information on the running distro
64 #
65 my ($ddir,$dver) = pb_distro_get();
66  
67 =head1 USAGE
68  
69 =over 4
70  
71 =item B<pb_distro_conffile>
72  
73 This function returns the mandatory configuration file used for distribution/OS detection
74  
75 =cut
76  
77 sub pb_distro_conffile {
78  
79 0 ▶return("/usr/local/etc/pb/pb.conf");
Subroutine pb_distro_conffile: not called CC=1 SCAR=6.9
Pod documented
80 }
81  
82  
83 =item B<pb_distro_init>
84  
85 This function returns a hash of parameters indicating the distribution name, version, family, type of build system, suffix of packages, update command line, installation command line and architecture of the underlying Linux distribution. The value of the fields may be "unknown" in case the function was unable to recognize on which distribution it is running.
86  
87 As an example, Ubuntu and Debian are in the same "du" family. As well as RedHat, RHEL, CentOS, fedora are on the same "rh" family.
88 Mandriva, Open SuSE and Fedora have all the same "rpm" type of build system. Ubuntu and Debian have the same "deb" type of build system.
89 And "fc" is the extension generated for all Fedora packages (Version will be added by pb).
90 All this information is stored in an external configuration file typically at /etc/pb/pb.conf
91  
92 When passing the distribution name and version as parameters, the B<pb_distro_init> function returns the parameter of that distribution instead of the underlying one.
93  
94 Cf: http://linuxmafia.com/faq/Admin/release-files.html
95 Ideas taken from http://search.cpan.org/~kerberus/Linux-Distribution-0.14/lib/Linux/Distribution.pm
96  
97 =cut
98  
99  
100 sub pb_distro_init {
101  
102 0 ▶my $pbos = {
Subroutine pb_distro_init: not called CC=14 SCAR=53.5
Pod documented
103 'name' => undef,
104 'version' => undef,
105 'arch' => undef,
106 'family' => "unknown",
107 'suffix' => "unknown",
108 'update' => "unknown",
109 'install' => "unknown",
110 'type' => "unknown",
111 'os' => "unknown",
112 'nover' => "false",
113 'rmdot' => "false",
114 'useminor' => "false",
115 };
116 0 $pbos->{'name'} = shift;
117 0 $pbos->{'version'} = shift;
118 0 $pbos->{'arch'} = shift;
119  
120 # Adds conf file for distribution description
121 # the location of the conf file is finalyzed at install time
122 # depending whether we deal with package install or tar file install
123 0 pb_conf_add(pb_distro_conffile());
124  
125 # If we don't know which distribution we're on, then guess it
126 0 ▶($pbos->{'name'},$pbos->{'version'}) = pb_distro_get() if ((not defined $pbos->{'name'}) || (not defined $pbos->{'version'}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pbos->{"name"} and defined $pbos->{"version"} 0 0 0
Condition0%0/3
defined $pbos->{"name"} and defined $pbos->{"version"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $pbos->{"name"} and defined $pbos->{"version"}
defined $pbos->{"name"} defined $pbos->{"version"}
Truth table0%0/3
A and B
A= defined $pbos->{"name"}B= defined $pbos->{"version"}
ABresult
0X0
100
111
127  
128 # For some rare cases, typically nover ones
129 0 ▶$pbos->{'name'} = "unknown" if (not defined $pbos->{'name'});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pbos->{"name"} 0 0 0
130 0 ▶$pbos->{'version'} = "unknown" if (not defined $pbos->{'version'});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pbos->{"version"} 0 0 0
131  
132 # Initialize arch
133 0 ▶$pbos->{'arch'} = pb_get_arch() if (not defined $pbos->{'arch'});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pbos->{"arch"} 0 0 0
134 # Solves a bug on Red Hat 6.x where real arch is not detected when using setarch and a chroot
135 # As it was only i386 forcing it here.
136 0 ▶$pbos->{'arch'} = "i386" if (($pbos->{'name'} eq "redhat") && ($pbos->{'version'} =~ /^6\./));
Branch: 1 branch
BranchTrueFalseTotal
if $pbos->{"name"} eq "redhat" and $pbos->{"version"} =~ /^6\./ 0 0 0
Condition0%0/3
$pbos->{"name"} eq "redhat" and $pbos->{"version"} =~ /^6\./
!ll&&!rl&&r
000
MC/DC0%0/2
$pbos->{"name"} eq "redhat" and $pbos->{"version"} =~ /^6\./
$pbos->{"name"} eq "redhat" $pbos->{"version"} =~ /^6\./
Truth table0%0/3
A and B
A= $pbos->{"name"} eq "redhat"B= $pbos->{"version"} =~ /^6\./
ABresult
0X0
100
111
137  
138 # Dig into the tuple to find the best answer
139 # Do NOT factorize here, as it won't work as of now for hash creation
140 # Do NOT change order without caution
141 0 $pbos->{'useminor'} = pb_distro_get_param($pbos,pb_conf_get("osuseminorrel"));
142 0 $pbos->{'family'} = pb_distro_get_param($pbos,pb_conf_get("osfamily"));
143 0 $pbos->{'type'} = pb_distro_get_param($pbos,pb_conf_get("ostype"));
144 0 ($pbos->{'os'},$pbos->{'install'},$pbos->{'suffix'},$pbos->{'nover'},$pbos->{'rmdot'},$pbos->{'update'}) = pb_distro_get_param($pbos,pb_conf_get("os","osins","ossuffix","osnover","osremovedotinver","osupd"));
145 #($pbos->{'family'},$pbos->{'type'},$pbos->{'os'},$pbos->{'install'},$pbos->{'suffix'},$pbos->{'nover'},$pbos->{'rmdot'},$pbos->{'update'}) = pb_distro_get_param($pbos,pb_conf_get("osfamily","ostype","os","osins","ossuffix","osnover","osremovedotinver","osupd"));
146  
147 # Some OS have no interesting version
148 0 ▶$pbos->{'version'} = "nover" if ((defined $pbos->{'nover'}) && ($pbos->{'nover'} eq "true"));
Branch: 1 branch
BranchTrueFalseTotal
if defined $pbos->{"nover"} and $pbos->{"nover"} eq "true" 0 0 0
Condition0%0/3
defined $pbos->{"nover"} and $pbos->{"nover"} eq "true"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $pbos->{"nover"} and $pbos->{"nover"} eq "true"
defined $pbos->{"nover"} $pbos->{"nover"} eq "true"
Truth table0%0/3
A and B
A= defined $pbos->{"nover"}B= $pbos->{"nover"} eq "true"
ABresult
0X0
100
111
149  
150 # For some OS remove the . in version name for extension
151 0 my $dver2 = $pbos->{'version'};
152 0 ▶$dver2 =~ s/\.//g if ((defined $pbos->{'rmdot'}) && ($pbos->{'rmdot'} eq "true"));
Branch: 1 branch
BranchTrueFalseTotal
if defined $pbos->{"rmdot"} and $pbos->{"rmdot"} eq "true" 0 0 0
Condition0%0/3
defined $pbos->{"rmdot"} and $pbos->{"rmdot"} eq "true"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $pbos->{"rmdot"} and $pbos->{"rmdot"} eq "true"
defined $pbos->{"rmdot"} $pbos->{"rmdot"} eq "true"
Truth table0%0/3
A and B
A= defined $pbos->{"rmdot"}B= $pbos->{"rmdot"} eq "true"
ABresult
0X0
100
111
153  
154 0 ▶if ((not defined $pbos->{'suffix'}) || ($pbos->{'suffix'} eq "")) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $pbos->{'suffix'} or $pbos->{'suffix'} eq '') { } 0 0 0
Condition0%0/3
not defined $pbos->{"suffix"} or $pbos->{"suffix"} eq ""
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $pbos->{"suffix"} or $pbos->{"suffix"} eq ""
not defined $pbos->{"suffix"} $pbos->{"suffix"} eq ""
Truth table0%0/3
not(A) or B
A= not defined $pbos->{"suffix"}B= $pbos->{"suffix"} eq ""
ABresult
1X1
011
000
155 # By default suffix is a concatenation of name and version
156 0 $pbos->{'suffix'} = ".$pbos->{'name'}$dver2"
157 } else {
158 # concat just the version to what has been found
159 0 $pbos->{'suffix'} = ".$pbos->{'suffix'}$dver2";
160 }
161  
162 # if ($arch eq "x86_64") {
163 # $opt="--exclude=*.i?86";
164 # }
165 0 pb_log(2,"DEBUG: pb_distro_init: ".Dumper($pbos)."\n");
166  
167 0 return($pbos);
168 }
169  
170 =item B<pb_distro_get>
171  
172 This function returns a list of 2 parameters indicating the distribution name and version of the underlying Linux distribution. The value of those 2 fields may be "unknown" in case the function was unable to recognize on which distribution it is running.
173  
174 On my home machine it would currently report ("mandriva","2010.2").
175  
176 =cut
177  
178 sub pb_distro_get {
179  
180 # 1: List of files that unambiguously indicates what distro we have
181 # 2: List of files that ambiguously indicates what distro we have
182 # 3: Should have the same keys as the previous one. If ambiguity, which other distributions should be checked
183 # 4: Matching Rg. Expr to detect distribution and version
184 0 ▶my ($single_rel_files, $ambiguous_rel_files,$distro_similar,$distro_match) = pb_conf_get("osrelfile","osrelambfile","osambiguous","osrelexpr");
Subroutine pb_distro_get: not called CC=15 SCAR=54.8
Pod documented
185  
186 0 my $release;
187 my $distro;
188  
189 # Begin to test presence of non-ambiguous files
190 # that way we reduce the choice
191 0 my ($d,$r);
192 0 ▶while (($d,$r) = each %$single_rel_files) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$single_rel_files) 0 0 0
193 0 ▶ if (defined $ambiguous_rel_files->{$d}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ambiguous_rel_files->{$d}) 0 0 0
194 0 print STDERR "The key $d is considered as both unambiguous and ambigous.\n";
195 0 print STDERR "Please fix your configuration file.\n"
196 }
197 0 ▶ if (-f "$r" && ! -l "$r") {
Branch: 1 branch
BranchTrueFalseTotal
if (-f "$r" and not -l "$r") 0 0 0
Condition0%0/3
-f "$r" and not -l "$r"
!ll&&!rl&&r
000
MC/DC0%0/2
-f "$r" and not -l "$r"
-f "$r" not -l "$r"
Truth table0%0/3
A and not(B)
A= -f "$r"B= not -l "$r"
ABresult
0X0
100
111
198 0 my $tmp=pb_get_content("$r");
199 # Found the only possibility.
200 # Try to get version and return
201 0 ▶ if (defined ($distro_match->{$d})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $distro_match->{$d}) { } 0 0 0
202 0 ($release) = $tmp =~ m/$distro_match->{$d}/m;
203 } else {
204 0 print STDERR "Unable to find $d version in $r (non-ambiguous)\n";
205 0 print STDERR "Please report to the maintainer bruno_at_project-builder.org\n";
206 0 $release = "unknown";
207 }
208 0 return($d,$release);
209 }
210 }
211  
212 # Now look at ambiguous files
213 # Ubuntu before 10.04 includes a /etc/debian_version file that creates an ambiguity with debian
214 # So we need to look at distros in reverse alphabetic order to treat ubuntu always first via lsb
215 0 my $found = 0;
216 0 foreach $d (reverse keys %$ambiguous_rel_files) {
217 0 $r = $ambiguous_rel_files->{$d};
218 0 ▶ if (-f "$r" && !-l "$r") {
Branch: 1 branch
BranchTrueFalseTotal
if (-f "$r" and not -l "$r") 0 0 0
Condition0%0/3
-f "$r" and not -l "$r"
!ll&&!rl&&r
000
MC/DC0%0/2
-f "$r" and not -l "$r"
-f "$r" not -l "$r"
Truth table0%0/3
A and not(B)
A= -f "$r"B= not -l "$r"
ABresult
0X0
100
111
219 # Found one possibility.
220 # Get all distros concerned by that file
221 0 my $tmp=pb_get_content("$r");
222 0 my $ptr = $distro_similar->{$d};
223 0 pb_log(2,"amb: ".Dumper($ptr)."\n");
224 0 $release = "unknown";
225 0 foreach my $dd (split(/,/,$ptr)) {
226 0 pb_log(2,"check $dd\n");
227 # Try to check pattern
228 0 ▶ if (defined $distro_match->{$dd}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $distro_match->{$dd}) 0 0 0
229 0 pb_log(2,"cmp: $distro_match->{$dd} - vs - $tmp\n");
230 0 ($release) = $tmp =~ m/$distro_match->{$dd}/m;
231 0 ▶ if ((defined $release) && ($release ne "unknown")) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $release and $release ne "unknown") 0 0 0
Condition0%0/3
defined $release and $release ne "unknown"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $release and $release ne "unknown"
defined $release $release ne "unknown"
Truth table0%0/3
A and B
A= defined $releaseB= $release ne "unknown"
ABresult
0X0
100
111
232 0 $distro = $dd;
233 0 $found = 1;
234 0 last;
235 }
236 }
237 }
238 0 ▶ last if ($found == 1);
Branch: 1 branch
BranchTrueFalseTotal
if $found == 1 0 0 0
239 }
240 }
241 0 ▶if ($found == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($found == 0) { } 0 0 0
242 0 print STDERR "Unable to find a version in ".join(' ',keys %$ambiguous_rel_files)." (ambiguous)\n";
243 0 print STDERR "Please report to the maintainer bruno_at_project-builder.org\n";
244 0 return("unknown","unknown");
245 } else {
246 0 return($distro,$release);
247 }
248 }
249  
250 =item B<pb_distro_getlsb>
251  
252 This function returns the 5 lsb values LSB version, distribution ID, Description, release and codename.
253 As entry it takes an optional parameter to specify whether the output is short or not.
254  
255 =cut
256  
257 sub pb_distro_getlsb {
258  
259 0 ▶my $s = shift;
Subroutine pb_distro_getlsb: not called CC=14 SCAR=53.5
Pod documented
260 0 pb_log(3,"Entering pb_distro_getlsb\n");
261  
262 0 my ($ambiguous_rel_files) = pb_conf_get("osrelambfile");
263 0 my $lsbf = $ambiguous_rel_files->{"lsb"};
264  
265 # LSB has not been configured.
266 0 ▶if (not defined $lsbf) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $lsbf) 0 0 0
267 0 print STDERR "no lsb entry defined for osrelambfile\n";
268 0 confess "You modified upstream delivery and lost !\n";
269 }
270  
271 0 ▶if (-r $lsbf) {
Branch: 1 branch
BranchTrueFalseTotal
if (-r $lsbf) { } 0 0 0
272 0 my $rep = pb_get_content($lsbf);
273 # Create elementary fields
274 0 my ($c, $r, $d, $i, $l) = ("", "", "", "", "");
275 0 for my $f (split(/\n/,$rep)) {
276 0 pb_log(3,"Reading file part ***$f***\n");
277 0 ▶ $c = $f if ($f =~ /^DISTRIB_CODENAME/);
Branch: 1 branch
BranchTrueFalseTotal
if $f =~ /^DISTRIB_CODENAME/ 0 0 0
278 0 $c =~ s/DISTRIB_CODENAME=/Codename:\t/;
279 0 ▶ $r = $f if ($f =~ /^DISTRIB_RELEASE/);
Branch: 1 branch
BranchTrueFalseTotal
if $f =~ /^DISTRIB_RELEASE/ 0 0 0
280 0 $r =~ s/DISTRIB_RELEASE=/Release:\t/;
281 0 ▶ $d = $f if ($f =~ /^DISTRIB_DESCRIPTION/);
Branch: 1 branch
BranchTrueFalseTotal
if $f =~ /^DISTRIB_DESCRIPTION/ 0 0 0
282 0 $d =~ s/DISTRIB_DESCRIPTION=/Description:\t/;
283 0 $d =~ s/"//g;
284 0 ▶ $i = $f if ($f =~ /^DISTRIB_ID/);
Branch: 1 branch
BranchTrueFalseTotal
if $f =~ /^DISTRIB_ID/ 0 0 0
285 0 $i =~ s/DISTRIB_ID=/Distributor ID:\t/;
286 0 ▶ $l = $f if ($f =~ /^LSB_VERSION/);
Branch: 1 branch
BranchTrueFalseTotal
if $f =~ /^LSB_VERSION/ 0 0 0
287 0 $l =~ s/LSB_VERSION=/LSB Version:\t/;
288 }
289 0 my $regexp = "^[A-z ]*:[\t ]*";
290 0 ▶ $c =~ s/$regexp// if (defined $s);
Branch: 1 branch
BranchTrueFalseTotal
if defined $s 0 0 0
291 0 ▶ $r =~ s/$regexp// if (defined $s);
Branch: 1 branch
BranchTrueFalseTotal
if defined $s 0 0 0
292 0 ▶ $d =~ s/$regexp// if (defined $s);
Branch: 1 branch
BranchTrueFalseTotal
if defined $s 0 0 0
293 0 ▶ $i =~ s/$regexp// if (defined $s);
Branch: 1 branch
BranchTrueFalseTotal
if defined $s 0 0 0
294 0 ▶ $l =~ s/$regexp// if (defined $s);
Branch: 1 branch
BranchTrueFalseTotal
if defined $s 0 0 0
295 0 return($l, $i, $d, $r, $c);
296 } else {
297 0 print STDERR "Unable to read $lsbf file\n";
298 0 confess "Please report to the maintainer bruno_at_project-builder.org\n";
299 }
300 }
301  
302 # Internal function
303  
304 sub pb_apply_conf_proxy {
305 0 ▶my ($pbos) = @_;
Subroutine pb_apply_conf_proxy: not called CC=7 SCAR=40.3
Pod undocumented
306  
307 0 my $ftp_proxy = pb_distro_get_param($pbos,pb_conf_get_if("ftp_proxy"));
308 0 my $http_proxy = pb_distro_get_param($pbos,pb_conf_get_if("http_proxy"));
309  
310 # We do not overwrite shell settings
311 0 ▶$ENV{ftp_proxy} ||= $ftp_proxy if ((defined $ftp_proxy) && ($ftp_proxy ne ""));
Branch: 1 branch
BranchTrueFalseTotal
if defined $ftp_proxy and $ftp_proxy ne "" 0 0 0
Condition0%0/6
defined $ftp_proxy and $ftp_proxy ne ""
!ll&&!rl&&r
000
$ENV{"ftp_proxy"} ||= $ftp_proxy
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $ftp_proxy and $ftp_proxy ne ""
defined $ftp_proxy $ftp_proxy ne ""
MC/DC0%0/2
$ENV{"ftp_proxy"} ||= $ftp_proxy
$ENV{"ftp_proxy"} $ftp_proxy
Truth table0%0/3
A and B
A= defined $ftp_proxyB= $ftp_proxy ne ""
ABresult
0X0
100
111
Truth table0%0/3
A ||= B
A= $ENV{"ftp_proxy"}B= $ftp_proxy
ABresult
1X1
011
000
312 0 ▶$ENV{http_proxy} ||= $http_proxy if ((defined $http_proxy) && ($http_proxy ne ""));
Branch: 1 branch
BranchTrueFalseTotal
if defined $http_proxy and $http_proxy ne "" 0 0 0
Condition0%0/6
defined $http_proxy and $http_proxy ne ""
!ll&&!rl&&r
000
$ENV{"http_proxy"} ||= $http_proxy
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $http_proxy and $http_proxy ne ""
defined $http_proxy $http_proxy ne ""
MC/DC0%0/2
$ENV{"http_proxy"} ||= $http_proxy
$ENV{"http_proxy"} $http_proxy
Truth table0%0/3
A and B
A= defined $http_proxyB= $http_proxy ne ""
ABresult
0X0
100
111
Truth table0%0/3
A ||= B
A= $ENV{"http_proxy"}B= $http_proxy
ABresult
1X1
011
000
313 }
314  
315 =item B<pb_distro_installdeps>
316  
317 This function install the dependencies required to build the package on a distro.
318 Dependencies can be passed as a parameter in which case they are not computed
319  
320 =cut
321  
322 sub pb_distro_installdeps {
323  
324 # SPEC file
325 0 ▶my $f = shift;
Subroutine pb_distro_installdeps: not called CC=12 SCAR=50.5
Pod documented
326 0 my $pbos = shift;
327 0 my $deps = shift;
328  
329 # Protection
330 0 ▶confess "Missing install command for $pbos->{name}-$pbos->{version}-$pbos->{arch}" unless (defined $pbos->{install} && $pbos->{install} =~ /\w/);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pbos->{"install"} and $pbos->{"install"} =~ /\w/ 0 0 0
Condition0%0/3
defined $pbos->{"install"} and $pbos->{"install"} =~ /\w/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $pbos->{"install"} and $pbos->{"install"} =~ /\w/
defined $pbos->{"install"} $pbos->{"install"} =~ /\w/
Truth table0%0/3
A and B
A= defined $pbos->{"install"}B= $pbos->{"install"} =~ /\w/
ABresult
0X0
100
111
331 0 pb_apply_conf_proxy($pbos);
332  
333 # Get dependencies in the build file if not forced
334 0 ▶$deps = pb_distro_getdeps($f,$pbos) if (not defined $deps);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $deps 0 0 0
335 0 ▶pb_log(1, "ftp_proxy=$ENV{ftp_proxy}\n") if (defined $ENV{ftp_proxy});
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"ftp_proxy"} 0 0 0
336 0 ▶pb_log(1, "http_proxy=$ENV{http_proxy}\n") if (defined $ENV{http_proxy});
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"http_proxy"} 0 0 0
337 0 pb_log(2,"deps: $deps\n");
338 0 ▶return if ((not defined $deps) || ($deps =~ /^\s*$/));
Branch: 1 branch
BranchTrueFalseTotal
if not defined $deps or $deps =~ /^\s*$/ 0 0 0
Condition0%0/3
not defined $deps or $deps =~ /^\s*$/
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $deps or $deps =~ /^\s*$/
not defined $deps $deps =~ /^\s*$/
Truth table0%0/3
not(A) or B
A= not defined $depsB= $deps =~ /^\s*$/
ABresult
1X1
011
000
339  
340 # This may not be // proof. We should test for availability of repo and sleep if not
341 0 my $cmd = "$pbos->{'install'} $deps";
342 0 my $ret = pb_system($cmd, "Installing dependencies ($cmd)","mayfail");
343 # Try to accomodate deficient proxies
344 0 ▶if ($ret != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ret != 0) 0 0 0
345 0 pb_system($cmd, "Re-trying installing dependencies ($cmd)");
346 }
347 # Check that all deps have been installed correctly
348 0 $deps = pb_distro_getdeps($f, $pbos);
349 0 ▶confess "Some dependencies did not install ($deps)" if ((defined $deps) && ($deps =~ /\S/) && ($Global::pb_stop_on_error));
Branch: 1 branch
BranchTrueFalseTotal
if defined $deps and $deps =~ /\S/ and $Global::pb_stop_on_error 0 0 0
Condition0%0/6
defined $deps and $deps =~ /\S/ and $Global::pb_stop_on_error
!ll&&!rl&&r
000
defined $deps and $deps =~ /\S/
!ll&&!rl&&r
000
MC/DC0%0/3
defined $deps and $deps =~ /\S/ and $Global::pb_stop_on_error
defined $deps $deps =~ /\S/ $Global::pb_stop_on_error
Truth table0%0/4
A and B and C
A= defined $depsB= $deps =~ /\S/C= $Global::pb_stop_on_error
ABCresult
0XX0
10X0
1100
1111
350 }
351  
352 =item B<pb_distro_getdeps>
353  
354 This function computes the dependencies indicated in the build file and return them as a string of packages to install
355  
356 =cut
357  
358 sub pb_distro_getdeps {
359  
360 0 ▶my $f = shift;
Subroutine pb_distro_getdeps: not called CC=13 SCAR=52.0
Pod documented
361 0 my $pbos = shift;
362  
363 0 my $regexp = "";
364 0 my $deps = "";
365 0 my $sep = $/;
366  
367 # Protection
368 0 ▶return("") if (not defined $pbos->{'type'});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pbos->{"type"} 0 0 0
369 0 ▶return("") if (not defined $f);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $f 0 0 0
370  
371 0 pb_log(3,"entering pb_distro_getdeps: $pbos->{'type'} - $f\n");
372 0 ▶if ($pbos->{'type'} eq "rpm") {
Branch: 3 branches
BranchTrueFalseTotal
if ($pbos->{'type'} eq 'rpm') { } 0 0 0
elsif ($pbos->{'type'} eq 'deb') { } 0 0 0
elsif ($pbos->{'type'} eq 'ebuild') { } 0 0 0
373 # In RPM this could include files, but we do not handle them atm.
374 0 $regexp = '^BuildRequires:(.*)$';
375 } elsif ($pbos->{'type'} eq "deb") {
376 0 $regexp = '^Build-Depends:(.*)$';
377 } elsif ($pbos->{'type'} eq "ebuild") {
378 0 $sep = '"'.$/;
379 0 $regexp = '^DEPEND="(.*)"\n'
380 } else {
381 # No idea
382 0 return("");
383 }
384 0 pb_log(2,"regexp: $regexp\n");
385  
386 # Preserve separator before using the one we need
387 0 my $oldsep = $/;
388 0 $/ = $sep;
389 0 ▶open(DESC,"$f") || confess "Unable to open $f";
Branch: 1 branch
BranchTrueFalseTotal
open DESC, "$f" or confess("Unable to open $f") 0 0 0
390 0 ▶while (<DESC>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline DESC)) 0 0 0
391 0 pb_log(4,"read: $_\n");
392 0 ▶ next if (! /$regexp/);
Branch: 1 branch
BranchTrueFalseTotal
unless /$regexp/ 0 0 0
393 0 chomp();
394  
395 0 my $nextline;
396 # Support multi-lines deps for .deb
397 0 ▶ if ($pbos->{type} eq 'deb') {
Branch: 1 branch
BranchTrueFalseTotal
if ($pbos->{"type"} eq "deb") 0 0 0
398 0 ▶ while ($nextline = <DESC>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($nextline = readline DESC)) 0 0 0
399 0 ▶ last unless $nextline =~ /^\s+(.+)$/o;
Branch: 1 branch
BranchTrueFalseTotal
unless $nextline =~ /^\s+(.+)$/o 0 0 0
400 0 $_ .= $1;
401 }
402 }
403  
404 # What we found with the regexp is the list of deps.
405 0 pb_log(2,"found deps: $_\n");
406 0 s/$regexp/$1/i;
407 0 pb_log(4,"found deps 1: $_\n");
408 # Remove conditions in the middle and at the end for deb
409 0 s/\(\s*[><=]+.*\)[^,]*,/,/g;
410 0 pb_log(4,"found deps 2: $_\n");
411 0 s/\(\s*[><=]+.*$//g;
412 0 pb_log(4,"found deps 3: $_\n");
413 # Same for rpm
414 0 s/[><=]+[^,]*,/,/g;
415 0 pb_log(4,"found deps 4: $_\n");
416 0 s/[><=]+.*$//g;
417 0 pb_log(4,"found deps 5: $_\n");
418 # Improve string format (remove , and spaces at start, end and in double
419 0 s/,/ /g;
420 0 pb_log(4,"found deps 6: $_\n");
421 0 s/^\s*//;
422 0 pb_log(4,"found deps 7: $_\n");
423 # $ here removes the \n
424 0 s/\s*$//;
425 0 pb_log(4,"found deps 8: $_\n");
426 0 s/\s+/ /g;
427 0 pb_log(4,"found deps 9: $_\n");
428 0 $deps .= " ".$_;
429 0 pb_log(4,"found deps end: $deps\n");
430  
431 # Support multi-lines deps for .deb (fwup)
432 0 ▶ if (defined $nextline) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nextline) 0 0 0
433 0 $_ = $nextline;
434 0 redo;
435 }
436 }
437 0 close(DESC);
438 0 $/ = $oldsep;
439 0 pb_log(2,"now deps: $deps\n");
440 0 my $deps2 = pb_distro_only_deps_needed($pbos,$deps);
441 0 return($deps2);
442 }
443  
444  
445 =item B<pb_distro_only_deps_needed>
446  
447 This function returns only the dependencies not yet installed
448  
449 =cut
450  
451 sub pb_distro_only_deps_needed {
452  
453 0 ▶my $pbos = shift;
Subroutine pb_distro_only_deps_needed: not called CC=16 SCAR=56.1
Pod documented
454 0 my $deps = shift;
455  
456 0 ▶return("") if ((not defined $deps) || ($deps =~ /^\s*$/));
Branch: 1 branch
BranchTrueFalseTotal
if not defined $deps or $deps =~ /^\s*$/ 0 0 0
Condition0%0/3
not defined $deps or $deps =~ /^\s*$/
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $deps or $deps =~ /^\s*$/
not defined $deps $deps =~ /^\s*$/
Truth table0%0/3
not(A) or B
A= not defined $depsB= $deps =~ /^\s*$/
ABresult
1X1
011
000
457 0 my $deps2 = "";
458 # Avoid to install what is already there
459 0 delete $ENV{COLUMNS};
460 0 foreach my $p (split(/\s+/,$deps)) {
461 0 ▶ next if $p =~ /^\s*$/o;
Branch: 1 branch
BranchTrueFalseTotal
if $p =~ /^\s*$/o 0 0 0
462 0 ▶ if ($pbos->{'type'} eq "rpm") {
Branch: 3 branches
BranchTrueFalseTotal
if ($pbos->{'type'} eq 'rpm') { } 0 0 0
elsif ($pbos->{'type'} eq 'deb') { } 0 0 0
elsif ($pbos->{'type'} eq 'ebuild') { } 0 0 0
463 0 my $rpmcmd = "rpm -q --whatprovides --quiet";
464 # whatprovides doesn't work for RH6.2
465 0 ▶ $rpmcmd = "rpm -q --quiet" if (($pbos->{'name'} eq "redhat") && ($pbos->{'version'} =~ /6/));
Branch: 1 branch
BranchTrueFalseTotal
if $pbos->{"name"} eq "redhat" and $pbos->{"version"} =~ /6/ 0 0 0
Condition0%0/3
$pbos->{"name"} eq "redhat" and $pbos->{"version"} =~ /6/
!ll&&!rl&&r
000
MC/DC0%0/2
$pbos->{"name"} eq "redhat" and $pbos->{"version"} =~ /6/
$pbos->{"name"} eq "redhat" $pbos->{"version"} =~ /6/
Truth table0%0/3
A and B
A= $pbos->{"name"} eq "redhat"B= $pbos->{"version"} =~ /6/
ABresult
0X0
100
111
466 0 my $res = pb_system("$rpmcmd $p","Looking for $p","mayfail");
467 0 ▶ next if ($res eq 0);
Branch: 1 branch
BranchTrueFalseTotal
if $res eq 0 0 0 0
468 0 pb_log(1, "INFO: missing dependency $p\n");
469 } elsif ($pbos->{'type'} eq "deb") {
470 0 my $res = pb_system("dpkg -L $p","Looking for $p","mayfail");
471 0 ▶ next if ($res eq 0);
Branch: 1 branch
BranchTrueFalseTotal
if $res eq 0 0 0 0
472 0 ▶ open(CMD,"dpkg -l $p |") or confess "Unable to run dpkg -l $p: $!";
Branch: 1 branch
BranchTrueFalseTotal
open CMD, "dpkg -l $p |" or confess("Unable to run dpkg -l ${p}: $!") 0 0 0
473 0 my $ok = 0;
474 0 ▶ while (<CMD>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline CMD)) 0 0 0
475 0 ▶ $ok = 1 if /^ii\s+$p/;
Branch: 1 branch
BranchTrueFalseTotal
if /^ii\s+$p/ 0 0 0
476 }
477 0 close(CMD);
478 0 ▶ next if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 0 0 0
479 0 pb_log(1, "INFO: missing dependency $p\n");
480 } elsif ($pbos->{'type'} eq "ebuild") {
481 } else {
482 # Not reached
483 }
484 0 pb_log(2,"found deps2: $p\n");
485 0 $deps2 .= " $p";
486 }
487  
488 0 $deps2 =~ s/^\s*//;
489 0 pb_log(2,"now deps2: $deps2\n");
490 0 return($deps2);
491 }
492  
493 =item B<pb_distro_setuposrepo>
494  
495 This function sets up potential additional repository for the setup phase
496  
497 =cut
498  
499 sub pb_distro_setuposrepo {
500  
501 0 ▶my $pbos = shift;
Subroutine pb_distro_setuposrepo: not called CC=1 SCAR=6.9
Pod documented
502  
503 0 pb_distro_setuprepo_gen($pbos,pb_distro_conffile(),"osrepo");
504 }
505  
506 =item B<pb_distro_setuprepo>
507  
508 This function sets up potential additional repository to the build environment
509  
510 =cut
511  
512 sub pb_distro_setuprepo {
513  
514 0 ▶my $pbos = shift;
Subroutine pb_distro_setuprepo: not called CC=1 SCAR=6.9
Pod documented
515  
516 0 pb_distro_setuprepo_gen($pbos,"$ENV{'PBDESTDIR'}/pbrc","addrepo");
517 }
518  
519 # Internal
520 sub pb_distro_compare_repo {
521  
522 0 ▶my $src = shift;
Subroutine pb_distro_compare_repo: not called CC=6 SCAR=37.4
Pod undocumented
523 0 my $dest = shift;
524  
525 0 ▶if (not -f $dest) {
Branch: 3 branches
BranchTrueFalseTotal
if (not -f $dest) { } 0 0 0
elsif (-f $dest and -s $dest == 0) { } 0 0 0
elsif (-f $dest and compare("$src", $dest) == 0) { } 0 0 0
526 0 pb_log(1, "INFO: Creating new file $dest\n");
527 ▶} elsif (-f $dest && -s $dest == 0) {
Condition0%0/3
-f $dest and -s $dest == 0
!ll&&!rl&&r
000
MC/DC0%0/2
-f $dest and -s $dest == 0
-f $dest -s $dest == 0
Truth table0%0/3
A and B
A= -f $destB= -s $dest == 0
ABresult
0X0
100
111
528 0 pb_log(1, "INFO: Overwriting empty file $dest\n");
529 ▶} elsif (-f $dest && compare("$src", $dest) == 0) {
Condition0%0/3
-f $dest and compare("$src", $dest) == 0
!ll&&!rl&&r
000
MC/DC0%0/2
-f $dest and compare("$src", $dest) == 0
-f $dest compare("$src", $dest) == 0
Truth table0%0/3
A and B
A= -f $destB= compare("$src", $dest) == 0
ABresult
0X0
100
111
530 0 pb_log(1, "INFO: Overwriting identical file $dest\n");
531 } else {
532 0 pb_log(0, "ERROR: destination file $dest exists and is different than source $src\n");
533 0 pb_system("cat $dest","INFO: Dest...\n");
534 0 pb_system("cat $src","INFO: New...\n");
535 0 pb_log("INFO: Returning...\n");
536 0 return(0);
537 }
538 # TRUE
539 0 return(1);
540 }
541  
542 =item B<pb_distro_setuprepo_gen>
543  
544 This function sets up in a generic way potential additional repository
545  
546 =cut
547  
548 sub pb_distro_setuprepo_gen {
549  
550 0 ▶my $pbos = shift;
Subroutine pb_distro_setuprepo_gen: not called CC=22 SCAR=62.3
Pod documented
551 0 my $pbconf = shift;
552 0 my $pbkey = shift;
553  
554 0 ▶return if (not defined $pbconf);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pbconf 0 0 0
555 0 ▶return if (not defined $pbkey);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pbkey 0 0 0
556 0 my ($addrepo) = pb_conf_read($pbconf,$pbkey);
557 0 ▶return if (not defined $addrepo);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $addrepo 0 0 0
558  
559 0 my $param = pb_distro_get_param($pbos,$addrepo);
560 0 ▶return if ($param eq "");
Branch: 1 branch
BranchTrueFalseTotal
if $param eq "" 0 0 0
561  
562 0 pb_apply_conf_proxy($pbos);
563  
564 # Loop on the list of additional repo
565 0 foreach my $i (split(/,/,$param)) {
566  
567 0 my ($scheme, $account, $host, $port, $path) = pb_get_uri($i);
568 0 my $bn = basename($i);
569  
570 # The repo file can be local or remote. download or copy at the right place
571 0 ▶ if (($scheme eq "ftp") || ($scheme eq "http")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($scheme eq 'ftp' or $scheme eq 'http') { } 0 0 0
Condition0%0/3
$scheme eq "ftp" or $scheme eq "http"
l!l&&r!l&&!r
000
MC/DC0%0/2
$scheme eq "ftp" or $scheme eq "http"
$scheme eq "ftp" $scheme eq "http"
Truth table0%0/3
A or B
A= $scheme eq "ftp"B= $scheme eq "http"
ABresult
1X1
011
000
572 0 pb_system("wget -O $ENV{'PBTMP'}/$bn $i","Downloading additional repository file $i");
573 } else {
574 0 copy($i,"$ENV{'PBTMP'}/$bn");
575 }
576  
577 # The repo file can be a real file or a package
578 0 ▶ if ($pbos->{'type'} eq "rpm") {
Branch: 2 branches
BranchTrueFalseTotal
if ($pbos->{'type'} eq 'rpm') { } 0 0 0
elsif ($pbos->{'type'} eq 'deb') { } 0 0 0
579 0 ▶ if ($bn =~ /\.rpm$/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($bn =~ /\.rpm$/) { } 0 0 0
elsif ($bn =~ /\.repo$/) { } 0 0 0
elsif ($bn =~ /\.addmedia/) { } 0 0 0
580 0 my $pn = $bn;
581 0 $pn =~ s/\.rpm//;
582 0 ▶ if (pb_system("rpm -q --quiet $pn","","mayfail") != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (pb_system("rpm -q --quiet $pn", "", "mayfail") != 0) 0 0 0
583 0 pb_system("sudo rpm -Uvh $ENV{'PBTMP'}/$bn","Adding package to setup repository");
584 }
585 } elsif ($bn =~ /\.repo$/) {
586 0 my $dirdest = "";
587 0 my $reponame = "";
588 # TODO: could go in pb.conf in fact
589 0 ▶ if ($pbos->{install} =~ /\byum\b/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($pbos->{'install'} =~ /\byum\b/) { } 0 0 0
elsif ($pbos->{'install'} =~ /\bdnf\b/) { } 0 0 0
elsif ($pbos->{'install'} =~ /\bzypper\b/) { } 0 0 0
590 0 $reponame="yum";
591 0 $dirdest = "/etc/yum.repos.d";
592 } elsif ($pbos->{install} =~ /\bdnf\b/) {
593 0 $reponame="dnf";
594 0 $dirdest = "/etc/yum.repos.d";
595 } elsif ($pbos->{install} =~ /\bzypper\b/) {
596 0 $reponame="zypper";
597 0 $dirdest = "/etc/zypp/repos.d";
598 } else {
599 0 confess "Unknown location for repository file for '$pbos->{install}' command";
600 }
601 0 my $dest = "$dirdest/$bn";
602 0 ▶ return if (pb_distro_compare_repo("$ENV{'PBTMP'}/$bn",$dest));
Branch: 1 branch
BranchTrueFalseTotal
if pb_distro_compare_repo(qq[$ENV{"PBTMP"}/$bn], $dest) 0 0 0
603 0 ▶ confess "Missing directory $dirdest ($reponame)" unless (-d $dirdest);
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dirdest 0 0 0
604 0 ▶ pb_system("sudo mv $ENV{'PBTMP'}/$bn $dirdest/$bn","Adding $reponame repository") if (not -f "$dirdest/$bn");
Branch: 1 branch
BranchTrueFalseTotal
unless -f "$dirdest/$bn" 0 0 0
605 } elsif ($bn =~ /\.addmedia/) {
606 # URPMI repo
607 # We should test that it's not already a urpmi repo
608 0 pb_system("chmod 755 $ENV{'PBTMP'}/$bn ; sudo $ENV{'PBTMP'}/$bn 2>&1 > /dev/null","Adding urpmi repository");
609 } else {
610 0 pb_log(0,"ERROR: Unable to deal with repository file $i on rpm distro ! Please report to dev team\n");
611 }
612 } elsif ($pbos->{'type'} eq "deb") {
613 0 ▶ if ($bn =~ /\.sources.list$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bn =~ /\.sources.list$/) { } 0 0 0
614 0 my $dest = "/etc/apt/sources.list.d/$bn";
615 0 ▶ return if (pb_distro_compare_repo("$ENV{'PBTMP'}/$bn",$dest));
Branch: 1 branch
BranchTrueFalseTotal
if pb_distro_compare_repo(qq[$ENV{"PBTMP"}/$bn], $dest) 0 0 0
616 0 pb_system("sudo mv $ENV{'PBTMP'}/$bn /etc/apt/sources.list.d","Adding apt repository");
617 0 pb_system("sudo apt-get update","Updating apt repository");
618 } else {
619 0 pb_log(0,"ERROR: Unable to deal with repository file $i on deb distro ! Please report to dev team\n");
620 }
621 } else {
622 0 pb_log(0,"ERROR: Unable to deal with repository file $i on that distro ! Please report to dev team\n");
623 }
624 }
625 0 return;
626 }
627  
628 =item B<pb_distro_to_keylist>
629  
630 Given a pbos object (first param) and the generic key (second param), get the list of possible keys for looking up variable for
631 filter names. The list will be sorted most-specific to least specific.
632  
633 =cut
634  
635 sub pb_distro_to_keylist ($$) {
636  
637 0 ▶my ($pbos, $generic) = @_;
Subroutine pb_distro_to_keylist: not called CC=7 SCAR=40.3
Pod documented
638  
639 0 foreach my $key (qw/name version arch family type os/) {
640 0 ▶ confess "missing pbos key $key" unless (defined $pbos->{$key});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pbos->{$key} 0 0 0
641 }
642  
643 0 my @keylist = ("$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}", "$pbos->{'name'}-$pbos->{'version'}");
644  
645 # Loop to include also previous minor versions
646 # if configured so
647 0 ▶if ((defined $pbos->{'useminor'}) && ($pbos->{'useminor'} eq "true") && ($pbos->{'version'} =~ /^(\d+)\.(\d+)$/o)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pbos->{"useminor"} and $pbos->{"useminor"} eq "true" and $pbos->{"version"} =~ /^(\d+)\.(\d+)$/o) 0 0 0
Condition0%0/6
defined $pbos->{"useminor"} and $pbos->{"useminor"} eq "true" and $pbos->{"version"} =~ /^(\d+)\.(\d+)$/o
!ll&&!rl&&r
000
defined $pbos->{"useminor"} and $pbos->{"useminor"} eq "true"
!ll&&!rl&&r
000
MC/DC0%0/3
defined $pbos->{"useminor"} and $pbos->{"useminor"} eq "true" and $pbos->{"version"} =~ /^(\d+)\.(\d+)$/o
defined $pbos->{"useminor"} $pbos->{"useminor"} eq "true" $pbos->{"version"} =~ /^(\d+)\.(\d+)$/o
Truth table0%0/4
A and B and C
A= defined $pbos->{"useminor"}B= $pbos->{"useminor"} eq "true"C= $pbos->{"version"} =~ /^(\d+)\.(\d+)$/o
ABCresult
0XX0
10X0
1100
1111
648 0 my ($major, $minor) = ($1, $2);
649 0 ▶ while ($minor > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($minor > 0) 0 0 0
650 0 $minor--;
651 0 push (@keylist, "$pbos->{'name'}-${major}.$minor");
652 }
653 0 push (@keylist, "$pbos->{'name'}-$major");
654 }
655  
656 0 push (@keylist, $pbos->{'name'}, $pbos->{'family'}, $pbos->{'type'}, $pbos->{'os'}, $generic);
657 0 return @keylist;
658 }
659  
660 =item B<pb_distro_get_param>
661  
662 This function gets the parameter in the conf file from the most precise tuple up to default
663  
664 =cut
665  
666 sub pb_distro_get_param {
667  
668 0 ▶my @param = ();
Subroutine pb_distro_get_param: not called CC=6 SCAR=37.4
Pod documented
669 0 my $pbos = shift;
670  
671 0 my @keylist = pb_distro_to_keylist($pbos,"default");
672 0 pb_log(2,"DEBUG: pb_distro_get_param on $pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'} for ".Dumper(@_)."\n");
673 0 foreach my $opt (@_) {
674 0 my $param = "";
675 0 foreach my $key (@keylist) {
676 0 ▶ if (defined $opt->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt->{$key}) 0 0 0
677 0 $param = $opt->{$key};
678 0 last;
679 }
680 }
681 # Allow replacement of variables inside the parameter such as name, version, arch for rpmbootstrap
682 # but not shell variable which are backslashed
683 0 ▶ if ($param =~ /[^\\]\$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($param =~ /[^\\]\$/) 0 0 0
684 0 pb_log(3,"Expanding variable on $param\n");
685 0 eval { $param =~ s/(\$\w+->\{\'\w+\'\})/$1/eeg };
686 }
687 0 push @param,$param;
688 }
689  
690 0 pb_log(2,"DEBUG: pb_distro_get_param on $pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'} returns ==".Dumper(@param)."==\n");
691  
692 # Return one param if user only asked for one lookup, an array if not.
693 0 my $nb = @param;
694 0 ▶if ($nb eq 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nb eq 1) { } 0 0 0
695 0 return($param[0]);
696 } else {
697 0 return(@param);
698 }
699 }
700  
701 =item B<pb_distro_get_context>
702  
703 This function gets the OS context passed as parameter and return the corresponding distribution hash
704 If passed undef or "" then auto-detects
705  
706 =cut
707  
708  
709 sub pb_distro_get_context {
710  
711 0 ▶my $os = shift;
Subroutine pb_distro_get_context: not called CC=6 SCAR=37.4
Pod documented
712 0 my $pbos;
713  
714 0 ▶if ((defined $os) && ($os ne "")) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $os and $os ne '') { } 0 0 0
Condition0%0/3
defined $os and $os ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $os and $os ne ""
defined $os $os ne ""
Truth table0%0/3
A and B
A= defined $osB= $os ne ""
ABresult
0X0
100
111
715 0 my ($name,$ver,$darch) = split(/-/,$os);
716 0 ▶ pb_log(0,"Bad format for $os") if ((not defined $name) || (not defined $ver) || (not defined $darch)) ;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and defined $ver and defined $darch 0 0 0
Condition0%0/6
defined $name and defined $ver and defined $darch
!ll&&!rl&&r
000
defined $name and defined $ver
!ll&&!rl&&r
000
MC/DC0%0/3
defined $name and defined $ver and defined $darch
defined $name defined $ver defined $darch
Truth table0%0/4
A and B and C
A= defined $nameB= defined $verC= defined $darch
ABCresult
0XX0
10X0
1100
1111
717 0 chomp($darch);
718 0 $pbos = pb_distro_init($name,$ver,$darch);
719 } else {
720 0 $pbos = pb_distro_init();
721 }
722 0 return($pbos);
723 }
724  
725 =item B<pb_distro_conf_print>
726  
727 This function prints every configuration parameter in order to help debug stacking issues with conf files. If a VM/VE/RM is given restrict display to this distribution. Ifparameters are passed, restrict again the display to these values only.
728  
729 =cut
730  
731 sub pb_distro_conf_print {
732  
733 0 ▶my $pbos = shift;
Subroutine pb_distro_conf_print: not called CC=6 SCAR=37.4
Pod documented
734 0 my @keys = @_;
735  
736 0 ▶if ($#keys == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#keys == -1) 0 0 0
737 0 pb_log(0,"Full pb configuration for project $ENV{'PBPROJ'}\n");
738 0 pb_log(0,"================================================\n");
739 }
740 0 ▶if (defined $ENV{'PBV'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ENV{'PBV'}) { } 0 0 0
741 0 pb_log(0,"Distribution $ENV{'PBV'}\n");
742 0 pb_log(0,"========================\n");
743 } else {
744 0 pb_log(0,"Local Distribution\n");
745 0 pb_log(0,"==================\n");
746 }
747  
748 0 ▶if ($#keys == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#keys == -1) { } 0 0 0
749 0 foreach my $k (pb_conf_get_all()) {
750 0 pb_log(0,"$k => ".Dumper(pb_conf_get($k))."\n");
751 }
752 } else {
753 0 foreach my $k (@keys) {
754 0 pb_log(0,"$k=".pb_distro_get_param($pbos,pb_conf_get($k))."\n");
755 }
756 }
757 }
758  
759  
760 =back
761  
762 =head1 WEB SITES
763  
764 The main Web site of the project is available at L<http://www.project-builder.org/>. Bug reports should be filled using the trac instance of the project at L<http://trac.project-builder.org/>.
765  
766 =head1 USER MAILING LIST
767  
768 None exists for the moment.
769  
770 =head1 AUTHORS
771  
772 The Project-Builder.org team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>.
773  
774 =head1 COPYRIGHT
775  
776 Project-Builder.org is distributed under the GPL v2.0 license
777 described in the file C<COPYING> included with the distribution.
778  
779 =cut
780  
781  
782 1 1;
↑ Summary blib/lib/ProjectBuilder/Base.pm »