Expression.hs 2.07 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 17
    getInput, getOutput, getSingleton, getSetting, getSettingList, getFlag,
    getTopDirectory,
Ben Gamari's avatar
Ben Gamari committed
18 19

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

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

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

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

39 40 41 42
import Oracles.Config.Flag
import Oracles.Config.Setting
import Oracles.Path

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

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

55
-- Basic operations on expressions:
56

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

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

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

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

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

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

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

getTopDirectory :: Expr FilePath
getTopDirectory = expr topDirectory