module Dib.Target(
Target(Target),
addDependency,
addDependencies,
getDependencies,
makePhonyTarget,
makeCommandTarget,
targetDepChecksum
) where
import Dib.Types
import Dib.Gatherers
import Data.Word
import qualified Data.Digest.CRC32 as Hash
import qualified Data.Text as T
import qualified Data.Text.Encoding as TE
addDependency :: Target -> Target -> Target
addDependency (Target name checksum deps stages gatherers) newDep = Target name checksum (newDep : deps) stages gatherers
addDependencies :: Target -> [Target] -> Target
addDependencies (Target name checksum deps stages gatherers) newDeps = Target name checksum (newDeps ++ deps) stages gatherers
getDependencies :: Target -> [Target]
getDependencies (Target _ _ deps _ _) = deps
makePhonyTarget :: T.Text -> [Target] -> Target
makePhonyTarget name deps = Target name (const 0) deps [] []
makeCommandTarget :: T.Text -> [Target] -> IO () -> Target
makeCommandTarget name deps command = Target name (const 0) deps [] [makeCommandGatherer command]
targetDepChecksum :: Target -> Word32
targetDepChecksum (Target _ _ deps _ _) = Hash.crc32 $ TE.encodeUtf8 $ T.intercalate "^" $ map (\(Target n _ _ _ _) -> n) deps