dc095e10755ba8a2a5319d4faeef35da34a4be22
[hadrian.git] / src / Expression.hs
1 module Expression (
2 -- * Expressions
3 Expr, Predicate, Args, Ways,
4
5 -- ** Construction and modification
6 expr, exprIO, arg, remove,
7
8 -- ** Predicates
9 (?), stage, stage0, stage1, stage2, notStage0, package, notPackage,
10 libraryPackage, builder, way, input, inputs, output, outputs,
11
12 -- ** Evaluation
13 interpret, interpretInContext,
14
15 -- * Convenient accessors
16 getBuildRoot, getContext, getPkgData, getPkgDataList, getOutputs, getInputs,
17 getInput, getOutput,
18
19 -- * Re-exports
20 module Base,
21 module Builder,
22 module Context,
23 module GHC
24 ) where
25
26 import Base
27 import Builder
28 import Context hiding (stage, package, way)
29 import Expression.Type
30 import GHC
31 import Hadrian.Expression hiding (Expr, Predicate, Args)
32 import Oracles.PackageData
33
34 -- | Get a value from the @package-data.mk@ file of the current context.
35 getPkgData :: (FilePath -> PackageData) -> Expr String
36 getPkgData key = expr . pkgData . key =<< getBuildPath
37
38 -- | Get a list of values from the @package-data.mk@ file of the current context.
39 getPkgDataList :: (FilePath -> PackageDataList) -> Expr [String]
40 getPkgDataList key = expr . pkgDataList . key =<< getBuildPath
41
42 -- | Is the build currently in the provided stage?
43 stage :: Stage -> Predicate
44 stage s = (s ==) <$> getStage
45
46 -- | Is a particular package being built?
47 package :: Package -> Predicate
48 package p = (p ==) <$> getPackage
49
50 -- | This type class allows the user to construct both precise builder
51 -- predicates, such as @builder (Ghc CompileHs Stage1)@, as well as predicates
52 -- covering a set of similar builders. For example, @builder (Ghc CompileHs)@
53 -- matches any stage, and @builder Ghc@ matches any stage and any GHC mode.
54 class BuilderPredicate a where
55 -- | Is a particular builder being used?
56 builder :: a -> Predicate
57
58 instance BuilderPredicate Builder where
59 builder b = (b ==) <$> getBuilder
60
61 instance BuilderPredicate a => BuilderPredicate (Stage -> a) where
62 builder f = builder . f =<< getStage
63
64 instance BuilderPredicate a => BuilderPredicate (CcMode -> a) where
65 builder f = do
66 b <- getBuilder
67 case b of
68 Cc c _ -> builder (f c)
69 _ -> return False
70
71 instance BuilderPredicate a => BuilderPredicate (GhcMode -> a) where
72 builder f = do
73 b <- getBuilder
74 case b of
75 Ghc c _ -> builder (f c)
76 _ -> return False
77
78 instance BuilderPredicate a => BuilderPredicate (FilePath -> a) where
79 builder f = do
80 b <- getBuilder
81 case b of
82 Configure path -> builder (f path)
83 _ -> return False
84
85 -- | Is the current build 'Way' equal to a certain value?
86 way :: Way -> Predicate
87 way w = (w ==) <$> getWay
88
89 -- | Is the build currently in stage 0?
90 stage0 :: Predicate
91 stage0 = stage Stage0
92
93 -- | Is the build currently in stage 1?
94 stage1 :: Predicate
95 stage1 = stage Stage1
96
97 -- | Is the build currently in stage 2?
98 stage2 :: Predicate
99 stage2 = stage Stage2
100
101 -- | Is the build /not/ in stage 0 right now?
102 notStage0 :: Predicate
103 notStage0 = notM stage0
104
105 -- | Is a certain package /not/ built right now?
106 notPackage :: Package -> Predicate
107 notPackage = notM . package
108
109 -- | Is a library package currently being built?
110 libraryPackage :: Predicate
111 libraryPackage = isLibrary <$> getPackage