From 39f0eea533056c8a26da089a774a27b13097e489 Mon Sep 17 00:00:00 2001 From: Iustin Pop Date: Tue, 13 Nov 2012 11:46:04 +0100 Subject: [PATCH] Automatically enable version-dependent GHC flags Some GHC flags are very useful, but only appear in more recent GHC versions. To support the use of such flags while still supporting older compilers, let's add conditional checks and enabling based on the results. Currently only `-fwarn-incomplete-uni-patterns` is enabled, which detects refutable patterns in lambda expressions and pattern bindings (e.g. "let (Just x) = y"); such constructs are bad as they can lead to runtime exceptions. Additionally, fix an existing such bad construct in a test case; we workaround it by using error, since that should never fail. Signed-off-by: Iustin Pop Reviewed-by: Guido Trotter --- Makefile.am | 7 ++++++- configure.ac | 11 +++++++++++ htest/Test/Ganeti/HTools/Cluster.hs | 6 +++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Makefile.am b/Makefile.am index d6a0e28..7daf778 100644 --- a/Makefile.am +++ b/Makefile.am @@ -401,7 +401,12 @@ HS_ALL_PROGS = \ HS_PROG_SRCS = $(patsubst %,%.hs,$(HS_ALL_PROGS)) HS_BUILT_TEST_HELPERS = $(HS_BIN_ROLES:%=htest/%) htest/hail -HFLAGS = -O -Wall -Werror -fwarn-monomorphism-restriction -fwarn-tabs -ihtools +HFLAGS = \ + -O -Wall -Werror -ihtools \ + -fwarn-monomorphism-restriction \ + -fwarn-tabs \ + $(GHC_BYVERSION_FLAGS) + # extra flags that can be overriden on the command line (e.g. -Wwarn, etc.) HEXTRA = # internal extra flags (used for htest/test mainly) diff --git a/configure.ac b/configure.ac index 3e134a2..1cc62d5 100644 --- a/configure.ac +++ b/configure.ac @@ -430,6 +430,17 @@ if test -z "$GHC"; then AC_MSG_FAILURE([ghc not found, compilation will not possible]) fi +AC_MSG_CHECKING([checking for extra GHC flags]) +GHC_BYVERSION_FLAGS="" +# check for GHC supported flags that vary accross versions +for flag in -fwarn-incomplete-uni-patterns; do + if $GHC -e "0" $flag >/dev/null 2>/dev/null; then + GHC_BYVERSION_FLAGS="$GHC_BYVERSION_FLAGS $flag" + fi +done +AC_MSG_RESULT($GHC_BYVERSION_FLAGS) +AC_SUBST(GHC_BYVERSION_FLAGS) + # Check for ghc-pkg AC_ARG_VAR(GHC_PKG, [ghc-pkg path]) AC_PATH_PROG(GHC_PKG, [ghc-pkg], []) diff --git a/htest/Test/Ganeti/HTools/Cluster.hs b/htest/Test/Ganeti/HTools/Cluster.hs index fdc4924..96bd1cf 100644 --- a/htest/Test/Ganeti/HTools/Cluster.hs +++ b/htest/Test/Ganeti/HTools/Cluster.hs @@ -346,7 +346,11 @@ prop_AllocBalance = prop_CheckConsistency :: Node.Node -> Instance.Instance -> Bool prop_CheckConsistency node inst = let nl = makeSmallCluster node 3 - [node1, node2, node3] = Container.elems nl + (node1, node2, node3) = + case Container.elems nl of + [a, b, c] -> (a, b, c) + l -> error $ "Invalid node list out of makeSmallCluster/3: " ++ + show l node3' = node3 { Node.group = 1 } nl' = Container.add (Node.idx node3') node3' nl inst1 = Instance.setBoth inst (Node.idx node1) (Node.idx node2) -- 1.7.10.4