--------------------------------------------------------------------------------{-# LANGUAGE DeriveDataTypeable #-}moduleHakyll.Core.Dependencies(Dependency(..),DependencyFacts,outOfDate)where--------------------------------------------------------------------------------importControl.Applicative((<$>),(<*>))importControl.Monad(foldM,forM_,unless,when)importControl.Monad.Reader(ask)importControl.Monad.RWS(RWS,runRWS)importqualifiedControl.Monad.StateasStateimportControl.Monad.Writer(tell)importData.Binary(Binary(..),getWord8,putWord8)importData.List(find)importData.Map(Map)importqualifiedData.MapasMimportData.Maybe(fromMaybe)importData.Set(Set)importqualifiedData.SetasSimportData.Typeable(Typeable)--------------------------------------------------------------------------------importHakyll.Core.IdentifierimportHakyll.Core.Identifier.Pattern--------------------------------------------------------------------------------dataDependency=PatternDependencyPattern[Identifier]|IdentifierDependencyIdentifierderiving(Show,Typeable)--------------------------------------------------------------------------------instanceBinaryDependencywhereput(PatternDependencypis)=putWord80>>putp>>putisput(IdentifierDependencyi)=putWord81>>putiget=getWord8>>=\t->casetof0->PatternDependency<$>get<*>get1->IdentifierDependency<$>get_->error"Data.Binary.get: Invalid Dependency"--------------------------------------------------------------------------------typeDependencyFacts=MapIdentifier[Dependency]--------------------------------------------------------------------------------outOfDate::[Identifier]-- ^ All known identifiers->SetIdentifier-- ^ Initially out-of-date resources->DependencyFacts-- ^ Old dependency facts->(SetIdentifier,DependencyFacts,[String])outOfDateuniverseoodoldFacts=let(_,state,logs)=runRWSrwsuniverse(DependencyStateoldFactsood)in(dependencyOodstate,dependencyFactsstate,logs)whererws=docheckNewcheckChangedPatternsbruteForce--------------------------------------------------------------------------------dataDependencyState=DependencyState{dependencyFacts::DependencyFacts,dependencyOod::SetIdentifier}deriving(Show)--------------------------------------------------------------------------------typeDependencyMa=RWS[Identifier][String]DependencyStatea--------------------------------------------------------------------------------markOod::Identifier->DependencyM()markOodid'=State.modify$\s->s{dependencyOod=S.insertid'$dependencyOods}--------------------------------------------------------------------------------dependenciesFor::Identifier->DependencyM[Identifier]dependenciesForid'=dofacts<-dependencyFacts<$>State.getreturn$concatMapdependenciesFor'$fromMaybe[]$M.lookupid'factswheredependenciesFor'(IdentifierDependencyi)=[i]dependenciesFor'(PatternDependency_is)=is--------------------------------------------------------------------------------checkNew::DependencyM()checkNew=douniverse<-askfacts<-dependencyFacts<$>State.getforM_universe$\id'->unless(id'`M.member`facts)$dotell[showid'++" is out-of-date because it is new"]markOodid'--------------------------------------------------------------------------------checkChangedPatterns::DependencyM()checkChangedPatterns=dofacts<-M.toList.dependencyFacts<$>State.getforM_facts$\(id',deps)->dodeps'<-foldM(goid')[]depsState.modify$\s->s{dependencyFacts=M.insertid'deps'$dependencyFactss}wherego_ds(IdentifierDependencyi)=return$IdentifierDependencyi:dsgoid'ds(PatternDependencypls)=douniverse<-askletls'=filterMatchespuniverseifls==ls'thenreturn$PatternDependencypls:dselsedotell[showid'++" is out-of-date because a pattern changed"]markOodid'return$PatternDependencypls':ds--------------------------------------------------------------------------------bruteForce::DependencyM()bruteForce=dotodo<-askgotodowheregotodo=do(todo',changed)<-foldMcheck([],False)todowhenchanged(gotodo')check(todo,changed)id'=dodeps<-dependenciesForid'ood<-dependencyOod<$>State.getcasefind(`S.member`ood)depsofNothing->return(id':todo,changed)Justd->dotell[showid'++" is out-of-date because "++showd++" is out-of-date"]markOodid'return(todo,True)