[commit: ghc] wip/nfs-locking: Refactor oracle rules. (21e48fc)

git at git.haskell.org git at git.haskell.org
Thu Oct 26 23:49:31 UTC 2017


Repository : ssh://git@git.haskell.org/ghc

On branch  : wip/nfs-locking
Link       : http://ghc.haskell.org/trac/ghc/changeset/21e48fc51345e7294e1dd2a642a1c305230ceb2f/ghc

>---------------------------------------------------------------

commit 21e48fc51345e7294e1dd2a642a1c305230ceb2f
Author: Andrey Mokhov <andrey.mokhov at gmail.com>
Date:   Sun Jan 11 20:08:00 2015 +0000

    Refactor oracle rules.


>---------------------------------------------------------------

21e48fc51345e7294e1dd2a642a1c305230ceb2f
 src/Oracles.hs | 34 ++++++++++++++++++++++------------
 1 file changed, 22 insertions(+), 12 deletions(-)

diff --git a/src/Oracles.hs b/src/Oracles.hs
index 3321610..3a0c430 100644
--- a/src/Oracles.hs
+++ b/src/Oracles.hs
@@ -17,31 +17,41 @@ import Oracles.Option
 import Oracles.Builder
 import Oracles.PackageData
 
-oracleRules :: Rules ()
-oracleRules = do
+defaultConfig, userConfig :: FilePath
+defaultConfig = cfgPath </> "default.config"
+userConfig    = cfgPath </> "user.config"
+
+-- Oracle for configuration files.
+configOracle :: Rules ()
+configOracle = do
     cfg <- newCache $ \() -> do
-        unless (doesFileExist $ cfgPath </> "default.config.in") $ do
+        unless (doesFileExist $ defaultConfig <.> "in") $ do
             error $ "\nDefault configuration file '"
-                ++ (cfgPath </> "default.config.in")
+                ++ (defaultConfig <.> "in")
                 ++ "' is missing; unwilling to proceed."
             return ()
-        need [cfgPath </> "default.config"]
-        cfgDefault <- liftIO $ readConfigFile $ cfgPath </> "default.config"
-        existsUser <- doesFileExist $ cfgPath </> "user.config"
+        need [defaultConfig]
+        cfgDefault <- liftIO $ readConfigFile defaultConfig
+        existsUser <- doesFileExist userConfig
         cfgUser    <- if existsUser
-                      then liftIO $ readConfigFile $ cfgPath </> "user.config"
+                      then liftIO $ readConfigFile userConfig
                       else do
                           putLoud $ "\nUser defined configuration file '"
-                              ++ (cfgPath </> "user.config")
-                              ++ "' is missing; proceeding with default configuration.\n"
+                              ++ userConfig ++ "' is missing; "
+                              ++ "proceeding with default configuration.\n"
                           return M.empty
         return $ cfgUser `M.union` cfgDefault
-
     addOracle $ \(ConfigKey key) -> M.lookup key <$> cfg ()
+    return ()
 
+-- Oracle for 'package-data.mk' files.
+packageDataOracle :: Rules ()
+packageDataOracle = do
     pkgData <- newCache $ \file -> do
         need [file]
         liftIO $ readConfigFile file
-
     addOracle $ \(PackageDataKey (file, key)) -> M.lookup key <$> pkgData file
     return ()
+
+oracleRules :: Rules ()
+oracleRules = configOracle <> packageDataOracle



More information about the ghc-commits mailing list