Package: sbuild
Version: 0.65.2-1
Severity: normal
Tags: patch

Hi,

sbuild has the ability to crossbuild using a chroot of the build
architecture without any modifications (plainly created using
sbuild-createchroot). If I want to build on amd64 for mipsel, then using
a chroot with name sid-amd64-sbuild will work. It will properly call
`dpkg --add-architecture` to add mipsel as a foreign architecture and
then do the right thing when cross building. Then why is it that the
default chroot name when doing cross building looks for the *host*
architecture? This way, it would look for a chroot named
sid-mipsel-sbuild which does not make any sense because if anything,
then that chroot is probably a native mipsel chroot. I do not see any
reason why the current default would be useful but instead it would be
very useful if a crossbuild from amd64 to mipsel would look for the
amd64 chroot.

The attached patch partly reverts the offending commit 5ad92654 to fix
this problem.

Thanks!

cheers, josch
commit baa895f07fd69e2cf3cd273ab9048985a373d504
Author: Johannes 'josch' Schauer <[email protected]>
Date:   Wed Jul 29 11:09:13 2015 +0200

    partly revert commit 5ad92654 to look for a chroot at BUILD_ARCH instead

diff --git a/lib/Sbuild/Build.pm b/lib/Sbuild/Build.pm
index a28d0d2..20a4afa 100644
--- a/lib/Sbuild/Build.pm
+++ b/lib/Sbuild/Build.pm
@@ -364,7 +364,7 @@ sub run_chroot_session {
 	my $session = $chroot_info->create('chroot',
 					   $self->get_conf('DISTRIBUTION'),
 					   $self->get_conf('CHROOT'),
-					   $self->get_conf('HOST_ARCH'));
+					   $self->get_conf('BUILD_ARCH'));
 
 	$self->check_abort();
 	if (!$session->begin_session()) {
diff --git a/lib/Sbuild/ChrootInfo.pm b/lib/Sbuild/ChrootInfo.pm
index 62b264e..25f2a73 100644
--- a/lib/Sbuild/ChrootInfo.pm
+++ b/lib/Sbuild/ChrootInfo.pm
@@ -59,7 +59,7 @@ sub create {
     my $namespace = shift;
     my $distribution = shift;
     my $chroot = shift;
-    my $arch = shift;
+    my $arch = shift; # this is the build arch
 
     my $chrootid = $self->find($namespace, $distribution, $chroot, $arch);
 
@@ -78,7 +78,7 @@ sub find {
     my $namespace = shift;
     my $distribution = shift;
     my $chroot = shift;
-    my $arch = shift;
+    my $arch = shift; # this is the build arch
 
     # Use namespace given from $distribution if one is found
     if ($distribution =~ /^([^:]+):/msx) {
@@ -90,12 +90,9 @@ sub find {
 
     # Don't do strict arch checking if ARCH == HOST_ARCH.
     if (!defined($arch) || $arch eq "") {
-	$arch = $self->get_conf('HOST_ARCH');
+	$arch = $self->get_conf('BUILD_ARCH');
     }
-    my $arch_set = ($arch eq $self->get_conf('HOST_ARCH')) ? 0 : 1;
-    my $build_arch = $self->get_conf('BUILD_ARCH');
-
-    my $arch_found = 0;
+    my $host_arch = $self->get_conf('HOST_ARCH');
 
     if (!defined $chroot) {
 	my $ns = $chroots->{$namespace};
@@ -109,20 +106,17 @@ sub find {
 	    }
 	}
 
-        if ($arch ne $build_arch &&
-            defined($ns->{"${distribution}-${build_arch}-${arch}-sbuild"})) {
-            $chroot = "${namespace}:${distribution}-${build_arch}-${arch}-sbuild";
-            $arch_found = 1;
+        if ($arch ne $host_arch &&
+            defined($ns->{"${distribution}-${arch}-${host_arch}-sbuild"})) {
+            $chroot = "${namespace}:${distribution}-${arch}-${host_arch}-sbuild";
         }
-        elsif ($arch ne $build_arch &&
-            defined($ns->{"${distribution}-${build_arch}-${arch}"})) {
-            $chroot = "${namespace}:${distribution}-${build_arch}-${arch}";
-            $arch_found = 1;
+        elsif ($arch ne $host_arch &&
+            defined($ns->{"${distribution}-${arch}-${host_arch}"})) {
+            $chroot = "${namespace}:${distribution}-${arch}-${host_arch}";
         }
         elsif ($arch ne "" &&
             defined($ns->{"${distribution}-${arch}-sbuild"})) {
             $chroot = "${namespace}:${distribution}-${arch}-sbuild";
-            $arch_found = 1;
         }
         elsif (defined($ns->{"${distribution}-sbuild"})) {
             $chroot = "${namespace}:${distribution}-sbuild";
@@ -130,16 +124,9 @@ sub find {
         elsif ($arch ne "" &&
                defined($ns->{"${distribution}-${arch}"})) {
             $chroot = "${namespace}:${distribution}-${arch}";
-            $arch_found = 1;
         } elsif (defined($ns->{$distribution})) {
             $chroot = "${namespace}:${distribution}";
 	}
-
-#	if ($arch_set && !$arch_found && $host_arch ne "") {
-#	    # TODO: Return error, rather than die.
-#	    die "Chroot $distribution for architecture $host_arch not found\n";
-#	    return undef;
-#	}
     }
 
     if (!$chroot) {
diff --git a/man/sbuild.1.in b/man/sbuild.1.in
index 7b6ec09..e5d1e4a 100644
--- a/man/sbuild.1.in
+++ b/man/sbuild.1.in
@@ -165,8 +165,8 @@ this option is equivalent to "\-\-host=architecture \-\-build=architecture".
 .BR "\-\-host=\fIarchitecture\fP"
 Build using the host architecture specified.  If $host and $build don't match, a
 chroot named \fI$distribution\-$build\-$host\-sbuild\fP or \fI$distribution\-$build\-$host\fP
-is searched for, falling back to \fI$distribution\-$host\-sbuild\fP or
-\fI$distribution\-$host\fP, in that order of preference.  This option is only
+is searched for, falling back to \fI$distribution\-$build\-sbuild\fP or
+\fI$distribution\-$build\fP, in that order of preference.  This option is only
 useful for cross-building when used together with \-\-build.
 .TP
 .BR "\-\-build=\fIarchitecture\fP"

Reply via email to