]> git.ipfire.org Git - thirdparty/libtool.git/commitdiff
libtool: Add option to reorder the shared library cache
authorIleana Dumitrescu <ileanadumitrescu95@gmail.com>
Mon, 11 Nov 2024 19:24:08 +0000 (21:24 +0200)
committerIleana Dumitrescu <ileanadumitrescu95@gmail.com>
Tue, 12 Nov 2024 18:17:11 +0000 (20:17 +0200)
Add option to reorder the shared library cache in OpenBSD so that user
preferred directories for shared libraries can be used when linking
before directories previously listed in the shared library cache.

This allows for users in OpenBSD to easily switch between versions of
libraries with the same name during testing.

* NEWS: Update for new (OpenBSD) option.
* build-aux/ltmain.in: Add option --reorder-cache=DIRS.
* doc/libtool.texi: Update documentation for new option.
* test/bug_71489.at: Alter test for OpenBSD to utilize new option.

NEWS
build-aux/ltmain.in
doc/libtool.texi
tests/bug_71489.at

diff --git a/NEWS b/NEWS
index 28e4ecbc4a3c712b1b47c129f1e88165587806ad..4694cab7c26747d7391b0361b7d80fda818e9bba 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,9 @@ NEWS - list of user-visible changes between releases of GNU Libtool
   - New libtool command line flags, --test and --check, to skip executing
     finish_cmds that would alter the shared library cache during testing.
 
+  - New libtool command line flag, --reorder-cache=DIRS, to reorder the
+    shared library cache, only on OpenBSD.
+
 ** Bug fixes:
 
   - Fix incorrect use of workarounds designed for Darwin versions that
index 1801dd569e5ecadded2b881debf4fc8a8d4a2e5e..b571c442c50bf7a6cead4361f5bf9df3d853ff80 100644 (file)
@@ -141,6 +141,7 @@ usage_message="Options:
        --mode=MODE          use operation mode MODE
        --no-warnings        equivalent to '-Wnone'
        --preserve-dup-deps  don't remove duplicate dependency libraries
+       --reorder-cache=DIRS reorder shared library cache for preferred DIRS
        --test, --check      don't update shared library cache during testing
        --quiet, --silent    don't print informational messages
        --tag=TAG            use configuration variables from tag TAG
@@ -376,6 +377,7 @@ libtool_options_prep ()
     opt_dry_run=false
     opt_help=false
     opt_mode=
+    opt_reorder_cache=false
     opt_preserve_dup_deps=false
     opt_quiet=false
     opt_testing=true
@@ -491,6 +493,24 @@ libtool_parse_options ()
                         func_append preserve_args " $_G_opt"
                         ;;
 
+        --reorder-cache)
+                        opt_reorder_cache=true
+                        shared_lib_dirs=$1
+                        if test -n "$shared_lib_dirs"; then
+                          case $1 in
+                            # Must begin with /:
+                            /*) ;;
+
+                            # Catch anything else as an error (relative paths)
+                            *) func_warning "invalid argument '$1' for $_G_opt"
+                               func_warning "absolute paths are required for $_G_opt"
+                               exit_cmd=exit
+                               break
+                               ;;
+                          esac
+                        fi
+                        ;;
+
         --silent|--quiet)
                         opt_quiet=:
                         opt_verbose=false
@@ -1061,6 +1081,15 @@ func_convert_path_front_back_pathsep ()
 # end func_convert_path_front_back_pathsep
 
 
+# func_convert_delimited_path PATH ORIG_DELIMITER NEW_DELIMITER
+# Replaces a delimiter for a given path.
+func_convert_delimited_path ()
+{
+       converted_path=`$ECHO "$1" | $SED "s#$2#$3#g"`
+}
+# end func_convert_delimited_path
+
+
 ##################################################
 # $build to $host FILE NAME CONVERSION FUNCTIONS #
 ##################################################
@@ -1395,6 +1424,65 @@ func_dll_def_p ()
 }
 
 
+# func_reorder_shared_lib_cache DIRS
+# Reorder the shared library cache by unconfiguring previous shared library cache
+# and configuring preferred search directories before previous search directories.
+# Previous shared library cache: /usr/lib /usr/local/lib
+# Preferred search directories: /tmp/testing
+# Reordered shared library cache: /tmp/testing /usr/lib /usr/local/lib
+func_reorder_shared_lib_cache ()
+{
+       $debug_cmd
+
+       case $host_os in
+         openbsd*)
+           get_search_directories=`PATH="$PATH:/sbin" ldconfig -r | $GREP "search directories" | $SED "s#.*search directories:\ ##g"`
+           func_convert_delimited_path "$get_search_directories" ':' '\ '
+           save_search_directories=$converted_path
+           func_convert_delimited_path "$1" ':' '\ '
+
+           # Ensure directories exist
+           for dir in $converted_path; do
+             # Ensure each directory is an absolute path
+             case $dir in
+               /*) ;;
+               *) func_warning "Directory '$dir' is not an absolute path"
+                  exit $EXIT_FAILURE ;;
+             esac
+             # Ensure no trailing slashes
+             func_stripname '' '/' "$dir"
+             dir=$func_stripname_result
+             if test -d "$dir"; then
+               if test -n "$preferred_search_directories"; then
+                 preferred_search_directories="$preferred_search_directories $dir"
+               else
+                 preferred_search_directories=$dir
+               fi
+             else
+               func_warning "Directory '$dir' does not exist"
+               exit $EXIT_FAILURE
+             fi
+           done
+
+           PATH="$PATH:/sbin" ldconfig -U $save_search_directories
+           PATH="$PATH:/sbin" ldconfig -m $preferred_search_directories $save_search_directories
+           get_search_directories=`PATH="$PATH:/sbin" ldconfig -r | $GREP "search directories" | $SED "s#.*search directories:\ ##g"`
+           func_convert_delimited_path "$get_search_directories" ':' '\ '
+           reordered_search_directories=$converted_path
+
+           $ECHO "Original: $save_search_directories"
+           $ECHO "Reordered: $reordered_search_directories"
+           exit $EXIT_SUCCESS
+         ;;
+         *)
+           func_warning "--reorder-cache is not supported for host_os=$host_os."
+           exit $EXIT_FAILURE
+         ;;
+       esac
+}
+# end func_reorder_shared_lib_cache
+
+
 # func_mode_compile arg...
 func_mode_compile ()
 {
@@ -1967,6 +2055,12 @@ if $opt_help; then
 fi
 
 
+# If option '--reorder-cache', reorder the shared library cache and exit.
+if $opt_reorder_cache; then
+    func_reorder_shared_lib_cache $shared_lib_dirs
+fi
+
+
 # func_mode_execute arg...
 func_mode_execute ()
 {
index 484077ff533745e61ca56e945d8a3e341e1da745..9dfd57383c02b1198be10adb898f51e63b523be0 100644 (file)
@@ -1275,8 +1275,59 @@ that libtool knows it can safely.
 @item --test
 @itemx --check
 Do not execute finish_cmds (disabled by default). This option is for
-specifying that the testsuite is executing so that ldconfig will not alter
-the shared library cache, which is an issue observed on OpenBSD 7.5.
+specifying that testing of local changes to shared libraries is being
+performed so that ldconfig will not alter the shared library cache, which
+is an issue observed on OpenBSD 7.5. This option should be combined with
+the usage of @option{--mode=install} and @option{--mode=finish} to have
+any effect. Prior to utilizing this option, the shared library cache must
+not contain links to the listed install directory for shared libraries
+undergoing testing; otherwise, it will have no useful effect. The shared
+library cache can be reordered to prefer directories for testing shared
+libraries over the directories already listed in the shared library cache
+with @option{--reorder-cache=@var{shared_lib_dirs}}.
+
+@item --reorder-cache=@var{shared_lib_dirs}
+Reorder the shared library cache by providing the preferred directories
+(@var{shared_lib_dirs}) to link shared libraries from. The previous
+shared library cache is unconfigured, and the preferred directories are
+configured with the previous directories appended to the end (if not in
+the preferred directory list)@footnote{Additionally, all directories
+that no longer exist will be removed from the shared library cache.}.
+This option is currently only available on OpenBSD where @code{make
+install} has been required before @code{make check} for the shared
+library cache to be updated.
+
+This option is essentially a wrapper for executing @command{ldconfig},
+and it should be used as an independent option before and after testing
+changes to shared libraries. Below are some usage examples:
+
+@example
+$ @kbd{libtool --reorder-cache=/tmp/testing}
+Original: /usr/lib /usr/X11R6/lib /usr/local/lib
+Reordered: /tmp/testing /usr/lib /usr/X11R6/lib /usr/local/lib
+$ @kbd{libtool --reorder-cache=/usr/lib:/usr/X11R6/lib:/usr/local/lib}
+Original: /tmp/testing /usr/lib /usr/X11R6/lib /usr/local/lib
+Reordered: /usr/lib /usr/X11R6/lib /usr/local/lib /tmp/testing
+@end example
+
+@example
+$ @kbd{libtool --reorder-cache=/tmp/testing}
+Original: /usr/lib /usr/X11R6/lib /usr/local/lib
+Reordered: /tmp/testing /usr/lib /usr/X11R6/lib /usr/local/lib
+$ @kbd{rm -rf /tmp/testing}
+$ @kbd{libtool --reorder-cache=/usr/lib:/usr/X11R6/lib:/usr/local/lib}
+Original: /tmp/testing /usr/lib /usr/X11R6/lib /usr/local/lib
+Reordered: /usr/lib /usr/X11R6/lib /usr/local/lib
+@end example
+
+@example
+$ @kbd{libtool --reorder-cache=/tmp/testing:/usr/local/lib:/home/user/dir}
+Original: /usr/lib /usr/X11R6/lib /usr/local/lib
+Reordered: /tmp/testing /usr/local/lib /home/user/dir /usr/lib /usr/X11R6/lib
+$ @kbd{libtool --reorder-cache=/usr/lib /usr/X11R6/lib /usr/local/lib}
+Original: /tmp/testing /usr/local/lib /home/user/dir /usr/lib /usr/X11R6/lib
+Reordered: /usr/lib /usr/X11R6/lib /usr/local/lib /tmp/testing /home/user/dir
+@end example
 
 @item --quiet
 @itemx --silent
@@ -6862,7 +6913,7 @@ shell does not support the shell option @code{nocaseglob}, making
 @defvar finish_cmds
 Commands to tell the dynamic linker how to find shared libraries in a
 specific directory. These commands can be disabled during testing local
-changes with @option{--test} or @option{--check}.
+changes to shared libraries with @option{--test} or @option{--check}.
 @end defvar
 
 @defvar finish_eval
index ef4f51f7428f6ca427c7edd6cd3dacf8f41d4afa..0819696647e8be2d028aa944b921d48b230d3364 100644 (file)
@@ -382,6 +382,16 @@ echo "Building local copy of the project"
     cd build_local
     LT_AT_CONFIGURE([--prefix=$prefix], [$ltb2/configure])
     LT_AT_MAKE([])
+
+    case $host_os in
+    openbsd*)
+      build_local_dir=$(pwd)
+      AT_CHECK(
+      [
+        $LIBTOOL --reorder-cache="$build_local_dir/liba/.libs:$build_local_dir/libb/.libs"
+      ], 0, ignore, ignore);;
+    *) ;;
+    esac
 )
 
 # Although we have installed ltb2, we still expect that we are using the local