diff mbox

[01/17] Add BUILD_ARCH and HOST_ARCH throughout

Message ID 1323885273-23505-1-git-send-email-wookey@linaro.org
State Accepted
Headers show

Commit Message

Wookey Dec. 14, 2011, 5:54 p.m. UTC
From: Wookey <wookey@wookware.org>

---
 bin/sbuild                     |    6 ++++--
 bin/sbuild-update              |    2 ++
 lib/Sbuild/Build.pm            |   27 +++++++++++++++++----------
 lib/Sbuild/ConfBase.pm         |   20 ++++++++++++++------
 lib/Sbuild/InternalResolver.pm |    8 ++++----
 lib/Sbuild/Options.pm          |    9 ++++++++-
 lib/Sbuild/ResolverBase.pm     |   10 +++++-----
 man/sbuild.1.in                |   15 ++++++++++++++-
 8 files changed, 68 insertions(+), 29 deletions(-)
diff mbox

Patch

diff --git a/bin/sbuild b/bin/sbuild
index 9aabbe5..2c56f32 100755
--- a/bin/sbuild
+++ b/bin/sbuild
@@ -97,8 +97,10 @@  sub main () {
 	    if $conf->get('DEBUG');
 	print "Selected chroot " . $conf->get('CHROOT') . "\n"
 	    if $conf->get('DEBUG') and defined $conf->get('CHROOT');
-	print "Selected architecture " . $conf->get('ARCH') . "\n"
-	    if $conf->get('DEBUG' && defined($conf->get('ARCH')));
+	print "Selected host architecture " . $conf->get('HOST_ARCH') . "\n"
+	    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')));
 
 	$job = Sbuild::Build->new($jobname, $conf);
 	$job->set('Pkg Status Trigger', \&status_trigger);
diff --git a/bin/sbuild-update b/bin/sbuild-update
index fa2d3bc..cb0bd48 100755
--- a/bin/sbuild-update
+++ b/bin/sbuild-update
@@ -80,6 +80,8 @@  sub set_options {
     $self->add_options(
 	"arch=s" => sub {
 	    $self->set_conf('ARCH', $_[1]);
+	    $self->set_conf('HOST_ARCH', $_[1]);
+	    $self->set_conf('BUILD_ARCH', $_[1]);
 	},
 	"update|u" => sub {
 	    $self->set_conf('UPDATE', 1);
diff --git a/lib/Sbuild/Build.pm b/lib/Sbuild/Build.pm
index 6b1930e..4b1a017 100644
--- a/lib/Sbuild/Build.pm
+++ b/lib/Sbuild/Build.pm
@@ -74,7 +74,6 @@  sub new {
 
     $self->set('ABORT', undef);
     $self->set('Job', $dsc);
-    $self->set('Arch', undef);
     $self->set('Chroot Dir', '');
     $self->set('Chroot Build Dir', '');
     $self->set('Build Dir', '');
@@ -401,7 +400,9 @@  sub run_chroot_session {
 	# TODO: Don't hack the build location in; add a means to customise
 	# the chroot directly.  i.e. allow changing of /build location.
 	$self->set('Chroot Build Dir',
-		   tempdir($self->get('Package') . '-XXXXXX',
+		   tempdir($self->get_conf('USERNAME') . '-' .
+			   $self->get('Package_SVersion') . '-' .
+			   $self->get('BUILD_ARCH') . '-XXXXXX',
 			   DIR =>  $session->get('Location') . "/build"));
 
 	$self->set('Build Dir', $session->strip_chroot_path($self->get('Chroot Build Dir')));
@@ -466,7 +467,9 @@  sub run_chroot_session {
 
 	my $resolver = get_resolver($self->get('Config'), $session, $host);
 	$resolver->set('Log Stream', $self->get('Log Stream'));
-	$resolver->set('Arch', $self->get('Arch'));
+	$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('Chroot Build Dir', $self->get('Chroot Build Dir'));
 	$self->set('Dependency Resolver', $resolver);
 
@@ -793,7 +796,8 @@  sub fetch_source_files {
     my $build_dir = $self->get('Chroot Build Dir');
     my $pkg = $self->get('Package');
     my $ver = $self->get('OVersion');
-    my $arch = $self->get('Arch');
+    my $host_arch = $self->get_conf('HOST_ARCH');
+    my $build_arch = $self->get_conf('BUILD_ARCH');
 
     my ($dscarchs, $dscpkg, $dscver, @fetched);
 
@@ -979,7 +983,7 @@  sub fetch_source_files {
 	    !($dscarchs eq "all" && $self->get_conf('BUILD_ARCH_ALL')) )  {
 	    my $msg = "$dsc: $arch not in arch list or does not match any arch wildcards: $dscarchs -- skipping\n";
 	    $self->log($msg);
-	    Sbuild::Exception::Build->throw(error => "$dsc: $arch not in arch list or does not match any arch wildcards: $dscarchs -- skipping",
+	    Sbuild::Exception::Build->throw(error => "$dsc: $host_arch not in arch list or does not match any arch wildcards: $dscarchs -- skipping",
 					    status => "skipped",
 					    failstage => "arch-check");
 	    return 0;
@@ -1190,7 +1194,8 @@  sub build {
     my $dscdir = $self->get('DSC Dir');
     my $pkg = $self->get('Package');
     my $build_dir = $self->get('Chroot Build Dir');
-    my $arch = $self->get('Arch');
+    my $host_arch = $self->get_conf('HOST_ARCH');
+    my $build_arch = $self->get_conf('BUILD_ARCH');
 
     my( $rv, $changes );
     local( *PIPE, *F, *F2 );
@@ -1573,7 +1578,6 @@  sub build {
 	    }
 	}
 
-
 	# Restore write access to build tree now build is complete.
 	$self->get('Session')->run_command(
 	    { COMMAND => ['chmod', '-R', 'g+w', $self->get('Build Dir')],
@@ -1902,7 +1906,8 @@  sub generate_stats {
     $self->add_stat('Package', $self->get('Package'));
     $self->add_stat('Version', $self->get('Version'));
     $self->add_stat('Source-Version', $self->get('OVersion'));
-    $self->add_stat('Architecture', $self->get('Arch'));
+    $self->add_stat('Architecture', $self->get_conf('HOST_ARCH'));
+    $self->add_stat('Build Architecture', $self->get_conf('BUILD_ARCH'));
     $self->add_stat('Distribution', $self->get_conf('DISTRIBUTION'));
     $self->add_stat('Space', $self->get('This Space'));
     $self->add_stat('Build-Time',
@@ -2154,7 +2159,7 @@  sub open_build_log {
     $self->log("sbuild (Debian sbuild) $version ($release_date) on $hostname\n");
 
     my $head1 = $self->get('Package') . ' ' . $self->get('Version') .
-	' (' . $self->get('Arch') . ') ';
+	' (' . $arch_string . ') ';
     my $head2 = strftime("%d %b %Y %H:%M",
 			 localtime($self->get('Pkg Start Time')));
     my $head = $head1 . ' ' x (80 - 4 - length($head1) - length($head2)) .
@@ -2165,7 +2170,9 @@  sub open_build_log {
     $self->log("Version: " . $self->get('Version') . "\n");
     $self->log("Source Version: " . $self->get('OVersion') . "\n");
     $self->log("Distribution: " . $self->get_conf('DISTRIBUTION') . "\n");
-    $self->log("Architecture: " . $self->get('Arch') . "\n");
+    $self->log("Architecture: " . $self->get_conf('BUILD_ARCH') . "\n");
+    $self->log("Host Architecture: " . $self->get_conf('HOST_ARCH') . "\n");
+    $self->log("Build Architecture: " . $self->get_conf('BUILD_ARCH') . "\n");
     $self->log("\n");
 }
 
diff --git a/lib/Sbuild/ConfBase.pm b/lib/Sbuild/ConfBase.pm
index 8c17ce3..769f56d 100644
--- a/lib/Sbuild/ConfBase.pm
+++ b/lib/Sbuild/ConfBase.pm
@@ -102,7 +102,7 @@  sub init_allowed_keys {
     chomp(my $hostname = `hostname -f`);
 
     # Not user-settable.
-    chomp(my $host_arch =
+    chomp(my $native_arch =
 	  readpipe("dpkg --print-architecture"));
 
     my %common_keys = (
@@ -148,19 +148,27 @@  sub init_allowed_keys {
 	    HELP => 'Program to use to send mail'
 	},
 	# TODO: Check if defaulted in code assuming undef
+	# ARCH is the native (system) architecture.  Not used for host/build.
 	'ARCH'					=> {
 	    TYPE => 'STRING',
-	    VARNAME => 'arch',
-	    GROUP => 'Build options',
-	    DEFAULT => $host_arch,
+	    GROUP => '__INTERNAL',
+	    DEFAULT => $native_arch
 	    HELP => 'Build architecture.'
 	},
 	'HOST_ARCH'				=> {
 	    TYPE => 'STRING',
-	    GROUP => '__INTERNAL',
-	    DEFAULT => $host_arch,
+	    VARNAME => 'host_arch',
+	    GROUP => 'Build options',
+	    DEFAULT => $native_arch
 	    HELP => 'Host architecture'
 	},
+	'BUILD_ARCH'				=> {
+	    TYPE => 'STRING',
+	    VARNAME => 'build_arch',
+	    GROUP => 'Build options',
+	    DEFAULT => $native_arch
+	    HELP => 'Build architecture.'
+	},
 	'HOSTNAME'				=> {
 	    TYPE => 'STRING',
 	    GROUP => '__INTERNAL',
diff --git a/lib/Sbuild/InternalResolver.pm b/lib/Sbuild/InternalResolver.pm
index dbe91ee..56af6e5 100644
--- a/lib/Sbuild/InternalResolver.pm
+++ b/lib/Sbuild/InternalResolver.pm
@@ -84,10 +84,10 @@  sub install_deps {
 
     my $positive = deps_parse(join(", ", @apt_positive),
 			      reduce_arch => 1,
-			      host_arch => $self->get('Arch'));
+			      host_arch => $self->get('Host Arch'));
     my $negative = deps_parse(join(", ", @apt_negative),
 			      reduce_arch => 1,
-			      host_arch => $self->get('Arch'));
+			      host_arch => $self->get('Host Arch'));
 
     my $build_depends = $positive;
     my $build_conflicts = $negative;
@@ -207,10 +207,10 @@  sub parse_one_srcdep {
 		my ($use_it, $ignore_it, $include) = (0, 0, 0);
 		foreach (@archs) {
 		    if (/^!/) {
-			$ignore_it = 1 if Dpkg::Arch::debarch_is($self->get('Arch'), substr($_, 1));
+			$ignore_it = 1 if Dpkg::Arch::debarch_is($self->get('Host Arch'), substr($_, 1));
 		    }
 		    else {
-			$use_it = 1 if Dpkg::Arch::debarch_is($self->get('Arch'), $_);
+			$use_it = 1 if Dpkg::Arch::debarch_is($self->get('Host Arch'), $_);
 			$include = 1;
 		    }
 		}
diff --git a/lib/Sbuild/Options.pm b/lib/Sbuild/Options.pm
index f80030a..2d86f63 100644
--- a/lib/Sbuild/Options.pm
+++ b/lib/Sbuild/Options.pm
@@ -40,7 +40,14 @@  sub set_options {
     my $self = shift;
 
     $self->add_options("arch=s" => sub {
-			   $self->set_conf('ARCH', $_[1]);
+			   $self->set_conf('HOST_ARCH', $_[1]);
+			   $self->set_conf('BUILD_ARCH', $_[1]);
+		       },
+		       "build=s" => sub {
+			   $self->set_conf('BUILD_ARCH', $_[1]);
+		       },
+		       "host=s" => sub {
+			   $self->set_conf('HOST_ARCH', $_[1]);
 		       },
 		       "A|arch-all" => sub {
 			   $self->set_conf('BUILD_ARCH_ALL', 1);
diff --git a/lib/Sbuild/ResolverBase.pm b/lib/Sbuild/ResolverBase.pm
index 4ed99f5..3f003c8 100644
--- a/lib/Sbuild/ResolverBase.pm
+++ b/lib/Sbuild/ResolverBase.pm
@@ -585,7 +585,7 @@  sub setup_apt_archive {
 	return 0;
     }
 
-    my $arch = $self->get('Arch');
+    my $arch = $self->get('Host Arch');
     print DUMMY_CONTROL <<"EOF";
 Package: $dummy_pkg_name
 Version: 0.invalid.0
@@ -618,17 +618,17 @@  EOF
     if ($self->get_conf('BUILD_ARCH_ALL')) {
 	$positive = deps_parse(join(", ", @positive, @positive_indep),
 			       reduce_arch => 1,
-			       host_arch => $self->get('Arch'));
+			       host_arch => $self->get('Host Arch'));
 	$negative = deps_parse(join(", ", @negative, @negative_indep),
 			       reduce_arch => 1,
-			       host_arch => $self->get('Arch'));
+			       host_arch => $self->get('Host Arch'));
     } else {
 	$positive = deps_parse(join(", ", @positive),
 			      reduce_arch => 1,
-			      host_arch => $self->get('Arch'));
+			      host_arch => $self->get('Host Arch'));
 	$negative = deps_parse(join(", ", @negative),
 			      reduce_arch => 1,
-			      host_arch => $self->get('Arch'));
+			      host_arch => $self->get('Host Arch'));
     }
 
     $self->log("Merged Build-Depends: $positive\n") if $positive;
diff --git a/man/sbuild.1.in b/man/sbuild.1.in
index c06ad6a..a027fdc 100644
--- a/man/sbuild.1.in
+++ b/man/sbuild.1.in
@@ -29,6 +29,8 @@  sbuild \- build debian packages from source
 .RB [ \-d \[or] \-\-dist=\fIdistribution\fP ]
 .RB [ \-c \[or] \-\-chroot=\fIchroot\fP ]
 .RB [ \-\-arch=\fIarchitecture\fP ]
+.RB [ \-\-build=\fIarchitecture\fP ]
+.RB [ \-\-host=\fIarchitecture\fP ]
 .RB [ \-s \[or] \-\-source ]
 .RB [ \-\-force\-orig\-source ]
 .RB [ \-\-make\-binNMU=\fIchangelog-entry\fP ]
@@ -138,7 +140,18 @@  Build using the architecture specified.  A chroot named
 \fI$distribution\-$arch-sbuild\fP or \fI$distribution\-arch\fP is searched for,
 in that order of preference.  The chroot must be installed and configured
 appropriately to build as that architecture, e.g. using
-\fIpersonality=linux32\fP to build i386 packages on an amd64 system.
+\fIpersonality=linux32\fP to build i386 packages on an amd64 system.  Note that
+this option is equivalent to "\-\-host=architecture \-\-build=architecture".
+.TP
+.BR "\-\-host=\fIarchitecture\fP"
+Build using the host architecture specified.  A chroot named
+\fI$distribution\-$arch-sbuild\fP or \fI$distribution\-arch\fP is searched for,
+in that order of preference.  This option is only useful for cross-building
+when used together with \-\-build.
+.TP
+.BR "\-\-build=\fIarchitecture\fP"
+Build using the build architecture specified.  This option is only useful for
+cross-building when used together with \-\-host.
 .TP
 .BR \-A ", " "\-\-arch\-all"
 Also build Architecture: all packages, i.e. use dpkg\-buildpackage \-b