Here's a first go at a patch for my feature request #474160. Please see
the attached patch (which is relative to
git://git.debian.org/git/buildd-tools/sbuild.git branch "master"),
or git://git.debian.org/~smcv-guest/sbuild.git branch "master".

For the moment, sbuild-apt etc. all interpret their parameter as a
distribution (so sbuild will prefer a chroot called unstable-i386-sbuild
or whatever, if you ask for unstable), but perhaps they should use chroot
names too. I'd be happy to add this; if this is preferred, I think the logic
for choosing unstable-i386-sbuild should move out of
Sbuild::Chroot::begin_session() into the sbuild script itself, and
Sbuild::Chroot should entirely work in terms of chroot names rather than
distribution names.

    Simon
From 30c3519de865611b29e0e816a57a5ec04c1c8715 Mon Sep 17 00:00:00 2001
From: Simon McVittie <[EMAIL PROTECTED]>
Date: Sun, 13 Apr 2008 17:20:54 +0100
Subject: [PATCH] sbuild: add a -c/--chroot option to override the distribution

This allows builds to be done in an alternative chroot (perhaps pulling
from a local repository containing recently-built packages which are not
yet in the archive) without affecting the contents of the .changes file.
Debian bug #474160.

(For the moment Sbuild::Utility passes undef for the $chroot parameter,
to keep current semantics, but perhaps the sbuild-* tools should be
changed to operate on chroots rather than distributions).
---
 bin/sbuild            |    6 ++++-
 lib/Sbuild/Chroot.pm  |   50 +++++++++++++++++++++++++++++-------------------
 lib/Sbuild/Utility.pm |    2 +-
 man/sbuild.1.in       |   10 +++++++-
 4 files changed, 44 insertions(+), 24 deletions(-)

diff --git a/bin/sbuild b/bin/sbuild
index 83ef805..966dca1 100755
--- a/bin/sbuild
+++ b/bin/sbuild
@@ -124,6 +124,7 @@ check_group_membership();
 umask(022);
 
 $main::distribution = "unstable";
+undef $main::chroot;
 
 chomp( $main::arch = `$conf::dpkg --print-installation-architecture` );
 $main::user_arch = "";
@@ -189,6 +190,7 @@ exit 1 if !GetOptions ("arch=s" => \$main::user_arch,
 			   $main::binNMUver ||= 1;
 		       },
 		       "binNMU=i" => \$main::binNMUver,
+		       "c|chroot=s" => \$main::chroot,
 		       "database=s" => \$main::database,
 		       "D|debug+" => \$conf::debug,
 		       "d|dist=s" => sub {
@@ -233,6 +235,8 @@ exit 1 if !GetOptions ("arch=s" => \$main::user_arch,
 
 print "Selected distribution $main::distribution\n"
     if $conf::debug;
+print "Selected chroot $main::chroot\n"
+    if $conf::debug and defined $main::chroot;
 print "Selected architecture $main::user_arch\n"
     if $conf::debug;
 
@@ -325,7 +329,7 @@ foreach $dscfile (@ARGV) {
 	goto cleanup_close;
     }
 
-    if (!begin_session($main::distribution, $main::user_arch)) {
+    if (!begin_session($main::distribution, $main::chroot, $main::user_arch)) {
 	print PLOG "Skipping $pkg\n";
 	$main::pkg_status = "skipped";
 	goto cleanup_close;
diff --git a/lib/Sbuild/Chroot.pm b/lib/Sbuild/Chroot.pm
index 015ba82..5484ad0 100644
--- a/lib/Sbuild/Chroot.pm
+++ b/lib/Sbuild/Chroot.pm
@@ -48,7 +48,7 @@ our $current;
 sub _get_schroot_info ($);
 sub init ();
 sub _setup_options ($);
-sub begin_session ($$);
+sub begin_session ($$$);
 sub end_session ();
 sub strip_chroot_path ($);
 sub log_command ($$);
@@ -167,26 +167,31 @@ sub _setup_options ($) {
     }
 }
 
-sub begin_session ($$) {
+sub begin_session ($$$) {
     my $distribution = shift;
+    my $chroot = shift;
     my $arch = shift;
 
     $arch = "" if !defined($arch);
 
     my $arch_found = 0;
 
-    if ($arch ne "" &&
-	defined($chroots{"${distribution}-${arch}-sbuild"})) {
-	$distribution = "${distribution}-${arch}-sbuild";
-	$arch_found = 1;
-    }
-    elsif (defined($chroots{"${distribution}-sbuild"})) {
-	$distribution = "${distribution}-sbuild";
-    }
-    elsif ($arch ne "" &&
-	   defined($chroots{"${distribution}-${arch}"})) {
-	$distribution = "${distribution}-${arch}";
-	$arch_found = 1;
+    if (!defined $chroot) {
+        if ($arch ne "" &&
+            defined($chroots{"${distribution}-${arch}-sbuild"})) {
+            $chroot = "${distribution}-${arch}-sbuild";
+            $arch_found = 1;
+        }
+        elsif (defined($chroots{"${distribution}-sbuild"})) {
+            $chroot = "${distribution}-sbuild";
+        }
+        elsif ($arch ne "" &&
+               defined($chroots{"${distribution}-${arch}"})) {
+            $chroot = "${distribution}-${arch}";
+            $arch_found = 1;
+        } elsif (defined($chroots{$distribution})) {
+            $chroot = $distribution;
+	}
     }
 
     if (!$arch_found && $arch ne "") {
@@ -194,19 +199,24 @@ sub begin_session ($$) {
 	return 0;
     }
 
-    $schroot_session=`$Sbuild::Conf::schroot -c $distribution --begin-session`;
+    if (!$chroot) {
+	print STDERR "Chroot for distribution $distribution, architecture $arch not found\n";
+	return 0;
+    }
+
+    $schroot_session=`$Sbuild::Conf::schroot -c $chroot --begin-session`;
     chomp($schroot_session);
     if ($?) {
 	print STDERR "Chroot setup failed\n";
 
-	if (-d "chroot-$distribution" || -l "chroot-$distribution") {
-	    print STDERR "\nFound obsolete chroot: ${Sbuild::Conf::build_dir}/chroot-$distribution\n";
+	if (-d "chroot-$chroot" || -l "chroot-$chroot") {
+	    print STDERR "\nFound obsolete chroot: ${Sbuild::Conf::build_dir}/chroot-$chroot\n";
 	    print STDERR "Chroot access via sudo has been replaced with schroot chroot management.\n";
 	    print STDERR "To upgrade to schroot, add the following lines to /etc/schroot/schroot.conf:\n\n";
-	    print STDERR "[$distribution]\n";
+	    print STDERR "[$chroot]\n";
 	    print STDERR "type=directory\n";
 	    print STDERR "description=Debian $distribution autobuilder\n";
-	    print STDERR "location=${Sbuild::Conf::build_dir}/chroot-$distribution\n";
+	    print STDERR "location=${Sbuild::Conf::build_dir}/chroot-$chroot\n";
 	    print STDERR "priority=3\n";
 	    print STDERR "groups=root,sbuild\n";
 	    print STDERR "root-groups=root,sbuild\n";
@@ -217,7 +227,7 @@ sub begin_session ($$) {
 	}
 	return 0;
     }
-    print STDERR "Setting up chroot $distribution (session id $schroot_session)\n"
+    print STDERR "Setting up chroot $chroot (session id $schroot_session)\n"
 	if $Sbuild::Conf::debug;
     _get_schroot_info($schroot_session);
     _setup_options($schroot_session);
diff --git a/lib/Sbuild/Utility.pm b/lib/Sbuild/Utility.pm
index 392afa4..ef8902e 100644
--- a/lib/Sbuild/Utility.pm
+++ b/lib/Sbuild/Utility.pm
@@ -84,7 +84,7 @@ sub setup ($) {
     $chroot = get_dist($chroot);
 
     # TODO: Allow user to specify arch.
-    if (!begin_session($chroot, $arch)) {
+    if (!begin_session($chroot, undef, $arch)) {
 	print STDERR "Error setting up $chroot chroot\n";
 	return 1;
     }
diff --git a/man/sbuild.1.in b/man/sbuild.1.in
index 9ad7818..d37843c 100644
--- a/man/sbuild.1.in
+++ b/man/sbuild.1.in
@@ -64,8 +64,9 @@ remote one by specifying an explicit dpkg version.
 Note: \fBsbuild\fR must be run in the directory (\fI~/build\fP by default) with
 the chroot\-{stable,testing,unstable} symlink to the chroot or it will do the
 build in the base install which is not what you want.  When using schroot,
-these requirements do not apply; the chroot having the name (or alias) of the
-specified distribution will be used; schroot uses a chroot named
+these requirements do not apply. If the \-c or \-\-chroot option is used, the
+specified chroot will be used. Otherwise, the chroot having the name (or alias) 
+of the specified distribution will be used; schroot uses a chroot named
 \fI$distribution\-$arch-sbuild\fP, \fI$distribution\-sbuild\fP,
 \fI$distribution\-$arch\fP or \fI$distribution\fP, in that order of preference.
 .SH OPTIONS
@@ -92,6 +93,11 @@ instead of \-B.
 Operate in batchmode, i.e. write a build-progress file during execution
 and files on shutdown to facilitate a clean restart.
 .TP
+.IR \-c , "\-\-chroot"
+Use the specified chroot. If not specified, the default is the first of
+\fI$distribution\-$arch\-sbuild\fP, \fI$distribution\-sbuild\fP,
+\fI$distribution\-$arch\fP or \fI$distribution\fP that exists.
+.TP
 .IR \-C , "\-\-check\-depends\-algorithm=<algorithm>"
 Selects the algorithm to check for build dependencies. The default algorithm
 (\[oq]first-only\[cq]) just checks the first package, even if there are
-- 
1.5.5

Attachment: signature.asc
Description: Digital signature

Reply via email to