[ovs-dev] [PATCH 1/2] autoconf: Don't die on grep error.

Jesse Gross jesse at nicira.com
Wed Nov 3 01:02:41 UTC 2010


On Tue, Nov 2, 2010 at 5:05 PM, Ben Pfaff <blp at nicira.com> wrote:
> On Tue, Nov 02, 2010 at 04:53:09PM -0700, Jesse Gross wrote:
>> The most likely cause of an error when grepping for a compatibility
>> string is that the file doesn't exist.  Since this can be a valid
>> result when files are added in later versions, we shouldn't kill
>> the build.  Instead, note that the file doesn't exist but otherwise
>> treat it as if the string was not found.
>
> It's good to tolerate a missing file, but wouldn't it be better to do so
> by checking for it beforehand with "test -r", instead of assuming that
> any error from "grep" means a missing file?

Probably.  I changed it to this:

commit 7507ec485f72c2ec56731ee5c9790a20d6d694fd
Author: Jesse Gross <jesse at nicira.com>
Date:   Tue Nov 2 16:00:16 2010 -0700

    autoconf: Tolerate missing file when grepping.

    Currently we die when grepping for compatibility strings if the
    file does not exist.  Since this can be a valid situation when
    files are added in later versions, we shouldn't kill the build.
    Instead, note that the file doesn't exist but otherwise treat it
    as if the string was not found.

diff --git a/acinclude.m4 b/acinclude.m4
index f1322fa..0af7fd0 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -108,21 +108,26 @@ dnl
 dnl Greps FILE for REGEX.  If it matches, runs IF-MATCH, otherwise IF-NO-MATCH.
 AC_DEFUN([OVS_GREP_IFELSE], [
   AC_MSG_CHECKING([whether $2 matches in $1])
-  grep '$2' $1 >/dev/null 2>&1
-  status=$?
-  case $status in
-    0)
-      AC_MSG_RESULT([yes])
-      $3
-      ;;
-    1)
-      AC_MSG_RESULT([no])
-      $4
-      ;;
-    *)
-      AC_MSG_ERROR([grep exited with status $status])
-      ;;
-  esac
+  if test -f $1; then
+    grep '$2' $1 >/dev/null 2>&1
+    status=$?
+    case $status in
+      0)
+        AC_MSG_RESULT([yes])
+        $3
+        ;;
+      1)
+        AC_MSG_RESULT([no])
+        $4
+        ;;
+      *)
+        AC_MSG_ERROR([grep exited with status $status])
+        ;;
+    esac
+  else
+    AC_MSG_RESULT([file not found])
+    $4
+  fi
 ])

 dnl OVS_DEFINE(NAME)




More information about the dev mailing list