[dpkg] 121/200: dpkg-source: Generate Testsuite-Restrictions fields from test restrictions

Ximin Luo infinity0 at debian.org
Wed Apr 5 15:17:27 UTC 2017


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch master
in repository dpkg.

commit 9899bdcf9bde76d969b124abf0a898fcbb202c70
Author: Guillem Jover <guillem at debian.org>
Date:   Fri Dec 16 22:39:38 2016 +0100

    dpkg-source: Generate Testsuite-Restrictions fields from test restrictions
    
    This information is currently only available in the Restrictions field in
    the debian/tests/control file.
    
    When dispatching tests, it might be inconvenient to have to download and
    unpack the source package beforehand. Let's expose this via the .dsc in
    a similar way we do for the Testsuite-Triggers field.
    
    Closes: #847926
    Based-on-patch-by: Iain Lane <laney at debian.org>
---
 debian/changelog                                        |  3 +++
 man/dsc.man                                             |  7 +++++++
 scripts/Dpkg/Control/FieldsCore.pm                      |  7 ++++++-
 scripts/Makefile.am                                     |  1 +
 scripts/dpkg-source.pl                                  | 17 +++++++++++++++++
 scripts/t/dpkg_source.t                                 | 16 +++++++++++++++-
 .../t/dpkg_source/{testsuite_1.dsc => testsuite_4.dsc}  |  9 +++++----
 7 files changed, 54 insertions(+), 6 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 6e83226..6bc2eaa 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -12,6 +12,9 @@ dpkg (1.18.19) UNRELEASED; urgency=medium
   * Refactor update-alternatives pathname existence check into a new function.
   * Avoid useless repeated lstat()s in update-alternatives.
   * Only check for debian/tests/control file once in dpkg-source.
+  * Generate Testsuite-Restrictions fields from the test restrictions in
+    dpkg-source into .dsc files. Closes: #847926
+    Based on a patch by Iain Lane <laney at debian.org>.
   * Portability:
     - On GNU/Hurd try to use the new process executable name attribute from
       libps, to properly match on start-stop-daemon --exec.
diff --git a/man/dsc.man b/man/dsc.man
index 70ccb87..6464fe0 100644
--- a/man/dsc.man
+++ b/man/dsc.man
@@ -153,6 +153,13 @@ generated by this source package and meta-dependencies such as \fB@\fP or
 Rationale: this field is needed because otherwise to be able to get the
 test dependencies, each source package would need to be unpacked.
 .TP
+.BI Testsuite\-Restrictions: " name-list"
+This field declares the comma-separated union of all test restrictions
+(\fBRestrictions\fP fields in \fIdebian/tests/control\fP file).
+
+Rationale: this field is needed because otherwise to be able to get the
+test restrictions, each source package would need to be unpacked.
+.TP
 .BI Build\-Depends: " package-list"
 .TQ
 .BI Build\-Depends\-Arch: " package-list"
diff --git a/scripts/Dpkg/Control/FieldsCore.pm b/scripts/Dpkg/Control/FieldsCore.pm
index 8eeddad..70fcc9d 100644
--- a/scripts/Dpkg/Control/FieldsCore.pm
+++ b/scripts/Dpkg/Control/FieldsCore.pm
@@ -383,6 +383,10 @@ our %FIELDS = (
         allowed => ALL_SRC,
         separator => FIELD_SEP_COMMA,
     },
+    'Testsuite-Restrictions' => {
+        allowed => ALL_SRC,
+        separator => FIELD_SEP_COMMA,
+    },
     'Testsuite-Triggers' => {
         allowed => ALL_SRC,
         separator => FIELD_SEP_COMMA,
@@ -472,7 +476,8 @@ our %FIELD_ORDER = (
         qw(Format Source Binary Architecture Version Origin Maintainer
         Uploaders Homepage Standards-Version Vcs-Browser
         Vcs-Arch Vcs-Bzr Vcs-Cvs Vcs-Darcs Vcs-Git Vcs-Hg Vcs-Mtn
-        Vcs-Svn Testsuite Testsuite-Triggers), &field_list_src_dep(),
+        Vcs-Svn Testsuite Testsuite-Triggers Testsuite-Restrictions),
+        &field_list_src_dep(),
         qw(Package-List), @checksum_fields, qw(Files)
     ],
     CTRL_FILE_BUILDINFO() => [
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 5583fa9..953efdb 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -326,6 +326,7 @@ test_data = \
 	t/dpkg_source/testsuite_1.dsc \
 	t/dpkg_source/testsuite_2.dsc \
 	t/dpkg_source/testsuite_3.dsc \
+	t/dpkg_source/testsuite_4.dsc \
 	t/merge_changelogs/ch-old \
 	t/merge_changelogs/ch-a \
 	t/merge_changelogs/ch-b \
diff --git a/scripts/dpkg-source.pl b/scripts/dpkg-source.pl
index da5f25e..bdbe911 100755
--- a/scripts/dpkg-source.pl
+++ b/scripts/dpkg-source.pl
@@ -520,6 +520,7 @@ sub set_testsuite_fields
         $tests->load("$dir/debian/tests/control");
 
         set_testsuite_triggers_field($tests, $fields, @binarypackages);
+        set_testsuite_restrictions_field($tests, $fields);
     } elsif ($testsuite{autopkgtest}) {
         warning(g_('%s field contains value %s, but no tests control file %s'),
                 'Testsuite', 'autopkgtest', 'debian/tests/control');
@@ -550,6 +551,22 @@ sub set_testsuite_triggers_field
     $fields->{'Testsuite-Triggers'} = join ', ', sort keys %testdeps;
 }
 
+sub set_testsuite_restrictions_field
+{
+    my ($tests, $fields) = @_;
+    my %restrict;
+
+    # Never overwrite a manually defined field.
+    return if $fields->{'Testsuite-Restrictions'};
+
+    foreach my $test ($tests->get()) {
+        next unless $test->{Restrictions};
+
+        $restrict{$_} = 1 foreach (split /[,\s]+/, $test->{Restrictions});
+    }
+    $fields->{'Testsuite-Restrictions'} = join ', ', sort keys %restrict;
+}
+
 sub setopmode {
     my $opmode = shift;
 
diff --git a/scripts/t/dpkg_source.t b/scripts/t/dpkg_source.t
index 2de0c0d..317e445 100644
--- a/scripts/t/dpkg_source.t
+++ b/scripts/t/dpkg_source.t
@@ -16,7 +16,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 8;
+use Test::More tests => 10;
 use Test::Dpkg qw(test_neutralize_checksums);
 
 use File::Spec::Functions qw(rel2abs);
@@ -64,12 +64,20 @@ Architecture: all
 Description: test package
 TMPL_CONTROL
 
+my $tmpl_tests_control = <<'TMPL_TESTS_CONTROL';
+Test-Command: ${test-command}
+Depends: ${test-depends}
+Restrictions: ${test-restrictions}
+TMPL_TESTS_CONTROL
+
 my %default_substvars = (
     'source-name' => 'test-source',
     'source-version' => 0,
     'source-section' => 'test',
     'source-priority' => 'optional',
     'source-testsuite' => 'autopkgtest',
+    'test-command' => 'true',
+    'test-depends' => '@',
     'suite' => 'unstable',
     'urgency' => 'low',
     'maintainer' => 'Dpkg Developers <debian-dpkg at lists.debian.org>',
@@ -168,4 +176,10 @@ $dirname = gen_source('source-name' => 'testsuite',
                       'source-version' => 3);
 test_build_source($dirname);
 
+$dirname = gen_source('source-name' => 'testsuite',
+                      'source-version' => 4,
+                      'test-restrictions' => 'needs-root,build-needed  allow-stderr',
+                      'control-test' => $tmpl_tests_control);
+test_build_source($dirname);
+
 1;
diff --git a/scripts/t/dpkg_source/testsuite_1.dsc b/scripts/t/dpkg_source/testsuite_4.dsc
similarity index 61%
copy from scripts/t/dpkg_source/testsuite_1.dsc
copy to scripts/t/dpkg_source/testsuite_4.dsc
index c408625..197cdbc 100644
--- a/scripts/t/dpkg_source/testsuite_1.dsc
+++ b/scripts/t/dpkg_source/testsuite_4.dsc
@@ -2,15 +2,16 @@ Format: 3.0 (native)
 Source: testsuite
 Binary: test-binary
 Architecture: all
-Version: 1
+Version: 4
 Maintainer: Dpkg Developers <debian-dpkg at lists.debian.org>
 Standards-Version: 1.0
 Testsuite: autopkgtest
+Testsuite-Restrictions: allow-stderr, build-needed, needs-root
 Package-List:
  test-binary deb test optional arch=all
 Checksums-Sha1:
- 0000000000000000000000000000000000000000 0 testsuite_1.tar.xz
+ 0000000000000000000000000000000000000000 0 testsuite_4.tar.xz
 Checksums-Sha256:
- 0000000000000000000000000000000000000000000000000000000000000000 0 testsuite_1.tar.xz
+ 0000000000000000000000000000000000000000000000000000000000000000 0 testsuite_4.tar.xz
 Files:
- 00000000000000000000000000000000 0 testsuite_1.tar.xz
+ 00000000000000000000000000000000 0 testsuite_4.tar.xz

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/dpkg.git



More information about the Reproducible-commits mailing list