Hi Roger, On Thu, Oct 02, 2008 at 12:36:34AM +0100, Roger Leigh wrote: > OK. I think calling external scripts here would be a good idea. We > could use run-parts to run all the scripts in e.g. /etc/sbuild/setup.d, > for example, in a similar manner to the schroot setup scripts, but with > all of the relevant sbuild state exported in the environment. This > would make it trivially extensible by users and other packages.
I'm finally getting back to looking at this. It does seem likely that system-wide setup scripts could be good, but I'm not sure the specific use-case I'm after would really be done here (for example, I don't want to do this for Debian builds, only Ubuntu builds). It doesn't seem right to make those choices in /etc/sbuild/setup.d/something is the right place -- i.e. it should really be up to the sbuild invoker. > Agreed. If you haven't already, you might be interested in looking at > the current sbuild in git: > > git://git.debian.org/git/buildd-tools/sbuild.git > > Here, the main build state, configuration, chroot information etc. have > all been object-oriented using perl objects. We can easily write a few > lines of perl to dump the object state into the environment so scripts > can access it. This would only be possible for scalar and perhaps array > values realistically, but it would give you all you need to do what you > want. Where should this happen? My particular use-case seems to need details from both $build and $options. Should exec_command export all of those values into the environment in addition to the stuff listed in Defaults->ENV? SBUILD_BUILD_... and SBUILD_OPTION_... ? I've updated the patch (untested...) to use all the new calling conventions in git, just for reference... Thanks! -Kees -- Kees Cook @debian.org
diff --git a/bin/sbuild b/bin/sbuild index 98752ce..9d829d1 100755 --- a/bin/sbuild +++ b/bin/sbuild @@ -218,6 +218,26 @@ sub main () { goto cleanup_close; } + # Setup command + if ($conf->get('SETUP_SCRIPT')) { + my $pipe = $session->pipe_command({ + COMMAND => [$conf->get('SETUP_SCRIPT'), + $build->get('DSC File'), + $options->get('Distribution')], + USER => "root", + PRIORITY => 0, + CHROOT => 1 }); + while(<$pipe>) { + $build->log($_); + } + close($pipe); + if ($?) { + $build->log("setup-cmd ($cmd) 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 " . diff --git a/lib/Sbuild/Conf.pm b/lib/Sbuild/Conf.pm index f204d05..c375863 100644 --- a/lib/Sbuild/Conf.pm +++ b/lib/Sbuild/Conf.pm @@ -472,6 +472,7 @@ sub read_config { our $sbuild_mode = undef; our $debug = undef; our $force_orig_source = undef; + our $setup_script = undef; our %individual_stalled_pkg_timeout; undef %individual_stalled_pkg_timeout; our $path = undef; @@ -537,6 +538,7 @@ sub read_config { $self->set('CHROOT_SPLIT', $chroot_split); $self->set('SBUILD_MODE', $sbuild_mode); $self->set('FORCE_ORIG_SOURCE', $force_orig_source); + $self->set('SETUP_SCRIPT', $setup_script); $self->set('INDIVIDUAL_STALLED_PKG_TIMEOUT', \%individual_stalled_pkg_timeout); $self->set('PATH', $path); diff --git a/lib/Sbuild/Options.pm b/lib/Sbuild/Options.pm index a66f02c..d930177 100644 --- a/lib/Sbuild/Options.pm +++ b/lib/Sbuild/Options.pm @@ -158,6 +158,9 @@ sub parse_options { "stats-dir=s" => sub { $self->set_conf('STATS_DIR', $_[1]); }, + "setup-script=s" => sub { + $self->set_conf('SETUP_SCRIPT', $_[1]); + }, "use-snapshot" => sub { $self->set_conf('GCC_SNAPSHOT', 1); $self->set_conf('LD_LIBRARY_PATH',