]> Savannah Git Hosting - gnulib.git/commitdiff
gnulib-tool: simplify/speed startup
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 6 Jul 2024 14:41:44 +0000 (16:41 +0200)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 6 Jul 2024 14:44:18 +0000 (16:44 +0200)
* gnulib-tool, gnulib-tool.py (prog): New var.  Use it to simplify
and speed up startup in common cases.

ChangeLog
gnulib-tool
gnulib-tool.py

index b68ed39449de2edf9c8642c2e2056a31787c643d..340efb2de3ec95fb0292ba0d5d4fda8a5cb85f66 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-07-06  Paul Eggert  <eggert@cs.ucla.edu>
+
+       gnulib-tool: simplify/speed startup
+       * gnulib-tool, gnulib-tool.py (prog): New var.  Use it to simplify
+       and speed up startup in common cases.
+
 2024-07-04  Bruno Haible  <bruno@clisp.org>
 
        gitlog-to-changelog: Tweak documentation.
index 789fe916a88d0ec6cc4a2b39c98d76a213ff2f71..5cfc5bbb52ea165f85da9b3f74561d507b0b92c6 100755 (executable)
@@ -137,23 +137,35 @@ func_gnulib_dir ()
   gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
 }
 
-func_gnulib_dir
+# If $progname contains '/' and is not a symlink, it suffices for $prog to be
+# the same as $progname with except with basename 'gnulib-tool’; this
+# speeds startup and might avoid problems in oddball development environments.
+# Otherwise, $prog is the absolute name of the gnulib-tool executable.
+if case $progname in
+     */*) test -h "$0" ;;
+   esac
+then
+  func_gnulib_dir
+  prog=$gnulib_dir/gnulib-tool
+else
+  prog=${progname%/*}/gnulib-tool
+fi
 
 case "$GNULIB_TOOL_IMPL" in
   '')
     # Use the Python implementation if a suitable Python version is found
     # in $PATH. This is the same Python version test as in gnulib-tool.py.
     if (python3 -c 'import sys; sys.exit(not sys.version_info >= (3,7))') 2>/dev/null; then
-      exec "$gnulib_dir/gnulib-tool.py" "$@"
+      exec "$prog.py" "$@"
     else
       echo "gnulib-tool: warning: python3 not found or too old, using the slow shell-based implementation" 1>&2
-      exec "$gnulib_dir/gnulib-tool.sh" "$@"
+      exec "$prog.sh" "$@"
     fi
     ;;
   sh)
-    exec "$gnulib_dir/gnulib-tool.sh" "$@" ;;
+    exec "$prog.sh" "$@" ;;
   py)
-    exec "$gnulib_dir/gnulib-tool.py" "$@" ;;
+    exec "$prog.py" "$@" ;;
   sh+py)
     case " $* " in
       *" --import"* | *" --add-import"* | *" --remove-import"* | *" --update"* | *" --copy-file"*)
@@ -183,10 +195,14 @@ case "$GNULIB_TOOL_IMPL" in
           func_exit 1
         }
         # Execute gnulib-tool.py in the clone directory.
-        (cd "$tmp" && "$gnulib_dir/gnulib-tool.py" "$@" >"$tmp-py-out" 2>"$tmp-py-err")
+        case $prog in
+          /*) absprog=$prog ;;
+          *)  absprog=$PWD/prog ;;
+        esac
+        (cd "$tmp" && "$absprog.py" "$@" >"$tmp-py-out" 2>"$tmp-py-err")
         pyrc=$?
         # Execute gnulib-tool.sh in the current directory.
-        "$gnulib_dir/gnulib-tool.sh" "$@" >"$tmp-sh-out" 2>"$tmp-sh-err"
+        "$prog.sh" "$@" >"$tmp-sh-out" 2>"$tmp-sh-err"
         shrc=$?
         if test $shrc != 0; then
           if test $pyrc = 0; then
@@ -233,10 +249,10 @@ case "$GNULIB_TOOL_IMPL" in
         # Find another directory name.
         tmp="$dir-glpy$$"
         # Execute gnulib-tool.py, creating a different directory.
-        "$gnulib_dir/gnulib-tool.py" "$@" --dir="$tmp" >"$tmp-py-out" 2>"$tmp-py-err"
+        "$prog.py" "$@" --dir="$tmp" >"$tmp-py-out" 2>"$tmp-py-err"
         pyrc=$?
         # Execute gnulib-tool.sh, creating the intended directory.
-        "$gnulib_dir/gnulib-tool.sh" "$@" >"$tmp-sh-out" 2>"$tmp-sh-err"
+        "$prog.sh" "$@" >"$tmp-sh-out" 2>"$tmp-sh-err"
         shrc=$?
         if test $shrc != 0; then
           if test $pyrc = 0; then
@@ -274,10 +290,10 @@ case "$GNULIB_TOOL_IMPL" in
         # A gnulib-tool invocation that produces only output, no files.
         tmp="glpy$$"
         # Execute gnulib-tool.py.
-        "$gnulib_dir/gnulib-tool.py" "$@" >"$tmp-py-out" 2>"$tmp-py-err"
+        "$prog.py" "$@" >"$tmp-py-out" 2>"$tmp-py-err"
         pyrc=$?
         # Execute gnulib-tool.sh.
-        "$gnulib_dir/gnulib-tool.sh" "$@" >"$tmp-sh-out" 2>"$tmp-sh-err"
+        "$prog.sh" "$@" >"$tmp-sh-out" 2>"$tmp-sh-err"
         shrc=$?
         if test $shrc != 0; then
           if test $pyrc = 0; then
index 52389dcd7858125c9b386a469a19b67ef1227e68..bd13a8aa02b8d89f675db5e9b1489965270d1617 100755 (executable)
@@ -128,7 +128,19 @@ func_gnulib_dir ()
   gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
 }
 
-func_gnulib_dir
+# If $progname contains '/' and is not a symlink, it suffices for $prog to be
+# the same as $progname with except with basename '.gnulib-tool.py'; this
+# speeds startup and might avoid problems in oddball development environments.
+# Otherwise, $prog is the absolute name of the .gnulib-tool.py file.
+if case $progname in
+     */*) test -h "$0" ;;
+   esac
+then
+  func_gnulib_dir
+  prog=$gnulib_dir/.gnulib-tool.py
+else
+  prog=${progname%/*}/.gnulib-tool.py
+fi
 
 # Check the Python version.
 if (python3 -c 'import sys; sys.exit(not sys.version_info >= (3,7))') 2>/dev/null; then
@@ -157,4 +169,4 @@ fi
 profiler_args=
 # For profiling, cf. <https://docs.python.org/3/library/profile.html>.
 #profiler_args="-m cProfile -s tottime"
-exec python3 $profiler_args "$gnulib_dir/.gnulib-tool.py" "$@"
+exec python3 $profiler_args -- "$prog" "$@"