Make build badges more informative
[hadrian.git] / src / Target.hs
1 {-# LANGUAGE DeriveGeneric, FlexibleInstances #-}
2 module Target (
3 Target (..)
4 , PartialTarget (..)
5 , unsafeFromPartial
6 , fullTarget
7 , fullTargetWithWay
8 ) where
9
10 import Control.Monad.Trans.Reader
11
12 import Base
13 import Builder
14 import GHC.Generics (Generic)
15 import Package
16 import Stage
17 import Way
18
19 -- | Parameters relevant to the current build target.
20 data Target = Target
21 {
22 stage :: Stage, -- ^ Stage being built
23 package :: Package, -- ^ Package being built
24 builder :: Builder, -- ^ Builder to be invoked
25 way :: Way, -- ^ Way to build (set to vanilla for most targets)
26 inputs :: [FilePath], -- ^ Source files passed to the builder
27 outputs :: [FilePath] -- ^ Files to be produced
28 }
29 deriving (Show, Eq, Generic)
30
31 -- | If values of type @a@ form a 'Monoid' then we can also derive a 'Monoid'
32 -- instance for values of type @'ReaderT' 'Target' 'Action' a@:
33 --
34 -- * the empty computation is the identity element of the underlying type
35 -- * two computations can be combined by combining their results
36 instance Monoid a => Monoid (ReaderT Target Action a) where
37 mempty = return mempty
38 mappend = liftM2 mappend
39
40 -- | A partially constructed Target with fields 'Stage' and 'Package' only.
41 -- 'PartialTarget's are used for generating build rules.
42 data PartialTarget = PartialTarget Stage Package deriving (Eq, Show)
43
44 -- | Convert 'PartialTarget' to a 'Target' assuming that unknown fields won't
45 -- be used.
46 unsafeFromPartial :: PartialTarget -> Target
47 unsafeFromPartial (PartialTarget s p) = Target
48 {
49 stage = s,
50 package = p,
51 builder = error "unsafeFromPartial: builder not set",
52 way = error "unsafeFromPartial: way not set",
53 inputs = error "unsafeFromPartial: inputs not set",
54 outputs = error "unsafeFromPartial: outputs not set"
55 }
56
57 -- | Construct a full 'Target' by augmenting a 'PartialTarget' with missing
58 -- fields. Most targets are built only one way, 'vanilla', hence it is set by
59 -- default. Use 'fullTargetWithWay' otherwise.
60 fullTarget ::
61 PartialTarget
62 -> Builder
63 -> [FilePath] -- ^ Source files
64 -> [FilePath] -- ^ Produced files
65 -> Target
66 fullTarget (PartialTarget s p) b srcs fs = Target
67 {
68 stage = s,
69 package = p,
70 builder = b,
71 way = vanilla,
72 inputs = map unifyPath srcs,
73 outputs = map unifyPath fs
74 }
75
76 -- | Like 'fullTarget', but allows an explicit 'Way' parameter.
77 fullTargetWithWay ::
78 PartialTarget
79 -> Builder
80 -> Way
81 -> [FilePath] -- ^ Source files
82 -> [FilePath] -- ^ Produced files
83 -> Target
84 fullTargetWithWay pt b w srcs fs = (fullTarget pt b srcs fs) { way = w }
85
86 instance Binary Target
87 instance NFData Target
88 instance Hashable Target