Factor out Context from Target.
[hadrian.git] / src / Target.hs
1 {-# LANGUAGE DeriveGeneric, FlexibleInstances #-}
2 module Target (Target (..), dummyTarget) where
3
4 import Control.Monad.Trans.Reader
5 import GHC.Generics (Generic)
6
7 import Base
8 import Builder
9 import Context
10
11 -- | Parameters relevant to the current build target.
12 data Target = Target
13 { context :: Context -- ^ Current build context
14 , builder :: Builder -- ^ Builder to be invoked
15 , inputs :: [FilePath] -- ^ Source files passed to the builder
16 , outputs :: [FilePath] -- ^ Files to be produced
17 } deriving (Show, Eq, Generic)
18
19 -- | If values of type @a@ form a 'Monoid' then we can also derive a 'Monoid'
20 -- instance for values of type @'ReaderT' 'Target' 'Action' a@:
21 --
22 -- * the empty computation is the identity element of the underlying type
23 -- * two computations can be combined by combining their results
24 instance Monoid a => Monoid (ReaderT Target Action a) where
25 mempty = return mempty
26 mappend = liftM2 mappend
27
28 dummyTarget :: Context -> Target
29 dummyTarget ctx = Target
30 { context = ctx
31 , builder = error "dummyTarget: builder not set"
32 , inputs = error "dummyTarget: inputs not set"
33 , outputs = error "dummyTarget: outputs not set" }
34
35 instance Binary Target
36 instance NFData Target
37 instance Hashable Target