forked from commercialhaskell/stack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompilerBuild.hs
More file actions
39 lines (33 loc) · 1.32 KB
/
CompilerBuild.hs
File metadata and controls
39 lines (33 loc) · 1.32 KB
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
{-# LANGUAGE NoImplicitPrelude #-}
module Stack.Types.CompilerBuild
(CompilerBuild(..)
,compilerBuildName
,compilerBuildSuffix
,parseCompilerBuild
) where
import Stack.Prelude
import Data.Aeson.Extended (FromJSON, parseJSON, withText)
import Data.Text as T
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) return . 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 "" = return CompilerBuildStandard
parseCompilerBuild "standard" = return CompilerBuildStandard
parseCompilerBuild name = return (CompilerBuildSpecialized name)