automake-patches
[Top][All Lists]
Advanced

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

[PATCH 09/14] Refactor code requiring compilers in testsuite.


From: Stefano Lattarini
Subject: [PATCH 09/14] Refactor code requiring compilers in testsuite.
Date: Fri, 2 Jul 2010 15:14:19 +0200
User-agent: KMail/1.12.1 (Linux/2.6.30-2-686; KDE/4.3.4; i686; ; )

This refactoring will be superseded by a new one later in the patch
series, so nitpicking at it it's not worthy IMO.  And yes, I'd rather
keep this "temporary" refactory anyway, since:
 1. it avoids some yet unneeded complexities, and
 2. it helped me shaping the next refactoring.

Regards,
    Stefano

-*-*-*-

* tests/defs.in (require_compiler): New function.
(require_gnu_compiler): Likewise.
Use them throughout.
---
 ChangeLog     |    5 +++
 tests/defs.in |   93 ++++++++++++++++++++++++++++++++-------------------------
 2 files changed, 57 insertions(+), 41 deletions(-)
From 88e5a5365d6f23486320abd7d20fd25941e497a4 Mon Sep 17 00:00:00 2001
From: Stefano Lattarini <address@hidden>
Date: Fri, 2 Jul 2010 12:41:30 +0200
Subject: [PATCH 09/14] Refactor code requiring compilers in testsuite.

* tests/defs.in (require_compiler): New function.
(require_gnu_compiler): Likewise.
Use them throughout.
---
 ChangeLog     |    5 +++
 tests/defs.in |   93 ++++++++++++++++++++++++++++++++-------------------------
 2 files changed, 57 insertions(+), 41 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 7aa5ad3..4e2c685 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2010-07-02  Stefano Lattarini  <address@hidden>
 
+       Refactor code requiring compilers in testsuite.
+       * tests/defs.in (require_compiler): New function.
+       (require_gnu_compiler): Likewise.
+       Use them throughout.
+
        Fixes/renamings for "synced tests" among `silent*.test'.
        * tests/silent.test: Renamed to ...
        * tests/silent1a.test: ... this.
diff --git a/tests/defs.in b/tests/defs.in
index 426424d..d97581f 100644
--- a/tests/defs.in
+++ b/tests/defs.in
@@ -88,6 +88,53 @@ echo "$PATH"
 # (See note about `export' in the Autoconf manual.)
 export PATH
 
+# Usage: require_compiler ENV-VARIABLE [FALLBACK-GNU-COMPILERS]
+# Presently, this function is meant for internal use only.
+require_compiler()
+{
+  eval compiler=\$$1
+  if eval test x"$compiler" = x"no"; then
+    # The user told explicitly he doesn't want a compiler of this kind
+    # to be used.
+    echo "$me: \$$1 is \"no\", skipping test"
+    exit 77
+  elif test -z "$compiler"; then
+    if test $# -gt 1; then
+      # The user specified no explicit compiler in its environment, so
+      # we try to force the use of a GNU compiler.
+      require_gnu_compiler "$@"
+    else
+      echo "$me: \$$1 is unset or empty, and no default GNU compiler" \
+           "has been specified"
+      exit 77
+    fi
+  fi
+  unset compiler
+}
+
+# Usage: require_gnu_compiler ENV-VARIABLE GNU-COMPILER [OTHER-GNU-COMPILERS]
+# Presently, this function is meant for internal use only.
+require_gnu_compiler()
+{
+  environment_variable=$1
+  shift
+  have_gnu_compiler=false
+  for gnu_compiler in ${1+"$@"}; do
+    echo "$me: running $gnu_compiler --version"
+    "$gnu_compiler" --version || continue
+    # This gives more information about the compiler, and also checks for
+    # e.g. broken gcj installations.
+    echo "$me: running $gnu_compiler -v"
+    "$gnu_compiler" -v || continue
+    echo # gracefully separate verbose information from rest of testlog
+    have_gnu_compiler=:
+  done
+  $have_gnu_compiler || exit 77
+  eval $environment_variable=\$gnu_compiler
+  export $environment_variable
+  unset environment_variable gnu_compiler have_gnu_compiler
+}
+
 for tool in : $required
 do
   # Check that each required tool is present.
@@ -121,55 +168,19 @@ do
       ( $MAKE --version -v | grep GNU ) || exit 77
       ;;
     cc)
-      if test x"$CC" = x"no"; then
-        # The user told explicitly it don't want a C compiler to be used.
-        echo "$me: \$CC is \"no\", skipping test"
-        exit 77
-      elif test -z "$CC"; then
-        # The user specified no explicit compiler in its environment, so
-        # we try to force the use of gcc as C compiler.
-        CC=gcc
-        export CC
-        echo "$me: running $CC --version"
-        ( $CC --version ) || exit 77
-      fi
+      require_compiler 'CC' gcc
       ;;
     gcc)
-      # When gcc is required, export `CC=gcc' so that ./configure
-      # always use it.  This is important only when the user
-      # has defined CC in his environment, otherwise ./configure will
-      # prefer gcc to other compilers.
-      CC=gcc
-      export CC
-      echo "$me: running $CC --version"
-      ( $CC --version ) || exit 77
+      require_gnu_compiler 'CC' gcc
       ;;
     gcj)
-      GCJ=gcj
-      export GCJ
-      echo "$me: running $GCJ --version"
-      ( $GCJ --version ) || exit 77
-      ( $GCJ -v ) || exit 77
+      require_gnu_compiler 'GCJ' gcj
       ;;
     c++)
-      if test x"$CXX" = x"no"; then
-        # The user told explicitly it don't want a C++ compiler to be used.
-        echo "$me: \$CXX is \"no\", skipping test"
-        exit 77
-      elif test -z "$CXX"; then
-        # The user specified no explicit compiler in its environment, so
-        # we try to force the use of g++ as C++ compiler.
-        CXX=g++
-        export CXX
-        echo "$me: running $CXX --version"
-        ( $CXX --version ) || exit 77
-      fi
+      require_compiler 'CXX' g++
       ;;
     g++)
-      CXX=g++
-      export CXX
-      echo "$me: running $CXX --version"
-      ( $CXX --version ) || exit 77
+      require_gnu_compiler 'CXX' g++
       ;;
     icc)
       CC=icc
-- 
1.6.5


reply via email to

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