Commit 2f9338d4 authored by Andrey Mokhov's avatar Andrey Mokhov
Browse files

Simplify PackageData.

parent f79678a9
......@@ -43,5 +43,5 @@ oracleRules = do
need [file]
liftIO $ readConfigFile file
addOracle $ \(PackageDataPair (file, key)) -> M.lookup key <$> pkgData file
addOracle $ \(PackageDataKey (file, key)) -> M.lookup key <$> pkgData file
return ()
{-# LANGUAGE DeriveDataTypeable, GeneralizedNewtypeDeriving #-}
module Oracles.PackageData (
PackageDataPair (..),
PackageDataKey (..),
PackageData (..)
) where
......@@ -9,19 +9,11 @@ import Development.Shake.Classes
import Base
import Util
newtype PackageDataPair = PackageDataPair (FilePath, String)
newtype PackageDataKey = PackageDataKey (FilePath, String)
deriving (Show, Typeable, Eq, Hashable, Binary, NFData)
packagaDataWithDefault :: FilePath -> String -> Action String -> Action String
packagaDataWithDefault file key defaultAction = do
maybeValue <- askOracle $ PackageDataPair (file, key)
case maybeValue of
Just value -> return value
Nothing -> defaultAction
data PackageData = Modules FilePath | SrcDirs FilePath | PackageKey FilePath
| IncludeDirs FilePath | Deps FilePath | DepKeys FilePath
deriving Show
instance ShowAction PackageData where
showAction key = do
......@@ -33,6 +25,8 @@ instance ShowAction PackageData where
Deps file -> ("DEPS" , file, "" )
DepKeys file -> ("DEP_KEYS" , file, "" )
keyFullName = replaceSeparators '_' $ takeDirectory file ++ "_" ++ keyName
res <- packagaDataWithDefault file keyFullName $
error $ "\nCannot find key '" ++ keyName ++ "' in " ++ file ++ "."
return $ words $ if res == "" then ifEmpty else res
res <- askOracle $ PackageDataKey (file, keyFullName)
return $ words $ case res of
Nothing -> error $ "\nCannot find key '" ++ keyName ++ "' in " ++ file ++ "."
Just "" -> ifEmpty
Just value -> value
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