Explorar o código

dpkg-source: Generate Testsuite-Triggers field from test dependencies

Sometimes autopkgtests regress due to change in a package which is only
a test dependency (Depends: in debian/tests/control), not a build or
binary one. It is useful to trigger a test if such a test dependency
changes.

Record the union of all test dependency packages in a new
Testsuite-Triggers field in the .dsc, so that they will be recorded in
the Sources package index. Ignore versions and flatten OR dependencies
as they are not interesting for determining reverse test dependencies
and should not be (ab)used for replacing debian/tests/control parsing.

Closes: #779559
LP: #1491145
Based-on-patch-by: Martin Pitt <martin.pitt@ubuntu.com>
Signed-off-by: Guillem Jover <guillem@debian.org>
Guillem Jover %!s(int64=10) %!d(string=hai) anos
pai
achega
90324cfa94
Modificáronse 3 ficheiros con 40 adicións e 2 borrados
  1. 3 0
      debian/changelog
  2. 6 2
      scripts/Dpkg/Control/FieldsCore.pm
  3. 31 0
      scripts/dpkg-source.pl

+ 3 - 0
debian/changelog

@@ -9,6 +9,9 @@ dpkg (1.18.8) UNRELEASED; urgency=medium
     under either the dpkg system or user configuration directories.
     under either the dpkg system or user configuration directories.
     Closes: #539692, #765494
     Closes: #539692, #765494
   * Check that debian/tests/control is a regular file before parsing it.
   * Check that debian/tests/control is a regular file before parsing it.
+  * Generate Testsuite-Triggers field from test dependencies in dpkg-source
+    into .dsc files. Based on a patch by Martin Pitt <martin.pitt@ubuntu.com>.
+    Closes: #779559
   * Perl modules:
   * Perl modules:
     - Use warnings::warnif() instead of carp() for deprecated warnings.
     - Use warnings::warnif() instead of carp() for deprecated warnings.
     - Add new format_range() method and deprecate dpkg() and rfc822() methods
     - Add new format_range() method and deprecate dpkg() and rfc822() methods

+ 6 - 2
scripts/Dpkg/Control/FieldsCore.pm

@@ -354,6 +354,10 @@ our %FIELDS = (
         allowed => ALL_SRC,
         allowed => ALL_SRC,
         separator => FIELD_SEP_COMMA,
         separator => FIELD_SEP_COMMA,
     },
     },
+    'Testsuite-Triggers' => {
+        allowed => ALL_SRC,
+        separator => FIELD_SEP_COMMA,
+    },
     'Timestamp' => {
     'Timestamp' => {
         allowed => CTRL_CHANGELOG,
         allowed => CTRL_CHANGELOG,
     },
     },
@@ -439,8 +443,8 @@ our %FIELD_ORDER = (
         qw(Format Source Binary Architecture Version Origin Maintainer
         qw(Format Source Binary Architecture Version Origin Maintainer
         Uploaders Homepage Standards-Version Vcs-Browser
         Uploaders Homepage Standards-Version Vcs-Browser
         Vcs-Arch Vcs-Bzr Vcs-Cvs Vcs-Darcs Vcs-Git Vcs-Hg Vcs-Mtn
         Vcs-Arch Vcs-Bzr Vcs-Cvs Vcs-Darcs Vcs-Git Vcs-Hg Vcs-Mtn
-        Vcs-Svn Testsuite), &field_list_src_dep(), qw(Package-List),
-        @checksum_fields, qw(Files)
+        Vcs-Svn Testsuite Testsuite-Triggers), &field_list_src_dep(),
+        qw(Package-List), @checksum_fields, qw(Files)
     ],
     ],
     CTRL_FILE_CHANGES() => [
     CTRL_FILE_CHANGES() => [
         qw(Format Date Source Binary Binary-Only Built-For-Profiles Architecture
         qw(Format Date Source Binary Binary-Only Built-For-Profiles Architecture

+ 31 - 0
scripts/dpkg-source.pl

@@ -41,7 +41,9 @@ use Dpkg::Deps;
 use Dpkg::Compression;
 use Dpkg::Compression;
 use Dpkg::Conf;
 use Dpkg::Conf;
 use Dpkg::Control::Info;
 use Dpkg::Control::Info;
+use Dpkg::Control::Tests;
 use Dpkg::Control::Fields;
 use Dpkg::Control::Fields;
+use Dpkg::Index;
 use Dpkg::Substvars;
 use Dpkg::Substvars;
 use Dpkg::Version;
 use Dpkg::Version;
 use Dpkg::Vars;
 use Dpkg::Vars;
@@ -359,6 +361,7 @@ if ($options{opmode} =~ /^(build|print-format|(before|after)-build|commit)$/) {
 
 
     # Check if we have a testsuite, and handle manual and automatic values.
     # Check if we have a testsuite, and handle manual and automatic values.
     set_testsuite_field($fields);
     set_testsuite_field($fields);
+    set_testsuite_triggers_field($fields, @binarypackages);
 
 
     # Scan fields of dpkg-parsechangelog
     # Scan fields of dpkg-parsechangelog
     foreach (keys %{$changelog}) {
     foreach (keys %{$changelog}) {
@@ -515,6 +518,34 @@ sub set_testsuite_field
     $fields->{'Testsuite'} = join ', ', sort keys %testsuite;
     $fields->{'Testsuite'} = join ', ', sort keys %testsuite;
 }
 }
 
 
+sub set_testsuite_triggers_field
+{
+    my ($fields, @binarypackages) = @_;
+    my %testdeps;
+
+    # Never overwrite a manually defined field.
+    return if $fields->{'Testsuite-Triggers'};
+
+    # We only support autopkgtests.
+    return unless -e "$dir/debian/tests/control";
+
+    my $tests = Dpkg::Control::Tests->new();
+    $tests->load("$dir/debian/tests/control");
+
+    foreach my $test ($tests->get()) {
+        next unless $test->{Depends};
+
+        my $deps = deps_parse($test->{Depends}, use_arch => 0, tests_dep => 1);
+        deps_iterate($deps, sub { $testdeps{$_[0]->{package}} = 1 });
+    }
+
+    # Remove our own binaries and meta-depends.
+    foreach my $pkg (@binarypackages, qw(@ @builddeps@)) {
+        delete $testdeps{$pkg};
+    }
+    $fields->{'Testsuite-Triggers'} = join ', ', sort keys %testdeps;
+}
+
 sub setopmode {
 sub setopmode {
     my $opmode = shift;
     my $opmode = shift;