on master help sign in
Rewrite Run module a bit, get rid off obsolete
commit3ea3c52f535d3faaa930dfc4ef5812f0ef690ec3 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateTue 11 Jan 2011, 20:20 (16 years ago) parent607b1d7
1 file changed+21−15
src/Hakyll/Core/Run.hs+21−15
src/Hakyll/Core/Run.hs+21−15
@@ -12,7 +12,7 @@ import Control.Arrow ((&&&))
1212import Control.Monad (foldM, forM_, forM, filterM)
1313import Data.Map (Map)
1414import qualified Data.Map as M
15−import Data.Monoid (mempty)
15+import Data.Monoid (mempty, mappend)
1616import Data.Typeable (Typeable)
1717import Data.Binary (Binary)
1818import System.FilePath ((</>))
@@ -56,7 +56,6 @@ hakyll rules = do
5656
5757 state = HakyllState
5858 { hakyllModified = S.empty
59− , hakyllObsolete = S.empty
6059 , hakyllGraph = mempty
6160 }
6261
@@ -68,7 +67,6 @@ data HakyllEnvironment = HakyllEnvironment
6867
6968data HakyllState = HakyllState
7069 { hakyllModified :: Set Identifier
71− , hakyllObsolete :: Set Identifier
7270 , hakyllGraph :: DirectedGraph Identifier
7371 }
7472
@@ -98,7 +96,10 @@ addNewCompilers oldCompilers newCompilers = Hakyll $ do
9896 provider <- hakyllResourceProvider <$> ask
9997 store <- hakyllStore <$> ask
10098
101− let -- All compilers
99+ let -- Create a set of new compilers
100+ newCompilerIdentifiers = S.fromList $ map fst newCompilers
101+
102+ -- All compilers
102103 compilers = oldCompilers ++ newCompilers
103104
104105 -- Get all dependencies for the compilers
@@ -110,39 +111,44 @@ addNewCompilers oldCompilers newCompilers = Hakyll $ do
110111 compilerMap = M.fromList compilers
111112
112113 -- Create the dependency graph
113− graph = fromList dependencies
114+ currentGraph = fromList dependencies
115+
116+ -- Find the old graph and append the new graph to it. This forms the
117+ -- complete graph
118+ completeGraph <- (mappend currentGraph) . hakyllGraph <$> get
114119
115− liftIO $ writeDot "dependencies.dot" show graph
120+ liftIO $ writeDot "dependencies.dot" show completeGraph
116121
117122 -- Check which items are up-to-date. This only needs to happen for the new
118123 -- compilers
119124 oldModified <- hakyllModified <$> get
120125 newModified <- liftIO $ modified provider store $ map fst newCompilers
121− oldObsolete <- hakyllObsolete <$> get
122126
123127 let modified' = oldModified `S.union` newModified
124128
125− -- Find obsolete items
126− obsolete = reachableNodes (oldObsolete `S.union` modified') $
127− reverse graph
129+ -- Find obsolete items. Every item that is reachable from a modified
130+ -- item is considered obsolete. From these obsolete items, we are only
131+ -- interested in ones that are in the current subgraph.
132+ obsolete = S.filter (`S.member` newCompilerIdentifiers)
133+ $ reachableNodes modified' $ reverse completeGraph
128134
129− -- Solve the graph, retain only the obsolete items
130− ordered = filter (`S.member` obsolete) $ solveDependencies graph
135+ -- Solve the graph and retain only the obsolete items
136+ ordered = filter (`S.member` obsolete) $ solveDependencies currentGraph
131137
132138 -- Join the order with the compilers again
133139 orderedCompilers = map (id &&& (compilerMap M.!)) ordered
134140
135141 liftIO $ putStrLn "Adding compilers..."
136142
137− modify $ updateState modified' obsolete
143+ modify $ updateState modified' completeGraph
138144
139145 -- Now run the ordered list of compilers
140146 unHakyll $ runCompilers orderedCompilers
141147 where
142148 -- Add the modified information for the new compilers
143− updateState modified' obsolete state = state
149+ updateState modified' graph state = state
144150 { hakyllModified = modified'
145− , hakyllObsolete = obsolete
151+ , hakyllGraph = graph
146152 }
147153
148154runCompilers :: [(Identifier, Compiler () CompileRule)]