diff options
author | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2011-04-06 14:40:36 +0200 |
---|---|---|
committer | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2011-04-06 14:40:36 +0200 |
commit | 901b672107ef681830f7c9013bba444eb6c90d84 (patch) | |
tree | bdff58a9253387bdb7796fb2ae6f6d8d4a53c3d2 /src/Hakyll/Core/Run.hs | |
parent | 80596b1f56b7d6f2d4ff64d566ae845b7c7a01f6 (diff) | |
download | hakyll-901b672107ef681830f7c9013bba444eb6c90d84.tar.gz |
Play with dependency analyzer
Diffstat (limited to 'src/Hakyll/Core/Run.hs')
-rw-r--r-- | src/Hakyll/Core/Run.hs | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/src/Hakyll/Core/Run.hs b/src/Hakyll/Core/Run.hs index c2cc21b..af2ad22 100644 --- a/src/Hakyll/Core/Run.hs +++ b/src/Hakyll/Core/Run.hs @@ -11,13 +11,11 @@ import Control.Monad.Trans (liftIO) import Control.Applicative (Applicative, (<$>)) import Control.Monad.Reader (ReaderT, runReaderT, ask) import Control.Monad.State.Strict (StateT, runStateT, get, put) -import Control.Arrow ((&&&)) import Data.Map (Map) import qualified Data.Map as M import Data.Monoid (mempty, mappend) import Data.Maybe (fromMaybe) import System.FilePath ((</>)) -import Data.Set (Set) import qualified Data.Set as S import Hakyll.Core.Routes @@ -31,7 +29,6 @@ import Hakyll.Core.Resource.Provider.File import Hakyll.Core.Rules.Internal import Hakyll.Core.DirectedGraph import Hakyll.Core.DirectedGraph.Dot -import Hakyll.Core.DirectedGraph.DependencySolver import Hakyll.Core.DependencyAnalyzer import Hakyll.Core.Writable import Hakyll.Core.Store @@ -65,14 +62,12 @@ run configuration rules = do , hakyllRoutes = rulesRoutes ruleSet , hakyllResourceProvider = provider , hakyllStore = store - , hakyllOldGraph = oldGraph } -- Run the program and fetch the resulting state ((), state') <- runStateT stateT $ RuntimeState { hakyllAnalyzer = makeDependencyAnalyzer mempty (const False) oldGraph , hakyllCompilers = M.empty - , hakyllModified = S.empty } -- We want to save the final dependency graph for the next run @@ -89,13 +84,11 @@ data RuntimeEnvironment = RuntimeEnvironment , hakyllRoutes :: Routes , hakyllResourceProvider :: ResourceProvider , hakyllStore :: Store - , hakyllOldGraph :: DirectedGraph Identifier } data RuntimeState = RuntimeState { hakyllAnalyzer :: DependencyAnalyzer Identifier , hakyllCompilers :: Map Identifier (Compiler () CompileRule) - , hakyllModified :: Set Identifier } newtype Runtime a = Runtime @@ -104,12 +97,14 @@ newtype Runtime a = Runtime -- | Return a set of modified identifiers -- +{- modified :: ResourceProvider -- ^ Resource provider -> Store -- ^ Store -> [Identifier] -- ^ Identifiers to check -> IO (Set Identifier) -- ^ Modified resources modified provider store ids = fmap S.fromList $ flip filterM ids $ \id' -> resourceModified provider (Resource id') store +-} -- | Add a number of compilers and continue using these compilers -- @@ -126,7 +121,6 @@ addNewCompilers newCompilers = Runtime $ do -- Old state information oldCompilers <- hakyllCompilers <$> get oldAnalyzer <- hakyllAnalyzer <$> get - oldModified <- hakyllModified <$> get let -- Create a new partial dependency graph dependencies = flip map newCompilers $ \(id', compiler) -> @@ -137,18 +131,30 @@ addNewCompilers newCompilers = Runtime $ do newGraph = fromList dependencies -- Check which items have been modified - newModified <- liftIO $ modified provider store $ map fst newCompilers + modified <- fmap S.fromList $ flip filterM (map fst newCompilers) $ + liftIO . resourceModified provider store . Resource + -- newModified <- liftIO $ modified provider store $ map fst newCompilers -- Create a new analyzer and append it to the currect one - let newAnalyzer = - makeDependencyAnalyzer newGraph (`S.member` newModified) mempty + let newAnalyzer = makeDependencyAnalyzer newGraph (`S.member` modified) $ + analyzerPreviousGraph oldAnalyzer analyzer = mappend oldAnalyzer newAnalyzer + -- Debugging + liftIO $ putStrLn $ "Remains: " ++ show (analyzerRemains newAnalyzer) + liftIO $ putStrLn $ "Done: " ++ show (analyzerDone newAnalyzer) + liftIO $ writeFile "old-prev.dot" $ toDot show (analyzerPreviousGraph oldAnalyzer) + liftIO $ writeFile "old.dot" $ toDot show (analyzerGraph oldAnalyzer) + liftIO $ writeFile "old-prev.dot" $ toDot show (analyzerPreviousGraph oldAnalyzer) + liftIO $ writeFile "new.dot" $ toDot show (analyzerGraph newAnalyzer) + liftIO $ writeFile "new-prev.dot" $ toDot show (analyzerPreviousGraph newAnalyzer) + liftIO $ writeFile "result.dot" $ toDot show (analyzerGraph analyzer) + liftIO $ writeFile "result-prev.dot" $ toDot show (analyzerPreviousGraph analyzer) + -- Update the state put $ RuntimeState { hakyllAnalyzer = analyzer , hakyllCompilers = M.union oldCompilers (M.fromList newCompilers) - , hakyllModified = S.union oldModified newModified } -- Continue @@ -162,7 +168,7 @@ stepAnalyzer = Runtime $ do put $ state { hakyllAnalyzer = analyzer' } case signal of Done -> return () - Cycle c -> return () + Cycle _ -> return () Build id' -> unRuntime $ build id' build :: Identifier -> Runtime () @@ -171,16 +177,15 @@ build id' = Runtime $ do routes <- hakyllRoutes <$> ask provider <- hakyllResourceProvider <$> ask store <- hakyllStore <$> ask - modified' <- hakyllModified <$> get compilers <- hakyllCompilers <$> get section logger $ "Compiling " ++ show id' - let -- Fetch the right compiler from the map - compiler = compilers M.! id' + -- Fetch the right compiler from the map + let compiler = compilers M.! id' - -- Check if the resource was modified - isModified = id' `S.member` modified' + -- Check if the resource was modified + isModified <- liftIO $ resourceModified provider store (Resource id') -- Run the compiler result <- timed logger "Total compile time" $ liftIO $ |