Package: sbuild
Version: 0.64.2-2
Severity: normal
Tags: patch

Hi,

with dpkg (>= 1.17.2) build profiles [1] have finally been introduced
[2]. The attached patch allows sbuild to make use of this new
functionality of dpkg by adding a --profiles option, honoring the
DEB_BUILD_PROFILES environment variable and passing the correct options
to dpkg deps_parse in ResolverBase.pm. In addition to this patch, sbuild
should probably also depend on libdpkg-perl (>= 1.17.2).

cheers, josch

[1] https://wiki.debian.org/BuildProfileSpec
[2] https://lists.debian.org/debian-dpkg/2013/12/msg00001.html
--- 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);
--- 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);
 
@@ -1889,6 +1891,7 @@ 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'));
     $self->add_stat('Distribution', $self->get_conf('DISTRIBUTION'));
     $self->add_stat('Space', $self->get('This Space'));
     $self->add_stat('Build-Time',
@@ -2156,6 +2159,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");
     $self->log("\n");
 }
 
--- 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',
--- 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]);
 		       },
--- 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;
--- a/man/sbuild.1.in
+++ b/man/sbuild.1.in
@@ -31,6 +31,7 @@ sbuild \- build debian packages from sou
 .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
 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, without the
+"\fBprofile.\fP" namespace prefix. 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

Reply via email to