Commit dec6aecc authored by byorgey's avatar byorgey
Browse files

fix for Trac #164: better error reporting for undefined flags

parent 67121da3
......@@ -47,7 +47,7 @@ module Distribution.Configuration (
Flag(..),
ConfVar(..),
Condition(..), parseCondition, simplifyCondition,
CondTree(..), ppCondTree, mapTreeData,
CondTree(..), ppCondTree, mapTreeData, freeVars,
--satisfyFlags,
resolveWithFlags, ignoreConditions,
DepTestRslt(..)
......@@ -382,6 +382,18 @@ ignoreConditions (CondNode a c ifs) = (a, c) `mappend` mconcat (concatMap f ifs)
where f (_, t, me) = ignoreConditions t
: maybeToList (fmap ignoreConditions me)
freeVars :: CondTree ConfVar c a -> [String]
freeVars t = [ s | Flag (ConfFlag s) <- freeVars' t ]
where
freeVars' (CondNode _ _ ifs) = concatMap compfv ifs
compfv (c, ct, mct) = condfv c ++ freeVars' ct ++ maybe [] freeVars' mct
condfv c = case c of
Var v -> [v]
Lit _ -> []
CNot c' -> condfv c'
COr c1 c2 -> condfv c1 ++ condfv c2
CAnd c1 c2 -> condfv c1 ++ condfv c2
------------------------------------------------------------------------------
-- Testing
......
......@@ -109,7 +109,7 @@ module Distribution.PackageDescription (
import Control.Monad(liftM, foldM, when)
import Data.Char
import Data.Maybe(isNothing, isJust, catMaybes, listToMaybe, maybeToList)
import Data.List (nub, maximumBy, unfoldr, partition)
import Data.List (nub, maximumBy, unfoldr, partition, (\\), intersperse)
import Text.PrettyPrint.HughesPJ as Pretty
import System.Directory(doesFileExist)
......@@ -947,6 +947,7 @@ parsePackageDescription file = do
warnIfRest
when (not (oldSyntax fields0)) $
maybeWarnCabalVersion pkg
checkForUndefinedFlags flags mlib exes
return (GenericPackageDescription pkg flags mlib exes)
where
......@@ -1117,6 +1118,23 @@ parsePackageDescription file = do
parseExeFields :: [Field] -> StT s ParseResult Executable
parseExeFields = lift . parseFields executableFieldDescrs nullExecutable
checkForUndefinedFlags ::
[Flag] ->
Maybe (CondTree ConfVar [Dependency] Library) ->
[(String, CondTree ConfVar [Dependency] Executable)] ->
PM ()
checkForUndefinedFlags flags mlib exes = do
let definedFlags = map flagName flags
maybe (return ()) (checkCondTreeFlags definedFlags) mlib
mapM_ (checkCondTreeFlags definedFlags . snd) exes
checkCondTreeFlags :: [String] -> CondTree ConfVar c a -> PM ()
checkCondTreeFlags definedFlags ct = do
let fv = nub $ freeVars ct
when (not . all (`elem` definedFlags) $ fv) $
error $ "Undefined flag(s) encountered: " ++
(concat . intersperse " " $ (fv \\ definedFlags))
parseFields :: [FieldDescr a] -> a -> [Field] -> ParseResult a
parseFields descrs ini fields =
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment