From c6d49a8cdea5a04d058d02cfd08fa4ea0157e704 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Mon, 18 Dec 2023 09:26:47 +0100 Subject: [PATCH] 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 --- perlmod-bin/genpackage.pl | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/perlmod-bin/genpackage.pl b/perlmod-bin/genpackage.pl index 711ee57..a056b83 100755 --- a/perlmod-bin/genpackage.pl +++ b/perlmod-bin/genpackage.pl @@ -135,20 +135,26 @@ use warnings; use DynaLoader; -sub library { - return '{{LIBRARY}}'; +sub library { '{{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! -sub libdirs { return (map "-L$_/auto", @INC); } +# Keep on a single line, potentially modified by testsuite! +sub libfile { find_lib() } sub load : prototype($) { my ($pkg) = @_; my $mod_name = $pkg->library(); - my @dirs = $pkg->libdirs(); - my $mod_file = DynaLoader::dl_findfile({{DEBUG_LIBPATH}}@dirs, $mod_name); + my $mod_file = find_lib($mod_name); 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)