summaryrefslogtreecommitdiff
path: root/distrib/compare/BuildInfo.hs
blob: 547e5ac85372cc56a89a1de9b4040d734af9152b (plain)
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

module BuildInfo where

import Control.Monad.State

data BuildInfo = BuildInfo {
                     biThingVersionMap :: ThingVersionMap,
                     biWays :: Ways
                 }
-- Mapping from thing (e.g. "Cabal") to version (e.g. "1.10.0.0")
type ThingVersionMap = [(String, String)]
-- The list of ways in the order the build system uses them, e.g.
-- ["v", "p", "dyn"] => we have ".depend-v-p-dyn.haskell" files
type Ways = [String]

addThingVersion :: ThingVersionMap -> String -> String -> Maybe ThingVersionMap
addThingVersion mapping thing version
 = case lookup thing mapping of
   Just version' ->
       if version == version'
       then Just mapping
       else Nothing
   Nothing ->
       Just ((thing, version) : mapping)

getThingVersionMap :: State BuildInfo ThingVersionMap
getThingVersionMap = do st <- get
                        return $ biThingVersionMap st

getWays :: State BuildInfo Ways
getWays = do st <- get
             return $ biWays st

putThingVersionMap :: ThingVersionMap -> State BuildInfo ()
putThingVersionMap tm = do st <- get
                           put $ st { biThingVersionMap = tm }

putWays :: Ways -> State BuildInfo ()
putWays ws = do st <- get
                put $ st { biWays = ws }