Dpkg/Arch.pm

filter: Statementstmt 88.7% 212 / 239 Branchbran 84.0% 84 / 100 Conditioncond 58.8% 50 / 85 MC/DCmcdc 33.3% 14 / 42 Subroutinesub 91.1% 41 / 45 Podpod 64.0% 16 / 25 totaltotal 77.8% 417 / 536 CC 87 SCAR 19.0
CC
87
Cov
82%
get_raw_host_arch
27.0
debarch_is
13.3
debtuple_to_gnutriplet
13.1
CRAP 6.7
« Dpkg/Changelog/Entry.pm ↑ Summary Dpkg/Getopt.pm »
1 # Copyright © 2006-2015 Guillem Jover <guillem@debian.org>
2 #
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <https://www.gnu.org/licenses/>.
15  
16 =encoding utf8
17  
18 =head1 NAME
19  
20 Dpkg::Arch - handle architectures
21  
22 =head1 DESCRIPTION
23  
24 The Dpkg::Arch module provides functions to handle Debian architectures,
25 wildcards, and mapping from and to GNU triplets.
26  
27 No symbols are exported by default. The :all tag can be used to import all
28 symbols. The :getters, :parsers, :mappers and :operators tags can be used
29 to import specific symbol subsets.
30  
31 =cut
32  
33 package Dpkg::Arch 1.04;
34  
35 15 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 15 our @EXPORT_OK = qw(
38 get_raw_build_arch
39 get_raw_host_arch
40 get_build_arch
41 get_host_arch
42 get_host_gnu_type
43 get_valid_arches
44 debarch_eq
45 debarch_is
46 debarch_is_wildcard
47 debarch_is_illegal
48 debarch_is_invalid
49 debarch_is_concerned
50 debarch_to_abiattrs
51 debarch_to_cpubits
52 debarch_to_gnutriplet
53 debarch_to_debtuple
54 debarch_to_multiarch
55 debarch_list_parse
56 debtuple_to_debarch
57 debtuple_to_gnutriplet
58 gnutriplet_to_debarch
59 gnutriplet_to_debtuple
60 gnutriplet_to_multiarch
61 );
62 15 our %EXPORT_TAGS = (
63 all => [ @EXPORT_OK ],
64 getters => [ qw(
65 get_raw_build_arch
66 get_raw_host_arch
67 get_build_arch
68 get_host_arch
69 get_host_gnu_type
70 get_valid_arches
71 ) ],
72 parsers => [ qw(
73 debarch_list_parse
74 ) ],
75 mappers => [ qw(
76 debarch_to_abiattrs
77 debarch_to_gnutriplet
78 debarch_to_debtuple
79 debarch_to_multiarch
80 debtuple_to_debarch
81 debtuple_to_gnutriplet
82 gnutriplet_to_debarch
83 gnutriplet_to_debtuple
84 gnutriplet_to_multiarch
85 ) ],
86 operators => [ qw(
87 debarch_eq
88 debarch_is
89 debarch_is_wildcard
90 debarch_is_illegal
91 debarch_is_invalid
92 debarch_is_concerned
93 ) ],
94 );
95  
96  
97 15 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
98 15 ▶use List::Util qw(any);
Subroutine BEGIN: called CC=1 SCAR=0.0
99  
100 15 ▶use Dpkg ();
Subroutine BEGIN: called CC=1 SCAR=0.0
101 15 ▶use Dpkg::Gettext;
Subroutine BEGIN: called CC=1 SCAR=0.0
102 15 ▶use Dpkg::ErrorHandling;
Subroutine BEGIN: called CC=1 SCAR=0.0
103 15 ▶use Dpkg::BuildEnv;
Subroutine BEGIN: called CC=1 SCAR=0.0
104  
105 15 my (@cpu, @os);
106 15 my (%cputable, %ostable);
107 15 my (%cputable_regex, %ostable_regex);
108 15 my (%cpubits, %cpuendian);
109 15 my %abibits;
110  
111 15 my %debtuple_to_debarch;
112 15 my %debarch_to_debtuple;
113  
114 =head1 FUNCTIONS
115  
116 =over 4
117  
118 =item $arch = get_raw_build_arch()
119  
120 Get the raw build Debian architecture, without taking into account variables
121 from the environment.
122  
123 =cut
124  
125 sub get_raw_build_arch
126 0 ▶{
Subroutine get_raw_build_arch: not called CC=3 SCAR=19.6
Pod documented
127 0 state $build_arch;
128  
129 0 ▶ return $build_arch if defined $build_arch;
Branch: 1 branch
BranchTrueFalseTotal
if defined $build_arch 0 0 0
130  
131 # Note: We *always* require an installed dpkg when inferring the
132 # build architecture. The bootstrapping case is handled by
133 # dpkg-architecture itself, by avoiding computing the DEB_BUILD_
134 # variables when they are not requested.
135  
136 ## no critic (TestingAndDebugging::ProhibitNoWarnings)
137 15 ▶ no warnings qw(exec);
Subroutine BEGIN: called CC=1 SCAR=0.0
138 0 $build_arch = qx(dpkg --print-architecture);
139 0 ▶ subprocerr('dpkg --print-architecture') if $?;
Branch: 1 branch
BranchTrueFalseTotal
if $? 0 0 0
140  
141 0 chomp $build_arch;
142 0 return $build_arch;
143 }
144  
145 =item $arch = get_build_arch()
146  
147 Get the build Debian architecture, using DEB_BUILD_ARCH from the environment
148 if available.
149  
150 =cut
151  
152 sub get_build_arch
153 50 ▶{
Subroutine get_build_arch: called CC=2 SCAR=9.2
Pod documented
154 50 ▶ return Dpkg::BuildEnv::get('DEB_BUILD_ARCH') || get_raw_build_arch();
Condition33%1/3
Dpkg::BuildEnv::get('DEB_BUILD_ARCH') || get_raw_build_arch()
l!l&&r!l&&!r
5000
MC/DC0%0/2
Dpkg::BuildEnv::get('DEB_BUILD_ARCH') || get_raw_build_arch()
Dpkg::BuildEnv::get('DEB_BUILD_ARCH') get_raw_build_arch()
Truth table33%1/3
A || B
A= Dpkg::BuildEnv::get('DEB_BUILD_ARCH')B= get_raw_build_arch()
ABresult
1X1
011
000
155 }
156  
157 {
158 15 my %cc_host_gnu_type;
159  
160 sub get_host_gnu_type
161 2 ▶ {
Subroutine get_host_gnu_type: called CC=4 SCAR=13.9
Pod undocumented
162 2 ▶ my $CC = $ENV{CC} || 'gcc';
Condition50%1/2
$ENV{'CC'} || 'gcc'
l!l
20
MC/DC0%0/1
$ENV{'CC'} || 'gcc'
$ENV{'CC'}
Truth table50%1/2
A
A= $ENV{'CC'}
Aresult
11
00
163  
164 2 ▶ return $cc_host_gnu_type{$CC} if defined $cc_host_gnu_type{$CC};
Branch: 1 branch
BranchTrueFalseTotal
if defined $cc_host_gnu_type{$CC} 0 2 2
165  
166 ## no critic (TestingAndDebugging::ProhibitNoWarnings)
167 15 ▶ no warnings qw(exec);
Subroutine BEGIN: called CC=1 SCAR=0.0
168 2 $cc_host_gnu_type{$CC} = qx($CC -dumpmachine);
169 2 ▶ if ($? >> 8) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? >> 8) { } 1 1 2
170 1 $cc_host_gnu_type{$CC} = '';
171 } else {
172 1 chomp $cc_host_gnu_type{$CC};
173 }
174  
175 2 return $cc_host_gnu_type{$CC};
176 }
177  
178 sub set_host_gnu_type
179 0 ▶ {
Subroutine set_host_gnu_type: not called CC=2 SCAR=17.9
Pod undocumented
180 0 my ($host_gnu_type) = @_;
181 0 ▶ my $CC = $ENV{CC} || 'gcc';
Condition0%0/2
$ENV{'CC'} || 'gcc'
l!l
00
MC/DC0%0/1
$ENV{'CC'} || 'gcc'
$ENV{'CC'}
Truth table0%0/2
A
A= $ENV{'CC'}
Aresult
11
00
182  
183 0 $cc_host_gnu_type{$CC} = $host_gnu_type;
184 }
185 }
186  
187 =item $arch = get_raw_host_arch()
188  
189 Get the raw host Debian architecture, without taking into account variables
190 from the environment.
191  
192 =cut
193  
194 sub get_raw_host_arch
195 15 ▶{
Subroutine get_raw_host_arch: not called CC=5 SCAR=33.0
Pod documented
196 0 state $host_arch;
197  
198 0 ▶ return $host_arch if defined $host_arch;
Branch: 1 branch
BranchTrueFalseTotal
if defined $host_arch 0 0 0
199  
200 0 my $host_gnu_type = get_host_gnu_type();
201  
202 0 ▶ if ($host_gnu_type eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($host_gnu_type eq '') { } 0 0 0
203 0 warning(g_('cannot determine CC system type, falling back to ' .
204 'default (native compilation)'));
205 } else {
206 0 my @host_archtuple = gnutriplet_to_debtuple($host_gnu_type);
207 0 $host_arch = debtuple_to_debarch(@host_archtuple);
208  
209 0 ▶ if (defined $host_arch) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $host_arch) { } 0 0 0
210 0 $host_gnu_type = debtuple_to_gnutriplet(@host_archtuple);
211 } else {
212 0 warning(g_('unknown CC system type %s, falling back to ' .
213 'default (native compilation)'), $host_gnu_type);
214 0 $host_gnu_type = '';
215 }
216 0 set_host_gnu_type($host_gnu_type);
217 }
218  
219 0 ▶ if (! defined($host_arch)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $host_arch) 0 0 0
220 # Switch to native compilation.
221 0 $host_arch = get_raw_build_arch();
222 }
223  
224 0 return $host_arch;
225 }
226  
227 =item $arch = get_host_arch()
228  
229 Get the host Debian architecture, using DEB_HOST_ARCH from the environment
230 if available.
231  
232 =cut
233  
234 sub get_host_arch
235 121 ▶{
Subroutine get_host_arch: called CC=2 SCAR=9.2
Pod documented
236 121 ▶ return Dpkg::BuildEnv::get('DEB_HOST_ARCH') || get_raw_host_arch();
Condition33%1/3
Dpkg::BuildEnv::get('DEB_HOST_ARCH') || get_raw_host_arch()
l!l&&r!l&&!r
12100
MC/DC0%0/2
Dpkg::BuildEnv::get('DEB_HOST_ARCH') || get_raw_host_arch()
Dpkg::BuildEnv::get('DEB_HOST_ARCH') get_raw_host_arch()
Truth table33%1/3
A || B
A= Dpkg::BuildEnv::get('DEB_HOST_ARCH')B= get_raw_host_arch()
ABresult
1X1
011
000
237 }
238  
239 =item @arch_list = get_valid_arches()
240  
241 Get an array with all currently known Debian architectures.
242  
243 =cut
244  
245 sub get_valid_arches
246 1 ▶{
Subroutine get_valid_arches: called CC=4 SCAR=13.9
Pod documented
247 1 _load_cputable();
248 1 _load_ostable();
249  
250 1 my @arches;
251  
252 1 foreach my $os (@os) {
253 20 foreach my $cpu (@cpu) {
254 680 my $arch = debtuple_to_debarch(split(/-/, $os, 3), $cpu);
255 680 ▶ push @arches, $arch if defined($arch);
Branch: 1 branch
BranchTrueFalseTotal
if defined $arch 201 479 680
256 }
257 }
258  
259 1 return @arches;
260 }
261  
262 15 my %table_loaded;
263 sub _load_table
264 138840 ▶{
Subroutine _load_table: called CC=4 SCAR=13.9
265 138840 my ($table, $loader) = @_;
266  
267 138840 ▶ return if $table_loaded{$table};
Branch: 1 branch
BranchTrueFalseTotal
if $table_loaded{$table} 138822 18 138840
268  
269 18 local $_;
270 18 local $/ = "\n";
271  
272 18 ▶ open my $table_fh, '<', "$Dpkg::DATADIR/$table"
Branch: 1 branch
BranchTrueFalseTotal
open my $table_fh, "<", "$Dpkg::DATADIR/$table" or syserr(g_("cannot open %s"), $table) 18 0 18
273 or syserr(g_('cannot open %s'), $table);
274 18 ▶ while (<$table_fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $table_fh)) 811 18 829
275 811 $loader->($_);
276 }
277 18 close $table_fh;
278  
279 18 $table_loaded{$table} = 1;
280 }
281  
282 sub _load_cputable
283 48742 ▶{
Subroutine _load_cputable: called CC=1 SCAR=0.0
284 324 ▶ _load_table('cputable', sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
285 324 ▶ if (m/^(?!\#)(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^(?!\#)(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/u) 204 120 324
286 204 $cputable{$1} = $2;
287 204 $cputable_regex{$1} = $3;
288 204 $cpubits{$1} = $4;
289 204 $cpuendian{$1} = $5;
290 204 push @cpu, $1;
291 }
292 48742 });
293 }
294  
295 sub _load_ostable
296 407 ▶{
Subroutine _load_ostable: called CC=1 SCAR=0.0
297 38 ▶ _load_table('ostable', sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
298 38 ▶ if (m/^(?!\#)(\S+)\s+(\S+)\s+(\S+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^(?!\#)(\S+)\s+(\S+)\s+(\S+)/u) 20 18 38
299 20 $ostable{$1} = $2;
300 20 $ostable_regex{$1} = $3;
301 20 push @os, $1;
302 }
303 407 });
304 }
305  
306 sub _load_abitable
307 41356 ▶{
Subroutine _load_abitable: called CC=1 SCAR=0.0
308 65 ▶ _load_table('abitable', sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
309 65 ▶ if (m/^(?!\#)(\S+)\s+(\S+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^(?!\#)(\S+)\s+(\S+)/u) 10 55 65
310 10 $abibits{$1} = $2;
311 }
312 41356 });
313 }
314  
315 sub _load_tupletable
316 48335 ▶{
Subroutine _load_tupletable: called CC=1 SCAR=0.0
317 48335 _load_cputable();
318  
319 384 ▶ _load_table('tupletable', sub {
Subroutine __ANON__: called CC=6 SCAR=17.9
320 384 ▶ if (m/^(?!\#)(\S+)\s+(\S+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^(?!\#)(\S+)\s+(\S+)/u) 246 138 384
321 246 my $debtuple = $1;
322 246 my $debarch = $2;
323  
324 246 ▶ if ($debtuple =~ /<cpu>/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($debtuple =~ /<cpu>/u) { } 30 216 246
325 30 foreach my $_cpu (@cpu) {
326 1020 (my $dt = $debtuple) =~ s/<cpu>/$_cpu/;
327 1020 (my $da = $debarch) =~ s/<cpu>/$_cpu/;
328  
329 next if exists $debarch_to_debtuple{$da}
330 1020 ▶ or exists $debtuple_to_debarch{$dt};
Branch: 1 branch
BranchTrueFalseTotal
if exists $debarch_to_debtuple{$da} or exists $debtuple_to_debarch{$dt} 24 996 1020
Condition66%2/3
exists $debarch_to_debtuple{$da} or exists $debtuple_to_debarch{$dt}
l!l&&r!l&&!r
240996
MC/DC50%1/2
exists $debarch_to_debtuple{$da} or exists $debtuple_to_debarch{$dt}
exists $debarch_to_debtuple{$da} exists $debtuple_to_debarch{$dt}
Truth table66%2/3
A or B
A= exists $debarch_to_debtuple{$da}B= exists $debtuple_to_debarch{$dt}
ABresult
1X1
011
000
331  
332 996 $debarch_to_debtuple{$da} = $dt;
333 996 $debtuple_to_debarch{$dt} = $da;
334 }
335 } else {
336 216 $debarch_to_debtuple{$2} = $1;
337 216 $debtuple_to_debarch{$1} = $2;
338 }
339 }
340 48335 });
341 }
342  
343 sub debtuple_to_gnutriplet
344 203 ▶{
Subroutine debtuple_to_gnutriplet: called CC=7 SCAR=25.7
Pod undocumented
345 203 my ($abi, $libc, $os, $cpu) = @_;
346  
347 203 _load_cputable();
348 203 _load_ostable();
349  
350 return unless
351 defined $abi && defined $libc && defined $os && defined $cpu &&
352 203 ▶ exists $cputable{$cpu} && exists $ostable{"$abi-$libc-$os"};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $abi and defined $libc and defined $os and defined $cpu and exists $cputable{$cpu} and exists $ostable{"$abi-$libc-$os"} 0 203 203
Condition33%5/15
defined $abi and defined $libc and defined $os and defined $cpu and exists $cputable{$cpu} and exists $ostable{"$abi-$libc-$os"}
!ll&&!rl&&r
00203
defined $abi and defined $libc and defined $os and defined $cpu and exists $cputable{$cpu}
!ll&&!rl&&r
00203
defined $abi and defined $libc and defined $os and defined $cpu
!ll&&!rl&&r
00203
defined $abi and defined $libc and defined $os
!ll&&!rl&&r
00203
defined $abi and defined $libc
!ll&&!rl&&r
00203
MC/DC0%0/6
defined $abi and defined $libc and defined $os and defined $cpu and exists $cputable{$cpu} and exists $ostable{"$abi-$libc-$os"}
defined $abi defined $libc defined $os defined $cpu exists $cputable{$cpu} exists $ostable{"$abi-$libc-$os"}
Truth table14%1/7
A and B and C and D and E and F
A= defined $abiB= defined $libcC= defined $osD= defined $cpuE= exists $cputable{$cpu}F= exists $ostable{"$abi-$libc-$os"}
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
353 203 return join('-', $cputable{$cpu}, $ostable{"$abi-$libc-$os"});
354 }
355  
356 sub gnutriplet_to_debtuple
357 204 ▶{
Subroutine gnutriplet_to_debtuple: called CC=10 SCAR=23.2
Pod undocumented
358 204 my $gnu = shift;
359 204 ▶ return unless defined($gnu);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $gnu 1 203 204
360 203 my ($gnu_cpu, $gnu_os) = split(/-/, $gnu, 2);
361 203 ▶ return unless defined($gnu_cpu) && defined($gnu_os);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $gnu_cpu and defined $gnu_os 0 203 203
Condition33%1/3
defined $gnu_cpu and defined $gnu_os
!ll&&!rl&&r
00203
MC/DC0%0/2
defined $gnu_cpu and defined $gnu_os
defined $gnu_cpu defined $gnu_os
Truth table33%1/3
A and B
A= defined $gnu_cpuB= defined $gnu_os
ABresult
0X0
100
111
362  
363 203 _load_cputable();
364 203 _load_ostable();
365  
366 203 my ($os, $cpu);
367  
368 203 foreach my $_cpu (@cpu) {
369 3387 ▶ if ($gnu_cpu =~ /^$cputable_regex{$_cpu}$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gnu_cpu =~ /^$cputable_regex{$_cpu}$/u) 202 3185 3387
370 202 $cpu = $_cpu;
371 202 last;
372 }
373 }
374  
375 203 foreach my $_os (@os) {
376 2110 ▶ if ($gnu_os =~ /^(.*-)?$ostable_regex{$_os}$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gnu_os =~ /^(.*-)?$ostable_regex{$_os}$/u) 202 1908 2110
377 202 $os = $_os;
378 202 last;
379 }
380 }
381  
382 203 ▶ return if ! defined($cpu) || ! defined($os);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cpu and defined $os 1 202 203
Condition66%2/3
defined $cpu and defined $os
!ll&&!rl&&r
10202
MC/DC50%1/2
defined $cpu and defined $os
defined $cpu defined $os
Truth table66%2/3
A and B
A= defined $cpuB= defined $os
ABresult
0X0
100
111
383 202 return (split(/-/, $os, 3), $cpu);
384 }
385  
386 =item $multiarch = gnutriplet_to_multiarch($gnutriplet)
387  
388 Map a GNU triplet into a Debian multiarch triplet.
389  
390 =cut
391  
392 sub gnutriplet_to_multiarch
393 2 ▶{
Subroutine gnutriplet_to_multiarch: called CC=2 SCAR=6.9
Pod documented
394 2 my $gnu = shift;
395 2 my ($cpu, $cdr) = split(/-/, $gnu, 2);
396  
397 2 ▶ if ($cpu =~ /^i[4567]86$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cpu =~ /^i[4567]86$/u) { } 1 1 2
398 1 return "i386-$cdr";
399 } else {
400 1 return $gnu;
401 }
402 }
403  
404 =item $multiarch = debarch_to_multiarch($arch)
405  
406 Map a Debian architecture into a Debian multiarch triplet.
407  
408 =cut
409  
410 sub debarch_to_multiarch
411 2 ▶{
Subroutine debarch_to_multiarch: called CC=1 SCAR=0.0
Pod documented
412 2 my $arch = shift;
413  
414 2 return gnutriplet_to_multiarch(debarch_to_gnutriplet($arch));
415 }
416  
417 sub debtuple_to_debarch
418 887 ▶{
Subroutine debtuple_to_debarch: called CC=6 SCAR=18.2
Pod undocumented
419 887 my ($abi, $libc, $os, $cpu) = @_;
420  
421 887 _load_tupletable();
422  
423 887 ▶ if (! defined $abi || ! defined $libc || ! defined $os || ! defined $cpu) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $abi && defined $libc && defined $os && defined $cpu) { } 3 884 887
elsif (exists $debtuple_to_debarch{"$abi-$libc-$os-$cpu"}) { } 404 480 884
Condition66%6/9
defined $abi && defined $libc && defined $os && defined $cpu
!ll&&!rl&&r
30884
defined $abi and defined $libc and defined $os
!ll&&!rl&&r
30884
defined $abi and defined $libc
!ll&&!rl&&r
30884
MC/DC25%1/4
defined $abi && defined $libc && defined $os && defined $cpu
defined $abi defined $libc defined $os defined $cpu
Truth table40%2/5
A and B and C && D
A= defined $abiB= defined $libcC= defined $osD= defined $cpu
ABCDresult
0XXX0
10XX0
110X0
11100
11111
424 3 return;
425 } elsif (exists $debtuple_to_debarch{"$abi-$libc-$os-$cpu"}) {
426 404 return $debtuple_to_debarch{"$abi-$libc-$os-$cpu"};
427 } else {
428 480 return;
429 }
430 }
431  
432 sub debarch_to_debtuple
433 47450 ▶{
Subroutine debarch_to_debtuple: called CC=5 SCAR=16.1
Pod undocumented
434 47450 my $arch = shift;
435  
436 47450 ▶ return if not defined $arch;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arch 2 47448 47450
437  
438 47448 _load_tupletable();
439  
440 47448 ▶ if ($arch =~ /^linux-([^-]*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arch =~ /^linux-([^-]*)/u) 7 47441 47448
441 # XXX: Might disappear in the future, not sure yet.
442 7 $arch = $1;
443 }
444  
445 47448 my $tuple = $debarch_to_debtuple{$arch};
446  
447 47448 ▶ if (defined($tuple)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tuple) { } 47428 20 47448
448 47428 my @tuple = split /-/, $tuple, 4;
449 47428 ▶ return @tuple if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 47425 3 47428
450 return {
451 3 abi => $tuple[0],
452 libc => $tuple[1],
453 os => $tuple[2],
454 cpu => $tuple[3],
455 };
456 } else {
457 20 return;
458 }
459 }
460  
461 =item $gnutriplet = debarch_to_gnutriplet($arch)
462  
463 Map a Debian architecture into a GNU triplet.
464  
465 =cut
466  
467 sub debarch_to_gnutriplet
468 2 ▶{
Subroutine debarch_to_gnutriplet: called CC=1 SCAR=0.0
Pod documented
469 2 my $arch = shift;
470  
471 2 return debtuple_to_gnutriplet(debarch_to_debtuple($arch));
472 }
473  
474 =item $arch = gnutriplet_to_debarch($gnutriplet)
475  
476 Map a GNU triplet into a Debian architecture.
477  
478 =cut
479  
480 sub gnutriplet_to_debarch
481 3 ▶{
Subroutine gnutriplet_to_debarch: called CC=1 SCAR=0.0
Pod documented
482 3 my $gnu = shift;
483  
484 3 return debtuple_to_debarch(gnutriplet_to_debtuple($gnu));
485 }
486  
487 sub debwildcard_to_debtuple
488 6617 ▶{
Subroutine debwildcard_to_debtuple: called CC=5 SCAR=16.1
Pod undocumented
489 6617 my $arch = shift;
490 6617 my @tuple = split /-/, $arch, 4;
491  
492 6617 ▶ if (any { $_ eq 'any' } @tuple) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { $_ eq 'any'; } , @tuple)) { } 6314 303 6617
493 6314 ▶ if (scalar @tuple == 4) {
Branch: 3 branches
BranchTrueFalseTotal
if (scalar @tuple == 4) { } 3922 2392 6314
elsif (scalar @tuple == 3) { } 1737 655 2392
elsif (scalar @tuple == 2) { } 654 1 655
494 3922 return @tuple;
495 } elsif (scalar @tuple == 3) {
496 1737 return ('any', @tuple);
497 } elsif (scalar @tuple == 2) {
498 654 return ('any', 'any', @tuple);
499 } else {
500 1 return ('any', 'any', 'any', 'any');
501 }
502 } else {
503 303 return debarch_to_debtuple($arch);
504 }
505 }
506  
507 sub debarch_to_abiattrs
508 41357 ▶{
Subroutine debarch_to_abiattrs: called CC=3 SCAR=11.0
Pod undocumented
509 41357 my $arch = shift;
510 41357 my ($abi, $libc, $os, $cpu) = debarch_to_debtuple($arch);
511  
512 41357 ▶ if (defined($cpu)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cpu) { } 41356 1 41357
513 41356 _load_abitable();
514  
515 41356 ▶ return ($abibits{$abi} // $cpubits{$cpu}, $cpuendian{$cpu});
Condition66%2/3
$abibits{$abi} // $cpubits{$cpu}
l!l&&r!l&&!r
1413550
MC/DC0%0/2
$abibits{$abi} // $cpubits{$cpu}
$abibits{$abi} $cpubits{$cpu}
Truth table66%2/3
A // B
A= $abibits{$abi}B= $cpubits{$cpu}
ABresult
1X1
011
000
516 } else {
517 1 return;
518 }
519 }
520  
521 sub debarch_to_cpubits
522 3 ▶{
Subroutine debarch_to_cpubits: called CC=2 SCAR=6.9
Pod undocumented
523 3 my $arch = shift;
524 3 my $cpu;
525  
526 3 ((undef) x 3, $cpu) = debarch_to_debtuple($arch);
527  
528 3 ▶ if (defined $cpu) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cpu) { } 2 1 3
529 2 return $cpubits{$cpu};
530 } else {
531 1 return;
532 }
533 }
534  
535 =item $bool = debarch_eq($arch_a, $arch_b)
536  
537 Evaluate the equality of a Debian architecture, by comparing with another
538 Debian architecture. No wildcard matching is performed.
539  
540 =cut
541  
542 sub debarch_eq
543 8 ▶{
Subroutine debarch_eq: called CC=7 SCAR=20.2
Pod documented
544 8 my ($a, $b) = @_;
545  
546 8 ▶ return 1 if ($a eq $b);
Branch: 1 branch
BranchTrueFalseTotal
if $a eq $b 2 6 8
547  
548 6 my @a = debarch_to_debtuple($a);
549 6 my @b = debarch_to_debtuple($b);
550  
551 6 ▶ return 0 if scalar @a != 4 or scalar @b != 4;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @a != 4 or scalar @b != 4 4 2 6
Condition100%3/3
scalar @a != 4 or scalar @b != 4
l!l&&r!l&&!r
222
MC/DC100%2/2
scalar @a != 4 or scalar @b != 4
scalar @a != 4 scalar @b != 4
Truth table100%3/3
A or B
A= scalar @a != 4B= scalar @b != 4
ABresult
1X1
011
000
552  
553 2 ▶ return $a[0] eq $b[0] && $a[1] eq $b[1] && $a[2] eq $b[2] && $a[3] eq $b[3];
Condition44%4/9
$a[0] eq $b[0] && $a[1] eq $b[1] && $a[2] eq $b[2] && $a[3] eq $b[3]
!ll&&!rl&&r
011
$a[0] eq $b[0] and $a[1] eq $b[1] and $a[2] eq $b[2]
!ll&&!rl&&r
002
$a[0] eq $b[0] and $a[1] eq $b[1]
!ll&&!rl&&r
002
MC/DC25%1/4
$a[0] eq $b[0] && $a[1] eq $b[1] && $a[2] eq $b[2] && $a[3] eq $b[3]
$a[0] eq $b[0] $a[1] eq $b[1] $a[2] eq $b[2] $a[3] eq $b[3]
Truth table40%2/5
A and B and C && D
A= $a[0] eq $b[0]B= $a[1] eq $b[1]C= $a[2] eq $b[2]D= $a[3] eq $b[3]
ABCDresult
0XXX0
10XX0
110X0
11100
11111
554 }
555  
556 =item $bool = debarch_is($arch, $arch_wildcard)
557  
558 Evaluate the identity of a Debian architecture, by matching with an
559 architecture wildcard.
560  
561 =cut
562  
563 sub debarch_is
564 5604 ▶{
Subroutine debarch_is: called CC=13 SCAR=25.9
Pod documented
565 5604 my ($real, $alias) = @_;
566  
567 5604 ▶ return 1 if ($alias eq $real or $alias eq 'any');
Branch: 1 branch
BranchTrueFalseTotal
if $alias eq $real or $alias eq "any" 274 5330 5604
Condition100%3/3
$alias eq $real or $alias eq "any"
l!l&&r!l&&!r
722025330
MC/DC100%2/2
$alias eq $real or $alias eq "any"
$alias eq $real $alias eq "any"
Truth table100%3/3
A or B
A= $alias eq $realB= $alias eq "any"
ABresult
1X1
011
000
568  
569 5330 my @real = debarch_to_debtuple($real);
570 5330 my @alias = debwildcard_to_debtuple($alias);
571  
572 5330 ▶ return 0 if scalar @real != 4 or scalar @alias != 4;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @real != 4 or scalar @alias != 4 4 5326 5330
Condition100%3/3
scalar @real != 4 or scalar @alias != 4
l!l&&r!l&&!r
225326
MC/DC100%2/2
scalar @real != 4 or scalar @alias != 4
scalar @real != 4 scalar @alias != 4
Truth table100%3/3
A or B
A= scalar @real != 4B= scalar @alias != 4
ABresult
1X1
011
000
573  
574 5326 ▶ if (($alias[0] eq $real[0] || $alias[0] eq 'any') &&
Branch: 1 branch
BranchTrueFalseTotal
if ($alias[0] eq $real[0] || $alias[0] eq "any" and $alias[1] eq $real[1] || $alias[1] eq "any" and $alias[2] eq $real[2] || $alias[2] eq "any" and $alias[3] eq $real[3] || $alias[3] eq "any") 5027 299 5326
Condition76%16/21
$alias[0] eq $real[0] || $alias[0] eq "any" and $alias[1] eq $real[1] || $alias[1] eq "any" and $alias[2] eq $real[2] || $alias[2] eq "any" and $alias[3] eq $real[3] || $alias[3] eq "any"
!ll&&!rl&&r
62935027
$alias[0] eq $real[0] || $alias[0] eq "any" and $alias[1] eq $real[1] || $alias[1] eq "any" and $alias[2] eq $real[2] || $alias[2] eq "any"
!ll&&!rl&&r
065320
$alias[0] eq $real[0] || $alias[0] eq "any" and $alias[1] eq $real[1] || $alias[1] eq "any"
!ll&&!rl&&r
005326
$alias[0] eq $real[0] or $alias[0] eq "any"
l!l&&r!l&&!r
170436220
$alias[1] eq $real[1] or $alias[1] eq "any"
l!l&&r!l&&!r
230730190
$alias[2] eq $real[2] or $alias[2] eq "any"
l!l&&r!l&&!r
250428166
$alias[3] eq $real[3] or $alias[3] eq "any"
l!l&&r!l&&!r
22122815293
MC/DC50%4/8
$alias[0] eq $real[0] || $alias[0] eq "any" and $alias[1] eq $real[1] || $alias[1] eq "any" and $alias[2] eq $real[2] || $alias[2] eq "any" and $alias[3] eq $real[3] || $alias[3] eq "any"
$alias[0] eq $real[0] $alias[0] eq "any" $alias[1] eq $real[1] $alias[1] eq "any" $alias[2] eq $real[2] $alias[2] eq "any" $alias[3] eq $real[3] $alias[3] eq "any"
Truth table61%19/31
A or B and C or D and E or F and G or H
A= $alias[0] eq $real[0]B= $alias[0] eq "any"C= $alias[1] eq $real[1]D= $alias[1] eq "any"E= $alias[2] eq $real[2]F= $alias[2] eq "any"G= $alias[3] eq $real[3]H= $alias[3] eq "any"
ABCDEFGHresult
00XXXXXX0
1X00XXXX0
0100XXXX0
1X1X00XX0
1X0100XX0
011X00XX0
010100XX0
1X1X1X000
1X1X01000
1X011X000
1X0101000
011X1X000
011X01000
01011X000
010101000
1X1X1X1X1
1X1X1X011
1X1X011X1
1X1X01011
1X011X1X1
1X011X011
1X01011X1
1X0101011
011X1X1X1
011X1X011
011X011X1
011X01011
01011X1X1
01011X011
0101011X1
010101011
575 ($alias[1] eq $real[1] || $alias[1] eq 'any') &&
576 ($alias[2] eq $real[2] || $alias[2] eq 'any') &&
577 ($alias[3] eq $real[3] || $alias[3] eq 'any')) {
578 5027 return 1;
579 }
580  
581 299 return 0;
582 }
583  
584 =item $bool = debarch_is_wildcard($arch)
585  
586 Evaluate whether a Debian architecture is an architecture wildcard.
587  
588 =cut
589  
590 sub debarch_is_wildcard
591 1288 ▶{
Subroutine debarch_is_wildcard: called CC=4 SCAR=13.9
Pod documented
592 1288 my $arch = shift;
593  
594 1288 ▶ return 0 if $arch eq 'all';
Branch: 1 branch
BranchTrueFalseTotal
if $arch eq "all" 1 1287 1288
595  
596 1287 my @tuple = debwildcard_to_debtuple($arch);
597  
598 1287 ▶ return 0 if scalar @tuple != 4;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @tuple != 4 3 1284 1287
599 1284 ▶ return 1 if any { $_ eq 'any' } @tuple;
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if &any(sub { $_ eq "any"; } , @tuple) 1283 1 1284
600 1 return 0;
601 }
602  
603 =item $bool = debarch_is_invalid($arch, %opts)
604  
605 Validate an architecture name.
606  
607 Options:
608  
609 =over
610  
611 =item B<positive>
612  
613 If set to a true value, only positive architectures will be accepted,
614 otherwise negated architectures are allowed.
615  
616 =back
617  
618 =cut
619  
620 sub debarch_is_invalid
621 30 ▶{
Subroutine debarch_is_invalid: called CC=2 SCAR=6.9
Pod documented
622 30 my ($arch, %opts) = @_;
623 30 my $arch_regex = qr/[a-zA-Z0-9][a-zA-Z0-9-]*/;
624  
625 30 ▶ if ($opts{positive}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{'positive'}) { } 5 25 30
626 5 return $arch !~ m/^$arch_regex$/;
627 } else {
628 25 return $arch !~ m/^!?$arch_regex$/;
629 }
630 }
631  
632 =item $bool = debarch_is_illegal($arch, %opts)
633  
634 This is a deprecated alias for L<debarch_is_invalid>.
635  
636 =cut
637  
638 sub debarch_is_illegal
639 0 ▶{
Subroutine debarch_is_illegal: not called CC=1 SCAR=6.9
Pod documented
640 0 my ($arch, %opts) = @_;
641  
642 0 warnings::warnif('deprecated',
643 'Dpkg::Arch::debarch_is_illegal() is deprecated, ' .
644 'use Dpkg::Arch::debarch_is_invalid() instead');
645 0 return debarch_is_invalid($arch, %opts);
646 }
647  
648 =item $bool = debarch_is_concerned($arch, @arches)
649  
650 Evaluate whether a Debian architecture applies to the list of architecture
651 restrictions, as usually found in dependencies inside square brackets.
652  
653 =cut
654  
655 sub debarch_is_concerned
656 175 ▶{
Subroutine debarch_is_concerned: called CC=5 SCAR=16.1
Pod documented
657 175 my ($host_arch, @arches) = @_;
658  
659 175 my $seen_arch = 0;
660 175 foreach my $arch (@arches) {
661 369 $arch = lc $arch;
662  
663 369 ▶ if ($arch =~ /^!/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($arch =~ /^!/u) { } 221 148 369
elsif (debarch_is($host_arch, $arch)) { } 28 120 148
664 221 my $not_arch = $arch;
665 221 $not_arch =~ s/^!//;
666  
667 221 ▶ if (debarch_is($host_arch, $not_arch)) {
Branch: 1 branch
BranchTrueFalseTotal
if (debarch_is($host_arch, $not_arch)) { } 44 177 221
668 44 $seen_arch = 0;
669 44 last;
670 } else {
671 # «!arch» includes by default all other arches
672 # unless they also appear in a «!otherarch».
673 177 $seen_arch = 1;
674 }
675 } elsif (debarch_is($host_arch, $arch)) {
676 28 $seen_arch = 1;
677 28 last;
678 }
679 }
680 175 return $seen_arch;
681 }
682  
683 =item @array = debarch_list_parse($arch_list, %opts)
684  
685 Parse an architecture list.
686  
687 Options:
688  
689 =over
690  
691 =item B<positive>
692  
693 If set to a true value, only positive architectures will be accepted,
694 otherwise negated architectures are allowed.
695  
696 =back
697  
698 =cut
699  
700 sub debarch_list_parse
701 14 ▶{
Subroutine debarch_list_parse: called CC=3 SCAR=11.0
Pod documented
702 14 my ($arch_list, %opts) = @_;
703 14 my @arch_list = split ' ', $arch_list;
704  
705 14 foreach my $arch (@arch_list) {
706 22 ▶ if (debarch_is_invalid($arch, %opts)) {
Branch: 1 branch
BranchTrueFalseTotal
if (debarch_is_invalid($arch, %opts)) 2 20 22
707 2 error(g_("'%s' is not a valid architecture in list '%s'"),
708 $arch, $arch_list);
709 }
710 }
711  
712 12 return @arch_list;
713 }
714  
715 15 1;
716  
717 =back
718  
719 =head1 CHANGES
720  
721 =head2 Version 1.04 (dpkg 1.23.0)
722  
723 New functions: debarch_is_invalid().
724  
725 Deprecated functions: debarch_is_illegal().
726  
727 =head2 Version 1.03 (dpkg 1.19.1)
728  
729 New argument: Accept a "positive" option in debarch_is_illegal() and
730 debarch_list_parse().
731  
732 =head2 Version 1.02 (dpkg 1.18.19)
733  
734 New import tags: ":all", ":getters", ":parsers", ":mappers", ":operators".
735  
736 =head2 Version 1.01 (dpkg 1.18.5)
737  
738 New functions: debarch_is_illegal(), debarch_list_parse().
739  
740 =head2 Version 1.00 (dpkg 1.18.2)
741  
742 Mark the module as public.
743  
744 =head1 SEE ALSO
745  
746 L<dpkg-architecture(1)>.
« Dpkg/Changelog/Entry.pm ↑ Summary Dpkg/Getopt.pm »