Hi,

the build profile spec changed since the last spec but since sbuild is just
using libdpkg-perl, the only thing that changed in the patch is the
documentation which mentioned prefixes before but those are no more.

I tested the attached refreshed patch with the fixed manpages with my patched
versions of dpkg and apt. Even though dpkg and apt did not apply those patches
yet, this patch works for either version and can thus be applied right away.

cheers, josch
From f7aefb553f7956a6da9cb6c9fc31cca35210e980 Mon Sep 17 00:00:00 2001
From: josch <j.scha...@email.de>
Date: Tue, 2 Sep 2014 21:43:49 +0200
Subject: [PATCH] Support for build profiles

 - respect the DEB_BUILD_PROFILES environment variable
 - add new -P or --profiles option to set build profiles
 - use reduce_profiles and build_profiles options when calling
   Dpkg::Deps::deps_parse
---
 bin/sbuild                 |  2 ++
 lib/Sbuild/Build.pm        | 12 ++++++++++++
 lib/Sbuild/ConfBase.pm     |  7 +++++++
 lib/Sbuild/Options.pm      |  4 ++++
 lib/Sbuild/ResolverBase.pm |  9 +++++++--
 man/sbuild.1.in            |  6 ++++++
 6 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/bin/sbuild b/bin/sbuild
index e12bf72..a9435df 100755
--- a/bin/sbuild
+++ b/bin/sbuild
@@ -115,6 +115,8 @@ sub main () {
 	    if $conf->get('DEBUG' && defined($conf->get('HOST_ARCH')));
 	print "Selected build architecture " . $conf->get('BUILD_ARCH') . "\n"
 	    if $conf->get('DEBUG' && defined($conf->get('BUILD_ARCH')));
+	print "Selected build profiles " . $conf->get('BUILD_PROFILES') . "\n"
+	    if $conf->get('DEBUG' && defined($conf->get('BUILD_PROFILES')));
 
 	$job = Sbuild::Build->new($jobname, $conf);
 	$job->set('Pkg Status Trigger', \&status_trigger);
diff --git a/lib/Sbuild/Build.pm b/lib/Sbuild/Build.pm
index a8d39d6..1ab992b 100644
--- a/lib/Sbuild/Build.pm
+++ b/lib/Sbuild/Build.pm
@@ -264,6 +264,7 @@ sub run {
 	# Acquire the architectures we're building for and on.
 	$self->set('Host Arch', $self->get_conf('HOST_ARCH'));
 	$self->set('Build Arch', $self->get_conf('BUILD_ARCH'));
+	$self->set('Build Profiles', $self->get_conf('BUILD_PROFILES'));
 
 	my $dist = $self->get_conf('DISTRIBUTION');
 	if (!defined($dist) || !$dist) {
@@ -461,6 +462,7 @@ sub run_chroot_session {
 	$resolver->set('Arch', $self->get_conf('ARCH'));
 	$resolver->set('Host Arch', $self->get_conf('HOST_ARCH'));
 	$resolver->set('Build Arch', $self->get_conf('BUILD_ARCH'));
+	$resolver->set('Build Profiles', $self->get_conf('BUILD_PROFILES'));
 	$resolver->set('Chroot Build Dir', $self->get('Chroot Build Dir'));
 	$self->set('Dependency Resolver', $resolver);
 
@@ -1413,6 +1415,13 @@ sub build {
 	push (@{$buildcmd}, '-a' . $host_arch);
     }
 
+    if (defined($self->get_conf('BUILD_PROFILES')) &&
+	$self->get_conf('BUILD_PROFILES')) {
+	my $profiles = $self->get_conf('BUILD_PROFILES');
+	$profiles =~ tr/ /,/;
+	push (@{$buildcmd}, '-P' . $profiles);
+    }
+
     if (defined($self->get_conf('PGP_OPTIONS')) &&
 	$self->get_conf('PGP_OPTIONS')) {
 	if (ref($self->get_conf('PGP_OPTIONS')) eq 'ARRAY') {
@@ -1889,6 +1898,8 @@ sub generate_stats {
     $self->add_stat('Machine Architecture', $self->get_conf('ARCH'));
     $self->add_stat('Host Architecture', $self->get('Host Arch'));
     $self->add_stat('Build Architecture', $self->get('Build Arch'));
+    $self->add_stat('Build Profiles', $self->get('Build Profiles'))
+        if $self->get('Build Profiles');
     $self->add_stat('Distribution', $self->get_conf('DISTRIBUTION'));
     $self->add_stat('Space', $self->get('This Space'));
     $self->add_stat('Build-Time',
@@ -2156,6 +2167,7 @@ sub open_build_log {
     $self->log("Machine Architecture: " . $self->get_conf('ARCH') . "\n");
     $self->log("Host Architecture: " . $self->get('Host Arch') . "\n");
     $self->log("Build Architecture: " . $self->get('Build Arch') . "\n");
+    $self->log("Build Profiles: " . $self->get('Build Profiles') . "\n") if $self->get('Build Profiles');
     $self->log("\n");
 }
 
diff --git a/lib/Sbuild/ConfBase.pm b/lib/Sbuild/ConfBase.pm
index 87172fa..818c4ec 100644
--- a/lib/Sbuild/ConfBase.pm
+++ b/lib/Sbuild/ConfBase.pm
@@ -169,6 +169,13 @@ sub init_allowed_keys {
 	    DEFAULT => $native_arch,
 	    HELP => 'Build architecture (Arch we are building on).'
 	},
+	'BUILD_PROFILES'        => {
+	    TYPE => 'STRING',
+	    VARNAME => 'build_profiles',
+	    GROUP => 'Build options',
+	    DEFAULT => $ENV{'DEB_BUILD_PROFILES'},
+	    HELP => 'Build profiles. Separated by spaces.'
+	},
 	'HOSTNAME'				=> {
 	    TYPE => 'STRING',
 	    GROUP => '__INTERNAL',
diff --git a/lib/Sbuild/Options.pm b/lib/Sbuild/Options.pm
index 4a232bf..dfff7a2 100644
--- a/lib/Sbuild/Options.pm
+++ b/lib/Sbuild/Options.pm
@@ -55,6 +55,10 @@ sub set_options {
 		       "no-arch-all" => sub {
 			   $self->set_conf('BUILD_ARCH_ALL', 0);
 		       },
+		       "profiles=s" => sub {
+			   $_[1] =~ tr/,/ /;
+			   $self->set_conf('BUILD_PROFILES', $_[1]);
+		       },
 		       "add-depends=s" => sub {
 			   push(@{$self->get_conf('MANUAL_DEPENDS')}, $_[1]);
 		       },
diff --git a/lib/Sbuild/ResolverBase.pm b/lib/Sbuild/ResolverBase.pm
index efa6d9d..a4d7b6b 100644
--- a/lib/Sbuild/ResolverBase.pm
+++ b/lib/Sbuild/ResolverBase.pm
@@ -58,6 +58,7 @@ sub new {
     # Typically set by Sbuild::Build, but not outside a build context.
     $self->set('Host Arch', $self->get_conf('HOST_ARCH'));
     $self->set('Build Arch', $self->get_conf('BUILD_ARCH'));
+    $self->set('Build Profiles', $self->get_conf('BUILD_PROFILES'));
 
     my $dummy_archive_list_file = $session->get('Location') .
         '/etc/apt/sources.list.d/sbuild-build-depends-archive.list';
@@ -738,14 +739,18 @@ EOF
 			      reduce_arch => 1,
 			      host_arch => $self->get('Host Arch'),
 			      build_arch => $self->get('Build Arch'),
-			      build_dep => 1);
+			      build_dep => 1,
+			      reduce_profiles => 1,
+			      build_profiles => [ split / /, $self->get('Build Profiles') ]);
     my $negative = deps_parse(join(", ", @negative,
 				   @negative_arch, @negative_indep),
 			      reduce_arch => 1,
 			      host_arch => $self->get('Host Arch'),
 			      build_arch => $self->get('Build Arch'),
 			      build_dep => 1,
-			      union => 1);
+			      union => 1,
+			      reduce_profiles => 1,
+			      build_profiles => [ split / /, $self->get('Build Profiles') ]);
 
     $self->log("Merged Build-Depends: $positive\n") if $positive;
     $self->log("Merged Build-Conflicts: $negative\n") if $negative;
diff --git a/man/sbuild.1.in b/man/sbuild.1.in
index a91a064..3db57dc 100644
--- a/man/sbuild.1.in
+++ b/man/sbuild.1.in
@@ -31,6 +31,7 @@ sbuild \- build debian packages from source
 .RB [ \-\-arch=\fIarchitecture\fP ]
 .RB [ \-\-build=\fIarchitecture\fP ]
 .RB [ \-\-host=\fIarchitecture\fP ]
+.RB [ \-\-profiles=\fIprofile[,...]\fP ]
 .RB [ \-s \[or] \-\-source ]
 .RB [ \-\-force\-orig\-source ]
 .RB [ \-\-make\-binNMU=\fIchangelog-entry\fP ]
@@ -260,6 +261,11 @@ log file, but print everything to stdout. Also do not send any log mails.
 Convenience option to set \fIpurge-mode\fR for build directory, build
 dependencies and session.
 .TP
+.BR \-\-profiles=\fIprofile[,...]\fP"
+Specify the profile(s) we build, as a comma-separated list. Defaults to the
+space separated list of profiles in the \fBDEB_BUILD_PROFILES\fP environment
+variable.
+.TP
 .BR "\-\-purge\-build=\fIpurge-mode\fP"
 \fIpurge-mode\fR determines if the build directory will be deleted after a
 build. Possible values are \fBalways\fR (default), \fBnever\fR, and
-- 
2.0.1

Reply via email to