Commit 21f3e056 authored by kaiha's avatar kaiha
Browse files

Add Oracle 'DirectoryContent'

parent 787cb4f1
......@@ -30,6 +30,7 @@ executable hadrian
, Oracles.Config.Flag
, Oracles.Config.Setting
, Oracles.Dependencies
, Oracles.DirectoryContent
, Oracles.LookupInPath
, Oracles.ModuleFiles
, Oracles.PackageData
......
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Oracles.DirectoryContent (
getDirectoryContent, directoryContentOracle, Exclude(..), ExcludeNot(..)
) where
import Base
import System.Directory.Extra
newtype DirectoryContent = DirectoryContent (Exclude, ExcludeNot, FilePath)
deriving (Binary, Eq, Hashable, NFData, Show, Typeable)
newtype Exclude = Exclude [FilePattern]
deriving (Binary, Eq, Hashable, NFData, Show, Typeable)
newtype ExcludeNot = ExcludeNot [FilePattern]
deriving (Binary, Eq, Hashable, NFData, Show, Typeable)
-- | Get the directory content. 'Exclude' and 'ExcludeNot' are a list of file
-- patterns matched with '?=='.
getDirectoryContent :: Exclude -> ExcludeNot -> FilePath -> Action [FilePath]
getDirectoryContent exclude excludeNot dir =
askOracle $ DirectoryContent (exclude, excludeNot, dir)
directoryContentOracle :: Rules ()
directoryContentOracle = void $ addOracle oracle
where
oracle :: DirectoryContent -> Action [FilePath]
oracle (DirectoryContent (Exclude exclude, ExcludeNot excludeNot, dir)) =
liftIO $ filter test <$> listFilesInside (return . test) dir
where
test a = include' a || not (exclude' a)
exclude' a = any (?== a) exclude
include' a = any (?== a) excludeNot
......@@ -4,6 +4,7 @@ import Base
import qualified Oracles.ArgsHash
import qualified Oracles.Config
import qualified Oracles.Dependencies
import qualified Oracles.DirectoryContent
import qualified Oracles.LookupInPath
import qualified Oracles.ModuleFiles
import qualified Oracles.PackageData
......@@ -15,6 +16,7 @@ oracleRules = do
Oracles.ArgsHash.argsHashOracle
Oracles.Config.configOracle
Oracles.Dependencies.dependenciesOracles
Oracles.DirectoryContent.directoryContentOracle
Oracles.LookupInPath.lookupInPathOracle
Oracles.ModuleFiles.moduleFilesOracle
Oracles.PackageData.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