diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2004-11-18 21:48:03 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2004-11-18 21:48:03 +0000 |
commit | 8d5511c2c78613ccea6d3bae00ab06cb4f58f89e (patch) | |
tree | af36b84d59823786b5710e7d805a130ce39e52a0 /usr.sbin | |
parent | 570bfe13cae5ebfbf5ee9fcfaa6a737cddb85735 (diff) |
support depend (similar to libdepend and newdepend) and wantlib:
put lookup_library code in a separate routine, and add a `harder' mode
for wantlib, that will also look in system libraries, and in the full
tree of dependent packages.
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Add.pm | 9 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Update.pm | 16 | ||||
-rw-r--r-- | usr.sbin/pkg_add/pkg_add | 121 |
3 files changed, 121 insertions, 25 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Add.pm b/usr.sbin/pkg_add/OpenBSD/Add.pm index a0eee8feddd..0e2c2809ef4 100644 --- a/usr.sbin/pkg_add/OpenBSD/Add.pm +++ b/usr.sbin/pkg_add/OpenBSD/Add.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Add.pm,v 1.20 2004/11/14 19:50:44 espie Exp $ +# $OpenBSD: Add.pm,v 1.21 2004/11/18 21:48:02 espie Exp $ # # Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org> # @@ -500,16 +500,17 @@ sub install sub available_lib { - my ($self, $avail) = @_; + my ($self, $avail, $pkgname) = @_; my $fullname = $self->fullname(); if ($fullname =~ m/^(.*\.so\.\d+)\.(\d+)$/) { my ($stem, $minor) = ($1, $2); - if (!defined $avail->{"$stem"} || $avail->{"$stem"} < $minor) { - $avail->{"$stem"} = $minor; + if (!defined $avail->{"$stem"} || $avail->{"$stem"}->[0] < $minor) { + $avail->{"$stem"} = [$minor, $pkgname]; } } } + package OpenBSD::PackingElement::Arch; sub check diff --git a/usr.sbin/pkg_add/OpenBSD/Update.pm b/usr.sbin/pkg_add/OpenBSD/Update.pm index 71edc223357..75961b99792 100644 --- a/usr.sbin/pkg_add/OpenBSD/Update.pm +++ b/usr.sbin/pkg_add/OpenBSD/Update.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Update.pm,v 1.32 2004/11/14 19:25:45 espie Exp $ +# $OpenBSD: Update.pm,v 1.33 2004/11/18 21:48:02 espie Exp $ # # Copyright (c) 2004 Marc Espie <espie@openbsd.org> # @@ -189,6 +189,20 @@ sub validate_depend } } +package OpenBSD::PackingElement::Dependency; +use OpenBSD::Error; + +sub validate_depend +{ + my ($self, $state, $wanting, $toreplace, $replacement) = @_; + + return unless OpenBSD::PkgSpec::match($self->{pattern}, $toreplace); + if (!OpenBSD::PkgSpec::match($self->{pattern}, $replacement)) { + $state->{okay} = 0; + Warn "Can't update forward dependency of $wanting on $toreplace\n"; + } +} + package OpenBSD::Update; use OpenBSD::RequiredBy; use OpenBSD::PackingList; diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add index 169c822e17d..1ea7c3d49c4 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.122 2004/11/14 19:25:45 espie Exp $ +# $OpenBSD: pkg_add,v 1.123 2004/11/18 21:48:02 espie Exp $ # # Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org> # @@ -189,7 +189,7 @@ sub solve_dependencies } push(@$to_register, $dep->{name}); } - for my $dep (@{$plist->{newdepend}}, @{$plist->{libdepend}}) { + for my $dep (@{$plist->{depend}}, @{$plist->{newdepend}}, @{$plist->{libdepend}}) { next if defined $dep->{name} and $dep->{name} ne $plist->pkgname(); my @candidates = OpenBSD::PkgSpec::match($dep->{pattern}, installed_packages()); if (@candidates >= 1) { @@ -257,8 +257,9 @@ sub check_lib_specs if ($spec =~ m/^(.*)\.(\d+)\.(\d+)$/) { my ($libname, $major, $minor) = ($1, $2, $3); my $exists = $available->{"$dir/lib$libname.so.$major"}; - if ((defined $exists) && $exists >= $minor) { - print "found $dir/lib$libname.so.$major.$exists\n" if $verbose; + if ((defined $exists) && $exists->[0] >= $minor) { + my ($m, $where) = @$exists; + print "found $dir/lib$libname.so.$major.$m in $where\n" if $verbose; } else { print "not found\n" if $verbose; return undef; @@ -469,19 +470,18 @@ sub build_deptree sub find_old_lib { - my ($state, $dep, $global_avail, $dependencies) = @_; + my ($state, $pattern, $lib, $global_avail, $dependencies) = @_; - my $pattern = ".libs-".$dep->{pattern}; + $pattern = ".libs-".$pattern; for my $try (OpenBSD::PkgSpec::match($pattern, installed_packages())) { my $plist = OpenBSD::PackingList->from_installation($try, \&OpenBSD::PackingList::LibraryOnly); my $available = {}; - $plist->visit('available_lib', $available); + $plist->visit('available_lib', $available, $try); if (check_lib_specs($state->{very_verbose}, - $state->{destdir}.$plist->pkgbase(), $dep->{libspec}, - $available)) { - Warn "Found libspec ", $dep->{libspec}, " in old package $try\n"; - $plist->visit('available_lib', $global_avail); + $state->{destdir}.$plist->pkgbase(), $lib, $available)) { + Warn "Found library ", $lib, " in old package $try\n"; + $plist->visit('available_lib', $global_avail, $try); push(@$dependencies, $try); return 1; } @@ -489,6 +489,83 @@ sub find_old_lib return 0; } +my $syst_avail; + +sub add_system_libs +{ + my ($destdir, $avail) = @_; + for my $dir ("/usr/lib", "/usr/X11R6/lib") { + local *DIR; + opendir(DIR, $destdir.$dir); + while (my $d = readdir(DIR)) { + next unless $d =~ m/^(.*\.so\.\d+)\.(\d+)$/; + my ($stem, $minor) = ($1, $2); + $stem = "$dir/$stem"; + if (!defined $avail->{"$stem"} || $avail->{"$stem"}->[0] < $minor) { + $avail->{"$stem"} = [$minor, 'system']; + } + } + closedir(DIR); + } +} + +sub lookup_library +{ + my ($state, $lib, $available, $plist, $dependencies, $harder) = @_; + + if (check_lib_specs($state->{very_verbose}, + $state->{destdir}.$plist->pkgbase(), $lib, $available)) { + return 1; + } + if ($harder && $lib !~ m|/|) { + if (!defined $syst_avail) { + $syst_avail = {}; + add_system_libs($state->{destdir}, $syst_avail); + } + if (check_lib_specs($state->{very_verbose}, + $state->{destdir}."/usr", $lib, $syst_avail)) { + return 1; + } + if (check_lib_specs($state->{very_verbose}, + $state->{destdir}."/usr/X11R6", $lib, $syst_avail)) { + return 1; + } + } + for my $dep (@{$plist->{depends}}) { + if (find_old_lib($state, $dep->{pattern}, $lib, $available, + $dependencies)) { + return 1; + } + } + return 0 unless $harder; + # lookup through the full tree... + my $done = {}; + my %base_dependencies = map {($_, 1)} @$dependencies; + my @todo = @$dependencies; + while (my $dep = pop @todo) { + require OpenBSD::RequiredBy; + + next if $done->{$dep}; + $done->{$dep} = 1; + for my $dep2 (OpenBSD::Requiring->new($dep)->list()) { + push(@todo, $dep2) unless $done->{$dep2}; + } + next if $base_dependencies{$dep}; + my $plist = OpenBSD::PackingList->from_installation($dep, + \&OpenBSD::PackingList::LibraryOnly); + my $avail2 = {}; + $plist->visit('available_lib', $avail2, $dep); + if (check_lib_specs($state->{very_verbose}, + $state->{destdir}.$plist->pkgbase(), $lib, $avail2)) { + Warn "Found library ", $lib, " in dependent package $dep\n"; + $plist->visit('available_lib', $available, $dep); + push(@$dependencies, $dep); + return 1; + } + } +} + + sub install_package { my ($pkg, $state, @todo) = @_; @@ -538,18 +615,22 @@ sub install_package for my $dep (@{$handle->{solved_dependencies}}) { my $plist = OpenBSD::PackingList->from_installation($dep, \&OpenBSD::PackingList::LibraryOnly); - $plist->visit('available_lib', $available); + $plist->visit('available_lib', $available, $dep); } for my $dep (@{$plist->{libdepend}}) { return () if defined $dep->{name} and $dep->{name} ne $plist->pkgname(); - if (!check_lib_specs($state->{very_verbose}, - $state->{destdir}.$plist->pkgbase(), $dep->{libspec}, $available)) { - # second chance - if (!find_old_lib($state, $dep, $available, $handle->{solved_dependencies})) { - Warn "Can't install $pkg: incorrect libspec: ", - $dep->{libspec}, "\n"; - return () unless $forced{libdepends}; - } + if (!lookup_library($state, $dep->{libspec}, $available, + $plist, $handle->{solved_dependencies}, 0)) { + Warn "Can't install $pkg: lib not found ", $dep->{libspec}, "\n"; + return () unless $forced{libdepends}; + } + } +# add_system_libs($state->{destdir}, $available); + for my $lib (@{$plist->{wantlib}}) { + if (!lookup_library($state, $lib->{name}, $available, + $plist, $handle->{solved_dependencies}, 1)) { + Warn "Can't install $pkg: lib not found ", $lib->{name}, "\n"; + return () unless $forced{libdepends}; } } really_add($handle, $state); |