Add dependencies to Target.
[hadrian.git] / src / Target.hs
1 {-# LANGUAGE DeriveGeneric, TypeSynonymInstances #-}
2 module Target (
3 Target (..), StageTarget (..), StagePackageTarget (..), FullTarget (..),
4 stageTarget, stagePackageTarget, fullTarget, fullTargetWithWay
5 ) where
6
7 import Way
8 import Stage
9 import Package
10 import Builder
11 import GHC.Generics
12 import Development.Shake.Classes
13
14 -- Target captures all parameters relevant to the current build target:
15 -- * Stage and Package being built,
16 -- * dependencies (e.g., source files) that need to be tracked,
17 -- * Builder to be invoked,
18 -- * Way to be built (set to vanilla for most targets),
19 -- * file(s) to be produced.
20 data Target = Target
21 {
22 stage :: Stage,
23 package :: Package,
24 dependencies :: [FilePath],
25 builder :: Builder,
26 way :: Way,
27 files :: [FilePath]
28 }
29 deriving (Show, Eq, Generic)
30
31 -- StageTarget is a partially constructed Target. Only stage is guaranteed to
32 -- be assigned.
33 type StageTarget = Target
34
35 stageTarget :: Stage -> StageTarget
36 stageTarget s = Target
37 {
38 stage = s,
39 package = error "stageTarget: package not set",
40 dependencies = error "stageTarget: dependencies not set",
41 builder = error "stageTarget: builder not set",
42 way = vanilla,
43 files = error "stageTarget: files not set"
44 }
45
46 -- StagePackageTarget is a partially constructed Target. Only stage and package
47 -- are guaranteed to be assigned.
48 type StagePackageTarget = Target
49
50 stagePackageTarget :: Stage -> Package -> StagePackageTarget
51 stagePackageTarget s p = Target
52 {
53 stage = s,
54 package = p,
55 dependencies = error "stagePackageTarget: dependencies not set",
56 builder = error "stagePackageTarget: builder not set",
57 way = vanilla,
58 files = error "stagePackageTarget: files not set"
59 }
60
61 -- FullTarget is a Target whose fields are all assigned
62 type FullTarget = Target
63
64 -- Most targets are built only one way, vanilla, hence we set it by default.
65 fullTarget :: StagePackageTarget -> [FilePath] -> Builder -> [FilePath] -> FullTarget
66 fullTarget target deps b fs = target
67 {
68 dependencies = deps,
69 builder = b,
70 way = vanilla,
71 files = fs
72 }
73
74 -- Use this function to be explicit about the build way.
75 fullTargetWithWay :: StagePackageTarget -> [FilePath] -> Builder -> Way -> [FilePath] -> FullTarget
76 fullTargetWithWay target deps b w fs = target
77 {
78 dependencies = deps,
79 builder = b,
80 way = w,
81 files = fs
82 }
83
84 -- Instances for storing in the Shake database
85 instance Binary FullTarget
86 instance NFData FullTarget
87 instance Hashable FullTarget