4 import Control.Monad.State
6 type BIMonad = StateT BuildInfo Maybe
8 data BuildInfo = BuildInfo {
9 biThingVersionMap :: ThingVersionMap,
10 biThingHashMap :: ThingHashMap,
11 biMaybeWays :: Maybe Ways
15 type ThingMap = [(String, String)]
16 -- Mapping from thing (e.g. "Cabal") to version (e.g. "1.10.0.0")
17 type ThingVersionMap = ThingMap
18 -- Mapping from thing (e.g. "Cabal") to ABI hash
19 -- (e.g. "e1f7c380581d61d42b0360d440cc35ed")
20 type ThingHashMap = ThingMap
21 -- The list of ways in the order the build system uses them, e.g.
22 -- ["v", "p", "dyn"] => we have ".depend-v-p-dyn.haskell" files
25 emptyBuildInfo :: Maybe Ways -> BuildInfo
26 emptyBuildInfo mWays = BuildInfo {
27 biThingVersionMap = [],
32 addThingMap :: ThingMap -> String -> String -> Maybe ThingMap
33 addThingMap mapping thing str
34 = case lookup thing mapping of
40 Just ((thing, str) : mapping)
42 getMaybeWays :: BIMonad (Maybe Ways)
43 getMaybeWays = do st <- get
44 return $ biMaybeWays st
46 haveThingVersion :: String -> String -> BIMonad ()
47 haveThingVersion thing thingVersion
49 case addThingMap (biThingVersionMap st) thing thingVersion of
50 Nothing -> fail "Inconsistent version"
51 Just tvm -> put $ st { biThingVersionMap = tvm }
53 haveThingHash :: String -> String -> BIMonad ()
54 haveThingHash thing thingHash
56 case addThingMap (biThingHashMap st) thing thingHash of
57 Nothing -> fail "Inconsistent hash"
58 Just thm -> put $ st { biThingHashMap = thm }