Hi! Here's my proposed patch to implement --setup-hook, which exports the build settings, as well as the build Config into the environment.
-Kees -- Kees Cook @debian.org
--- sbuild-0.58.2.orig/bin/sbuild +++ sbuild-0.58.2/bin/sbuild @@ -213,6 +213,25 @@ goto cleanup_close; } + # Setup command + if ($conf->get('SETUP_HOOK')) { + my $pipe = $session->pipe_command({ + COMMAND => [$conf->get('SETUP_HOOK')], + ENV => $build->get_env('SBUILD_BUILD_'), + USER => "root", + PRIORITY => 0, + CHROOT => 1 }); + while(<$pipe>) { + $build->log($_); + } + close($pipe); + if ($?) { + $build->log("setup-hook failed\n"); + $build->set('Pkg Status', 'skipped'); + goto cleanup_packages; + } + } + $build->set('Pkg Fail Stage', 'install-deps'); if (!$build->install_deps()) { $build->log("Source-dependencies not satisfied; skipping " . only in patch2: unchanged: --- sbuild-0.58.2.orig/lib/Sbuild/Options.pm +++ sbuild-0.58.2/lib/Sbuild/Options.pm @@ -157,6 +157,9 @@ "stats-dir=s" => sub { $self->set_conf('STATS_DIR', $_[1]); }, + "setup-hook=s" => sub { + $self->set_conf('SETUP_HOOK', $_[1]); + }, "use-snapshot" => sub { $self->set_conf('GCC_SNAPSHOT', 1); $self->set_conf('LD_LIBRARY_PATH', only in patch2: unchanged: --- sbuild-0.58.2.orig/lib/Sbuild/Conf.pm +++ sbuild-0.58.2/lib/Sbuild/Conf.pm @@ -298,6 +298,9 @@ 'SBUILD_MODE' => { DEFAULT => 'user' }, + 'SETUP_HOOK' => { + DEFAULT => undef + }, 'FORCE_ORIG_SOURCE' => { DEFAULT => 0 }, @@ -471,6 +474,7 @@ our $sbuild_mode = undef; our $debug = undef; our $force_orig_source = undef; + our $setup_hook = undef; our %individual_stalled_pkg_timeout; undef %individual_stalled_pkg_timeout; our $path = undef; @@ -537,6 +541,7 @@ $self->set('CHROOT_SPLIT', $chroot_split); $self->set('SBUILD_MODE', $sbuild_mode); $self->set('FORCE_ORIG_SOURCE', $force_orig_source); + $self->set('SETUP_HOOK', $setup_hook); $self->set('INDIVIDUAL_STALLED_PKG_TIMEOUT', \%individual_stalled_pkg_timeout); $self->set('PATH', $path); only in patch2: unchanged: --- sbuild-0.58.2.orig/lib/Sbuild/Base.pm +++ sbuild-0.58.2/lib/Sbuild/Base.pm @@ -66,6 +66,30 @@ return $self->get('Config')->get($key); } +# Produce a hash suitable for ENV export +sub get_env ($$) { + my $self = shift; + my $prefix = shift; + + sub _env_loop ($$$$) { + my ($env,$ref,$keysref,$prefix) = @_; + + foreach my $key (keys( %{ $keysref } )) { + my $value = $ref->get($key); + next if (!defined($value)); + next if (ref($value)); + my $name = "${prefix}${key}"; + $name =~ s/ /_/g; + $env->{$name} = $value; + } + } + + my $envlist = {}; + _env_loop($envlist, $self, $self, $prefix); + _env_loop($envlist, $self->get('Config'), $self->get('Config')->{'KEYS'}, "${prefix}CONF_"); + return $envlist; +} + sub set_conf { my $self = shift; my $key = shift;