ArgsHash.hs 1.34 KB
Newer Older
1 2
{-# LANGUAGE DeriveDataTypeable, GeneralizedNewtypeDeriving #-}
module Oracles.ArgsHash (
3
    checkArgsHash, argsHashOracle
4 5
    ) where

6
import Target
7
import Expression
8
import Settings
9
import Settings.Args
10

11 12
newtype ArgsHashKey = ArgsHashKey Target
    deriving (Show, Eq, Typeable, Binary, Hashable, NFData)
13

14 15 16 17
-- This is an action that given a full target determines the corresponding
-- argument list and computes its hash. The resulting value is tracked in a
-- Shake oracle, hence initiating rebuilts when the hash is changed (a hash
-- change indicates changes in the build system).
Andrey Mokhov's avatar
Andrey Mokhov committed
18 19 20 21 22 23
-- Note: we replace target sources with ["src"] for performance reasons -- to
-- avoid storing long lists of source files passed to some builders (e.g. Ar)
-- in the Shake database. This optimisation is harmless, because argument list
-- constructors are assumed not to examine target sources, but only append them
-- to argument lists where appropriate.
-- TODO: enforce the above assumption via type trickery?
24
checkArgsHash :: Target -> Action ()
25
checkArgsHash target = do
Andrey Mokhov's avatar
Andrey Mokhov committed
26
    _ <- askOracle . ArgsHashKey $ target { sources = ["src"] } :: Action Int
27
    return ()
28 29 30

-- Oracle for storing per-target argument list hashes
argsHashOracle :: Rules ()
Andrey Mokhov's avatar
Andrey Mokhov committed
31
argsHashOracle = when trackBuildSystem $ do
Andrey Mokhov's avatar
Andrey Mokhov committed
32
    _ <- addOracle $ \(ArgsHashKey target) -> hash <$> interpret target getArgs
33
    return ()