summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2010-12-20 09:23:24 +0000
committerMarc Espie <espie@cvs.openbsd.org>2010-12-20 09:23:24 +0000
commit102c82cec7eb4db49f28c449a5924d220119ed4d (patch)
treebe8b04eb81199b6b4af5b4d21fc292dc6cb3d578
parentd546d95f9176bd60f9fb58910e9e19676920e653 (diff)
move stuff around
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Dependencies.pm414
1 files changed, 207 insertions, 207 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Dependencies.pm b/usr.sbin/pkg_add/OpenBSD/Dependencies.pm
index 854e9ad44b4..8de8db798a8 100644
--- a/usr.sbin/pkg_add/OpenBSD/Dependencies.pm
+++ b/usr.sbin/pkg_add/OpenBSD/Dependencies.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: Dependencies.pm,v 1.141 2010/12/20 09:10:51 espie Exp $
+# $OpenBSD: Dependencies.pm,v 1.142 2010/12/20 09:23:23 espie Exp $
#
# Copyright (c) 2005-2010 Marc Espie <espie@openbsd.org>
#
@@ -17,6 +17,8 @@
use strict;
use warnings;
+use OpenBSD::SharedLibs;
+
# generic dependencies lookup class: walk the dependency tree as far
# as necessary to resolve dependencies
package OpenBSD::lookup;
@@ -307,18 +309,219 @@ sub clone
}
package OpenBSD::Dependencies::Solver;
-our @ISA = (qw(OpenBSD::Cloner));
-
-use OpenBSD::PackageInfo;
+our @ISA = qw(OpenBSD::Cloner);
my $global_cache = {};
+sub cached
+{
+ my ($self, $dep) = @_;
+ return $global_cache->{$dep->{pattern}} ||
+ $self->{cache}{$dep->{pattern}};
+}
+
+sub set_cache
+{
+ my ($self, $dep, $value) = @_;
+ $self->{cache}{$dep->{pattern}} = $value;
+}
+
+sub set_global
+{
+ my ($self, $dep, $value) = @_;
+ $global_cache->{$dep->{pattern}} = $value;
+}
+
+sub find_candidate
+{
+ my ($self, $dep, @list) = @_;
+ my @candidates = $dep->spec->filter(@list);
+ if (@candidates >= 1) {
+ return $candidates[0];
+ } else {
+ return undef;
+ }
+}
+
+sub solve_dependency
+{
+ my ($self, $state, $dep, $package) = @_;
+
+ my $v;
+
+ if (defined $self->cached($dep)) {
+ if ($state->defines('stat_cache')) {
+ if (defined $global_cache->{$dep->{pattern}}) {
+ $state->print("Global ");
+ }
+ $state->say("Cache hit on #1: #2", $dep->{pattern},
+ $self->cached($dep)->pretty);
+ }
+ $v = $self->cached($dep)->do($self, $state, $dep, $package);
+ return $v if $v;
+ }
+ if ($state->defines('stat_cache')) {
+ $state->say("No cache hit on #1", $dep->{pattern});
+ }
+
+ if ($state->{allow_replacing}) {
+
+ $v = $self->find_dep_in_self($state, $dep);
+ if ($v) {
+ $self->set_cache($dep, _cache::self->new($v));
+ push(@{$package->{before}}, $v);
+ return $v;
+ }
+ $v = $self->find_candidate($dep, $self->{set}->older_names);
+ if ($v) {
+ push(@{$self->{bad}}, $dep->{pattern});
+ return $v;
+ }
+ $v = $self->find_dep_in_stuff_to_install($state, $dep);
+ return $v if $v;
+ }
+
+ $v = $self->find_candidate($dep, @{$self->installed_list});
+ if ($v) {
+ if ($state->{newupdates}) {
+ if ($state->tracker->is_known($v)) {
+ return $v;
+ }
+ my $set = $state->updateset->add_older(OpenBSD::Handle->create_old($v, $state));
+ $set->merge_paths($self->{set});
+ $self->add_dep($set);
+ $self->set_cache($dep, _cache::to_update->new($v));
+ $state->tracker->todo($set);
+ }
+ return $v;
+ }
+ if (!$state->{allow_replacing}) {
+ $v = $self->find_dep_in_stuff_to_install($state, $dep);
+ return $v if $v;
+ }
+
+ $v = $self->find_dep_in_repositories($state, $dep);
+
+ my $s;
+ if ($v) {
+ $s = $state->updateset_from_location($v);
+ $v = $v->name;
+ } else {
+ # resort to default if nothing else
+ $v = $dep->{def};
+ $s = $state->updateset_with_new($v);
+ }
+
+ $s->merge_paths($self->{set});
+ $state->tracker->todo($s);
+ $self->add_dep($s);
+ $self->set_cache($dep, _cache::to_install->new($v));
+ return $v;
+}
+
+sub solve_depends
+{
+ my ($self, $state) = @_;
+
+ $self->{all_dependencies} = {};
+ $self->{to_register} = {};
+ $self->{deplist} = {};
+ delete $self->{installed};
+
+ for my $package ($self->{set}->newer, $self->{set}->kept) {
+ $package->{before} = [];
+ for my $dep (@{$package->{plist}->{depend}}) {
+ my $v = $self->solve_dependency($state, $dep, $package);
+ $self->{all_dependencies}->{$v} = $dep;
+ $self->{to_register}->{$package}->{$v} = $dep;
+ }
+ }
+
+ return values %{$self->{deplist}};
+}
+
+sub solve_wantlibs
+{
+ my ($solver, $state) = @_;
+ my $okay = 1;
+
+ my $lib_finder = OpenBSD::lookup::library->new($solver);
+ for my $h ($solver->{set}->newer) {
+ for my $lib (@{$h->{plist}->{wantlib}}) {
+ $solver->{localbase} = $h->{plist}->localbase;
+ next if $lib_finder->lookup($solver,
+ $solver->{to_register}->{$h}, $state,
+ $lib->spec);
+ if ($okay) {
+ $state->errsay("Can't install #1 because of libraries", $h->pkgname);
+ }
+ $okay = 0;
+ OpenBSD::SharedLibs::report_problem($state,
+ $lib->spec);
+ }
+ }
+ if (!$okay) {
+ $solver->dump($state);
+ $lib_finder->dump($state);
+ }
+ return $okay;
+}
+
+sub dump
+{
+ my ($self, $state) = @_;
+ if ($self->dependencies) {
+ $state->print("Direct dependencies for #1 resolve to #2",
+ $self->{set}->print, join(' ', $self->dependencies));
+ $state->print(" (todo: #1)",
+ join(' ', (map {$_->print} values %{$self->{deplist}})))
+ if %{$self->{deplist}};
+ $state->print("\n");
+ }
+}
+
+sub dependencies
+{
+ my $self = shift;
+ if (wantarray) {
+ return keys %{$self->{all_dependencies}};
+ } else {
+ return scalar(%{$self->{all_dependencies}});
+ }
+}
+
+sub check_lib_spec
+{
+ my ($self, $base, $spec, $dependencies) = @_;
+ my $r = OpenBSD::SharedLibs::lookup_libspec($base, $spec);
+ for my $candidate (@$r) {
+ if ($dependencies->{$candidate->origin}) {
+ return $candidate->origin;
+ }
+ }
+ return;
+}
+
sub add_dep
{
my ($self, $d) = @_;
$self->{deplist}{$d} = $d;
}
+use OpenBSD::PackageInfo;
+OpenBSD::Auto::cache(installed_list,
+ sub {
+ my $self = shift;
+
+ my @l = installed_packages();
+ for my $o ($self->{set}->older_names) {
+ @l = grep {$_ ne $o} @l;
+ }
+ return \@l;
+ }
+);
+
+
sub merge
{
my ($solver, @extra) = @_;
@@ -326,17 +529,6 @@ sub merge
$solver->clone('cache', @extra);
}
-sub find_candidate
-{
- my ($self, $dep, @list) = @_;
- my @candidates = $dep->spec->filter(@list);
- if (@candidates >= 1) {
- return $candidates[0];
- } else {
- return undef;
- }
-}
-
sub new
{
my ($class, $set) = @_;
@@ -388,16 +580,6 @@ sub check_for_loops
}
}
-sub dependencies
-{
- my $self = shift;
- if (wantarray) {
- return keys %{$self->{all_dependencies}};
- } else {
- return scalar(%{$self->{all_dependencies}});
- }
-}
-
sub find_dep_in_repositories
{
my ($self, $state, $dep) = @_;
@@ -470,134 +652,6 @@ sub find_dep_in_stuff_to_install
return $v;
}
-sub cached
-{
- my ($self, $dep) = @_;
- return $global_cache->{$dep->{pattern}} ||
- $self->{cache}{$dep->{pattern}};
-}
-
-sub set_cache
-{
- my ($self, $dep, $value) = @_;
- $self->{cache}{$dep->{pattern}} = $value;
-}
-
-sub set_global
-{
- my ($self, $dep, $value) = @_;
- $global_cache->{$dep->{pattern}} = $value;
-}
-
-OpenBSD::Auto::cache(installed_list,
- sub {
- my $self = shift;
-
- my @l = installed_packages();
- for my $o ($self->{set}->older_names) {
- @l = grep {$_ ne $o} @l;
- }
- return \@l;
- }
-);
-
-sub solve_dependency
-{
- my ($self, $state, $dep, $package) = @_;
-
- my $v;
-
- if (defined $self->cached($dep)) {
- if ($state->defines('stat_cache')) {
- if (defined $global_cache->{$dep->{pattern}}) {
- $state->print("Global ");
- }
- $state->say("Cache hit on #1: #2", $dep->{pattern},
- $self->cached($dep)->pretty);
- }
- $v = $self->cached($dep)->do($self, $state, $dep, $package);
- return $v if $v;
- }
- if ($state->defines('stat_cache')) {
- $state->say("No cache hit on #1", $dep->{pattern});
- }
-
- if ($state->{allow_replacing}) {
-
- $v = $self->find_dep_in_self($state, $dep);
- if ($v) {
- $self->set_cache($dep, _cache::self->new($v));
- push(@{$package->{before}}, $v);
- return $v;
- }
- $v = $self->find_candidate($dep, $self->{set}->older_names);
- if ($v) {
- push(@{$self->{bad}}, $dep->{pattern});
- return $v;
- }
- $v = $self->find_dep_in_stuff_to_install($state, $dep);
- return $v if $v;
- }
-
- $v = $self->find_candidate($dep, @{$self->installed_list});
- if ($v) {
- if ($state->{newupdates}) {
- if ($state->tracker->is_known($v)) {
- return $v;
- }
- my $set = $state->updateset->add_older(OpenBSD::Handle->create_old($v, $state));
- $set->merge_paths($self->{set});
- $self->add_dep($set);
- $self->set_cache($dep, _cache::to_update->new($v));
- $state->tracker->todo($set);
- }
- return $v;
- }
- if (!$state->{allow_replacing}) {
- $v = $self->find_dep_in_stuff_to_install($state, $dep);
- return $v if $v;
- }
-
- $v = $self->find_dep_in_repositories($state, $dep);
-
- my $s;
- if ($v) {
- $s = $state->updateset_from_location($v);
- $v = $v->name;
- } else {
- # resort to default if nothing else
- $v = $dep->{def};
- $s = $state->updateset_with_new($v);
- }
-
- $s->merge_paths($self->{set});
- $state->tracker->todo($s);
- $self->add_dep($s);
- $self->set_cache($dep, _cache::to_install->new($v));
- return $v;
-}
-
-sub solve_depends
-{
- my ($self, $state) = @_;
-
- $self->{all_dependencies} = {};
- $self->{to_register} = {};
- $self->{deplist} = {};
- delete $self->{installed};
-
- for my $package ($self->{set}->newer, $self->{set}->kept) {
- $package->{before} = [];
- for my $dep (@{$package->{plist}->{depend}}) {
- my $v = $self->solve_dependency($state, $dep, $package);
- $self->{all_dependencies}->{$v} = $dep;
- $self->{to_register}->{$package}->{$v} = $dep;
- }
- }
-
- return values %{$self->{deplist}};
-}
-
sub check_depends
{
my $self = shift;
@@ -610,19 +664,6 @@ sub check_depends
return $self->{bad};
}
-sub dump
-{
- my ($self, $state) = @_;
- if ($self->dependencies) {
- $state->print("Direct dependencies for #1 resolve to #2",
- $self->{set}->print, join(' ', $self->dependencies));
- $state->print(" (todo: #1)",
- join(' ', (map {$_->print} values %{$self->{deplist}})))
- if %{$self->{deplist}};
- $state->print("\n");
- }
-}
-
sub register_dependencies
{
my ($self, $state) = @_;
@@ -652,20 +693,6 @@ sub repair_dependencies
}
}
-use OpenBSD::SharedLibs;
-
-sub check_lib_spec
-{
- my ($self, $base, $spec, $dependencies) = @_;
- my $r = OpenBSD::SharedLibs::lookup_libspec($base, $spec);
- for my $candidate (@$r) {
- if ($dependencies->{$candidate->origin}) {
- return $candidate->origin;
- }
- }
- return;
-}
-
sub find_old_lib
{
my ($self, $state, $base, $pattern, $lib) = @_;
@@ -682,33 +709,6 @@ sub find_old_lib
return undef;
}
-sub solve_wantlibs
-{
- my ($solver, $state) = @_;
- my $okay = 1;
-
- my $lib_finder = OpenBSD::lookup::library->new($solver);
- for my $h ($solver->{set}->newer) {
- for my $lib (@{$h->{plist}->{wantlib}}) {
- $solver->{localbase} = $h->{plist}->localbase;
- next if $lib_finder->lookup($solver,
- $solver->{to_register}->{$h}, $state,
- $lib->spec);
- if ($okay) {
- $state->errsay("Can't install #1 because of libraries", $h->pkgname);
- }
- $okay = 0;
- OpenBSD::SharedLibs::report_problem($state,
- $lib->spec);
- }
- }
- if (!$okay) {
- $solver->dump($state);
- $lib_finder->dump($state);
- }
- return $okay;
-}
-
sub solve_tags
{
my ($solver, $state) = @_;