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/>.
17 package Dpkg
::Build
::Types
;
22 our $VERSION = '0.02';
35 set_build_type_from_options
36 get_build_options_from_type
39 use Exporter
qw(import
);
42 use Dpkg
::ErrorHandling
;
48 Dpkg::Build::Types - track build types
52 The Dpkg::Build::Types module is used by various tools to track and decide
53 what artifacts need to be built.
55 The build types are bit constants that are exported by default. Multiple
64 This build is the default.
68 This build includes source artifacts.
72 This build includes architecture dependent binary artifacts.
74 =item BUILD_ARCH_INDEP
76 This build includes architecture independent binary artifacts.
80 This build includes binary artifacts.
84 This build includes source and binary artifacts.
93 BUILD_ARCH_INDEP
=> 8,
97 use constant BUILD_BINARY
=> BUILD_ARCH_DEP
| BUILD_ARCH_INDEP
;
98 use constant BUILD_FULL
=> BUILD_BINARY
| BUILD_SOURCE
;
100 my $current_type = BUILD_FULL
| BUILD_DEFAULT
;
101 my $current_option = undef;
103 my @build_types = qw(full source binary any all
);
106 source
=> BUILD_SOURCE
,
107 binary
=> BUILD_BINARY
,
108 any
=> BUILD_ARCH_DEP
,
109 all
=> BUILD_ARCH_INDEP
,
118 =item build_has_any($bits)
120 Return a boolean indicating whether the current build type has any of the
129 return $current_type & $bits;
132 =item build_has_all($bits)
134 Return a boolean indicating whether the current build type has all the
143 return ($current_type & $bits) == $bits;
146 =item build_has_none($bits)
148 Return a boolean indicating whether the current build type has none of the
157 return !($current_type & $bits);
160 =item build_is($bits)
162 Return a boolean indicating whether the current build type is the specified
171 return $current_type == $bits;
174 =item set_build_type($build_type, $build_option, %opts)
176 Set the current build type to $build_type, which was specified via the
177 $build_option command-line option.
179 The function will check and abort on incompatible build type assignments,
180 this behavior can be disabled by using the boolean option "nocheck".
186 my ($build_type, $build_option, %opts) = @_;
188 usageerr
(g_
('cannot combine %s and %s'), $current_option, $build_option)
189 if not $opts{nocheck
} and
190 build_has_none
(BUILD_DEFAULT
) and $current_type != $build_type;
192 $current_type = $build_type;
193 $current_option = $build_option;
196 =item set_build_type_from_options($build_type, $build_option, %opts)
198 Set the current build type from a list of build type components.
200 The function will check and abort on incompatible build type assignments,
201 this behavior can be disabled by using the boolean option "nocheck".
205 sub set_build_type_from_options
207 my ($build_parts, $build_option, %opts) = @_;
210 foreach my $type (split /,/, $build_parts) {
211 usageerr
(g_
('unknown build type %s'), $type)
212 unless exists $build_types{$type};
213 $build_type |= $build_types{$type};
216 set_build_type
($build_type, $build_option, %opts);
219 =item get_build_options_from_type()
221 Get the current build type as a set of comma-separated string options.
225 sub get_build_options_from_type
227 my $local_type = $current_type;
230 foreach my $type (@build_types) {
231 my $part_bits = $build_types{$type};
232 if (($local_type & $part_bits) == $part_bits) {
234 $local_type &= ~$part_bits;
238 return join ',', @parts;
247 This is a private module.