Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions Cabal-syntax/src/Distribution/Parsec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,11 @@ instance Parsec Bool where
parsec = P.munch1 isAlpha >>= postprocess
where
postprocess str
| str == "True" = pure True
| str == "False" = pure False
| lstr == "true" = parsecWarning PWTBoolCase caseWarning *> pure True
| lstr == "false" = parsecWarning PWTBoolCase caseWarning *> pure False
| lstr == "true" = pure True
| lstr == "false" = pure False
| otherwise = fail $ "Not a boolean: " ++ str
where
lstr = map toLower str
caseWarning =
"Boolean values are case sensitive, use 'True' or 'False'."

instance Parsec a => Parsec (Last a) where
parsec = parsecLast
Expand Down
2 changes: 0 additions & 2 deletions Cabal-syntax/src/Distribution/Parsec/Warning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ data PWarnType
PWTOther
| -- | Invalid UTF encoding
PWTUTF
| -- | @true@ or @false@, not @True@ or @False@
PWTBoolCase
| -- | there are version with tags
PWTVersionTag
| -- | New syntax used, but no @cabal-version: >= 1.2@ specified
Expand Down
1 change: 0 additions & 1 deletion Cabal-tests/tests/ParserTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ warningTests = testGroup "warnings triggered"
, warningTest PWTLexNBSP "nbsp.cabal"
, warningTest PWTLexTab "tab.cabal"
, warningTest PWTUTF "utf8.cabal"
, warningTest PWTBoolCase "bool.cabal"
, warningTest PWTVersionTag "versiontag.cabal"
, warningTest PWTNewSyntax "newsyntax.cabal"
, warningTest PWTOldSyntax "oldsyntax.cabal"
Expand Down
12 changes: 0 additions & 12 deletions Cabal-tests/tests/ParserTests/warnings/bool.cabal

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ tests = testGroup "Distribution.Simple.Program.GHC"
})
(Platform X86_64 Linux)
(mempty { ghcOptNumJobs = Flag (NumJobs (Just 4)) })
assertListEquals flags ["-j4", "-clear-package-db"]
assertListEquals flags ["-g0", "-j4", "-clear-package-db"]
]
]

Expand Down
10 changes: 0 additions & 10 deletions Cabal/src/Distribution/Simple/Command.hs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ module Distribution.Simple.Command
, reqArg'
, optArg
, optArg'
, optArgDef'
, noArg
, boolOpt
, boolOpt'
Expand Down Expand Up @@ -280,15 +279,6 @@ optArg'
optArg' ad mkflag showflag =
optArg ad (succeedReadE (mkflag . Just)) ("", mkflag Nothing) showflag

optArgDef'
:: Monoid b
=> ArgPlaceHolder
-> (String, Maybe String -> b)
-> (b -> [Maybe String])
-> MkOptDescr (a -> b) (b -> a -> a) a
optArgDef' ad (dv, mkflag) showflag =
optArg ad (succeedReadE (mkflag . Just)) (dv, mkflag Nothing) showflag

noArg :: Eq b => b -> MkOptDescr (a -> b) (b -> a -> a) a
noArg flag sf lf d = choiceOpt [(flag, (sf, lf), d)] sf lf d

Expand Down
58 changes: 39 additions & 19 deletions Cabal/src/Distribution/Simple/Compiler.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE PatternSynonyms #-}

-----------------------------------------------------------------------------

Expand Down Expand Up @@ -54,11 +56,13 @@ module Distribution.Simple.Compiler

-- * Support for optimisation levels
, OptimisationLevel (..)
, flagToOptimisationLevel
, toOptimisationLevel
, fromOptimisationLevel

-- * Support for debug info levels
, DebugInfoLevel (..)
, flagToDebugInfoLevel
, toDebugInfoLevel
, fromDebugInfoLevel

-- * Support for language extensions
, CompilerFlag
Expand Down Expand Up @@ -112,6 +116,7 @@ import Language.Haskell.Extension

import Data.Bool (bool)
import qualified Data.Map as Map (lookup)
import Distribution.Simple.Flag (Flag, pattern Flag, pattern NoFlag)
import System.Directory (canonicalizePath)

data Compiler = Compiler
Expand Down Expand Up @@ -329,12 +334,16 @@ parsecOptimisationLevel = boolParser <|> intParser
boolParser = bool NoOptimisation NormalOptimisation <$> parsec
intParser = intToOptimisationLevel <$> integral

flagToOptimisationLevel :: Maybe String -> OptimisationLevel
flagToOptimisationLevel Nothing = NormalOptimisation
flagToOptimisationLevel (Just s) = case reads s of
toOptimisationLevel :: String -> OptimisationLevel
toOptimisationLevel s = case reads s of
[(i, "")] -> intToOptimisationLevel i
_ -> error $ "Can't parse optimisation level " ++ s

fromOptimisationLevel :: Flag OptimisationLevel -> String
fromOptimisationLevel = \case
Flag op -> show $ fromEnum op
NoFlag -> "1"

intToOptimisationLevel :: Int -> OptimisationLevel
intToOptimisationLevel i
| i >= minLevel && i <= maxLevel = toEnum i
Expand Down Expand Up @@ -374,22 +383,33 @@ instance Parsec DebugInfoLevel where
parsec = parsecDebugInfoLevel

parsecDebugInfoLevel :: CabalParsing m => m DebugInfoLevel
parsecDebugInfoLevel = flagToDebugInfoLevel . pure <$> parsecToken

flagToDebugInfoLevel :: Maybe String -> DebugInfoLevel
flagToDebugInfoLevel Nothing = NormalDebugInfo
flagToDebugInfoLevel (Just s) = case reads s of
[(i, "")]
| i >= fromEnum (minBound :: DebugInfoLevel)
&& i <= fromEnum (maxBound :: DebugInfoLevel) ->
toEnum i
| otherwise ->
error $
"Bad debug info level: "
++ show i
++ ". Valid values are 0..3"
parsecDebugInfoLevel = boolParser <|> intParser
where
boolParser = bool NoDebugInfo NormalDebugInfo <$> parsec
intParser = intToDebugInfoLevel <$> integral

toDebugInfoLevel :: String -> DebugInfoLevel
toDebugInfoLevel s = case reads s of
[(i, "")] -> intToDebugInfoLevel i
_ -> error $ "Can't parse debug info level " ++ s

fromDebugInfoLevel :: Flag DebugInfoLevel -> String
fromDebugInfoLevel = \case
Flag db -> show $ fromEnum db
NoFlag -> "0"

intToDebugInfoLevel :: Int -> DebugInfoLevel
intToDebugInfoLevel i
| i >= minLevel && i <= maxLevel = toEnum i
| otherwise =
error $
"Bad debug info level: "
++ show i
++ ". Valid values are 0..3"
where
minLevel = fromEnum (minBound :: DebugInfoLevel)
maxLevel = fromEnum (maxBound :: DebugInfoLevel)

-- ------------------------------------------------------------

-- * Languages and Extensions
Expand Down
2 changes: 1 addition & 1 deletion Cabal/src/Distribution/Simple/GHC/Build/Link.hs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ linkOrLoadComponent
`mappend` linkerOpts mempty
`mappend` mempty
{ ghcOptMode = toFlag GhcModeInteractive
, ghcOptOptimisation = toFlag GhcNoOptimisation
, ghcOptOptimisation = toFlag NoOptimisation
}
replOpts_final =
replOpts
Expand Down
Loading
Loading