[PATCH 1/2] Add initial host/build arch separation for cross building
Roger Leigh
rleigh at debian.org
Sat Jan 22 21:32:34 UTC 2011
---
bin/sbuild | 6 ++-
bin/sbuild-createchroot | 18 ++++++-----
bin/sbuild-update | 2 +
lib/Sbuild/Build.pm | 61 +++++++++++++++++++++++++---------------
lib/Sbuild/Conf.pm | 9 +++++-
lib/Sbuild/ConfBase.pm | 10 ++++--
lib/Sbuild/InternalResolver.pm | 8 ++--
lib/Sbuild/Options.pm | 9 +++++-
lib/Sbuild/ResolverBase.pm | 10 +++---
lib/Sbuild/Utility.pm | 2 +-
man/sbuild.1.in | 15 +++++++++-
11 files changed, 101 insertions(+), 49 deletions(-)
diff --git a/bin/sbuild b/bin/sbuild
index cafbf1b..21e2911 100755
--- a/bin/sbuild
+++ b/bin/sbuild
@@ -69,8 +69,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')));
open_log($conf);
diff --git a/bin/sbuild-createchroot b/bin/sbuild-createchroot
index 722d9b4..4c23320 100755
--- a/bin/sbuild-createchroot
+++ b/bin/sbuild-createchroot
@@ -90,7 +90,9 @@ sub set_options {
$self->add_options(
"arch=s" => sub {
- $self->set_conf('ARCH', $_[1]);
+ # We use HOST_ARCH to store the bootstrap arch, and ARCH
+ # as the native arch
+ $self->set_conf('HOST_ARCH', $_[1]);
},
"foreign" => sub {
$self->set_conf('FOREIGN', 0);
@@ -177,7 +179,7 @@ if ($conf->get('VERBOSE')) {
print "I: SCRIPT: $script\n" if (defined($script));
}
-my @args = ("--arch=" . $conf->get('ARCH'),
+my @args = ("--arch=" . $conf->get('HOST_ARCH'),
"--variant=buildd");
push @args, "--verbose" if $conf->get('VERBOSE');
push @args, "--foreign" if $conf->get('FOREIGN');
@@ -250,11 +252,11 @@ dump_file("${target}/etc/apt/sources.list");
print "I: Please add any additional APT sources to ${target}/etc/apt/sources.list\n";
# Write out schroot chroot configuration.
-my $chrootname = "${suite}-" . $conf->get('ARCH') . "-sbuild";
+my $chrootname = "${suite}-" . $conf->get('HOST_ARCH') . "-sbuild";
# Determine the schroot chroot configuration to use.
my $config_entry;
-my $arch = $conf->get('ARCH');
+my $arch = $conf->get('HOST_ARCH');
if ($conf->get('MAKE_SBUILD_TARBALL')) {
my $tarball = $conf->get('MAKE_SBUILD_TARBALL');
@@ -300,8 +302,8 @@ if (-d "/etc/schroot/chroot.d") {
# Detect whether personality might be needed.
if ($conf->get('ARCH') ne $conf->get('HOST_ARCH')) {
# Take care of the known case(s).
- if ($conf->get('ARCH') eq 'i386' &&
- $conf->get('HOST_ARCH') eq 'amd64') {
+ if ($conf->get('HOST_ARCH') eq 'i386' &&
+ $conf->get('ARCH') eq 'amd64') {
$personality='linux32';
$personality_message =
"I: Added personality=$personality automatically (i386 on amd64).\n";
@@ -309,7 +311,7 @@ if (-d "/etc/schroot/chroot.d") {
else {
$personality_message =
"W: The selected architecture and the current architecture do not match\n" .
- "W: (" . $conf->get('ARCH') . " versus " . $conf->get('HOST_ARCH') . ").\n" .
+ "W: (" . $conf->get('HOST_ARCH') . " versus " . $conf->get('ARCH') . ").\n" .
"I: You probably need to add a personality option (see schroot(1)).\n" .
"I: You may want to report your use case to the sbuild developers so that\n" .
"I: the appropriate option gets automatically added in the future.\n\n";
@@ -384,7 +386,7 @@ if ($conf->get('ARCH') eq $conf->get('HOST_ARCH')) {
}
} else {
print "W: The selected architecture and the current architecture do not match\n";
- print "W: (" . $conf->get('ARCH') . " versus " . $conf->get('HOST_ARCH') . ").\n";
+ print "W: (" . $conf->get('HOST_ARCH') . " versus " . $conf->get('ARCH') . ").\n";
print "W: Not automatically updating APT package lists.\n";
print "I: Run \"apt-get update\" and \"apt-get dist-upgrade\" prior to use.\n";
print "I: Run \"sbuild-checkpackages --set\" to set reference package list.\n";
diff --git a/bin/sbuild-update b/bin/sbuild-update
index 350f126..e849f4a 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 b8ce7ab..1a9d8da 100644
--- a/lib/Sbuild/Build.pm
+++ b/lib/Sbuild/Build.pm
@@ -67,7 +67,6 @@ sub new {
bless($self, $class);
$self->set('Job', $dsc);
- $self->set('Arch', undef);
$self->set('Chroot Dir', '');
$self->set('Chroot Build Dir', '');
$self->set('Max Lock Trys', 120);
@@ -269,9 +268,6 @@ sub run {
$self->set('Pkg Start Time', time);
$self->set('Pkg End Time', $self->get('Pkg Start Time'));
- # Acquire the architecture we're building for.
- $self->set('Arch', $self->get_conf('ARCH'));
-
my $dist = $self->get_conf('DISTRIBUTION');
if (!defined($dist) || !$dist) {
$self->log("No distribution defined\n");
@@ -345,7 +341,7 @@ sub run {
my $session = $chroot_info->create('chroot',
$self->get_conf('DISTRIBUTION'),
$self->get_conf('CHROOT'),
- $self->get_conf('ARCH'));
+ $self->get_conf('HOST_ARCH'));
# Run pre build external commands
$self->run_external_commands("pre-build-commands",
@@ -360,7 +356,16 @@ sub run {
}
$self->set('Session', $session);
- $self->set('Arch', $self->chroot_arch());
+
+ my $chroot_arch = $self->chroot_arch();
+ if ($self->get_conf('HOST_ARCH') ne $chroot_arch) {
+ $self->log("Requested host architecture (" .
+ $self->get_conf('HOST_ARCH') .
+ ") and chroot architecture (" . $chroot_arch .
+ ") do not match. Skipping build.\n");
+ $self->set_status('failed');
+ goto cleanup_unlocked_session;
+ }
$self->set('Chroot Dir', $session->get('Location'));
# TODO: Don't hack the build location in; add a means to customise
@@ -368,7 +373,7 @@ sub run {
$self->set('Chroot Build Dir',
tempdir($self->get_conf('USERNAME') . '-' .
$self->get('Package_SVersion') . '-' .
- $self->get('Arch') . '-XXXXXX',
+ $self->get_conf('BUILD_ARCH') . '-XXXXXX',
DIR => $session->get('Location') . "/build"));
# Needed so chroot commands log to build log
@@ -387,7 +392,9 @@ sub run {
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);
@@ -607,7 +614,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);
@@ -785,14 +793,14 @@ sub fetch_source_files {
} else {
my $valid_arch;
for my $a (split(/\s+/, $dscarchs)) {
- if (Dpkg::Arch::debarch_is($arch, $a)) {
+ if (Dpkg::Arch::debarch_is($build_arch, $a)) {
$valid_arch = 1;
last;
}
}
if ($dscarchs ne "any" && !($valid_arch) &&
!($dscarchs eq "all" && $self->get_conf('BUILD_ARCH_ALL')) ) {
- my $msg = "$dsc: $arch not in arch list or does not match any arch ";
+ my $msg = "$dsc: $build_arch not in arch list or does not match any arch ";
$msg .= "wildcards: $dscarchs -- skipping\n";
$self->log($msg);
$self->set_status('skipped');
@@ -801,7 +809,7 @@ sub fetch_source_files {
}
}
- debug("Arch check ok ($arch included in $dscarchs)\n");
+ debug("Arch check ok ($build_arch included in $dscarchs)\n");
$self->set('Build Depends', $build_depends);
$self->set('Build Depends Indep', $build_depends_indep);
@@ -999,7 +1007,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 );
@@ -1120,7 +1129,7 @@ sub build {
" to version number; no source changes\n";
}
if ($self->get_conf('BIN_NMU')) {
- print F " * Binary-only non-maintainer upload for $arch; ",
+ print F " * Binary-only non-maintainer upload for $build_arch; ",
"no source changes.\n";
print F " * ", join( " ", split( "\n", $self->get_conf('BIN_NMU') )), "\n";
}
@@ -1304,7 +1313,7 @@ sub build {
}
}
- $changes = $self->get('Package_SVersion') . "_$arch.changes";
+ $changes = $self->get('Package_SVersion') . "_$build_arch.changes";
my @cfiles;
if (-r "$build_dir/$changes") {
my(@do_dists, @saved_dists);
@@ -1358,7 +1367,7 @@ sub build {
my @debcfiles = @cfiles;
foreach (@debcfiles) {
my $deb = "$build_dir/$_";
- next if $deb !~ /(\Q$arch\E|all)\.[\w\d.-]*$/;
+ next if $deb !~ /(\Q$build_arch\E|all)\.[\w\d.-]*$/;
$self->log_subsubsection("$_");
if (!open( PIPE, "dpkg --info $deb 2>&1 |" )) {
@@ -1623,7 +1632,7 @@ 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('BUILD_ARCH'));
$self->add_stat('Distribution', $self->get_conf('DISTRIBUTION'));
$self->add_stat('Space', $self->get('This Space'));
$self->add_stat('Build-Time',
@@ -1724,7 +1733,7 @@ sub open_build_log {
my $filename = $self->get_conf('LOG_DIR') . '/' .
$self->get('Package_SVersion') . '-' .
- $self->get('Arch') .
+ $self->get_conf('BUILD_ARCH') .
"-$date";
my $PLOG;
@@ -1755,7 +1764,7 @@ sub open_build_log {
$self->log_symlink($filename,
$self->get_conf('BUILD_DIR') . '/' .
$self->get('Package_SVersion') . '_' .
- $self->get('Arch') . '.build');
+ $self->get_conf('BUILD_ARCH') . '.build');
}
}
@@ -1792,8 +1801,12 @@ sub open_build_log {
my $hostname = $self->get_conf('HOSTNAME');
$self->log("sbuild (Debian sbuild) $version ($release_date) on $hostname\n");
+ my $arch_string = $self->get_conf('BUILD_ARCH');
+ $arch_string = 'CROSS host=' . $self->get_conf('BUILD_ARCH') .
+ '/build=' . $self->get_conf('BUILD_ARCH')
+ if ($self->get_conf('BUILD_ARCH') != $self->get_conf('BUILD_ARCH'));
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)) .
@@ -1803,7 +1816,9 @@ sub open_build_log {
$self->log("Package: " . $self->get('Package') . "\n");
$self->log("Version: " . $self->get('Version') . "\n");
$self->log("Source Version: " . $self->get('OVersion') . "\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");
}
sub close_build_log {
@@ -1843,8 +1858,8 @@ sub close_build_log {
my $subject = "Log for " . $self->get_status() .
" build of " . $self->get('Package_Version');
- if ($self->get('Arch')) {
- $subject .= " on " . $self->get('Arch');
+ if ($self->get_conf('BUILD_ARCH')) {
+ $subject .= " on " . $self->get_conf('BUILD_ARCH');
}
if ($self->get_conf('ARCHIVE')) {
$subject .= " (" . $self->get_conf('ARCHIVE') . "/" . $self->get_conf('DISTRIBUTION') . ")";
diff --git a/lib/Sbuild/Conf.pm b/lib/Sbuild/Conf.pm
index 65c518e..9624904 100644
--- a/lib/Sbuild/Conf.pm
+++ b/lib/Sbuild/Conf.pm
@@ -638,6 +638,8 @@ sub read ($) {
my $chroot = undef;
my $build_arch_all = undef;
my $arch = undef;
+ my $host_arch = undef;
+ my $build_arch = undef;
my $job_file = undef;
my $build_dir = undef;
my $build_dep_resolver = undef;
@@ -670,7 +672,12 @@ sub read ($) {
$conf->set('BUILD_DEP_RESOLVER', $build_dep_resolver);
$conf->set('RESOLVE_VIRTUAL', $resolve_virtual);
$conf->set('CORE_DEPENDS', $core_depends);
- $conf->set('ARCH', $arch);
+ # Don't ever set ARCH since it's the native arch.
+ # $conf->set('ARCH', $arch);
+ $conf->set('HOST_ARCH', $arch);
+ $conf->set('BUILD_ARCH', $arch);
+ $conf->set('HOST_ARCH', $host_arch);
+ $conf->set('BUILD_ARCH', $build_arch);
$conf->set('DISTRIBUTION', $distribution);
$conf->set('DEBUG', $debug);
$conf->set('MAILPROG', $mailprog);
diff --git a/lib/Sbuild/ConfBase.pm b/lib/Sbuild/ConfBase.pm
index c43b161..04fcafd 100644
--- a/lib/Sbuild/ConfBase.pm
+++ b/lib/Sbuild/ConfBase.pm
@@ -85,7 +85,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 = (
@@ -126,11 +126,15 @@ sub init_allowed_keys {
DEFAULT => '/usr/sbin/sendmail'
},
# TODO: Check if defaulted in code assuming undef
+ # ARCH is the native (system) architecture. Not used for host/build.
'ARCH' => {
- DEFAULT => $host_arch
+ DEFAULT => $native_arch
},
'HOST_ARCH' => {
- DEFAULT => $host_arch
+ DEFAULT => $native_arch
+ },
+ 'BUILD_ARCH' => {
+ DEFAULT => $native_arch
},
'HOSTNAME' => {
DEFAULT => $hostname
diff --git a/lib/Sbuild/InternalResolver.pm b/lib/Sbuild/InternalResolver.pm
index 7f5f77d..f7f43ba 100644
--- a/lib/Sbuild/InternalResolver.pm
+++ b/lib/Sbuild/InternalResolver.pm
@@ -83,10 +83,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;
@@ -206,10 +206,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 a48e194..13c147b 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 9d4d7cc..0597571 100644
--- a/lib/Sbuild/ResolverBase.pm
+++ b/lib/Sbuild/ResolverBase.pm
@@ -557,7 +557,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
@@ -590,17 +590,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'));
}
if ($positive ne "") {
diff --git a/lib/Sbuild/Utility.pm b/lib/Sbuild/Utility.pm
index 550c94e..e5c9d1a 100644
--- a/lib/Sbuild/Utility.pm
+++ b/lib/Sbuild/Utility.pm
@@ -99,7 +99,7 @@ sub setup ($$$) {
$session = $chroot_info->create($namespace,
$chroot,
undef, # TODO: Add --chroot option
- $conf->get('ARCH'));
+ $conf->get('HOST_ARCH'));
$session->set('Log Stream', \*STDOUT);
diff --git a/man/sbuild.1.in b/man/sbuild.1.in
index 763ffa5..bbb9e09 100644
--- a/man/sbuild.1.in
+++ b/man/sbuild.1.in
@@ -27,6 +27,8 @@ sbuild \- build debian packages from source
.RB [ \-\-archive=\fIarchive\fP ]
.RB [ \-d \[or] \-\-dist=\fIdistribution\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 ]
@@ -137,7 +139,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
--
1.7.2.3
--FkmkrVfFsRoUs1wW
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="0002-Sbuild-Build-Add-dpkg-buildpackage-a-option-when-cro.patch"
More information about the Buildd-tools-devel
mailing list