Remove Base.hs, move Stage definition to Stage.hs.
[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 parameters relevant to the current build target: Stage and
15 -- Package being built, Builder that is to be invoked, file(s) that are to
16 -- be built and the Way they are to be built.
17 data Target = Target
18 {
19 getStage :: Stage,
20 getPackage :: Package,
21 getFiles :: [FilePath],
22 getBuilder :: Builder,
23 getWay :: Way
24 }
25 deriving (Eq, Generic)
26
27 -- StageTarget is a Target whose field getStage is already assigned
28 type StageTarget = Target
29
30 stageTarget :: Stage -> StageTarget
31 stageTarget stage = Target
32 {
33 getStage = stage,
34 getPackage = error "stageTarget: Package not set",
35 getFiles = error "stageTarget: Files not set",
36 getBuilder = error "stageTarget: Builder not set",
37 getWay = vanilla -- most targets are built only one way (vanilla)
38 }
39
40 -- StagePackageTarget is a Target whose fields getStage and getPackage are
41 -- already assigned
42 type StagePackageTarget = Target
43
44 stagePackageTarget :: Stage -> Package -> StagePackageTarget
45 stagePackageTarget stage package = Target
46 {
47 getStage = stage,
48 getPackage = package,
49 getFiles = error "stagePackageTarget: Files not set",
50 getBuilder = error "stagePackageTarget: Builder not set",
51 getWay = vanilla
52 }
53
54 -- FullTarget is a Target whose fields are all assigned
55 type FullTarget = Target
56
57 -- Most targets are built only one way, vanilla, hence we set it by default.
58 fullTarget :: StagePackageTarget -> [FilePath] -> Builder -> FullTarget
59 fullTarget target files builder = target
60 {
61 getFiles = files,
62 getBuilder = builder,
63 getWay = vanilla
64 }
65
66 -- Use this function to be explicit about build the way.
67 fullTargetWithWay :: StagePackageTarget -> [FilePath] -> Builder -> Way -> FullTarget
68 fullTargetWithWay target files builder way = target
69 {
70 getFiles = files,
71 getBuilder = builder,
72 getWay = way
73 }
74
75 -- Shows a (full) target as "package:file@stage (builder, way)"
76 instance Show FullTarget where
77 show target = show (getPackage target)
78 ++ ":" ++ show (getFiles target)
79 ++ "@" ++ show (getStage target)
80 ++ " (" ++ show (getBuilder target)
81 ++ ", " ++ show (getWay target) ++ ")"
82
83 -- Instances for storing in the Shake database
84 instance Binary FullTarget
85 instance NFData FullTarget
86 instance Hashable FullTarget