Commit 21e48fc5 authored by Andrey Mokhov's avatar Andrey Mokhov
Browse files

Refactor oracle rules.

parent d264db19
...@@ -17,31 +17,41 @@ import Oracles.Option ...@@ -17,31 +17,41 @@ import Oracles.Option
import Oracles.Builder import Oracles.Builder
import Oracles.PackageData import Oracles.PackageData
oracleRules :: Rules () defaultConfig, userConfig :: FilePath
oracleRules = do defaultConfig = cfgPath </> "default.config"
userConfig = cfgPath </> "user.config"
-- Oracle for configuration files.
configOracle :: Rules ()
configOracle = do
cfg <- newCache $ \() -> do cfg <- newCache $ \() -> do
unless (doesFileExist $ cfgPath </> "default.config.in") $ do unless (doesFileExist $ defaultConfig <.> "in") $ do
error $ "\nDefault configuration file '" error $ "\nDefault configuration file '"
++ (cfgPath </> "default.config.in") ++ (defaultConfig <.> "in")
++ "' is missing; unwilling to proceed." ++ "' is missing; unwilling to proceed."
return () return ()
need [cfgPath </> "default.config"] need [defaultConfig]
cfgDefault <- liftIO $ readConfigFile $ cfgPath </> "default.config" cfgDefault <- liftIO $ readConfigFile defaultConfig
existsUser <- doesFileExist $ cfgPath </> "user.config" existsUser <- doesFileExist userConfig
cfgUser <- if existsUser cfgUser <- if existsUser
then liftIO $ readConfigFile $ cfgPath </> "user.config" then liftIO $ readConfigFile userConfig
else do else do
putLoud $ "\nUser defined configuration file '" putLoud $ "\nUser defined configuration file '"
++ (cfgPath </> "user.config") ++ userConfig ++ "' is missing; "
++ "' is missing; proceeding with default configuration.\n" ++ "proceeding with default configuration.\n"
return M.empty return M.empty
return $ cfgUser `M.union` cfgDefault return $ cfgUser `M.union` cfgDefault
addOracle $ \(ConfigKey key) -> M.lookup key <$> cfg () addOracle $ \(ConfigKey key) -> M.lookup key <$> cfg ()
return ()
-- Oracle for 'package-data.mk' files.
packageDataOracle :: Rules ()
packageDataOracle = do
pkgData <- newCache $ \file -> do pkgData <- newCache $ \file -> do
need [file] need [file]
liftIO $ readConfigFile file liftIO $ readConfigFile file
addOracle $ \(PackageDataKey (file, key)) -> M.lookup key <$> pkgData file addOracle $ \(PackageDataKey (file, key)) -> M.lookup key <$> pkgData file
return () return ()
oracleRules :: Rules ()
oracleRules = configOracle <> packageDataOracle
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment