Initial implementation of support for Build-Profiles fields. Thanks, Daniel Schepler.
authorJoey Hess <joey@kitenet.net>
Wed, 12 Feb 2014 17:13:02 +0000 (13:13 -0400)
committerJoey Hess <joey@kitenet.net>
Wed, 12 Feb 2014 17:13:02 +0000 (13:13 -0400)
Debian/Debhelper/Dh_Lib.pm
debhelper.pod
debian/changelog

index 7120a70..377454e 100644 (file)
@@ -761,6 +761,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}();
+                       }
+                       if ($debbuildprofiles{$packageprofile}) {
+                               return 1;
+                       }
+               }
+               return 0;
+       }
+}
+
 # Returns source package name
 sub sourcepackage {
        open (CONTROL, 'debian/control') ||
@@ -785,18 +823,20 @@ sub sourcepackage {
 # packages.
 # As a side effect, populates %package_arches and %package_types with the
 # types of all packages (not only those returned).
-my (%package_types, %package_arches);
+my (%package_types, %package_arches, %package_profiles);
 sub getpackages {
        my $type=shift;
 
        %package_types=();
        %package_arches=();
+       %package_profiles=();
        
        $type="" if ! defined $type;
 
        my $package="";
        my $arch="";
        my $package_type;
+       my $build_profiles;
        my @list=();
        my %seen;
        open (CONTROL, 'debian/control') ||
@@ -814,6 +854,7 @@ sub getpackages {
                                error("debian/control has a duplicate entry for $package");
                        }
                        $package_type="deb";
+                       $build_profiles="";
                }
                if (/^Architecture:\s*(.*)/) {
                        $arch=$1;
@@ -821,11 +862,15 @@ sub getpackages {
                if (/^(?:X[BC]*-)?Package-Type:\s*(.*)/) {
                        $package_type=$1;
                }
-               
+               if (/^Build-Profiles:\s*(.*)/) {
+                       $build_profiles=$1;
+               }
+
                if (!$_ or eof) { # end of stanza.
                        if ($package) {
                                $package_types{$package}=$package_type;
                                $package_arches{$package}=$arch;
+                               $package_profiles{$package}=$build_profiles;
                        }
 
                        if ($package &&
@@ -833,7 +878,8 @@ sub getpackages {
                             (($type eq 'arch'  || $type eq 'both') && ($arch eq 'any' ||
                                             ($arch ne 'all' &&
                                              samearch(buildarch(), $arch)))) ||
-                            ! $type)) {
+                            ! $type) &&
+                           buildprofilesmatch($build_profiles, $package)) {
                                push @list, $package;
                                $package="";
                                $arch="";
index 216360b..ca22cc4 100644 (file)
@@ -566,7 +566,16 @@ To facilitate this, as well as give you more control over which packages
 are acted on by debhelper programs, all debhelper programs accept the
 B<-a>, B<-i>, B<-p>, and B<-s> parameters. These parameters are cumulative. 
 If none are given, debhelper programs default to acting on all packages listed
-in the control file.
+in the control file, with the exceptions below.
+
+First, any package whose B<Architecture> field in B<debian/control> does not
+match the build architecture will be excluded
+(L<Debian Policy, section 5.6.8>).
+
+Also, some additional packages may be excluded based on the contents of the
+B<DEB_BUILD_PROFILES> environment variable and B<Build-Profiles> fields in
+binary package stanzas in B<debian/control>, according to the draft policy at
+L<https://wiki.debian.org/BuildProfileSpec>.
 
 =head2 Automatic generation of Debian install scripts
 
index 7e3d3ec..673b2a2 100644 (file)
@@ -1,4 +1,4 @@
-debhelper (9.20131228) UNRELEASED; urgency=medium
+debhelper (9.20140210) UNRELEASED; urgency=medium
 
   * dh_compress: Avoid compressing .map files, which may be html
     usemaps. Closes: #704443
@@ -10,6 +10,8 @@ debhelper (9.20131228) UNRELEASED; urgency=medium
     parameters intended to be passed on to debhelper commands.
     Closes: #737635
   * perl_build: Use realclean instead of distclean. Closes: #737662
+  * Initial implementation of support for Build-Profiles fields.
+    Thanks, Daniel Schepler.
 
  -- Joey Hess <joeyh@debian.org>  Sat, 25 Jan 2014 15:49:45 -0400