From 730eebe9894e73b7e86a6e5a7546ab5b2484c65d Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Fri, 25 Feb 2011 14:17:30 +0100 Subject: The dependency analyzer now knows a little more --- src/Hakyll/Core/Compiler/Internal.hs | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'src/Hakyll/Core/Compiler/Internal.hs') diff --git a/src/Hakyll/Core/Compiler/Internal.hs b/src/Hakyll/Core/Compiler/Internal.hs index 30a391f..d37c7ef 100644 --- a/src/Hakyll/Core/Compiler/Internal.hs +++ b/src/Hakyll/Core/Compiler/Internal.hs @@ -32,6 +32,15 @@ import Hakyll.Core.Logger -- type Dependencies = Set Identifier +-- | Environment in which the dependency analyzer runs +-- +data DependencyEnvironment = DependencyEnvironment + { -- | Target identifier + dependencyIdentifier :: Identifier + , -- | Resource provider + dependencyResourceProvider :: ResourceProvider + } + -- | Environment in which a compiler runs -- data CompilerEnvironment = CompilerEnvironment @@ -58,7 +67,7 @@ newtype CompilerM a = CompilerM -- | The compiler arrow -- data Compiler a b = Compiler - { compilerDependencies :: Reader ResourceProvider Dependencies + { compilerDependencies :: Reader DependencyEnvironment Dependencies , compilerJob :: a -> CompilerM b } @@ -109,19 +118,28 @@ runCompilerJob compiler identifier provider route store modified logger = } runCompilerDependencies :: Compiler () a + -> Identifier -> ResourceProvider -> Dependencies -runCompilerDependencies compiler = runReader (compilerDependencies compiler) +runCompilerDependencies compiler identifier provider = + runReader (compilerDependencies compiler) env + where + env = DependencyEnvironment + { dependencyIdentifier = identifier + , dependencyResourceProvider = provider + } fromJob :: (a -> CompilerM b) -> Compiler a b fromJob = Compiler (return S.empty) -fromDependencies :: (ResourceProvider -> [Identifier]) +fromDependencies :: (Identifier -> ResourceProvider -> [Identifier]) -> Compiler b b -fromDependencies deps = Compiler (S.fromList . deps <$> ask) return +fromDependencies collectDeps = flip Compiler return $ do + DependencyEnvironment identifier provider <- ask + return $ S.fromList $ collectDeps identifier provider -- | Wait until another compiler has finished before running this compiler -- fromDependency :: Identifier -> Compiler a a -fromDependency = fromDependencies . const . return +fromDependency = fromDependencies . const . const . return -- cgit v1.2.3