Package: sbuild
Version: 0.78.1-2
Severity: wishlist

When using my systemd-nspawn chroot mode backend, the installation
process is fairly slow due to it being on a BTRFS filesystem.  (And
also, I was never really comfortable with the current recommendation
to put "eatmydata" into the schroot configuration to apply to all
commands, in case the LD_PRELOAD applying also to dpkg-buildpackage
might break some package build.)  So, this patch adds the ability to
request sbuild to run just the apt-get commands under eatmydata.

(It might not apply cleanly to a current source package since I based
it on top of my previous patch from #939843.)
-- 
Daniel Schepler
Description: eatmydata support
 Adds support for executing only apt-get under eatmydata (instead of needing
 to configure schroot to execute everything, even dpkg-buildpackage, under
 eatmydata).
Author: Daniel Schepler <dschep...@gmail.com>

--- sbuild-0.78.1.orig/lib/Sbuild/ChrootNspawn.pm
+++ sbuild-0.78.1/lib/Sbuild/ChrootNspawn.pm
@@ -53,7 +53,7 @@ sub begin_session {
 	'</dev/null',
 	'>/dev/null',
 	'2>pipe', $CONTAINER_STDERR;
-    my $session_id, $location;
+    my ($session_id, $location);
     if (($_ = <$CONTAINER_STDERR>) =~ m/^Spawning container (\S*) on (.*)\.$/) {
 	$session_id = $1;
 	$location = $2;
--- sbuild-0.78.1.orig/lib/Sbuild/Conf.pm
+++ sbuild-0.78.1/lib/Sbuild/Conf.pm
@@ -476,6 +476,21 @@ sub setup ($) {
 	    DEFAULT => 'md5sum',
 	    HELP => 'Path to md5sum binary'
 	},
+	'EATMYDATA'				=> {
+	    TYPE => 'STRING',
+	    VARNAME => 'eatmydata',
+	    GROUP => 'Programs',
+	    DEFAULT => 'eatmydata',
+	    HELP => 'Path to eatmydata binary'
+	},
+	'USE_EATMYDATA'				=> {
+	    TYPE => 'BOOL',
+	    VARNAME => 'use_eatmydata',
+	    GROUP => 'Programs',
+	    DEFAULT => 0,
+	    HELP => 'Use eatmydata for installing packages?',
+	    CLI_OPTIONS => ['--use-eatmydata', '--no-use-eatmydata']
+	},
 	'STATS_DIR'				=> {
 	    TYPE => 'STRING',
 	    VARNAME => 'stats_dir',
--- sbuild-0.78.1.orig/lib/Sbuild/ResolverBase.pm
+++ sbuild-0.78.1/lib/Sbuild/ResolverBase.pm
@@ -646,7 +646,8 @@ sub upgrade {
 	{ COMMAND => [$self->get_conf('APT_GET'), '-uy', '-o', 'Dpkg::Options::=--force-confold', 'upgrade'],
 	  ENV => {'DEBIAN_FRONTEND' => 'noninteractive'},
 	  USER => 'root',
-	  DIR => '/' });
+	  DIR => '/',
+	  EATMYDATA => 1 });
     return $?;
 }
 
@@ -657,7 +658,8 @@ sub distupgrade {
 	{ COMMAND => [$self->get_conf('APT_GET'), '-uy', '-o', 'Dpkg::Options::=--force-confold', 'dist-upgrade'],
 	  ENV => {'DEBIAN_FRONTEND' => 'noninteractive'},
 	  USER => 'root',
-	  DIR => '/' });
+	  DIR => '/',
+	  EATMYDATA => 1 });
     return $?;
 }
 
@@ -690,7 +692,8 @@ sub autoremove {
 	{ COMMAND => [$self->get_conf('APT_GET'), '-y', 'autoremove'],
 	  ENV => {'DEBIAN_FRONTEND' => 'noninteractive'},
 	  USER => 'root',
-	  DIR => '/' });
+	  DIR => '/',
+	  EATMYDATA => 1});
     return $?;
 }
 
@@ -848,7 +851,8 @@ sub run_apt {
 	      ENV => {'DEBIAN_FRONTEND' => 'noninteractive'},
 	      USER => 'root',
 	      PRIORITY => 0,
-	      DIR => '/' });
+	      DIR => '/',
+	      EATMYDATA => 1 });
     if (!$pipe) {
 	$self->log("Can't open pipe to apt-get: $!\n");
 	return 0;
@@ -1555,6 +1559,15 @@ sub get_apt_command_internal {
 	@aptcommand = @$command;
     }
 
+    if (exists $options->{'EATMYDATA'} && $options->{'EATMYDATA'} &&
+	$self->get_conf('USE_EATMYDATA')) {
+	my $session = $self->get('Session');
+	if (defined($session->get('Session Purged')) &&
+	    $session->get('Session Purged') == 1) {
+	    unshift @aptcommand, $self->get_conf('EATMYDATA');
+	}
+    }
+
     debug2("APT Command: ", join(" ", @aptcommand), "\n");
 
     $options->{'INTCOMMAND'} = \@aptcommand;
--- sbuild-0.78.1.orig/man/sbuild.1.in
+++ sbuild-0.78.1/man/sbuild.1.in
@@ -66,6 +66,8 @@ sbuild \- build debian packages from sou
 .RB [ \-n \[or] \-\-nolog ]
 .RB [ \-\-clean\-source ]
 .RB [ \-\-no\-clean\-source ]
+.RB [ \-\-use-eatmydata ]
+.RB [ \-\-no-use-eatmydata ]
 .RB [ \-\-run\-lintian ]
 .RB [ \-\-no\-run\-lintian ]
 .RB [ \-\-lintian\-opt=\fIoptions\fP ]
@@ -645,6 +647,22 @@ This command line option sets the \fBCLE
 .BR sbuild.conf (5)
 for more information.
 .TP
+.BR \-\-use\-eatmydata
+When installing packages in the chroot, use eatmydata to speed up the
+installation. Note that this only has an effect on cloned chroots, and not
+for example when running sbuild\-update on a source chroot. It also requires
+the eatmydata package to be preinstalled in the chroot.
+This command line option sets the \fBUSE_EATMYDATA\fP configuration variable. See
+.BR sbuild.conf (5)
+for more information
+.TP
+.BR \-\-no\-use\-eatmydata
+When installing packages in the chroot, do not use eatmydata to speed up the
+installation.
+This command line option sets the \fBUSE_EATMYDATA\fP configuration variable. See
+.BR sbuild.conf (5)
+for more information
+.TP
 .BR \-\-run\-lintian
 Run lintian after a successful build.
 This command line option sets the \fBRUN_LINTIAN\fP configuration variable. See

Reply via email to