1 # Copyright © 2013 Guillem Jover <guillem@debian.org>
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.
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.
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/>.
20 Dpkg::BuildProfiles - handle build profiles
24 The Dpkg::BuildProfiles module provides functions to handle the build
29 package Dpkg
::BuildProfiles
1.00;
38 evaluate_restriction_formula
41 use Exporter
qw(import);
42 use List
::Util
qw(any);
53 =item @profiles = get_build_profiles()
55 Get an array with the currently active build profiles, taken from
56 the environment variable B<DEB_BUILD_PROFILES>.
60 sub get_build_profiles
{
61 return @build_profiles if $cache_profiles;
63 if (Dpkg
::BuildEnv
::has
('DEB_BUILD_PROFILES')) {
64 @build_profiles = split ' ', Dpkg
::BuildEnv
::get
('DEB_BUILD_PROFILES');
68 return @build_profiles;
71 =item set_build_profiles(@profiles)
73 Set C<@profiles> as the current active build profiles, by setting
74 the environment variable B<DEB_BUILD_PROFILES>.
78 sub set_build_profiles
{
82 @build_profiles = @profiles;
83 Dpkg
::BuildEnv
::set
('DEB_BUILD_PROFILES', join ' ', @profiles);
86 =item @profiles = parse_build_profiles($string)
88 Parses a build profiles specification, into an array of array references.
92 sub parse_build_profiles
{
95 $string =~ s/^\s*<\s*(.*)\s*>\s*$/$1/;
97 return map { [ split ' ' ] } split /\s*>\s+<\s*/, $string;
100 =item evaluate_restriction_formula(\@formula, \@profiles)
102 Evaluate whether a restriction formula of the form "<foo bar> <baz>", given as
103 a nested array, is true or false, given the array of enabled build profiles.
107 sub evaluate_restriction_formula
{
108 my ($formula, $profiles) = @_;
110 # Restriction formulas are in disjunctive normal form:
111 # (foo AND bar) OR (blub AND bla)
112 foreach my $restrlist (@
{$formula}) {
113 my $seen_profile = 1;
115 foreach my $restriction (@
$restrlist) {
116 next if $restriction !~ m/^(!)?(.+)/;
118 ## no critic (RegularExpressions::ProhibitCaptureWithoutTest)
119 my $negated = defined $1 && $1 eq '!';
121 my $found = any
{ $_ eq $profile } @
{$profiles};
123 # If a negative set profile is encountered, stop processing.
124 # If a positive unset profile is encountered, stop processing.
125 if ($found == $negated) {
131 # This conjunction evaluated to true so we don't have to evaluate
133 return 1 if $seen_profile;
142 =head2 Version 1.00 (dpkg 1.17.17)
144 Mark the module as public.