Oracles.hs 1.58 KB
Newer Older
1
module Oracles (
2
3
4
5
6
    module Oracles.Base,
    module Oracles.Flag,
    module Oracles.Option,
    module Oracles.Builder,
    module Oracles.PackageData,
7
8
9
    oracleRules
    ) where

10
import Development.Shake.Config
11
12
import qualified Data.HashMap.Strict as M
import Base
13
import Config
14
15
16
17
18
import Oracles.Base
import Oracles.Flag
import Oracles.Option
import Oracles.Builder
import Oracles.PackageData
19

20
21
22
oracleRules :: Rules ()
oracleRules = do
    cfg <- newCache $ \() -> do
23
        unless (doesFileExist $ cfgPath </> "default.config.in") $ do
24
            error $ "\nDefault configuration file '"
25
                ++ (cfgPath </> "default.config.in")
26
27
                ++ "' is missing; unwilling to proceed."
            return ()
28
29
30
        need [cfgPath </> "default.config"]
        cfgDefault <- liftIO $ readConfigFile $ cfgPath </> "default.config"
        existsUser <- doesFileExist $ cfgPath </> "user.config"
31
        cfgUser    <- if existsUser
32
                      then liftIO $ readConfigFile $ cfgPath </> "user.config"
33
34
                      else do
                          putLoud $ "\nUser defined configuration file '"
35
                              ++ (cfgPath </> "user.config")
36
37
38
                              ++ "' is missing; proceeding with default configuration.\n"
                          return M.empty
        return $ cfgUser `M.union` cfgDefault
39
40
41
42
43
44
45
46

    addOracle $ \(ConfigKey key) -> M.lookup key <$> cfg ()

    pkgData <- newCache $ \file -> do
        need [file]
        liftIO $ readConfigFile file

    addOracle $ \(PackageDataPair (file, key)) -> M.lookup key <$> pkgData file
47
    return ()