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