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

    -- ** Construction and modification
    expr, exprIO, append, arg, remove, (?),

Ben Gamari's avatar
Ben Gamari committed
8
    -- ** Evaluation
9
    interpret, interpretInContext,
10

11
    -- ** Context and Target
12
    Context, vanillaContext, stageContext, Target,
Ben Gamari's avatar
Ben Gamari committed
13 14

    -- * Convenient accessors
Andrey Mokhov's avatar
Andrey Mokhov committed
15
    getContext, getStage, getPackage, getBuilder, getOutputs, getInputs, getWay,
16
    getInput, getOutput, getSingleton, getSetting, getSettingList, getFlag,
Ben Gamari's avatar
Ben Gamari committed
17 18

    -- * Re-exports
Andrey Mokhov's avatar
Andrey Mokhov committed
19
    module Data.Semigroup,
Ben Gamari's avatar
Ben Gamari committed
20 21 22 23
    module Builder,
    module Package,
    module Stage,
    module Way
24 25
    ) where

Andrey Mokhov's avatar
Andrey Mokhov committed
26
import Data.Semigroup
27

28 29 30
import qualified Hadrian.Expression as H
import Hadrian.Expression hiding (Expr, Predicate, Args)

31
import Builder
32
import Context
Andrey Mokhov's avatar
Andrey Mokhov committed
33
import Package
Andrey Mokhov's avatar
Andrey Mokhov committed
34
import Stage
35
import Target
Andrey Mokhov's avatar
Andrey Mokhov committed
36
import Way
37

38 39 40
import Oracles.Config.Flag
import Oracles.Config.Setting

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

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

53
-- Basic operations on expressions:
54

Andrey Mokhov's avatar
Andrey Mokhov committed
55
-- | Append something to an expression.
Andrey Mokhov's avatar
Andrey Mokhov committed
56 57
append :: a -> Expr a
append = pure
Andrey Mokhov's avatar
Andrey Mokhov committed
58

Andrey Mokhov's avatar
Andrey Mokhov committed
59
-- | Get the 'Stage' of the current 'Context'.
60
getStage :: Expr Stage
61
getStage = stage <$> getContext
62

Andrey Mokhov's avatar
Andrey Mokhov committed
63
-- | Get the 'Package' of the current 'Context'.
64
getPackage :: Expr Package
65
getPackage = package <$> getContext
66

Andrey Mokhov's avatar
Andrey Mokhov committed
67 68
-- | Get the 'Way' of the current 'Context'.
getWay :: Expr Way
69
getWay = way <$> getContext
70 71 72 73 74 75 76 77 78

getSetting :: Setting -> Expr String
getSetting = expr . setting

getSettingList :: SettingList -> Expr [String]
getSettingList = expr . settingList

getFlag :: Flag -> Predicate
getFlag = expr . flag