Dpkg/BuildTypes.pm

filter: Statementstmt 100% 58 / 58 Branchbran 66.6% 4 / 6 Conditioncond 50.0% 4 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 15 / 15 Podpod 100% 8 / 8 totaltotal 89.9% 89 / 99 CC 10 SCAR 8.6
CC
10
Cov
92%
set_build_type
4.6
set_build_type_from_targets
3.0
set_build_type_from_options
3.0
CRAP 2.4
« Dpkg/Email/Address.pm ↑ Summary Dpkg/Control/Tests/Entry.pm »
1 # Copyright © 2007 Frank Lichtenheld <djpig@debian.org>
2 # Copyright © 2010, 2013-2016 Guillem Jover <guillem@debian.org>
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
16  
17 =encoding utf8
18  
19 =head1 NAME
20  
21 Dpkg::BuildTypes - track build types
22  
23 =head1 DESCRIPTION
24  
25 The Dpkg::BuildTypes module is used by various tools to track and decide
26 what artifacts need to be built.
27  
28 The build types are bit constants that are exported by default. Multiple
29 types can be ORed.
30  
31 B<Note>: This is a private module, its API can change at any time.
32  
33 =cut
34  
35 package Dpkg::BuildTypes 0.02;
36  
37 1 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 1 our @EXPORT = qw(
40 BUILD_DEFAULT
41 BUILD_SOURCE
42 BUILD_ARCH_DEP
43 BUILD_ARCH_INDEP
44 BUILD_BINARY
45 BUILD_FULL
46 build_has_any
47 build_has_all
48 build_has_none
49 build_is
50 set_build_type
51 set_build_type_from_options
52 set_build_type_from_targets
53 get_build_options_from_type
54 );
55  
56 1 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
57  
58 1 ▶use Dpkg::Gettext;
Subroutine BEGIN: called CC=1 SCAR=0.0
59 1 ▶use Dpkg::ErrorHandling;
Subroutine BEGIN: called CC=1 SCAR=0.0
60  
61 =head1 CONSTANTS
62  
63 =over 4
64  
65 =item BUILD_DEFAULT
66  
67 This build is the default.
68  
69 =item BUILD_SOURCE
70  
71 This build includes source artifacts.
72  
73 =item BUILD_ARCH_DEP
74  
75 This build includes architecture dependent binary artifacts.
76  
77 =item BUILD_ARCH_INDEP
78  
79 This build includes architecture independent binary artifacts.
80  
81 =item BUILD_BINARY
82  
83 This build includes binary artifacts.
84  
85 =item BUILD_FULL
86  
87 This build includes source and binary artifacts.
88  
89 =cut
90  
91 # Simple types.
92 1 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
93 1 BUILD_DEFAULT => 1,
94 BUILD_SOURCE => 2,
95 BUILD_ARCH_DEP => 4,
96 BUILD_ARCH_INDEP => 8,
97 1 };
98  
99 # Composed types.
100 1 ▶use constant BUILD_BINARY => BUILD_ARCH_DEP | BUILD_ARCH_INDEP;
Subroutine BEGIN: called CC=1 SCAR=0.0
101 1 ▶use constant BUILD_FULL => BUILD_BINARY | BUILD_SOURCE;
Subroutine BEGIN: called CC=1 SCAR=0.0
102  
103 1 my $current_type = BUILD_FULL | BUILD_DEFAULT;
104 1 my $current_option = undef;
105  
106 1 my @build_types = qw(full source binary any all);
107 1 my %build_types = (
108 full => BUILD_FULL,
109 source => BUILD_SOURCE,
110 binary => BUILD_BINARY,
111 any => BUILD_ARCH_DEP,
112 all => BUILD_ARCH_INDEP,
113 );
114 1 my %build_targets = (
115 'clean' => BUILD_SOURCE,
116 'build' => BUILD_BINARY,
117 'build-arch' => BUILD_ARCH_DEP,
118 'build-indep' => BUILD_ARCH_INDEP,
119 'binary' => BUILD_BINARY,
120 'binary-arch' => BUILD_ARCH_DEP,
121 'binary-indep' => BUILD_ARCH_INDEP,
122 );
123  
124 =back
125  
126 =head1 FUNCTIONS
127  
128 =over 4
129  
130 =item $bool = build_has_any($bits)
131  
132 Return a boolean indicating whether the current build type has any of the
133 specified $bits.
134  
135 =cut
136  
137 sub build_has_any
138 7 ▶{
Subroutine build_has_any: called CC=1 SCAR=0.0
Pod documented
139 7 my ($bits) = @_;
140  
141 7 return $current_type & $bits;
142 }
143  
144 =item $bool = build_has_all($bits)
145  
146 Return a boolean indicating whether the current build type has all the
147 specified $bits.
148  
149 =cut
150  
151 sub build_has_all
152 8 ▶{
Subroutine build_has_all: called CC=1 SCAR=0.0
Pod documented
153 8 my ($bits) = @_;
154  
155 8 return ($current_type & $bits) == $bits;
156 }
157  
158 =item $bool = build_has_none($bits)
159  
160 Return a boolean indicating whether the current build type has none of the
161 specified $bits.
162  
163 =cut
164  
165 sub build_has_none
166 7 ▶{
Subroutine build_has_none: called CC=1 SCAR=0.0
Pod documented
167 7 my ($bits) = @_;
168  
169 7 return ! ($current_type & $bits);
170 }
171  
172 =item $bool = build_is($bits)
173  
174 Return a boolean indicating whether the current build type is the specified
175 set of $bits.
176  
177 =cut
178  
179 sub build_is
180 11 ▶{
Subroutine build_is: called CC=1 SCAR=0.0
Pod documented
181 11 my ($bits) = @_;
182  
183 11 return $current_type == $bits;
184 }
185  
186 =item set_build_type($build_type, $build_option, %opts)
187  
188 Set the current build type to $build_type, which was specified via the
189 $build_option command-line option.
190  
191 The function will check and abort on incompatible build type assignments,
192 this behavior can be disabled by using the boolean option "no_check".
193  
194 =cut
195  
196 sub set_build_type
197 10 ▶{
Subroutine set_build_type: called CC=4 SCAR=15.2
Pod documented
198 10 my ($build_type, $build_option, %opts) = @_;
199  
200 usageerr(g_('cannot combine %s and %s'), $current_option, $build_option)
201 if not $opts{no_check} and
202 10 ▶ build_has_none(BUILD_DEFAULT) and $current_type != $build_type;
Branch: 1 branch
BranchTrueFalseTotal
if not $opts{"no_check"} and build_has_none(1) and $current_type != $build_type 0 10 10
Condition50%3/6
not $opts{"no_check"} and build_has_none(1) and $current_type != $build_type
!ll&&!rl&&r
1000
not $opts{"no_check"} and build_has_none(1)
!ll&&!rl&&r
820
MC/DC0%0/3
not $opts{"no_check"} and build_has_none(1) and $current_type != $build_type
not $opts{"no_check"} build_has_none(1) $current_type != $build_type
Truth table50%2/4
not(A) and B and C
A= not $opts{"no_check"}B= build_has_none(1)C= $current_type != $build_type
ABCresult
0XX0
10X0
1100
1111
203  
204 10 $current_type = $build_type;
205 10 $current_option = $build_option;
206 }
207  
208 =item set_build_type_from_options($build_types, $build_option, %opts)
209  
210 Set the current build type from a list of comma-separated build type
211 components.
212  
213 The function will check and abort on incompatible build type assignments,
214 this behavior can be disabled by using the boolean option "no_check".
215  
216 =cut
217  
218 sub set_build_type_from_options
219 3 ▶{
Subroutine set_build_type_from_options: called CC=3 SCAR=11.0
Pod documented
220 3 my ($build_parts, $build_option, %opts) = @_;
221  
222 3 my $build_type = 0;
223 3 foreach my $type (split /,/, $build_parts) {
224 usageerr(g_('unknown build type %s'), $type)
225 5 ▶ unless exists $build_types{$type};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $build_types{$type} 0 5 5
226 5 $build_type |= $build_types{$type};
227 }
228  
229 3 set_build_type($build_type, $build_option, %opts);
230 }
231  
232 =item set_build_type_from_targets($build_targets, $build_option, %opts)
233  
234 Set the current build type from a list of comma-separated build target
235 components.
236  
237 The function will check and abort on incompatible build type assignments,
238 this behavior can be disabled by using the boolean option "no_check".
239  
240 =cut
241  
242 sub set_build_type_from_targets
243 3 ▶{
Subroutine set_build_type_from_targets: called CC=3 SCAR=11.1
Pod documented
244 3 my ($build_targets, $build_option, %opts) = @_;
245  
246 3 my $build_type = 0;
247 3 foreach my $target (split /,/, $build_targets) {
248 5 ▶ $build_type |= $build_targets{$target} // BUILD_BINARY;
Condition50%1/2
$build_targets{$target} // 12
l!l
50
MC/DC0%0/1
$build_targets{$target} // 12
$build_targets{$target}
Truth table50%1/2
A
A= $build_targets{$target}
Aresult
11
00
249 }
250  
251 3 set_build_type($build_type, $build_option, %opts);
252 }
253  
254 =item $string = get_build_options_from_type()
255  
256 Get the current build type as a set of comma-separated string options.
257  
258 =cut
259  
260 sub get_build_options_from_type
261 7 ▶{
Subroutine get_build_options_from_type: called CC=3 SCAR=11.0
Pod documented
262 7 my $local_type = $current_type;
263  
264 7 my @parts;
265 7 foreach my $type (@build_types) {
266 35 my $part_bits = $build_types{$type};
267 35 ▶ if (($local_type & $part_bits) == $part_bits) {
Branch: 1 branch
BranchTrueFalseTotal
if (($local_type & $part_bits) == $part_bits) 8 27 35
268 8 push @parts, $type;
269 8 $local_type &= ~$part_bits;
270 }
271 }
272  
273 7 return join ',', @parts;
274 }
275  
276 =back
277  
278 =head1 CHANGES
279  
280 =head2 Version 0.xx
281  
282 This is a private module.
283  
284 =cut
285  
286 1 1;
« Dpkg/Email/Address.pm ↑ Summary Dpkg/Control/Tests/Entry.pm »