Control: tag -1 + pending patch Hi Sean,
CC-ing Martin Pitt to get this right. On Wed, 8 Jun 2016 15:13:58 +0900 Sean Whitton <spwhit...@spwhitton.name> wrote: > So the problem is to come up with a sensible default set of options to pass > to adt-run that will Just Work? This should work without any schroot: > > adt-run --changes foo.changes --- null > > Someone who *does* have a schroot will want to override this default to > use their schroot: in my experience, the null test is useful but it > doesn't catch some failures such as missing test dependencies. > > So we also need --adt-run-opts. The user will want to use %a in this, > and ideally a percent escape sequence representing the > suite/distribution -- this would also be useful in $piuparts_opts but I > don't believe it is currently supported. > > If we assume that sbuild implicitly passes the changes file to adt-run > as it currently does with lintian and piuparts, I could have > > $adt_run_opts = [ '---', 'schroot', '%D-%a-sbuild']; > > where %D is my imagined escape sequence giving the distribution. If I > need to do a build for a distribution that I don't have a schroot > prepared for, I could use `--no-run-adt-run --no-run-piuparts` to disable > those steps. I now have a local patch that adds autopkgtest support in the same way that piuparts support is added. But if I understand the changelog entry for version 4.0 correctly, then I should now use the autopkgtest binary instead of adt-run and use '--' instead of '---'. Is that correct? Somehow the autopkgtest man page still talks about '---' in the synopsis. The default is now to run: sudo -- autopkgtest foobar.changes -- null Should the default be to run autopkgtest with sudo in front? The '--autopkgtest-opts' command line option allows one to replace the '-- null' part in the example above with custom options. Implementing percentage escapes will come at a later point if required. Please open a separate bug for that and then I can also implement that for piuparts. The 'autopkgtest-root-args' command line option allows one to replace the 'sudo --' part in the example above. Does this sound sensible as an initial implementation? Patch attached. Thanks! cheers, josch
From f33ecbef3ad771c41e8421300c2eb0b48c7686f1 Mon Sep 17 00:00:00 2001 From: Johannes 'josch' Schauer <jo...@mister-muffin.de> Date: Tue, 2 Aug 2016 13:13:12 +0200 Subject: [PATCH] Add feature to run autopkgtest after a successful build. --- lib/Sbuild/Build.pm | 45 ++++++++++++++++++++++++++++++++++++++ lib/Sbuild/Conf.pm | 45 ++++++++++++++++++++++++++++++++++++++ lib/Sbuild/Options.pm | 31 ++++++++++++++++++++++++++ man/sbuild.1.in | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 181 insertions(+) diff --git a/lib/Sbuild/Build.pm b/lib/Sbuild/Build.pm index f453fbb..ed34ea0 100644 --- a/lib/Sbuild/Build.pm +++ b/lib/Sbuild/Build.pm @@ -821,6 +821,10 @@ sub run_fetch_install_packages { $self->check_abort(); $self->run_piuparts(); + # Run autopkgtest. + $self->check_abort(); + $self->run_autopkgtest(); + # Run post build external commands $self->check_abort(); if(!$self->run_external_commands("post-build-commands")) { @@ -1550,6 +1554,45 @@ sub run_piuparts { return 1; } +sub run_autopkgtest { + my $self = shift; + + return 1 unless ($self->get_conf('RUN_AUTOPKGTEST')); + + $self->log_subsubsection("autopkgtest"); + + my $autopkgtest = $self->get_conf('AUTOPKGTEST'); + my @autopkgtest_command; + if (scalar(@{$self->get_conf('AUTOPKGTEST_ROOT_ARGS')})) { + push @autopkgtest_command, @{$self->get_conf('AUTOPKGTEST_ROOT_ARGS')}; + } else { + push @autopkgtest_command, 'sudo', '--'; + } + push @autopkgtest_command, $autopkgtest, $self->get('Changes File'); + if (scalar(@{$self->get_conf('AUTOPKGTEST_OPTIONS')})) { + push @autopkgtest_command, @{$self->get_conf('AUTOPKGTEST_OPTIONS')}; + } else { + push @autopkgtest_command, '--', 'null'; + } + $self->get('Host')->run_command( + { COMMAND => \@autopkgtest_command, + PRIORITY => 0, + }); + my $status = $? >> 8; + $self->set('Autopkgtest Reason', 'pass'); + + $self->log("\n"); + # fail if neither all tests passed nor was the package without tests + if ($status != 0 && $status != 8) { + $self->log_error("Autopkgtest run failed.\n"); + $self->set('Autopkgtest Reason', 'fail'); + return 0; + } + + $self->log_info("Autopkgtest run was successful.\n"); + return 1; +} + sub build { my $self = shift; @@ -2345,6 +2388,8 @@ sub generate_stats { if $self->get('Lintian Reason'); $self->add_stat('Piuparts', $self->get('Piuparts Reason')) if $self->get('Piuparts Reason'); + $self->add_stat('Autopkgtest', $self->get('Autopkgtest Reason')) + if $self->get('Autopkgtest Reason'); } sub log_stats { diff --git a/lib/Sbuild/Conf.pm b/lib/Sbuild/Conf.pm index 331170c..14945ae 100644 --- a/lib/Sbuild/Conf.pm +++ b/lib/Sbuild/Conf.pm @@ -1074,6 +1074,51 @@ $crossbuild_core_depends = { HELP => 'Preceding arguments to launch piuparts as root. If no arguments are specified, piuparts will be launched via sudo.', CLI_OPTIONS => ['--piuparts-root-arg', '--piuparts-root-args'] }, + 'AUTOPKGTEST' => { + TYPE => 'STRING', + VARNAME => 'autopkgtest', + GROUP => 'Build validation', + CHECK => sub { + my $conf = shift; + my $entry = shift; + my $key = $entry->{'NAME'}; + + # Only validate if needed. + if ($conf->get('RUN_AUTOPKGTEST')) { + $validate_program->($conf, $entry); + } + }, + DEFAULT => 'autopkgtest', + HELP => 'Path to autopkgtest binary', + CLI_OPTIONS => ['--autopkgtest-opt', '--autopkgtest-opts'] + }, + 'RUN_AUTOPKGTEST' => { + TYPE => 'BOOL', + VARNAME => 'run_autopkgtest', + GROUP => 'Build validation', + CHECK => sub { + my $conf = shift; + $conf->check('AUTOPKGTEST'); + }, + DEFAULT => 0, + HELP => 'Run autopkgtest', + CLI_OPTIONS => ['--run-autopkgtest', '--no-run-autopkgtest'] + }, + 'AUTOPKGTEST_OPTIONS' => { + TYPE => 'ARRAY:STRING', + VARNAME => 'autopkgtest_opts', + GROUP => 'Build validation', + DEFAULT => [], + HELP => 'Options to pass to autopkgtest. Each option is a separate arrayref element. For example, [\'-b\', \'<chroot_tarball>\'] to add -b and <chroot_tarball>.' + }, + 'AUTOPKGTEST_ROOT_ARGS' => { + TYPE => 'ARRAY:STRING', + VARNAME => 'autopkgtest_root_args', + GROUP => 'Build validation', + DEFAULT => [], + HELP => 'Preceding arguments to launch autopkgtest as root. If no arguments are specified, autopkgtest will be launched via sudo.', + CLI_OPTIONS => ['--autopkgtest-root-arg', '--autopkgtest-root-args'] + }, 'EXTERNAL_COMMANDS' => { TYPE => 'HASH:ARRAY:STRING', VARNAME => 'external_commands', diff --git a/lib/Sbuild/Options.pm b/lib/Sbuild/Options.pm index ba7fa78..2b436ef 100644 --- a/lib/Sbuild/Options.pm +++ b/lib/Sbuild/Options.pm @@ -50,6 +50,7 @@ sub set_options { my ($opt_clean_source, $opt_no_clean_source); my ($opt_run_lintian, $opt_no_run_lintian); my ($opt_run_piuparts, $opt_no_run_piuparts); + my ($opt_run_autopkgtest, $opt_no_run_autopkgtest); $self->add_options("arch=s" => sub { if (defined $opt_arch && $opt_arch ne $_[1]) { @@ -440,6 +441,36 @@ sub set_options { push(@{$self->get_conf('PIUPARTS_ROOT_ARGS')}, $_[1]); }, + "run-autopkgtest" => sub { + if ($opt_no_run_autopkgtest) { + die "--run-autopkgtest cannot be used together with --no-run-autopkgtest"; + } + $self->set_conf('RUN_AUTOPKGTEST', 1); + $opt_run_autopkgtest = 1; + }, + "no-run-autopkgtest" => sub { + if ($opt_run_autopkgtest) { + die "--no-run-autopkgtest cannot be used together with --run-autopkgtest"; + } + $self->set_conf('RUN_AUTOPKGTEST', 0); + $opt_no_run_autopkgtest = 1; + }, + "autopkgtest-opts=s" => sub { + push(@{$self->get_conf('AUTOPKGTEST_OPTIONS')}, + split(/\s+/, $_[1])); + }, + "autopkgtest-opt=s" => sub { + push(@{$self->get_conf('AUTOPKGTEST_OPTIONS')}, + $_[1]); + }, + "autopkgtest-root-args=s" => sub { + push(@{$self->get_conf('AUTOPKGTEST_ROOT_ARGS')}, + split(/\s+/, $_[1])); + }, + "autopkgtest-root-arg=s" => sub { + push(@{$self->get_conf('AUTOPKGTEST_ROOT_ARGS')}, + $_[1]); + }, "pre-build-commands=s" => sub { push(@{${$self->get_conf('EXTERNAL_COMMANDS')}{"pre-build-commands"}}, $_[1]); diff --git a/man/sbuild.1.in b/man/sbuild.1.in index 32ca840..4022852 100644 --- a/man/sbuild.1.in +++ b/man/sbuild.1.in @@ -72,6 +72,12 @@ sbuild \- build debian packages from source .RB [ \-\-piuparts\-opts=\fIoptions\fP ] .RB [ \-\-piuparts\-root\-arg=\fIoptions\fP ] .RB [ \-\-piuparts\-root\-args=\fIoptions\fP ] +.RB [ \-\-run\-autopkgtest ] +.RB [ \-\-no\-run\-autopkgtest ] +.RB [ \-\-autopkgtest\-opt=\fIoptions\fP ] +.RB [ \-\-autopkgtest\-opts=\fIoptions\fP ] +.RB [ \-\-autopkgtest\-root\-arg=\fIoptions\fP ] +.RB [ \-\-autopkgtest\-root\-args=\fIoptions\fP ] .RB [ \-\-pre\-build\-commands=\fIstring\fP ] .RB [ \-\-chroot\-setup\-commands=\fIstring\fP ] .RB [ \-\-chroot\-update\-failed\-commands=\fIstring\fP ] @@ -649,6 +655,59 @@ This command line option appends to the \fBPIUPARTS_ROOT_ARGS\fP configuration v .BR sbuild.conf (5) for more information. .TP +.BR \-\-run\-autopkgtest +Run autopkgtest after a successful build. This command line option sets the +\fBRUN_AUTOPKGTEST\fP configuration variable. See +.BR sbuild.conf (5) +for more information. +.TP +.BR \-\-no\-run\-autopkgtest +Don't run autopkgtest after a successful build. If sbuild is configured to run +autopkgtest by default, this option will prevent autopkgtest being run. This +command line option sets the \fBRUN_AUTOPKGTEST\fP configuration variable. See +.BR sbuild.conf (5) +for more information. +.TP +.BR \-\-autopkgtest\-opt=\fIoptions\fP +Pass the specified option directly to autopkgtest in addition to the options +already passed by sbuild. This option can be passed multiple times (once per +autopkgtest option) and can be freely mixed with the \-\-autopkgtest\-opts +option. Options will be passed to autopkgtest in the order that the +\-\-autopkgtest\-opt and \-\-autopkgtest\-opts options are given on the command +line. This command line option appends to the \fBAUTOPKGTEST_OPTIONS\fP +configuration variable. See +.BR sbuild.conf (5) +for more information. +.TP +.BR \-\-autopkgtest\-opts=\fIoptions\fP +Pass the specified options directly to autopkgtest in addition to the options +already passed by sbuild. The argument will be split by whitespaces and the +resulting array passed to the autopkgtest invocation. If any options contain +spaces, use \-\-autopkgtest\-opt for them. This option can be passed multiple +times and can be freely mixed with the \-\-autopkgtest\-opts option. Options +will be passed to autopkgtest in the order that the \-\-autopkgtest\-opt and +\-\-autopkgtest\-opts options are given on the command line. This command line +option appends to the \fBAUTOPKGTEST_OPTIONS\fP configuration variable. See +.BR sbuild.conf (5) +for more information. +.TP +.BR \-\-autopkgtest\-root\-arg=\fIoptions\fP +Add an argument that is used to launch autopkgtest as root. If no arguments are +specified, autopkgtest will be launched via sudo. This option can be specified +multiple times. This command line option appends to the +\fBAUTOPKGTEST_ROOT_ARGS\fP configuration variable. See +.BR sbuild.conf (5) +for more information. +.TP +.BR \-\-autopkgtest\-root\-args=\fIoptions\fP +Add arguments that are used to launch autopkgtest as root. If no arguments are +specified, autopkgtest will be launched via sudo. The argument will be split by +whitespaces. To pass options containing whitespaces use the option +\-\-autopkgtest\-root\-arg. This command line option appends to the +\fBAUTOPKGTEST_ROOT_ARGS\fP configuration variable. See +.BR sbuild.conf (5) +for more information. +.TP .BR \-\-pre\-build\-commands=\fIstring\fP This is the earliest external command which is run right after the chroot session has been initialized and before anything else is done (like installing @@ -1055,6 +1114,7 @@ Cleanup build files and dependencies \f[CB]\-\-chroot\-cleanup\-commands\fP yes inside yes no yes Close schroot session Run piuparts (if configured) +Run autopkgtest (if configured) \f[CB]\-\-post\-build\-commands\fP yes outside yes yes yes .TE .if t \{\ -- 2.8.1
signature.asc
Description: signature