1 # Copyright © 2007 Frank Lichtenheld <djpig@debian.org>
2 # Copyright © 2010, 2013-2016 Guillem Jover <guillem@debian.org>
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.
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.
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/>.
21 Dpkg::BuildTypes - track build types
25 The Dpkg::BuildTypes module is used by various tools to track and decide
26 what artifacts need to be built.
28 The build types are bit constants that are exported by default. Multiple
31 B<Note>: This is a private module, its API can change at any time.
35 package Dpkg
::BuildTypes
0.02;
52 set_build_type_from_options
53 set_build_type_from_targets
54 get_build_options_from_type
57 use Exporter
qw(import);
60 use Dpkg
::ErrorHandling
;
68 This build is the default.
72 This build includes source artifacts.
76 This build includes architecture dependent binary artifacts.
78 =item BUILD_ARCH_INDEP
80 This build includes architecture independent binary artifacts.
84 This build includes binary artifacts.
88 This build includes source and binary artifacts.
97 BUILD_ARCH_INDEP
=> 8,
101 use constant BUILD_BINARY
=> BUILD_ARCH_DEP
| BUILD_ARCH_INDEP
;
102 use constant BUILD_FULL
=> BUILD_BINARY
| BUILD_SOURCE
;
104 my $current_type = BUILD_FULL
| BUILD_DEFAULT
;
105 my $current_option = undef;
107 my @build_types = qw(full source binary any all);
110 source
=> BUILD_SOURCE
,
111 binary
=> BUILD_BINARY
,
112 any
=> BUILD_ARCH_DEP
,
113 all
=> BUILD_ARCH_INDEP
,
115 my %build_targets = (
116 'clean' => BUILD_SOURCE
,
117 'build' => BUILD_BINARY
,
118 'build-arch' => BUILD_ARCH_DEP
,
119 'build-indep' => BUILD_ARCH_INDEP
,
120 'binary' => BUILD_BINARY
,
121 'binary-arch' => BUILD_ARCH_DEP
,
122 'binary-indep' => BUILD_ARCH_INDEP
,
131 =item build_has_any($bits)
133 Return a boolean indicating whether the current build type has any of the
142 return $current_type & $bits;
145 =item build_has_all($bits)
147 Return a boolean indicating whether the current build type has all the
156 return ($current_type & $bits) == $bits;
159 =item build_has_none($bits)
161 Return a boolean indicating whether the current build type has none of the
170 return !($current_type & $bits);
173 =item build_is($bits)
175 Return a boolean indicating whether the current build type is the specified
184 return $current_type == $bits;
187 =item set_build_type($build_type, $build_option, %opts)
189 Set the current build type to $build_type, which was specified via the
190 $build_option command-line option.
192 The function will check and abort on incompatible build type assignments,
193 this behavior can be disabled by using the boolean option "nocheck".
199 my ($build_type, $build_option, %opts) = @_;
201 usageerr
(g_
('cannot combine %s and %s'), $current_option, $build_option)
202 if not $opts{nocheck
} and
203 build_has_none
(BUILD_DEFAULT
) and $current_type != $build_type;
205 $current_type = $build_type;
206 $current_option = $build_option;
209 =item set_build_type_from_options($build_types, $build_option, %opts)
211 Set the current build type from a list of comma-separated build type
214 The function will check and abort on incompatible build type assignments,
215 this behavior can be disabled by using the boolean option "nocheck".
219 sub set_build_type_from_options
221 my ($build_parts, $build_option, %opts) = @_;
224 foreach my $type (split /,/, $build_parts) {
225 usageerr
(g_
('unknown build type %s'), $type)
226 unless exists $build_types{$type};
227 $build_type |= $build_types{$type};
230 set_build_type
($build_type, $build_option, %opts);
233 =item set_build_type_from_targets($build_targets, $build_option, %opts)
235 Set the current build type from a list of comma-separated build target
238 The function will check and abort on incompatible build type assignments,
239 this behavior can be disabled by using the boolean option "nocheck".
243 sub set_build_type_from_targets
245 my ($build_targets, $build_option, %opts) = @_;
248 foreach my $target (split /,/, $build_targets) {
249 $build_type |= $build_targets{$target} // BUILD_BINARY
;
252 set_build_type
($build_type, $build_option, %opts);
255 =item get_build_options_from_type()
257 Get the current build type as a set of comma-separated string options.
261 sub get_build_options_from_type
263 my $local_type = $current_type;
266 foreach my $type (@build_types) {
267 my $part_bits = $build_types{$type};
268 if (($local_type & $part_bits) == $part_bits) {
270 $local_type &= ~$part_bits;
274 return join ',', @parts;
283 This is a private module.