Package: debhelper
Version: 9.20140817
Severity: wishlist
Tags: patch

Dear debhelper maintainers,

the syntax for the Build-Profiles field was changed during the bootstrap
sprint in paris [1,2]. I wanted to file my patch for debhelper once dpkg
with the new syntax was released but since that release did not happen
during the past month and at the same time the freeze draws dangerously
close, I decided to file this bug with the patch anyways.

In contrast to apt, it is (as far as I know) not necessary that
debhelper in Jessie understands the syntax though. Only the tools which
are directly invoked by the buildd machinery must be able to understand
build profiles.

Nevertheless, in case you do another release before the freeze, consider
the attached patch. Maybe you want to wait until dpkg implements the new
syntax for better testing [3].

Otherwise, maybe you should remove the existing support for the old
build profile syntax because it is not compatible with what will end up
in dpkg and apt in Jessie.

Thanks a lot and sorry for the confusion and late submission.

cheers, josch

[1] https://wiki.debian.org/Sprints/2014/BootstrapSprint
[2] https://wiki.debian.org/BuildProfileSpec
[3] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760158
>From 2ef1b6bf001a9f847c2a25efe36682e496f92af9 Mon Sep 17 00:00:00 2001
From: josch <[email protected]>
Date: Mon, 1 Sep 2014 12:35:39 +0200
Subject: [PATCH] new build profile syntax

---
 Debian/Debhelper/Dh_Lib.pm | 59 +++++++++++++++++++++++++---------------------
 1 file changed, 32 insertions(+), 27 deletions(-)

diff --git a/Debian/Debhelper/Dh_Lib.pm b/Debian/Debhelper/Dh_Lib.pm
index 6a79c9c..27c9f99 100644
--- a/Debian/Debhelper/Dh_Lib.pm
+++ b/Debian/Debhelper/Dh_Lib.pm
@@ -767,39 +767,44 @@ sub buildos {
 # Passed a list of profiles to match against, returns true if
 # DEB_BUILD_PROFILES environment variable matched
 sub buildprofilesmatch {
-	my %debbuildprofiles = ();
-	if (exists $ENV{'DEB_BUILD_PROFILES'}) {
-		foreach my $profile (split(/\s+/, $ENV{'DEB_BUILD_PROFILES'})) {
-			$debbuildprofiles{$profile} = 1;
-		}
-	}
-
 	my $packageprofilesstr = shift;
 	my $package = shift;
-	my @packageprofiles = split(/\s+/, $packageprofilesstr);
-	my $err = sub { error("Build-Profiles field for package $package contains both positive and negative entries"); };
-	if ($#packageprofiles < 0 || $packageprofiles[0] =~ /^!/) {
-		# package profiles list is negative or empty
-		foreach my $packageprofile (@packageprofiles) {
-			$packageprofile =~ /^!(.*)$/ || &{$err}();
-			if ($debbuildprofiles{$1}) {
-				return 0;
-			}
-		}
-		return 1;
-	}
-	else {
-		# package profiles list is positive
-		foreach my $packageprofile (@packageprofiles) {
-			if ($packageprofile =~ /^!/) {
-				&{$err}();
+
+	return 1 if $packageprofilesstr eq "";
+
+	my @debbuildprofiles = split(/\s+/, $ENV{'DEB_BUILD_PROFILES'};
+
+	$packageprofilesstr =~ s/^\s*<(.*)>\s*$/$1/;
+	$formula = [ map { [ split /\s+/, $_ ] } split />\s+</, $packageprofilesstr ];
+
+	# the following code is from the function evaluate_restriction_formula in
+	# Dpkg::BuildProfiles
+
+	# restriction formulas are in disjunctive normal form:
+	# (foo AND bar) OR (blub AND bla)
+	foreach my $restrlist (@{$formula}) {
+		my $seen_profile = 1;
+		foreach my $restriction (@$restrlist) {
+			my ($neg, $prof) = $restriction =~ m/^(!)?(.*)/;
+			my $found = 0;
+			foreach (@debbuildprofiles) {
+				if ($_ eq $prof) {
+					$found = 1;
+					last;
+				}
 			}
-			if ($debbuildprofiles{$packageprofile}) {
-				return 1;
+			# if a negative set profile is encountered, stop processing
+			# if a positive unset profile is encountered, stop processing
+			if (not ($found xor defined $neg)) {
+				$seen_profile = 0;
+				last;
 			}
 		}
-		return 0;
+		# this conjunction evaluated to true so we don't have to evaluate the
+		# others
+		return 1 if $seen_profile;
 	}
+	return 0;
 }
 
 # Returns source package name
-- 
2.0.1

Reply via email to