diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2004-11-22 01:56:14 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2004-11-22 01:56:14 +0000 |
commit | f49425009f43801daa4f64eaaea2bfb41ed4619c (patch) | |
tree | 7763eb84133a2566ab291739e9d64bc4d9ac9a09 /usr.sbin/pkg_add | |
parent | 030cab12534e3306ecb508f1239812819abee5af (diff) |
implement global repository for shared libraries.
Diffstat (limited to 'usr.sbin/pkg_add')
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Add.pm | 19 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/SharedLibs.pm | 76 | ||||
-rw-r--r-- | usr.sbin/pkg_add/pkg_add | 77 |
3 files changed, 92 insertions, 80 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Add.pm b/usr.sbin/pkg_add/OpenBSD/Add.pm index 0e2c2809ef4..2118eac3369 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.21 2004/11/18 21:48:02 espie Exp $ +# $OpenBSD: Add.pm,v 1.22 2004/11/22 01:56:13 espie Exp $ # # Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org> # @@ -148,10 +148,6 @@ sub install { } -sub available_lib -{ -} - sub set_modes { my ($self, $name) = @_; @@ -498,19 +494,6 @@ sub install $self->mark_ldconfig_directory($state->{destdir}); } -sub available_lib -{ - 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"}->[0] < $minor) { - $avail->{"$stem"} = [$minor, $pkgname]; - } - } -} - package OpenBSD::PackingElement::Arch; sub check diff --git a/usr.sbin/pkg_add/OpenBSD/SharedLibs.pm b/usr.sbin/pkg_add/OpenBSD/SharedLibs.pm index 4bcc459fc15..14400d11959 100644 --- a/usr.sbin/pkg_add/OpenBSD/SharedLibs.pm +++ b/usr.sbin/pkg_add/OpenBSD/SharedLibs.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: SharedLibs.pm,v 1.2 2004/11/21 15:44:56 espie Exp $ +# $OpenBSD: SharedLibs.pm,v 1.3 2004/11/22 01:56:13 espie Exp $ # # Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org> # @@ -17,6 +17,20 @@ use strict; use warnings; +package OpenBSD::PackingElement; + +sub mark_available_lib +{ +} + +package OpenBSD::PackingElement::Lib; + +sub mark_available_lib +{ + my ($self, $pkgname) = @_; + OpenBSD::SharedLibs::register_lib($self->fullname(), $pkgname); +} + package OpenBSD::SharedLibs; use File::Basename; use OpenBSD::Error; @@ -72,28 +86,68 @@ our $registered_libs = {}; sub register_lib { - my ($stem, $minor, $pkg) = @_; - if (!defined $registered_libs->{"$stem"} || $registered_libs->{"$stem"}->[0] < $minor) { - $registered_libs->{"$stem"} = [$minor, $pkg]; + my ($name, $pkgname) = @_; + if ($name =~ m/^(.*\/lib.*?\.so\.\d+)\.(\d+)$/) { + my ($stem, $minor) = ($1, $2); + $registered_libs->{"$stem"} = [] + unless defined $registered_libs->{"$stem"}; + push(@{$registered_libs->{"$stem"}}, [$minor, $pkgname]); } } -my $done_system = 0; +my $done_plist = {}; sub add_system_libs { my ($destdir) = @_; - return if $done_system; - $done_system = 1; + return if $done_plist->{'system'}; + $done_plist->{'system'} = 1; for my $dirname ("/usr/lib", "/usr/X11R6/lib") { opendir(my $dir, $destdir.$dirname) or next; while (my $d = readdir($dir)) { - next unless $d =~ m/^(.*\.so\.\d+)\.(\d+)$/; - my ($stem, $minor) = ($1, $2); - $stem = "$dirname/$stem"; - register_lib($stem, $minor, 'system'); + register_lib("$dirname/$d", 'system'); } closedir($dir); } } + +sub add_package_libs +{ + my ($pkgname) = @_; + return if $done_plist->{$pkgname}; + $done_plist->{$pkgname} = 1; + my $plist = OpenBSD::PackingList->from_installation($pkgname, + \&OpenBSD::PackingList::LibraryOnly); + $plist->visit('mark_available_lib', $pkgname); +} + +sub _lookup_libspec +{ + my ($dir, $spec) = @_; + my @r; + + if ($spec =~ m/^(.*)\.(\d+)\.(\d+)$/) { + my ($libname, $major, $minor) = ($1, $2, $3); + my $exists = $registered_libs->{"$dir/lib$libname.so.$major"}; + if (defined $exists) { + for my $e (@$exists) { + if ($e->[0] >= $minor) { + push(@r, $e->[1]); + } + } + } + } + return @r; +} + +sub lookup_libspec +{ + my ($base, $libspec) = @_; + if ($libspec =~ m|(.*)/|) { + return _lookup_libspec("$base/$1", $'); + } else { + return _lookup_libspec("$base/lib", $libspec); + } +} + 1; diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add index 4bb9c30c95d..bc47da1c8e2 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.127 2004/11/21 15:44:55 espie Exp $ +# $OpenBSD: pkg_add,v 1.128 2004/11/22 01:56:13 espie Exp $ # # Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org> # @@ -31,6 +31,7 @@ use OpenBSD::Getopt; use OpenBSD::Error; use OpenBSD::ProgressMeter; use OpenBSD::Add; +use OpenBSD::SharedLibs; our %forced = (); @@ -244,30 +245,17 @@ sub solve_dependencies sub check_lib_spec { - my ($verbose, $base, $spec, $available) = @_; - my $dir; - print "checking libspec $spec " if $verbose; - if ($spec =~ m|(.*)/|) { - $dir = "$base/$1"; - $spec = $'; - } else { - $dir = "$base/lib"; - } - if ($spec =~ m/^(.*)\.(\d+)\.(\d+)$/) { - my ($libname, $major, $minor) = ($1, $2, $3); - my $exists = $available->{"$dir/lib$libname.so.$major"}; - 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; + my ($verbose, $base, $spec, $dependencies) = @_; + print "checking libspec $spec..." if $verbose; + my @r = OpenBSD::SharedLibs::lookup_libspec($base, $spec); + for my $candidate (@r) { + if ($dependencies->{$candidate}) { + print " found in $candidate\n" if $verbose; + return 1; } - } else { - print "bad spec\n" if $verbose; - return undef; } - return 1; + print " not found\n" if $verbose; + return undef; } sub do_script @@ -468,18 +456,14 @@ sub build_deptree sub find_old_lib { - my ($state, $pattern, $lib, $global_avail, $dependencies) = @_; + my ($state, $base, $pattern, $lib, $dependencies) = @_; $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, $try); + OpenBSD::SharedLibs::add_package_libs($try); if (check_lib_spec($state->{very_verbose}, - $state->{destdir}.$plist->pkgbase(), $lib, $available)) { + $state->{destdir}.$base, $lib, {$try => 1})) { Warn "Found library ", $lib, " in old package $try\n"; - $plist->visit('available_lib', $global_avail, $try); $dependencies->{$try} = 1; return 1; } @@ -489,28 +473,26 @@ sub find_old_lib sub lookup_library { - my ($state, $lib, $available, $plist, $dependencies, $harder) = @_; + my ($state, $lib, $plist, $dependencies, $harder) = @_; if (check_lib_spec($state->{very_verbose}, - $state->{destdir}.$plist->pkgbase(), $lib, $available)) { + $state->{destdir}.$plist->pkgbase(), $lib, $dependencies)) { return 1; } if ($harder && $lib !~ m|/|) { - require OpenBSD::SharedLibs; OpenBSD::SharedLibs::add_system_libs($state->{destdir}); if (check_lib_spec($state->{very_verbose}, - $state->{destdir}."/usr", $lib, $OpenBSD::SharedLibs::registered_libs)) { + $state->{destdir}."/usr", $lib, {system => 1})) { return 1; } if (check_lib_spec($state->{very_verbose}, - $state->{destdir}."/usr/X11R6", $lib, $OpenBSD::SharedLibs::registered_libs)) { + $state->{destdir}."/usr/X11R6", $lib, {system => 1})) { return 1; } } for my $dep (@{$plist->{depends}}) { - if (find_old_lib($state, $dep->{pattern}, $lib, $available, - $dependencies)) { + if (find_old_lib($state, $plist->pkgbase(), $dep->{pattern}, $lib, $dependencies)) { return 1; } } @@ -527,14 +509,10 @@ sub lookup_library push(@todo, $dep2) unless $done->{$dep2}; } next if $dependencies->{$dep}; - my $plist = OpenBSD::PackingList->from_installation($dep, - \&OpenBSD::PackingList::LibraryOnly); - my $avail2 = {}; - $plist->visit('available_lib', $avail2, $dep); + OpenBSD::SharedLibs::add_package_libs($dep); if (check_lib_spec($state->{very_verbose}, - $state->{destdir}.$plist->pkgbase(), $lib, $avail2)) { + $state->{destdir}.$plist->pkgbase(), $lib, {$dep => 1})) { Warn "Found library ", $lib, " in dependent package $dep\n"; - $plist->visit('available_lib', $available, $dep); $dependencies->{$dep} = 1; return 1; } @@ -587,25 +565,22 @@ sub install_package } # grab libraries - my $available = {}; for my $dep (keys %{$handle->{solved_dependencies}}) { - my $plist = OpenBSD::PackingList->from_installation($dep, - \&OpenBSD::PackingList::LibraryOnly); - $plist->visit('available_lib', $available, $dep); + OpenBSD::SharedLibs::add_package_libs($dep); } for my $dep (@{$plist->{libdepend}}) { return () if defined $dep->{name} and $dep->{name} ne $plist->pkgname(); for my $spec (split(/,/, $dep->{libspec})) { - if (!lookup_library($state, $spec, $available, - $plist, $handle->{solved_dependencies}, 0)) { + if (!lookup_library($state, $spec, $plist, + $handle->{solved_dependencies}, 0)) { Warn "Can't install $pkg: lib not found spec\n"; return () unless $forced{libdepends}; } } } for my $lib (@{$plist->{wantlib}}) { - if (!lookup_library($state, $lib->{name}, $available, - $plist, $handle->{solved_dependencies}, 1)) { + if (!lookup_library($state, $lib->{name}, $plist, + $handle->{solved_dependencies}, 1)) { Warn "Can't install $pkg: lib not found ", $lib->{name}, "\n"; return () unless $forced{libdepends}; } |