Running this script:

    $ ./all-modules --version
    ./all-modules: line 44: func_gnulib_dir: command not found
    sed: can't read /ChangeLog: No such file or directory
    ./all-modules: line 65: /build-aux/mdate-sh: No such file or directory
    all-modules (GNU gnulib )
    Copyright (C)  Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later 
<https://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.

    Written by Bruno Haible

The first patch copies the missing function from 'posix-modules'.

The date output in both of those scripts is incorrect for me:

    posix-modules (GNU gnulib 2024-04-04 00:00:00) 0.1.7344-83a61

I remember we addressed this when I first started working on the
Python version of gnulib-tool. There it caused an uncaught exception
because of an out of bounds index, instead of an incorrect time 
value. :)

The second patch just copies that change:

    git log ChangeLog

becomes:

    git log -n 1 --format=medium --date=iso ChangeLog

I *think* all 'git log' invocations should be safe now...

Collin
From c3f5f5858a5a3f7135d8186d1d882685174d32f8 Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Wed, 3 Apr 2024 17:32:46 -0700
Subject: [PATCH 1/2] all-modules: Fix warnings in --version output.

* all-modules (func_gnulib_dir): Copy missing function from
posix-modules.
---
 ChangeLog   |  6 ++++
 all-modules | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 86 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 6863c5e20b..0ce5afac22 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-04-03  Collin Funk  <collin.fu...@gmail.com>
+
+	all-modules: Fix warnings in --version output.
+	* all-modules (func_gnulib_dir): Copy missing function from
+	posix-modules.
+
 2024-04-03  Bruno Haible  <br...@clisp.org>
 
 	gnulib-tool.sh: Reduce code duplication in last commit.
diff --git a/all-modules b/all-modules
index 4d22f7fc47..7dd9295f0d 100755
--- a/all-modules
+++ b/all-modules
@@ -73,6 +73,86 @@ There is NO WARRANTY, to the extent permitted by law.
 Written by" "Bruno Haible"
 }
 
+# func_gnulib_dir
+# locates the directory where the gnulib repository lives
+# Input:
+# - progname                 name of this program
+# Sets variables
+# - self_abspathname         absolute pathname of this program
+# - gnulib_dir               absolute pathname of gnulib repository
+func_gnulib_dir ()
+{
+  case "$progname" in
+    /*) self_abspathname="$progname" ;;
+    */*) self_abspathname=`pwd`/"$progname" ;;
+    *)
+      # Look in $PATH.
+      # Iterate through the elements of $PATH.
+      # We use IFS=: instead of
+      #   for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`
+      # because the latter does not work when some PATH element contains spaces.
+      # We use a canonicalized $pathx instead of $PATH, because empty PATH
+      # elements are by definition equivalent to '.', however field splitting
+      # according to IFS=: loses empty fields in many shells:
+      #   - /bin/sh on OSF/1 and Solaris loses all empty fields (at the
+      #     beginning, at the end, and in the middle),
+      #   - /bin/sh on IRIX and /bin/ksh on IRIX and OSF/1 lose empty fields
+      #     at the beginning and at the end,
+      #   - GNU bash, /bin/sh on AIX and HP-UX, and /bin/ksh on AIX, HP-UX,
+      #     Solaris lose empty fields at the end.
+      # The 'case' statement is an optimization, to avoid evaluating the
+      # explicit canonicalization command when $PATH contains no empty fields.
+      self_abspathname=
+      if test "${PATH_SEPARATOR+set}" != set; then
+        # Determine PATH_SEPARATOR by trying to find /bin/sh in a PATH which
+        # contains only /bin. Note that ksh looks also at the FPATH variable,
+        # so we have to set that as well for the test.
+        PATH_SEPARATOR=:
+        (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 \
+          && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 \
+                 || PATH_SEPARATOR=';'
+             }
+      fi
+      if test "$PATH_SEPARATOR" = ";"; then
+        # On Windows, programs are searched in "." before $PATH.
+        pathx=".;$PATH"
+      else
+        # On Unix, we have to convert empty PATH elements to ".".
+        pathx="$PATH"
+        case :$PATH: in
+          *::*)
+            pathx=`echo ":$PATH:" | sed -e 's/:::*/:.:/g' -e 's/^://' -e 's/:\$//'`
+            ;;
+        esac
+      fi
+      saved_IFS="$IFS"
+      IFS="$PATH_SEPARATOR"
+      for d in $pathx; do
+        IFS="$saved_IFS"
+        test -z "$d" && d=.
+        if test -x "$d/$progname" && test ! -d "$d/$progname"; then
+          self_abspathname="$d/$progname"
+          break
+        fi
+      done
+      IFS="$saved_IFS"
+      if test -z "$self_abspathname"; then
+        func_fatal_error "could not locate the posix-modules program - how did you invoke it?"
+      fi
+      ;;
+  esac
+  while test -h "$self_abspathname"; do
+    # Resolve symbolic link.
+    linkval=`func_readlink "$self_abspathname"`
+    test -n "$linkval" || break
+    case "$linkval" in
+      /* ) self_abspathname="$linkval" ;;
+      * ) self_abspathname=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
+    esac
+  done
+  gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
+}
+
 # Excludes for mingw and MSVC.
 exclude_for_mingw=
 # <pwd.h> and <grp.h> do not exist.
-- 
2.44.0

From 55c16e00de4a3c080e983f8df27f3d6908c9cc46 Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Wed, 3 Apr 2024 17:48:56 -0700
Subject: [PATCH 2/2] posix-modules, all-modules: Fix --version output using
 git options.

* all-modules: Pass --format and --date options to git so the output
does not depend on the user's configuration. Pass '-n 1' to speed up the
operation, since we only need the first entry.
* posix-modules: Likewise.
---
 ChangeLog     | 8 ++++++++
 all-modules   | 2 +-
 posix-modules | 2 +-
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 0ce5afac22..70d6009679 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-04-03  Collin Funk  <collin.fu...@gmail.com>
+
+	posix-modules, all-modules: Fix --version output using git options.
+	* all-modules: Pass --format and --date options to git so the output
+	does not depend on the user's configuration. Pass '-n 1' to speed up the
+	operation, since we only need the first entry.
+	* posix-modules: Likewise.
+
 2024-04-03  Collin Funk  <collin.fu...@gmail.com>
 
 	all-modules: Fix warnings in --version output.
diff --git a/all-modules b/all-modules
index 7dd9295f0d..da69d66f8f 100755
--- a/all-modules
+++ b/all-modules
@@ -50,7 +50,7 @@ func_version ()
 s/^Date:[	 ]*//p
 q
 }'
-    date=`cd "$gnulib_dir" && git log ChangeLog | sed -n -e "$sed_extract_first_date"`
+    date=`cd "$gnulib_dir" && git log -n 1 --format=medium --date=iso ChangeLog | sed -n -e "$sed_extract_first_date"`
     # Turn "Fri Mar 21 07:16:51 2008 -0600" into "Mar 21 2008 07:16:51 -0600".
     sed_year_before_time='s/^[^ ]* \([^ ]*\) \([0-9]*\) \([0-9:]*\) \([0-9]*\) /\1 \2 \4 \3 /'
     date=`echo "$date" | sed -e "$sed_year_before_time"`
diff --git a/posix-modules b/posix-modules
index 0da6942738..c1eac5af8e 100755
--- a/posix-modules
+++ b/posix-modules
@@ -49,7 +49,7 @@ func_version ()
 s/^Date:[	 ]*//p
 q
 }'
-    date=`cd "$gnulib_dir" && git log ChangeLog | sed -n -e "$sed_extract_first_date"`
+    date=`cd "$gnulib_dir" && git log -n 1 --format=medium --date=iso ChangeLog | sed -n -e "$sed_extract_first_date"`
     # Turn "Fri Mar 21 07:16:51 2008 -0600" into "Mar 21 2008 07:16:51 -0600".
     sed_year_before_time='s/^[^ ]* \([^ ]*\) \([0-9]*\) \([0-9:]*\) \([0-9]*\) /\1 \2 \4 \3 /'
     date=`echo "$date" | sed -e "$sed_year_before_time"`
-- 
2.44.0

Reply via email to