1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
{-# LANGUAGE NoImplicitPrelude #-}
{-|
Module : Stack.Types.CompilerBuild
License : BSD-3-Clause
-}
module Stack.Types.CompilerBuild
( CompilerBuild (..)
, compilerBuildName
, compilerBuildSuffix
, parseCompilerBuild
) where
import Data.Aeson.Types ( FromJSON, parseJSON, withText )
import Data.Text as T hiding ( show )
import Stack.Prelude
-- | Build of the compiler distribution (e.g. standard, gmp4, tinfo6)
data CompilerBuild
= CompilerBuildStandard
| CompilerBuildSpecialized String
deriving Show
instance FromJSON CompilerBuild where
-- Strange structuring is to give consistent error messages
parseJSON =
withText
"CompilerBuild"
(either (fail . show) pure . parseCompilerBuild . T.unpack)
-- | Descriptive name for compiler build
compilerBuildName :: CompilerBuild -> String
compilerBuildName CompilerBuildStandard = "standard"
compilerBuildName (CompilerBuildSpecialized s) = s
-- | Suffix to use for filenames/directories constructed with compiler build
compilerBuildSuffix :: CompilerBuild -> String
compilerBuildSuffix CompilerBuildStandard = ""
compilerBuildSuffix (CompilerBuildSpecialized s) = '-' : s
-- | Parse compiler build from a String.
parseCompilerBuild :: (MonadThrow m) => String -> m CompilerBuild
parseCompilerBuild "" = pure CompilerBuildStandard
parseCompilerBuild "standard" = pure CompilerBuildStandard
parseCompilerBuild name = pure (CompilerBuildSpecialized name)
|