accordingly, load it "just in time" in State.
Most calls get simplified, and we can save more state for later.
# ex:ts=8 sw=4:
-# $OpenBSD: Dependencies.pm,v 1.173 2019/10/13 16:22:58 espie Exp $
+# $OpenBSD: Dependencies.pm,v 1.174 2023/05/21 16:07:35 espie Exp $
#
# Copyright (c) 2005-2010 Marc Espie <espie@openbsd.org>
#
use strict;
use warnings;
-use OpenBSD::SharedLibs;
use OpenBSD::Dependencies::SolverBase;
package _cache;
my $r = $state->repo->installed->match_locations(OpenBSD::Search::PkgSpec->new(".libs-".$pattern));
for my $try (map {$_->name} @$r) {
- OpenBSD::SharedLibs::add_libs_from_installed_package($try, $state);
- if ($self->check_lib_spec($base, $lib, {$try => 1})) {
+ $state->shlibs->add_libs_from_installed_package($try);
+ if ($self->check_lib_spec($state, $base, $lib, {$try => 1})) {
return $try;
}
}
# ex:ts=8 sw=4:
-# $OpenBSD: SolverBase.pm,v 1.13 2021/06/21 14:36:48 espie Exp $
+# $OpenBSD: SolverBase.pm,v 1.14 2023/05/21 16:07:35 espie Exp $
#
# Copyright (c) 2005-2018 Marc Espie <espie@openbsd.org>
#
my ($self, $solver, $state, $obj) = @_;
- my $r = $solver->check_lib_spec($solver->{localbase}, $obj,
+ my $r = $solver->check_lib_spec($state, $solver->{localbase}, $obj,
$self->{known});
if ($r) {
$self->say_found($state, $obj, $state->f("package #1", $r));
my ($self, $solver, $state, $obj) = @_;
return undef if !$obj->is_valid || defined $obj->{dir};
- OpenBSD::SharedLibs::add_libs_from_system($state->{destdir}, $state);
- for my $dir (OpenBSD::SharedLibs::system_dirs()) {
- if ($solver->check_lib_spec($dir, $obj, {system => 1})) {
+ $state->shlibs->add_libs_from_system($state->{destdir});
+ for my $dir ($state->shlibs->system_dirs) {
+ if ($solver->check_lib_spec($state, $dir, $obj, {system => 1})) {
$self->say_found($state, $obj, $state->f("#1/lib", $dir));
return 'system';
}
my ($self, $solver, $state, $obj, $dep) = @_;
if (defined $solver->{set}{newer}{$dep}) {
- OpenBSD::SharedLibs::add_libs_from_plist($solver->{set}{newer}{$dep}->plist, $state);
+ $state->shlibs->add_libs_from_plist($solver->{set}{newer}{$dep}->plist);
} else {
- OpenBSD::SharedLibs::add_libs_from_installed_package($dep, $state);
+ $state->shlibs->add_libs_from_installed_package($dep);
}
- if ($solver->check_lib_spec($solver->{localbase}, $obj, {$dep => 1})) {
+ if ($solver->check_lib_spec($state, $solver->{localbase}, $obj, {$dep => 1})) {
$self->say_found($state, $obj, $state->f("package #1", $dep));
return $dep;
}
$solver->errsay_library($state, $h);
}
$okay = 0;
- OpenBSD::SharedLibs::report_problem($state,
- $lib->spec);
+ $state->shlibs->report_problem($lib->spec);
}
}
if (!$okay) {
sub check_lib_spec
{
- my ($self, $base, $spec, $dependencies) = @_;
- my $r = OpenBSD::SharedLibs::lookup_libspec($base, $spec);
+ my ($self, $state, $base, $spec, $dependencies) = @_;
+ my $r = $state->shlibs->lookup_libspec($base, $spec);
for my $candidate (@$r) {
if ($dependencies->{$candidate->origin}) {
return $candidate->origin;
# ex:ts=8 sw=4:
-# $OpenBSD: OldLibs.pm,v 1.14 2023/05/16 14:31:26 espie Exp $
+# $OpenBSD: OldLibs.pm,v 1.15 2023/05/21 16:07:35 espie Exp $
#
# Copyright (c) 2004-2010 Marc Espie <espie@openbsd.org>
#
if ($state->{not}) {
- require OpenBSD::SharedLibs;
- OpenBSD::SharedLibs::add_libs_from_plist($stub_list, $state);
+ $state->shlibs->add_libs_from_plist($stub_list);
$stub_list->to_cache;
$o->plist->to_cache;
} else {
#! /usr/bin/perl
# ex:ts=8 sw=4:
-# $OpenBSD: PkgAdd.pm,v 1.139 2023/05/19 07:30:40 espie Exp $
+# $OpenBSD: PkgAdd.pm,v 1.140 2023/05/21 16:07:35 espie Exp $
#
# Copyright (c) 2003-2014 Marc Espie <espie@openbsd.org>
#
use OpenBSD::PackageName;
use OpenBSD::PkgCfl;
use OpenBSD::Add;
-use OpenBSD::SharedLibs;
use OpenBSD::UpdateSet;
use OpenBSD::Error;
for my $handle ($set->newer) {
my $pkgname = $handle->pkgname;
my $plist = $handle->plist;
- OpenBSD::SharedLibs::add_libs_from_plist($plist, $state);
+ $state->shlibs->add_libs_from_plist($plist);
OpenBSD::Add::tweak_plist_status($plist, $state);
OpenBSD::Add::register_installation($plist, $state);
add_installed($pkgname);
#! /usr/bin/perl
# ex:ts=8 sw=4:
-# $OpenBSD: PkgCheck.pm,v 1.76 2022/03/15 08:12:53 espie Exp $
+# $OpenBSD: PkgCheck.pm,v 1.77 2023/05/21 16:07:35 espie Exp $
#
# Copyright (c) 2003-2014 Marc Espie <espie@openbsd.org>
#
use warnings;
use OpenBSD::AddCreateDelete;
-use OpenBSD::SharedLibs;
package Installer::State;
our @ISA = qw(OpenBSD::PkgAdd::State);
sub mark_indirect_depends
{
- my $self = shift;
- $self->mark_available_lib(@_);
+ my ($self, $pkgname, $state) = @_;
+ $self->mark_available_lib($pkgname, $state->shlibs);
}
sub cache_depends
sub find_dependencies
{
my ($self, $state, $l, $checker, $pkgname) = @_;
- my $r = OpenBSD::SharedLibs::lookup_libspec($state->{localbase},
+ my $r = $state->shlibs->lookup_libspec($state->{localbase},
$self->spec);
if (defined $r && @$r != 0) {
my $okay = 0;
sub dependencies_check
{
my ($self, $state, $l) = @_;
- OpenBSD::SharedLibs::add_libs_from_system($state->{destdir}, $state);
+ $state->shlibs->add_libs_from_system($state->{destdir});
$self->for_all_packages($state, $l, "Direct dependencies", sub {
my $name = shift;
$state->log->set_context($name);
} else {
$plist->thorough_check($state);
}
- $plist->mark_available_lib($plist->pkgname, $state);
+ $plist->mark_available_lib($plist->pkgname, $state->shlibs);
});
}
#! /usr/bin/perl
# ex:ts=8 sw=4:
-# $OpenBSD: PkgCreate.pm,v 1.187 2023/05/17 15:51:58 espie Exp $
+# $OpenBSD: PkgCreate.pm,v 1.188 2023/05/21 16:07:35 espie Exp $
#
# Copyright (c) 2003-2014 Marc Espie <espie@openbsd.org>
#
use OpenBSD::AddCreateDelete;
use OpenBSD::Dependencies::SolverBase;
-use OpenBSD::SharedLibs;
use OpenBSD::Signer;
package OpenBSD::PkgCreate::State;
$solver->{to_register}{$h}, $state,
$lib->spec);
$okay = 0;
- OpenBSD::SharedLibs::report_problem($state,
- $lib->spec) if $final;
+ $state->shlibs->report_problem($lib->spec) if $final;
}
if (!$okay && $final) {
$solver->dump($state);
$self->to_cache($plist, $diskcache);
}
}
- OpenBSD::SharedLibs::add_libs_from_plist($plist, $state);
+ $state->shlibs->add_libs_from_plist($plist);
$self->{tag_finder}->find_in_plist($plist, $dep->{pkgpath});
$self->add_dep($plist);
return $plist->pkgname;
# ex:ts=8 sw=4:
-# $OpenBSD: SharedLibs.pm,v 1.59 2017/09/16 12:04:13 espie Exp $
+# $OpenBSD: SharedLibs.pm,v 1.60 2023/05/21 16:07:35 espie Exp $
#
# Copyright (c) 2003-2010 Marc Espie <espie@openbsd.org>
#
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-use strict;
-use warnings;
+use v5.36;
use OpenBSD::Paths;
use OpenBSD::LibSpec;
package OpenBSD::PackingElement;
-sub mark_available_lib
+sub mark_available_lib($, $, $)
{
}
package OpenBSD::PackingElement::Lib;
-sub mark_available_lib
+sub mark_available_lib($self, $pkgname, $object)
{
- my ($self, $pkgname, $state) = @_;
- OpenBSD::SharedLibs::register_libname($self->fullname,
- $pkgname, $state);
+ $object->register_libname($self->fullname, $pkgname);
}
package OpenBSD::SharedLibs;
use File::Basename;
use OpenBSD::Error;
-our $repo = OpenBSD::LibRepo->new;
+sub _basestate($)
+{
+ require OpenBSD::Basestate;
+ return 'OpenBSD::BaseState';
+}
-sub register_library
+sub new($class, $state = $class->_basestate)
{
- my ($lib, $pkgname) = @_;
- $repo->register($lib, $pkgname);
+ bless {
+ state => $state,
+ repo => OpenBSD::LibRepo->new,
+ printed => {},
+ done_plist => {},
+ done_system => 0
+ }, $class;
}
-sub register_libname
+
+sub register_library($self, $lib, $pkgname)
+{
+ $self->{repo}->register($lib, $pkgname);
+}
+
+sub register_libname($self, $name, $pkgname)
{
- my ($name, $pkgname, $state) = @_;
my $lib = OpenBSD::Library->from_string($name);
if ($lib->is_valid) {
- register_library($lib, $pkgname);
+ $self->register_library($lib, $pkgname);
} else {
- $state->errsay("Bogus library in #1: #2", $pkgname, $name)
- unless $pkgname eq 'system';
+ $self->{state}->errsay("Bogus library in #1: #2", $pkgname,
+ $name) unless $pkgname eq 'system';
}
}
sub find_best
{
- my ($class, $stem) = @_;
- return $repo->find_best($stem);
+ my ($self, $stem) = @_;
+ return $self->{repo}->find_best($stem);
}
-my $done_plist = {};
-
-sub system_dirs
+sub system_dirs($)
{
return OpenBSD::Paths->library_dirs;
}
-sub add_libs_from_system
+sub add_libs_from_system($self, $destdir)
{
- my ($destdir, $state) = @_;
- return if $done_plist->{'system'};
- $done_plist->{'system'} = 1;
- for my $dirname (system_dirs()) {
+ return if $self->{done_system};
+ $self->{done_system} = 1;
+ for my $dirname ($self->system_dirs) {
opendir(my $dir, $destdir.$dirname."/lib") or next;
while (my $d = readdir($dir)) {
next unless $d =~ m/\.so/;
- register_libname("$dirname/lib/$d", 'system', $state);
+ $self->register_libname("$dirname/lib/$d", 'system');
}
closedir($dir);
}
}
-sub add_libs_from_installed_package
+sub add_libs_from_installed_package($self, $pkgname)
{
- my ($pkgname, $state) = @_;
- return if $done_plist->{$pkgname};
- $done_plist->{$pkgname} = 1;
+ return if $self->{done_plist}{$pkgname};
+ $self->{done_plist}{$pkgname} = 1;
my $plist = OpenBSD::PackingList->from_installation($pkgname,
\&OpenBSD::PackingList::LibraryOnly);
return if !defined $plist;
- $plist->mark_available_lib($pkgname, $state);
+ $plist->mark_available_lib($pkgname, $self);
}
-sub add_libs_from_plist
+sub add_libs_from_plist($self, $plist)
{
- my ($plist, $state) = @_;
my $pkgname = $plist->pkgname;
- return if $done_plist->{$pkgname};
- $done_plist->{$pkgname} = 1;
- $plist->mark_available_lib($pkgname, $state);
+ return if $self->{done_plist}{$pkgname};
+ $self->{done_plist}{$pkgname} = 1;
+ $plist->mark_available_lib($pkgname, $self);
}
-sub lookup_libspec
+sub lookup_libspec($self, $base, $spec)
{
- my ($base, $spec) = @_;
- return $spec->lookup($repo, $base);
+ return $spec->lookup($self->{repo}, $base);
}
-my $printed = {};
-sub report_problem
+sub report_problem($self, $spec)
{
- my ($state, $spec) = @_;
my $name = $spec->to_string;
+ my $state = $self->{state};
my $base = $state->{localbase};
- my $approx = $spec->lookup_stem($repo);
+ my $approx = $spec->lookup_stem($self->{repo});
+ my $printed = $self->{printed};
my $r = "";
if (!$spec->is_valid) {
# ex:ts=8 sw=4:
-# $OpenBSD: State.pm,v 1.72 2023/05/19 07:25:16 espie Exp $
+# $OpenBSD: State.pm,v 1.73 2023/05/21 16:07:35 espie Exp $
#
# Copyright (c) 2007-2014 Marc Espie <espie@openbsd.org>
#
}
});
+OpenBSD::Auto::cache(shlibs,
+ sub {
+ my $self = shift;
+ require OpenBSD::SharedLibs;
+ return $self->{shlibs} //= OpenBSD::SharedLibs->new($self);
+ });
+
sub usage_is
{
my ($self, @usage) = @_;