1# ex:ts=8 sw=4: 2# $OpenBSD: ForwardDependencies.pm,v 1.11 2010/12/24 09:04:14 espie Exp $ 3# 4# Copyright (c) 2009 Marc Espie <espie@openbsd.org> 5# 6# Permission to use, copy, modify, and distribute this software for any 7# purpose with or without fee is hereby granted, provided that the above 8# copyright notice and this permission notice appear in all copies. 9# 10# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 17# handling of forward dependency adjustments 18 19use strict; 20use warnings; 21 22package OpenBSD::ForwardDependencies; 23 24require OpenBSD::RequiredBy; 25 26sub find 27{ 28 my ($class, $set) = @_; 29 my $forward = {}; 30 for my $old ($set->older) { 31 for my $f (OpenBSD::RequiredBy->new($old->pkgname)->list) { 32 next if defined $set->{older}->{$f}; 33 next if defined $set->{kept}->{$f}; 34 $forward->{$f} = 1; 35 } 36 } 37 bless { forward => $forward, set => $set}, $class; 38} 39 40sub adjust 41{ 42 my ($self, $state) = @_; 43 my $set = $self->{set}; 44 45 for my $f (keys %{$self->{forward}}) { 46 my $deps_f = OpenBSD::Requiring->new($f); 47 for my $check ($deps_f->list) { 48 my $h = $set->{older}->{$check}; 49 next unless defined $h; 50 if (!defined $h->{update_found}) { 51 $state->errsay("XXX #1", $check); 52 $deps_f->delete($check); 53 } else { 54 my $r = $h->{update_found}->pkgname; 55 $state->say("Adjusting #1 to #2 in #3", 56 $check, $r, $f) 57 if $state->verbose >= 3; 58 if ($check ne $r) { 59 $deps_f->delete($check)->add($r); 60 } 61 OpenBSD::RequiredBy->new($r)->add($f); 62 } 63 } 64 } 65} 66 67sub check 68{ 69 my ($self, $state) = @_; 70 my $forward = $self->{forward}; 71 my $set = $self->{set}; 72 73 my @r = keys %$forward; 74 75 my $result = {}; 76 77 return $result if @r == 0; 78 $state->say("Verifying dependencies still match for #1", 79 join(', ', @r)) if $state->verbose >= 2; 80 81 my @new = ($set->newer_names, $set->kept_names); 82 my @old = $set->older_names; 83 84 for my $f (@r) { 85 my $p2 = OpenBSD::PackingList->from_installation( 86 $f, \&OpenBSD::PackingList::DependOnly); 87 if (!defined $p2) { 88 $state->errsay("Error: #1 missing from installation", $f); 89 } else { 90 $p2->check_forward_dependency($f, \@old, \@new, $result); 91 } 92 } 93 if (%$result) { 94 $state->say("#1 forward dependencies:", $set->print); 95 while (my ($pkg, $l) = each %$result) { 96 my $deps = join(',', map {$_->{pattern}} @$l); 97 if (@$l == 1) { 98 $state->say("| Dependency of #1 on #2 doesn't match", 99 $pkg, $deps); 100 } else { 101 $state->say("| Dependencies of #1 on #2 don't match", 102 $pkg, $deps); 103 } 104 } 105 } 106 return $result; 107} 108 109package OpenBSD::PackingElement; 110sub check_forward_dependency 111{ 112} 113 114package OpenBSD::PackingElement::Dependency; 115sub check_forward_dependency 116{ 117 my ($self, $f, $old, $new, $r) = @_; 118 119 # nothing to validate if old dependency doesn't concern us. 120 return unless $self->spec->filter(@$old); 121 # nothing to do if new dependency just matches 122 return if $self->spec->filter(@$new); 123 124 push(@{$r->{$f}}, $self); 125} 126 1271; 128