Expression.hs 2.85 KB
Newer Older
1
module Expression (
Ben Gamari's avatar
Ben Gamari committed
2
    -- * Expressions
3
4
5
    Expr, Predicate, Args, Ways, Packages,

    -- ** Construction and modification
Andrey Mokhov's avatar
Andrey Mokhov committed
6
    expr, exprIO, arg, remove,
7
8
9

    -- ** Predicates
    (?), stage, stage0, stage1, stage2, notStage0, package, notPackage,
Andrey Mokhov's avatar
Andrey Mokhov committed
10
    libraryPackage, way, input, inputs, output, outputs,
11

Ben Gamari's avatar
Ben Gamari committed
12
    -- ** Evaluation
13
    interpret, interpretInContext,
14

15
    -- ** Context and Target
16
    Context, vanillaContext, stageContext, Target,
Ben Gamari's avatar
Ben Gamari committed
17
18

    -- * Convenient accessors
Andrey Mokhov's avatar
Andrey Mokhov committed
19
    getContext, getStage, getPackage, getBuilder, getOutputs, getInputs, getWay,
Andrey Mokhov's avatar
Andrey Mokhov committed
20
    getInput, getOutput, getSetting, getSettingList, getStagedSettingList,
Ben Gamari's avatar
Ben Gamari committed
21
22

    -- * Re-exports
Andrey Mokhov's avatar
Andrey Mokhov committed
23
    module Data.Semigroup,
Ben Gamari's avatar
Ben Gamari committed
24
25
26
27
    module Builder,
    module Package,
    module Stage,
    module Way
28
29
    ) where

30
import Control.Monad.Extra
Andrey Mokhov's avatar
Andrey Mokhov committed
31
import Data.Semigroup
32

33
34
35
import qualified Hadrian.Expression as H
import Hadrian.Expression hiding (Expr, Predicate, Args)

36
import Builder
37
import Context (Context, vanillaContext, stageContext, getStage, getPackage, getWay)
Andrey Mokhov's avatar
Andrey Mokhov committed
38
import Package
Andrey Mokhov's avatar
Andrey Mokhov committed
39
import Stage
40
import Target hiding (builder, inputs, outputs)
Andrey Mokhov's avatar
Andrey Mokhov committed
41
import Way
42

43
44
import Oracles.Config.Setting

Andrey Mokhov's avatar
Andrey Mokhov committed
45
46
-- | @Expr a@ is a computation that produces a value of type @Action a@ and can
-- read parameters of the current build 'Target'.
47
type Expr a = H.Expr Context Builder a
48

Ben Gamari's avatar
Ben Gamari committed
49
50
51
-- | The following expressions are used throughout the build system for
-- specifying conditions ('Predicate'), lists of arguments ('Args'), 'Ways'
-- and 'Packages'.
52
53
type Predicate = H.Predicate Context Builder
type Args      = H.Args      Context Builder
54
55
type Packages  = Expr [Package]
type Ways      = Expr [Way]
56

Andrey Mokhov's avatar
Andrey Mokhov committed
57
-- | Get a configuration setting.
58
59
60
getSetting :: Setting -> Expr String
getSetting = expr . setting

Andrey Mokhov's avatar
Andrey Mokhov committed
61
62
-- | Get a list of configuration settings.
getSettingList :: SettingList -> Args
63
64
getSettingList = expr . settingList

Andrey Mokhov's avatar
Andrey Mokhov committed
65
66
-- | Get a list of configuration settings for the current stage.
getStagedSettingList :: (Stage -> SettingList) -> Args
Andrey Mokhov's avatar
Andrey Mokhov committed
67
68
getStagedSettingList f = getSettingList . f =<< getStage

69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
-- | Is the build currently in the provided stage?
stage :: Stage -> Predicate
stage s = (s ==) <$> getStage

-- | Is a particular package being built?
package :: Package -> Predicate
package p = (p ==) <$> getPackage

-- | Is the current build 'Way' equal to a certain value?
way :: Way -> Predicate
way w = (w ==) <$> getWay

-- | Is the build currently in stage 0?
stage0 :: Predicate
stage0 = stage Stage0

-- | Is the build currently in stage 1?
stage1 :: Predicate
stage1 = stage Stage1

-- | Is the build currently in stage 2?
stage2 :: Predicate
stage2 = stage Stage2

-- | Is the build /not/ in stage 0 right now?
notStage0 :: Predicate
notStage0 = notM stage0

-- | Is a certain package /not/ built right now?
notPackage :: Package -> Predicate
notPackage = notM . package

-- | Is a library package currently being built?
libraryPackage :: Predicate
libraryPackage = isLibrary <$> getPackage