Dpkg/BuildAPI.pm

filter: Statementstmt 96.2% 51 / 53 Branchbran 83.3% 15 / 18 Conditioncond 72.7% 8 / 11 MC/DCmcdc 57.1% 4 / 7 Subroutinesub 100% 11 / 11 Podpod 100% 2 / 2 totaltotal 89.2% 91 / 102 CC 14 SCAR 16.8
CC
14
Cov
90%
get_build_api
9.2
__ANON__
6.0
BEGIN
1.0
CRAP 5.4
« Dpkg/ErrorHandling.pm ↑ Summary Dpkg/Substvars.pm »
1 # Copyright © 2020-2022 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::BuildAPI - handle build API versions
21  
22 =head1 DESCRIPTION
23  
24 The Dpkg::BuildAPI module provides functions to fetch the current dpkg
25 build API level.
26  
27 B<Note>: This is a private module, its API can change at any time.
28  
29 =cut
30  
31 package Dpkg::BuildAPI 0.01;
32  
33 3 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 3 our @EXPORT_OK = qw(
36 get_build_api
37 reset_build_api
38 );
39  
40 3 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 3 ▶use Dpkg::Gettext;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 3 ▶use Dpkg::ErrorHandling;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 3 ▶use Dpkg::BuildEnv;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 3 ▶use Dpkg::Version;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 3 ▶use Dpkg::Deps;
Subroutine BEGIN: called CC=1 SCAR=0.0
47  
48 3 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
49 3 DEFAULT_BUILD_API => '0',
50 MAX_BUILD_API => '1',
51 3 };
52  
53 3 my $build_api;
54  
55 =head1 FUNCTIONS
56  
57 =over 4
58  
59 =item $level = get_build_api([$ctrl])
60  
61 Get the build API level, from the environment variable B<DPKG_BUILD_API>,
62 or if not defined and a $ctrl L<Dpkg::Control::Info> object passed as an
63 argument, from its build dependency fields. If no $ctrl object gets passed
64 the previous value obtained is returned.
65  
66 =cut
67  
68 11 ▶sub get_build_api {
Subroutine get_build_api: called CC=9 SCAR=22.2
Pod documented
69 11 my $ctrl = shift;
70  
71 11 ▶ return $build_api if defined $build_api && ! defined $ctrl;
Branch: 1 branch
BranchTrueFalseTotal
if defined $build_api and not defined $ctrl 0 11 11
Condition33%1/3
defined $build_api and not defined $ctrl
!ll&&!rl&&r
1100
MC/DC0%0/2
defined $build_api and not defined $ctrl
defined $build_api not defined $ctrl
Truth table33%1/3
A and not(B)
A= defined $build_apiB= not defined $ctrl
ABresult
0X0
100
111
72  
73 11 ▶ if (Dpkg::BuildEnv::has('DPKG_BUILD_API')) {
Branch: 2 branches
BranchTrueFalseTotal
if (Dpkg::BuildEnv::has('DPKG_BUILD_API')) { } 2 9 11
elsif (defined $ctrl) { } 7 2 9
74 2 $build_api = Dpkg::BuildEnv::get('DPKG_BUILD_API');
75 } elsif (defined $ctrl) {
76 7 my $src = $ctrl->get_source();
77 my @dep_list = deps_concat(map {
78 7 $src->{$_ }
79 } qw(Build-Depends Build-Depends-Indep Build-Depends-Arch));
80  
81 7 my $deps = deps_parse(@dep_list,
82 build_dep => 1,
83 reduce_restrictions => 1,
84 );
85  
86 7 ▶ if (not defined $deps) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $deps) 0 7 7
87 0 $build_api = DEFAULT_BUILD_API;
88 0 return $build_api;
89 }
90  
91 7 ▶ deps_iterate($deps, sub {
Subroutine __ANON__: called CC=6 SCAR=18.0
92 7 my $dep = shift;
93  
94 7 ▶ return 1 if $dep->{package} ne 'dpkg-build-api';
Branch: 1 branch
BranchTrueFalseTotal
if $dep->{"package"} ne "dpkg-build-api" 0 7 7
95  
96 7 ▶ if (! defined $dep->{relation} || $dep->{relation} ne REL_EQ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $dep->{"relation"} or $dep->{"relation"} ne "=") 2 5 7
Condition100%3/3
not defined $dep->{"relation"} or $dep->{"relation"} ne "="
l!l&&r!l&&!r
115
MC/DC100%2/2
not defined $dep->{"relation"} or $dep->{"relation"} ne "="
not defined $dep->{"relation"} $dep->{"relation"} ne "="
Truth table100%3/3
not(A) or B
A= not defined $dep->{"relation"}B= $dep->{"relation"} ne "="
ABresult
1X1
011
000
97 2 error(g_('dpkg build API level needs an exact version'));
98 }
99  
100 5 ▶ if (defined $build_api and $build_api ne $dep->{version}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $build_api and $build_api ne $dep->{"version"}) 1 4 5
Condition66%2/3
defined $build_api and $build_api ne $dep->{"version"}
!ll&&!rl&&r
401
MC/DC50%1/2
defined $build_api and $build_api ne $dep->{"version"}
defined $build_api $build_api ne $dep->{"version"}
Truth table66%2/3
A and B
A= defined $build_apiB= $build_api ne $dep->{"version"}
ABresult
0X0
100
111
101 error(g_('dpkg build API level with conflicting versions: %s vs %s'),
102 1 $build_api, $dep->{version});
103 }
104  
105 4 $build_api = $dep->{version};
106  
107 4 return 1;
108 7 });
109 }
110  
111 8 ▶ $build_api //= DEFAULT_BUILD_API;
Condition100%2/2
$build_api //= 0
l!l
53
MC/DC100%1/1
$build_api //= 0
$build_api
Truth table100%2/2
A
A= $build_api
Aresult
11
00
112  
113 8 ▶ if ($build_api !~ m/^[0-9]+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($build_api =~ /^[0-9]+$/u) 2 6 8
114 2 error(g_("invalid dpkg build API level '%s'"), $build_api);
115 }
116  
117 6 ▶ if ($build_api > MAX_BUILD_API) {
Branch: 1 branch
BranchTrueFalseTotal
if ($build_api > 1) 2 4 6
118 2 error(g_("dpkg build API level '%s' greater than max '%s'"),
119 $build_api, MAX_BUILD_API);
120 }
121  
122 4 return $build_api;
123 }
124  
125 =item reset_build_api()
126  
127 Reset the cached build API level.
128  
129 =cut
130  
131 9 ▶sub reset_build_api {
Subroutine reset_build_api: called CC=1 SCAR=0.0
Pod documented
132 9 $build_api = undef;
133 }
134  
135 =back
136  
137 =head1 CHANGES
138  
139 =head2 Version 0.xx
140  
141 This is a private module.
142  
143 =cut
144  
145 3 1;
« Dpkg/ErrorHandling.pm ↑ Summary Dpkg/Substvars.pm »