Просмотр исходного кода

Dpkg::Deps::Multiple: Add profile_is_concerned() and reduce_profiles() methods

These got missed in commit 7662e0937bb064a0754d12605d80a96a17e2aadf.

The current dpkg code is not using those methods, but external programs
might need them.
Guillem Jover лет назад: 12
Родитель
Сommit
c87941de95
3 измененных файлов с 50 добавлено и 2 удалено
  1. 3 0
      debian/changelog
  2. 29 1
      scripts/Dpkg/Deps.pm
  3. 18 1
      scripts/t/Dpkg_Deps.t

+ 3 - 0
debian/changelog

@@ -40,6 +40,9 @@ dpkg (1.17.10) UNRELEASED; urgency=low
     - Bump $VERSION for Dpkg::Patch, missed in 1.16.1.
     - Bump $VERSION for Dpkg::Deps, missed in 1.17.0.
     - Update and fix CHANGES POD sections for public modules.
+    - Add missing Dpkg::Deps::Multiple profile_is_concerned() and
+      reduce_profiles() methods, inherited by Dpkg::Deps::Union,
+      Dpkg::Deps::AND and Dpkg::Deps::OR.
 
   [ Updated manpages translations ]
   * German (Helge Kreutzmann).

+ 29 - 1
scripts/Dpkg/Deps.pm

@@ -49,7 +49,7 @@ All the deps_* functions are exported by default.
 use strict;
 use warnings;
 
-our $VERSION = '1.03';
+our $VERSION = '1.04';
 
 use Dpkg::Version;
 use Dpkg::Arch qw(get_host_arch get_build_arch);
@@ -1001,6 +1001,26 @@ sub has_arch_restriction {
     return @res;
 }
 
+sub profile_is_concerned {
+    my ($self, $build_profiles) = @_;
+    my $res = 0;
+
+    foreach my $dep (@{$self->{list}}) {
+        $res = 1 if $dep->profile_is_concerned($build_profiles);
+    }
+    return $res;
+}
+
+sub reduce_profiles {
+    my ($self, $build_profiles) = @_;
+    my @new;
+
+    foreach my $dep (@{$self->{list}}) {
+        $dep->reduce_profiles($build_profiles);
+        push @new, $dep if $dep->profile_is_concerned($build_profiles);
+    }
+    $self->{list} = [ @new ];
+}
 
 sub is_empty {
     my $self = shift;
@@ -1440,6 +1460,14 @@ sub _evaluate_simple_dep {
 
 =head1 CHANGES
 
+=head2 Version 1.04
+
+New options: Add use_profiles, build_profiles, reduce_profiles and
+reduce_restrictions to Dpkg::Deps::deps_parse().
+
+New methods: Add $dep->profile_is_concerned() and $dep->reduce_profiles()
+for all dependency objects.
+
 =head2 Version 1.03
 
 New option: Add build_arch option to Dpkg::Deps::deps_parse().

+ 18 - 1
scripts/t/Dpkg_Deps.t

@@ -16,7 +16,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 31;
+use Test::More tests => 36;
 use Dpkg::Arch qw(get_host_arch);
 
 use_ok('Dpkg::Deps');
@@ -84,6 +84,19 @@ is($dep_stage1->output(), 'dep2, dep4, dep5, dep7', 'Profile reduce 2/4');
 is($dep_notest->output(), 'dep3, dep4, dep6, dep8', 'Profile reduce 3/4');
 is($dep_stage1notest->output(), 'dep2, dep3, dep4, dep5, dep7 | dep8', 'Profile reduce 4/4');
 
+$dep_noprof = deps_parse($field_profile);
+$dep_noprof->reduce_profiles([]);
+$dep_stage1 = deps_parse($field_profile);
+$dep_stage1->reduce_profiles(['stage1']);
+$dep_notest = deps_parse($field_profile);
+$dep_notest->reduce_profiles(['notest']);
+$dep_stage1notest = deps_parse($field_profile);
+$dep_stage1notest->reduce_profiles(['stage1', 'notest']);
+is($dep_noprof->output(), 'dep1, dep2, dep3, dep6', 'Profile post-reduce 1/4');
+is($dep_stage1->output(), 'dep2, dep4, dep5, dep7', 'Profile post-reduce 2/4');
+is($dep_notest->output(), 'dep3, dep4, dep6, dep8', 'Profile post-reduce 3/4');
+is($dep_stage1notest->output(), 'dep2, dep3, dep4, dep5, dep7 | dep8', 'Profile post-reduce 4/4');
+
 my $field_restrict = 'dep1 <!profile.bootstrap !other.restrict>, ' .
 'dep2 <profile.bootstrap other.restrict>, ' .
 'dep3 <!other.restrict>, ' .
@@ -91,6 +104,10 @@ my $field_restrict = 'dep1 <!profile.bootstrap !other.restrict>, ' .
 my $dep_restrict = deps_parse($field_restrict, reduce_restrictions => 1, build_profiles => []);
 is($dep_restrict->output(), 'dep1', 'Unknown restrictions reduce');
 
+$dep_restrict = deps_parse($field_restrict);
+$dep_restrict->reduce_profiles([]);
+is($dep_restrict->output(), 'dep1', 'Unknown restrictions post-reduce');
+
 my $facts = Dpkg::Deps::KnownFacts->new();
 $facts->add_installed_package('mypackage', '1.3.4-1', get_host_arch(), 'no');
 $facts->add_installed_package('mypackage2', '1.3.4-1', 'somearch', 'no');