diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2007-06-26 14:40:26 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2007-06-26 14:40:26 +0000 |
commit | 7f22278173d4417b7e8890f6e410a525a2dcfaee (patch) | |
tree | d9e1e6dc71e18519693686a01ac04e1360334198 /usr.sbin | |
parent | 51f633a6f11bec22789ba2ac93d7618cd55a8f82 (diff) |
the big gap one: create UpdateSet for all packages being installed, and
consider only UpdateSet internally. This involves moving stuff around a
bit to keep pkg_add -n working, adding creators from_location for UpdateSet,
and tweaking dependencies heavily.
More changes later, like sanitizing PackageLocation state engine, or
creating UpdateSet earlier for actual updates.
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Dependencies.pm | 84 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Vstat.pm | 20 | ||||
-rw-r--r-- | usr.sbin/pkg_add/pkg_add | 69 |
3 files changed, 93 insertions, 80 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Dependencies.pm b/usr.sbin/pkg_add/OpenBSD/Dependencies.pm index ffb4896e976..806eff3606e 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.58 2007/06/19 10:47:28 espie Exp $ +# $OpenBSD: Dependencies.pm,v 1.59 2007/06/26 14:40:25 espie Exp $ # # Copyright (c) 2005-2007 Marc Espie <espie@openbsd.org> # @@ -18,6 +18,8 @@ use strict; use warnings; +# generic dependencies lookup class: walk the dependency tree as far +# as necessary to resolve dependencies package OpenBSD::lookup; sub lookup @@ -54,7 +56,6 @@ sub lookup return 1; } - $self->dependency_not_found($state, $obj); return 0; } @@ -136,12 +137,6 @@ sub find_elsewhere return undef; } -sub dependency_not_found -{ - my ($self, $state, $obj) = @_; - print "libspec $obj not found\n" if $state->{very_verbose}; -} - package OpenBSD::lookup::tag; our @ISA=qw(OpenBSD::lookup); sub find_in_extra_sources @@ -228,39 +223,37 @@ sub add_todo require OpenBSD::PackageName; - for my $fullname (@extra) { + for my $set (@extra) { + my $fullname = $set->handle->{pkgname}; $self->{to_install}-> - {OpenBSD::PackageName::url2pkgname($fullname)} = $fullname; + {OpenBSD::PackageName::url2pkgname($fullname)} = $set; } } -sub add_new_dep -{ - my ($self, $pkgname, $satisfy) = @_; - push(@{$self->{deplist}}, $pkgname) if !is_installed($pkgname); - $self->{to_register}->{$pkgname} = $satisfy; -} - sub find_dep_in_repositories { my ($self, $state, $dep) = @_; require OpenBSD::PackageLocator; - my @candidates = OpenBSD::PackageLocator->match($dep->spec); + my @candidates = OpenBSD::PackageLocator->match_locations($dep->spec); + # XXX not really efficient, but hey + my %c = map {($_->{name}, $_)} @candidates; + my @pkgs = keys %c; if (!$state->{forced}->{allversions}) { - @candidates = OpenBSD::PackageName::keep_most_recent(@candidates); + @pkgs = OpenBSD::PackageName::keep_most_recent(@pkgs); } - if (@candidates == 1) { - return $candidates[0]; - } elsif (@candidates > 1) { + if (@pkgs == 1) { + return $c{$pkgs[0]}; + } elsif (@pkgs > 1) { require OpenBSD::Interactive; # put default first if available - @candidates = ((grep {$_ eq $dep->{def}} @candidates), - (sort (grep {$_ ne $dep->{def}} @candidates))); - return OpenBSD::Interactive::ask_list( + @pkgs = ((grep {$_ eq $dep->{def}} @pkgs), + (sort (grep {$_ ne $dep->{def}} @pkgs))); + my $good = OpenBSD::Interactive::ask_list( 'Ambiguous: choose dependency for '.$self->pkgname.': ', - $state->{interactive}, @candidates); + $state->{interactive}, @pkgs); + return $c{$good}; } else { return; } @@ -282,28 +275,34 @@ sub solve_dependency if ($state->{allow_replacing}) { $v = $self->find_dep_in_stuff_to_install($state, $dep); if ($v) { - push(@{$self->{deplist}}, $v); - $self->{to_register}->{$v} = $dep; - return; + push(@{$self->{deplist}}, $self->{to_install}->{$v}); + return $v; } } - if (!$v) { - $v = find_candidate($dep->spec, installed_packages()); + $v = find_candidate($dep->spec, installed_packages()); + if ($v) { + return $v; } - if (!$v && !$state->{allow_replacing}) { + if (!$state->{allow_replacing}) { $v = $self->find_dep_in_stuff_to_install($state, $dep); + if ($v) { + push(@{$self->{deplist}}, $self->{to_install}->{$v}); + return $v; + } } - if (!$v) { - $v = $self->find_dep_in_repositories($state, $dep); - } - # resort to default if nothing else - if (!$v) { - $v = $dep->{def}; + $v = $self->find_dep_in_repositories($state, $dep); + if ($v) { + push(@{$self->{deplist}}, + OpenBSD::UpdateSet->from_location($v->openPackage)); + return $v->{name}; } - $self->add_new_dep($v, $dep); + # resort to default if nothing else + $v = $dep->{def}; + push(@{$self->{deplist}}, OpenBSD::UpdateSet->create_new($v)); + return $v; } sub solve_depends @@ -313,7 +312,8 @@ sub solve_depends $self->add_todo(@extra); for my $dep (@{$self->{plist}->{depend}}) { - $self->solve_dependency($state, $dep); + my $v = $self->solve_dependency($state, $dep); + $self->{to_register}->{$v} = $dep; } return @{$self->{deplist}}; @@ -336,7 +336,9 @@ sub dump if ($self->dependencies) { print "Dependencies for ", $self->pkgname, " resolve to: ", join(', ', $self->dependencies); - print " (todo: ", join(',', @{$self->{deplist}}), ")" + print " (todo: ", + join(',', (map {$_->handle->{pkgname}} @{$self->{deplist}})), + ")" if @{$self->{deplist}} > 0; print "\n"; } diff --git a/usr.sbin/pkg_add/OpenBSD/Vstat.pm b/usr.sbin/pkg_add/OpenBSD/Vstat.pm index 025aaa9d675..9bf195b6284 100644 --- a/usr.sbin/pkg_add/OpenBSD/Vstat.pm +++ b/usr.sbin/pkg_add/OpenBSD/Vstat.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Vstat.pm,v 1.41 2007/06/16 09:29:37 espie Exp $ +# $OpenBSD: Vstat.pm,v 1.42 2007/06/26 14:40:25 espie Exp $ # # Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org> # @@ -380,6 +380,16 @@ sub create_new return $handle; } +sub from_location +{ + my ($class, $location) = @_; + my $handle = $class->new; + $handle->{pkgname} = $location->{name}; + $handle->{location} = $location; + $handle->{tweaked} = 0; + return $handle; +} + package OpenBSD::UpdateSet; sub new { @@ -497,6 +507,14 @@ sub create_new return $set; } +sub from_location +{ + my ($class, $location) = @_; + my $set = $class->new; + $set->add_newer(OpenBSD::Handle->from_location($location)); + return $set; +} + package OpenBSD::PackingList; sub compute_size { diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add index 2be184135c7..50b92f52e30 100644 --- a/usr.sbin/pkg_add/pkg_add +++ b/usr.sbin/pkg_add/pkg_add @@ -1,7 +1,7 @@ #! /usr/bin/perl # ex:ts=8 sw=4: -# $OpenBSD: pkg_add,v 1.325 2007/06/17 10:44:01 espie Exp $ +# $OpenBSD: pkg_add,v 1.326 2007/06/26 14:40:25 espie Exp $ # # Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org> # @@ -55,7 +55,8 @@ sub build_deptree $pkg = $tree->{$pkg}; } for my $i (@deps) { - $tree->{$i} = $pkg unless defined $tree->{$i}; + my $j = $i->handle->{pkgname}; + $tree->{$j} = $pkg unless defined $tree->{$j}; } } @@ -75,12 +76,6 @@ sub mark_installed $state->{installed}->{$pkg} = 1; } -sub mark_as_already_installed -{ - my ($state, $pkg) = @_; - $state->mark_installed($pkg); -} - sub is_installed { my ($state, $pkg) = @_; @@ -235,16 +230,6 @@ sub can_install package main; -sub prepare_to_add -{ - my ($pkg, $state) = @_; - - my $set = OpenBSD::UpdateSet->create_new($pkg); - $set->complete($state); - return $set; -} - - sub thunderbird_special_case { my $plist = shift; @@ -418,17 +403,19 @@ sub really_add $set->{solver}->adjust_old_dependencies($state); } -sub install_package +sub install_set { - my ($pkg, $state, @todo) = @_; - my $cache = $state->{cache}; + my ($set, $state, @todo) = @_; - if (!defined $cache->{$pkg}) { - $cache->{$pkg} = prepare_to_add($pkg, $state); + my $handle = $set->handle; + if ($state->is_installed($handle->{pkgname})) { + if (defined $handle->{location}) { + $handle->{location}->close_now; + } + return (); } - my $set = $cache->{$pkg}; - my $handle = $set->handle; + $set->complete($state); if ($handle->has_error(OpenBSD::Handle::ALREADY_INSTALLED)) { return (); } @@ -444,16 +431,11 @@ sub install_package } my $location = $handle->{location}; - if ($state->is_installed($handle->{pkgname})) { - $location->close_now; - return (); - } - my $plist = $handle->{plist}; if ($plist->has('arch')) { unless ($plist->{arch}->check($state->{arch})) { - print "$pkg is not for the right architecture\n"; + print "$handle->{pkgname} is not for the right architecture\n"; return () unless $forced{arch}; } } @@ -464,8 +446,8 @@ sub install_package $set->{solver}->dump; } if (@deps > 0) { - $state->build_deptree($pkg, @deps); - return (@deps, $pkg); + $state->build_deptree($handle->{pkgname}, @deps); + return (@deps, $set); } } @@ -473,7 +455,7 @@ sub install_package my @baddeps = $set->{solver}->check_depends; if (@baddeps) { - print "Can't install $pkg: can't resolve ", + print "Can't install $handle->{pkgname}: can't resolve ", join(',', @baddeps), "\n"; $location->close_now; $bad++; @@ -682,9 +664,20 @@ if ($bad) { exit(1); } +# convert everything to UpdateSets + +my @todo2 = (); +my $cache = {}; +for my $pkg (@todo) { + if (!defined $cache->{$pkg}) { + $cache->{$pkg} = OpenBSD::UpdateSet->create_new($pkg); + } + push(@todo2, $cache->{$pkg}); +} + eval { -while (my $pkg = shift @todo) { - unshift(@todo, install_package($pkg, $state, @todo)); +while (my $set = shift @todo2) { + unshift(@todo2, install_set($set, $state, @todo2)); } }; @@ -760,7 +753,7 @@ sub get_plist } my $plist = $location->plist; unless (defined $plist) { - print "Can't find CONTENTS from $pkg\n"; + print "Can't find CONTENTS from ", $location->url, "\n"; $location->close_with_client_error; $location->wipe_info; $handle->set_error(BAD_PACKAGE); @@ -784,7 +777,7 @@ sub get_plist OpenBSD::Add::tweak_package_status($pkgname, $state); print "Not reinstalling $pkgname\n" if $state->{verbose} and !$handle->{tweaked}; - $state->mark_as_already_installed($pkgname); + $state->mark_as_installed($pkgname); $location->close_now; $location->wipe_info; $handle->set_error(ALREADY_INSTALLED); |