summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Hakyll/Core/Compiler.hs17
-rw-r--r--src/Hakyll/Core/Compiler/Internal.hs7
-rw-r--r--src/Hakyll/Core/Run.hs4
-rw-r--r--src/Hakyll/Core/UnixFilter.hs12
4 files changed, 34 insertions, 6 deletions
diff --git a/src/Hakyll/Core/Compiler.hs b/src/Hakyll/Core/Compiler.hs
index 7d2d116..d6090e9 100644
--- a/src/Hakyll/Core/Compiler.hs
+++ b/src/Hakyll/Core/Compiler.hs
@@ -102,6 +102,7 @@ module Hakyll.Core.Compiler
, cached
, unsafeCompiler
, mapCompiler
+ , timedCompiler
) where
import Prelude hiding ((.), id)
@@ -124,6 +125,7 @@ import Hakyll.Core.Compiler.Internal
import Hakyll.Core.Store
import Hakyll.Core.Rules.Internal
import Hakyll.Core.Routes
+import Hakyll.Core.Logger
-- | Run a compiler, yielding the resulting target and it's dependencies. This
-- version of 'runCompilerJob' also stores the result
@@ -134,10 +136,12 @@ runCompiler :: Compiler () CompileRule -- ^ Compiler to run
-> Routes -- ^ Route
-> Store -- ^ Store
-> Bool -- ^ Was the resource modified?
+ -> Logger -- ^ Logger
-> IO CompileRule -- ^ Resulting item
-runCompiler compiler identifier provider routes store modified = do
+runCompiler compiler identifier provider routes store modified logger = do
-- Run the compiler job
- result <- runCompilerJob compiler identifier provider routes store modified
+ result <-
+ runCompilerJob compiler identifier provider routes store modified logger
-- Inspect the result
case result of
@@ -274,3 +278,12 @@ unsafeCompiler f = fromJob $ CompilerM . liftIO . f
mapCompiler :: Compiler a b
-> Compiler [a] [b]
mapCompiler (Compiler d j) = Compiler d $ mapM j
+
+-- | Log and time a compiler
+--
+timedCompiler :: String -- ^ Message
+ -> Compiler a b -- ^ Compiler to time
+ -> Compiler a b -- ^ Resulting compiler
+timedCompiler msg (Compiler d j) = Compiler d $ \x -> CompilerM $ do
+ logger <- compilerLogger <$> ask
+ timed logger msg $ unCompilerM $ j x
diff --git a/src/Hakyll/Core/Compiler/Internal.hs b/src/Hakyll/Core/Compiler/Internal.hs
index a524a66..30a391f 100644
--- a/src/Hakyll/Core/Compiler/Internal.hs
+++ b/src/Hakyll/Core/Compiler/Internal.hs
@@ -26,6 +26,7 @@ import Hakyll.Core.Identifier
import Hakyll.Core.ResourceProvider
import Hakyll.Core.Store
import Hakyll.Core.Routes
+import Hakyll.Core.Logger
-- | A set of dependencies
--
@@ -44,6 +45,8 @@ data CompilerEnvironment = CompilerEnvironment
compilerStore :: Store
, -- | Flag indicating if the underlying resource was modified
compilerResourceModified :: Bool
+ , -- | Logger
+ compilerLogger :: Logger
}
-- | The compiler monad
@@ -91,8 +94,9 @@ runCompilerJob :: Compiler () a -- ^ Compiler to run
-> Routes -- ^ Route
-> Store -- ^ Store
-> Bool -- ^ Was the resource modified?
+ -> Logger -- ^ Logger
-> IO a
-runCompilerJob compiler identifier provider route store modified =
+runCompilerJob compiler identifier provider route store modified logger =
runReaderT (unCompilerM $ compilerJob compiler ()) env
where
env = CompilerEnvironment
@@ -101,6 +105,7 @@ runCompilerJob compiler identifier provider route store modified =
, compilerRoutes = route
, compilerStore = store
, compilerResourceModified = modified
+ , compilerLogger = logger
}
runCompilerDependencies :: Compiler () a
diff --git a/src/Hakyll/Core/Run.hs b/src/Hakyll/Core/Run.hs
index 54c22c2..42db80a 100644
--- a/src/Hakyll/Core/Run.hs
+++ b/src/Hakyll/Core/Run.hs
@@ -183,8 +183,8 @@ runCompilers ((id', compiler) : compilers) = Runtime $ do
isModified = id' `S.member` modified'
-- Run the compiler
- result <- timed logger "Compiling item" $
- liftIO $ runCompiler compiler id' provider routes store isModified
+ result <- timed logger "Total compile time" $ liftIO $
+ runCompiler compiler id' provider routes store isModified logger
case result of
-- Compile rule for one item, easy stuff
diff --git a/src/Hakyll/Core/UnixFilter.hs b/src/Hakyll/Core/UnixFilter.hs
index 736acee..ee4b6cd 100644
--- a/src/Hakyll/Core/UnixFilter.hs
+++ b/src/Hakyll/Core/UnixFilter.hs
@@ -34,7 +34,17 @@ import Hakyll.Core.Compiler
unixFilter :: String -- ^ Program name
-> [String] -- ^ Program args
-> Compiler String String -- ^ Resulting compiler
-unixFilter programName args = unsafeCompiler $ \input -> do
+unixFilter programName args =
+ timedCompiler ("Executing external program " ++ programName) $
+ unsafeCompiler $ \input -> unixFilterIO programName args input
+
+-- | Internally used function
+--
+unixFilterIO :: String
+ -> [String]
+ -> String
+ -> IO String
+unixFilterIO programName args input = do
-- Create pipes
(stdinRead, stdinWrite) <- createPipe
(stdoutRead, stdoutWrite) <- createPipe