genpackage: change library loading

Replace the 'libdirs()' function with a 'libfile()' function.
To text a fixed file, we should only place that one file in there in
test suites.

Additionally, search LD_LIBRARY_PATH before the auto-dirs, which
should make custom testing via the command line easier as well.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2023-12-18 09:26:47 +01:00
parent fa7d62bf37
commit c6d49a8cde

View File

@ -135,20 +135,26 @@ use warnings;
use DynaLoader; use DynaLoader;
sub library { sub library { '{{LIBRARY}}' }
return '{{LIBRARY}}';
sub autodirs { map { "$_/auto" } @INC; }
sub envdirs { grep { length($_) } split(/:+/, $ENV{LD_LIBRARY_PATH} // '') }
sub find_lib {
my ($mod_name) = @_;
my @dirs = map { "-L$_" } (envdirs(), autodirs());
return DynaLoader::dl_findfile(@dirs, $mod_name);
} }
# Keep on a single line, modified by testsuite! # Keep on a single line, potentially modified by testsuite!
sub libdirs { return (map "-L$_/auto", @INC); } sub libfile { find_lib() }
sub load : prototype($) { sub load : prototype($) {
my ($pkg) = @_; my ($pkg) = @_;
my $mod_name = $pkg->library(); my $mod_name = $pkg->library();
my @dirs = $pkg->libdirs(); my $mod_file = find_lib($mod_name);
my $mod_file = DynaLoader::dl_findfile({{DEBUG_LIBPATH}}@dirs, $mod_name);
die "failed to locate shared library for $mod_name (lib${mod_name}.so)\n" if !$mod_file; die "failed to locate shared library for $mod_name (lib${mod_name}.so)\n" if !$mod_file;
my $lib = DynaLoader::dl_load_file($mod_file) my $lib = DynaLoader::dl_load_file($mod_file)