groff-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[groff] 29/30: Revamp build-time check of test(1) command.


From: G. Branden Robinson
Subject: [groff] 29/30: Revamp build-time check of test(1) command.
Date: Sun, 22 Dec 2024 19:39:21 -0500 (EST)

gbranden pushed a commit to branch master
in repository groff.

commit 4555d9be3913ce151147d62addf764219db776a0
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Sun Dec 22 17:13:39 2024 -0600

    Revamp build-time check of test(1) command.
    
    ...for POSIX conformance.
    
    "test -ef", long depended upon by the contributed program gdiffmk(1) for
    certain functionality, is now standard as of POSIX Issue 8 (2024).  The
    Austin Group's threshold criteria for inclusion in the standard mean
    that such a feature is widely available, and one need not
    pessimistically assume that the Bash shell must be used to obtain the
    feature.  Refactor and revise our detection and fallback techniques
    accordingly.
    
    * m4/groff.m4 (GROFF_HAVE_TEST_EF_OPTION): Rename this...
      (GROFF_PROG_TEST_SUPPORTS_EF_OPTION): ...to this.  Simplify,
      making it a simple test of the feature, using "sh -c" since we
      don't care whether the shell itself or a 'test' executable in
      the $PATH provides it.
    
      (GROFF_BASH): Rename this...
      (GROFF_PROG_SH_IS_POSIX_8_CONFORMING): ...to this.  It's a
      mouthful, but reflects our concerns.  We don't care about Bash
      per se (groff does not employ Bashisms); we care about whether
      the shell conforms to POSIX Issue 8.  Rename the `AC_SUBST`ed
      macro `BASH_PROG` to `POSIX_SHELL_PROG`.  If we don't find a
      conforming shell, _then_ fall back to Bash for
      `POSIX_SHELL_PROG`, if it is available; if not, configure-time
      tests are fruitless and programs must perform runtime checks for
      POSIX non-conformance (since we're not shipping our own shell or
      test(1) to close the gap).
    
    * configure.ac: Update expansion sites of m4 macros to use their new
      names.
    
    Tests of `gdiffmk` may fail at this commit.  (They don't on GBR's
    system, but the generated "gdiffmk" program text is not quite correct.)
---
 ChangeLog    | 31 +++++++++++++++++++++++++++++++
 configure.ac |  4 ++--
 m4/groff.m4  | 48 +++++++++++++++++++++++++++++++-----------------
 3 files changed, 64 insertions(+), 19 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index bca7e9786..0e73ffd3b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,34 @@
+2024-12-22  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       Revamp build-time check of POSIX-conforming test(1) command.
+
+       "test -ef", long depended upon by the contributed program
+       gdiffmk(1) for certain functionality, is now standard as of
+       POSIX Issue 8 (2024).  The Austin Group's threshold criteria for
+       inclusion in the standard mean that such a feature is widely
+       available, and one need not pessimistically assume that the Bash
+       shell must be used to obtain the feature.  Refactor and revise
+       our detection and fallback techniques accordingly.
+
+       * m4/groff.m4 (GROFF_HAVE_TEST_EF_OPTION): Rename this...
+       (GROFF_PROG_TEST_SUPPORTS_EF_OPTION): ...to this.  Simplify,
+       making it a simple test of the feature, using "sh -c" since we
+       don't care whether the shell itself or a 'test' executable in
+       the $PATH provides it.
+       (GROFF_BASH): Rename this...
+       (GROFF_PROG_SH_IS_POSIX_8_CONFORMING): ...to this.  It's a
+       mouthful, but reflects our concerns.  We don't care about Bash
+       per se (groff does not employ Bashisms); we care about whether
+       the shell conforms to POSIX Issue 8.  Rename the `AC_SUBST`ed
+       macro `BASH_PROG` to `POSIX_SHELL_PROG`.  If we don't find a
+       conforming shell, _then_ fall back to Bash for
+       `POSIX_SHELL_PROG`, if it is available; if not, configure-time
+       tests are fruitless and programs must perform runtime checks for
+       POSIX non-conformance (since we're not shipping our own shell or
+       test(1) to close the gap).
+       * configure.ac: Update expansion sites of m4 macros to use their
+       new names.
+
 2024-12-22  onf <onf@disroot.org>
 
        Support building without makeinfo(1) installed.
diff --git a/configure.ac b/configure.ac
index f9d52a45f..e9420c9ca 100644
--- a/configure.ac
+++ b/configure.ac
@@ -164,8 +164,8 @@ GROFF_PNMTOOLS_CAN_BE_QUIET
 GROFF_PNMTOPS_NOSETPAGE
 GROFF_MAKE_DEFINES_RM
 GROFF_DIFF_D
-GROFF_HAVE_TEST_EF_OPTION
-GROFF_BASH
+GROFF_PROG_TEST_SUPPORTS_EF_OPTION
+GROFF_PROG_SH_IS_POSIX_8_CONFORMING
 GROFF_GHOSTSCRIPT_VERSION_CHECK
 gl_GLIBC21
 gl_LOCALCHARSET
diff --git a/m4/groff.m4 b/m4/groff.m4
index aee7c8811..0fb6a7765 100644
--- a/m4/groff.m4
+++ b/m4/groff.m4
@@ -1792,24 +1792,38 @@ AC_DEFUN([GROFF_DIFF_D],
   AC_MSG_RESULT([$DIFF_PROG])
   AC_SUBST([DIFF_PROG])])
 
-# Check if 'test' supports the option -ef.
-
-AC_DEFUN([GROFF_HAVE_TEST_EF_OPTION],
-  [AC_MSG_CHECKING(whether test supports option -ef)
-  HAVE_TEST_EF_OPTION=no
-  test /dev/null -ef /dev/null > /dev/null 2>&1 && HAVE_TEST_EF_OPTION=yes
-  AC_MSG_RESULT([$HAVE_TEST_EF_OPTION])
-  AC_SUBST([HAVE_TEST_EF_OPTION])])
-
-# gdiffmk will attempt to use bash (for option -ef of 'test'). If bash
-# is not available it will use /bin/sh.
-
-AC_DEFUN([GROFF_BASH],
-  [AC_PATH_PROGS([BASH_PROG], [bash], [no])
-  if test "$BASH_PROG" = no; then
-     BASH_PROG=/bin/sh
+
+# Check if 'test' supports the option `-ef`.  POSIX Issue 8 (2024)
+# mandates it.  It could be a shell builtin or a separate executable; we
+# don't care as long as it works.
+
+AC_DEFUN([GROFF_PROG_TEST_SUPPORTS_EF_OPTION],
+  [AC_MSG_CHECKING(whether 'test' supports '-ef' option)
+  test_ef_works=no
+  sh -c 'test /dev/null -ef /dev/null > /dev/null 2>&1' \
+   && test_ef_works=yes
+  AC_MSG_RESULT([$test_ef_works])
+])
+
+
+# gdiffmk needs a working 'test' `-ef` option.  If one is not available
+# in the default /bin/sh or /bin/test, use Bash to get it.
+#
+# This test could be made more general by testing other POSIX Issue 8
+# (or earlier) shell features, if we happen to rely upon them.  Solaris
+# 10 /bin/sh is notoriously incapable.
+
+AC_DEFUN([GROFF_PROG_SH_IS_POSIX_8_CONFORMING],
+  POSIX_SHELL_PROG=/bin/sh
+  if test "$test_ef_works" = no
+  then
+    # Use Bash if it is available; otherwise programs must complain at
+    # runtime if the environment is non-conforming to POSIX.
+    [AC_PATH_PROGS([POSIX_SHELL_PROG], [bash], [no])
   fi
-  AC_SUBST([BASH_PROG])])
+  AC_SUBST([POSIX_SHELL_PROG])
+])
+
 
 # Search for uchardet library used by preconv.
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]