[Buildd-tools-devel] Bug#472350: Bug#472350: sbuild: Add support for running apt-get update before a build

Roger Leigh rleigh at whinlatter.ukfsn.org
Sun Apr 20 10:38:40 UTC 2008


tags 472350 + fixed-upstream pending
thanks

Timothy G Abbott <tabbott at MIT.EDU> writes:

> I would find it useful to have an option in sbuild that automatically
> runs "apt-get update" in the build chroot immediately prior to
> building, which ensures the build gets the newest dependencies, even
> if one has not done an apt update in the source chroot recently.
>
> I've attached a patch to implement this feature.

Many thanks.  I have applied the patch with a couple of minor
modifications (error handling and config file update).  What I have
applied follows below, and is also here:

http://git.debian.org/?p=buildd-tools/sbuild.git;a=commitdiff;h=d2582f13ea7e376d875d736cbbb350e92453e33b


Regards,
Roger


diff --git a/AUTHORS b/AUTHORS
index 2daf8c3..de90446 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -16,3 +16,7 @@ Roger Leigh		<rleigh at debian.org>
 Ryan Murray		<rmurray at debian.org>
      	modifications for security building
 	maintenance
+
+Timothy G Abbott	<tabbott at mit.edu>
+	support for running "apt-get update" in chroots prior to
+	fetching sources and building
\ No newline at end of file
diff --git a/bin/sbuild b/bin/sbuild
index 83ef805..22f09fb 100755
--- a/bin/sbuild
+++ b/bin/sbuild
@@ -3,7 +3,8 @@
 # sbuild: build packages, obeying source dependencies
 # Copyright © 1998-2000 Roman Hodek <Roman.Hodek at informatik.uni-erlangen.de>
 # Copyright © 2005      Ryan Murray <rmurray at debian.org>
-# Copyright © 2005-2007 Roger Leigh <rleigh at debian.org>
+# Copyright © 2005-2008 Roger Leigh <rleigh at debian.org
+# Copyright © 2008      Timothy G Abbott <tabbott at mit.edu>
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -191,6 +192,7 @@ exit 1 if !GetOptions ("arch=s" => \$main::user_arch,
 		       "binNMU=i" => \$main::binNMUver,
 		       "database=s" => \$main::database,
 		       "D|debug+" => \$conf::debug,
+		       "apt-update" => \$conf::apt_update,
 		       "d|dist=s" => sub {
 			   $main::distribution = $_[1];
 			   $main::distribution = "oldstable"
@@ -337,6 +339,22 @@ foreach $dscfile (@ARGV) {
 
     $main::arch = chroot_arch();
 
+    # Update APT cache.
+    if ($conf::apt_update) {
+	if (!open(PIPE, Sbuild::Chroot::get_apt_command("$conf::apt_get", "-q update", "root", 1) . " 2>&1 |")) {
+	    print PLOG "Can't open pipe to apt-get: $!\n";
+	    return 0;
+	}
+	while(<PIPE>) {
+	    print PLOG $_;
+	}
+	close(PIPE);
+	if ($?) {
+	    print PLOG "apt-get update failed\n" ;
+	    $main::pkg_status = "skipped";
+	    goto cleanup_close;
+	}
+    }
 
     $main::pkg_fail_stage = "fetch-src";
     my @files_to_rm = fetch_source_files( \$dscfile,
@@ -433,7 +451,7 @@ sub fetch_source_files ($$$$$) {
 	}
     } else {
 	my %entries = ();
-	my $retried = 0;
+	my $retried = $conf::apt_update;
       retry:
 	print PLOG "Checking available source versions...\n";
 	my $command = get_apt_command("$conf::apt_cache", "-q showsrc $pkg", $main::username, 0);
diff --git a/etc/sbuild.conf b/etc/sbuild.conf
index 46e9d9d..1cea5b5 100644
--- a/etc/sbuild.conf
+++ b/etc/sbuild.conf
@@ -85,6 +85,10 @@
 # cost.
 #$apt_policy = 1;
 
+# APT update.  1 to enable running "apt-get update" at the start of
+# each build, or 0 to disable.
+#$apt_update = 0;
+
 # Check watched packages to discover missing build dependencies.  This
 # can be disabled to increase the speed of builds
 #$check_watches = 1;
diff --git a/lib/Sbuild/Conf.pm b/lib/Sbuild/Conf.pm
index f13cf91..cc36717 100644
--- a/lib/Sbuild/Conf.pm
+++ b/lib/Sbuild/Conf.pm
@@ -33,19 +33,20 @@ BEGIN {
 
     @ISA = qw(Exporter);
 
-    @EXPORT = qw($HOME %alternatives $apt_policy $check_watches $cwd
-		 $username $verbose $nolog $mailprog $dpkg $su
-		 $schroot $schroot_options $fakeroot $apt_get
-		 $apt_cache $dpkg_source $md5sum $avg_time_db
-		 $avg_space_db $package_checklist $build_env_cmnd
-		 $pgp_options $log_dir $mailto $mailfrom
-		 @no_auto_upgrade $check_depends_algorithm
+    @EXPORT = qw($HOME %alternatives $apt_policy $apt_update
+		 $check_watches $cwd $username $verbose $nolog
+		 $mailprog $dpkg $su $schroot $schroot_options
+		 $fakeroot $apt_get $apt_cache $dpkg_source $md5sum
+		 $avg_time_db $avg_space_db $package_checklist
+		 $build_env_cmnd $pgp_options $log_dir $mailto
+		 $mailfrom @no_auto_upgrade $check_depends_algorithm
 		 $purge_build_directory @toolchain_regex
 		 $stalled_pkg_timeout $srcdep_lock_dir
 		 $srcdep_lock_wait @ignore_watches_no_build_deps
 		 $build_dir $sbuild_mode $debug $force_orig_source
 		 %individual_stalled_pkg_timeout $path
-		 $maintainer_name $uploader_name %watches $key_id); }
+		 $maintainer_name $uploader_name %watches $key_id);
+}
 
 # Originally from the main namespace.
 (our $HOME = $ENV{'HOME'})
@@ -100,6 +101,7 @@ our $path = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X
 our $maintainer_name;
 our $uploader_name;
 our $key_id;
+our $apt_update = 0;
 our %alternatives = ("info-browser"		=> "info",
 		     "httpd"			=> "apache",
 		     "postscript-viewer"	=> "ghostview",
diff --git a/man/sbuild.1.in b/man/sbuild.1.in
index 9ad7818..41d5607 100644
--- a/man/sbuild.1.in
+++ b/man/sbuild.1.in
@@ -111,6 +111,9 @@ is a line of source dependencies in the same format as in
 .IR \-D , "\-\-debug"
 Enable debug output.
 .TP
+.IR "\-\-apt\-update"
+Run apt-get update in the chroot before executing the build.
+.TP
 .IR \-m , "\-\-maintainer=<maintainer>"
 Passed to dpkg\-genchanges and is used to set the Maintainer: field in
 the .changes file(s).


-- 
  .''`.  Roger Leigh
 : :' :  Debian GNU/Linux             http://people.debian.org/~rleigh/
 `. `'   Printing on GNU/Linux?       http://gutenprint.sourceforge.net/
   `-    GPG Public Key: 0x25BFB848   Please GPG sign your mail.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 188 bytes
Desc: not available
Url : http://lists.alioth.debian.org/pipermail/buildd-tools-devel/attachments/20080420/114e0c7b/attachment.pgp 


More information about the Buildd-tools-devel mailing list