[v2,5/7] testsuite: stop using obsoleted egrep

Message ID 51908ccd68c022910f59a904556483c123ae428c.camel@xry111.site
State New
Headers
Series Avoid using obsoleted egrep/fgrep |

Commit Message

Xi Ruoyao June 27, 2022, 6:11 a.m. UTC
  egrep has been deprecated in favor of grep -E for a long time, and the
next grep release (3.8 or 4.0) will print a warning of egrep is used.
Stop using egrep so we won't see the warning.

However, simply replacing egrep with grep -E will break build on some
systems (notably Solaris) w/o a POSIX-conform grep.  We detect a
suitable command with AC_PROG_EGREP, and pass it to run_acats.sh for
Ada.

For Go, simply use grep instead of egrep as the pattern does not need
any ERE features.

gcc/ChangeLog:

	* Makefile.in (EGREP): New variable.
	* configure.ac (AC_PROG_EGREP): Call it.
	* configure: Regenerate.

gcc/ada/ChangeLog:

	* gcc-interface/Make-lang.in: Pass EGREP to run_acats.sh.

gcc/testsuite/ChangeLog:

	* ada/acats/run_all.sh: Use $EGREP instead of egrep.
	* go.test/go-test.exp: Use grep intead of egrep.
---
 gcc/Makefile.in                    |  1 +
 gcc/ada/gcc-interface/Make-lang.in |  3 +-
 gcc/configure                      | 71 +++++++++++++++++++++++++++++-
 gcc/configure.ac                   |  1 +
 gcc/testsuite/ada/acats/run_all.sh |  8 +++-
 gcc/testsuite/go.test/go-test.exp  |  2 +-
 6 files changed, 81 insertions(+), 5 deletions(-)
  

Comments

Arnaud Charlet June 27, 2022, 6:50 a.m. UTC | #1
> egrep has been deprecated in favor of grep -E for a long time, and the
> next grep release (3.8 or 4.0) will print a warning of egrep is used.
> Stop using egrep so we won't see the warning.
> 
> However, simply replacing egrep with grep -E will break build on some
> systems (notably Solaris) w/o a POSIX-conform grep.  We detect a
> suitable command with AC_PROG_EGREP, and pass it to run_acats.sh for
> Ada.
> 
> For Go, simply use grep instead of egrep as the pattern does not need
> any ERE features.
> 
> gcc/ChangeLog:
> 
> 	* Makefile.in (EGREP): New variable.
> 	* configure.ac (AC_PROG_EGREP): Call it.
> 	* configure: Regenerate.
> 
> gcc/ada/ChangeLog:
> 
> 	* gcc-interface/Make-lang.in: Pass EGREP to run_acats.sh.

The Ada change is OK

Arno
  

Patch

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index b6dcc45a58a..8b95ee20b46 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1090,6 +1090,7 @@  BACKENDLIBS = $(ISLLIBS) $(GMPLIBS) $(PLUGINLIBS) $(HOST_LIBS) \
 SYSLIBS = @GNAT_LIBEXC@
 
 # Used from ada/gcc-interface/Make-lang.in
+EGREP = @EGREP@
 GNATBIND = @GNATBIND@
 GNATMAKE = @GNATMAKE@
 
diff --git a/gcc/ada/gcc-interface/Make-lang.in b/gcc/ada/gcc-interface/Make-lang.in
index 1e245ed3b0f..e0cbb6ab1ed 100644
--- a/gcc/ada/gcc-interface/Make-lang.in
+++ b/gcc/ada/gcc-interface/Make-lang.in
@@ -1050,7 +1050,8 @@  check-acats:
 	  rm -rf $(ACATSDIR)-parallel; \
 	  mkdir $(ACATSDIR)-parallel; \
 	  ( testdir=`cd ${srcdir}/${ACATSDIR} && ${PWD_COMMAND}`; \
-	    export testdir; \
+	    EGREP="$EGREP"; \
+	    export testdir EGREP; \
 	    cd $(ACATSDIR) && $(SHELL) $${testdir}/$(ACATSCMD) NONE ) \
 	    || exit 1; \
 	  GCC_RUNTEST_PARALLELIZE_DIR=$$rootme/$(ACATSDIR)-parallel; \
diff --git a/gcc/configure b/gcc/configure
index c58ec9b2273..8bd384c3fcc 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -8416,6 +8416,73 @@  case ${AWK} in
   "") as_fn_error $? "can't build without awk, bailing out" "$LINENO" 5 ;;
 esac
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5
+$as_echo_n "checking for egrep... " >&6; }
+if ${ac_cv_path_EGREP+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if echo a | $GREP -E '(a|b)' >/dev/null 2>&1
+   then ac_cv_path_EGREP="$GREP -E"
+   else
+     if test -z "$EGREP"; then
+  ac_path_EGREP_found=false
+  # Loop through the user's path and test for each of PROGNAME-LIST
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_prog in egrep; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
+      ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext"
+      as_fn_executable_p "$ac_path_EGREP" || continue
+# Check for GNU ac_path_EGREP and select it if it is found.
+  # Check for GNU $ac_path_EGREP
+case `"$ac_path_EGREP" --version 2>&1` in
+*GNU*)
+  ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;;
+*)
+  ac_count=0
+  $as_echo_n 0123456789 >"conftest.in"
+  while :
+  do
+    cat "conftest.in" "conftest.in" >"conftest.tmp"
+    mv "conftest.tmp" "conftest.in"
+    cp "conftest.in" "conftest.nl"
+    $as_echo 'EGREP' >> "conftest.nl"
+    "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break
+    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
+    as_fn_arith $ac_count + 1 && ac_count=$as_val
+    if test $ac_count -gt ${ac_path_EGREP_max-0}; then
+      # Best one so far, save it but keep looking for a better one
+      ac_cv_path_EGREP="$ac_path_EGREP"
+      ac_path_EGREP_max=$ac_count
+    fi
+    # 10*(2^10) chars as input seems more than enough
+    test $ac_count -gt 10 && break
+  done
+  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
+esac
+
+      $ac_path_EGREP_found && break 3
+    done
+  done
+  done
+IFS=$as_save_IFS
+  if test -z "$ac_cv_path_EGREP"; then
+    as_fn_error $? "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
+  fi
+else
+  ac_cv_path_EGREP=$EGREP
+fi
+
+   fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5
+$as_echo "$ac_cv_path_EGREP" >&6; }
+ EGREP="$ac_cv_path_EGREP"
+
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ln -s works" >&5
 $as_echo_n "checking whether ln -s works... " >&6; }
 if ${gcc_cv_prog_LN_S+:} false; then :
@@ -19675,7 +19742,7 @@  else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 19678 "configure"
+#line 19745 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -19781,7 +19848,7 @@  else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 19784 "configure"
+#line 19851 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 80bdd8ceef9..bfb124e9456 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -1219,6 +1219,7 @@  case ${AWK} in
   "") AC_MSG_ERROR([can't build without awk, bailing out]) ;;
 esac
 
+AC_PROG_EGREP
 gcc_AC_PROG_LN_S
 ACX_PROG_LN($LN_S)
 AC_PROG_RANLIB
diff --git a/gcc/testsuite/ada/acats/run_all.sh b/gcc/testsuite/ada/acats/run_all.sh
index ac2a86bea6c..81d3f9edd5c 100755
--- a/gcc/testsuite/ada/acats/run_all.sh
+++ b/gcc/testsuite/ada/acats/run_all.sh
@@ -53,6 +53,12 @@  if [ "$dir" = "$testdir" ]; then
   exit 1
 fi
 
+if [ -z "$EGREP" ]; then
+  # Set a default suitable for all "modern" system in case this script is
+  # not invoked by GCC building system.
+  EGREP="grep -E"
+fi
+
 GCC="$BASE/xgcc -B$BASE/"
 
 target_gnatchop () {
@@ -367,7 +373,7 @@  for chapter in $chapters; do
       target_run $dir/tests/$chapter/$i/$binmain > $dir/tests/$chapter/$i/${i}.log 2>&1
       cd $dir/tests/$chapter/$i
       cat ${i}.log >> $dir/acats.log
-      egrep -e '(==== |\+\+\+\+ |\!\!\!\! )' ${i}.log > /dev/null 2>&1
+      $EGREP -e '(==== |\+\+\+\+ |\!\!\!\! )' ${i}.log > /dev/null 2>&1
       if [ $? -ne 0 ]; then
          grep 'tasking not implemented' ${i}.log > /dev/null 2>&1
 
diff --git a/gcc/testsuite/go.test/go-test.exp b/gcc/testsuite/go.test/go-test.exp
index 11c178ad7ec..c9dbd72d16a 100644
--- a/gcc/testsuite/go.test/go-test.exp
+++ b/gcc/testsuite/go.test/go-test.exp
@@ -1207,7 +1207,7 @@  proc go-gc-tests { } {
 		   || $test_line == "// \$G \$D/empty.go && errchk \$G \$D/\$F.go" } {
 	    # These tests import the same package under two different
 	    # names, which gccgo does not support.
-	} elseif { $test_line == "// \$G -S \$D/\$F.go | egrep initdone >/dev/null && echo BUG sinit || true" } {
+	} elseif { $test_line == "// \$G -S \$D/\$F.go | grep initdone >/dev/null && echo BUG sinit || true" } {
 	    # This tests whether initializers are written out
 	    # statically.  gccgo does not provide a way to test that,
 	    # as an initializer will be generated for any code which