Util.hs 3.1 KB
Newer Older
1
{-# LANGUAGE NoImplicitPrelude #-}
Andrey Mokhov's avatar
Andrey Mokhov committed
2

Andrey Mokhov's avatar
Andrey Mokhov committed
3
module Settings.Util (
4
    -- Primitive settings elements
Andrey Mokhov's avatar
Andrey Mokhov committed
5
    arg, argM, args,
6
7
8
9
10
11
12
    argConfig, argStagedConfig, argConfigList, argStagedConfigList,
    -- argBuilderPath, argStagedBuilderPath,
    -- argPackageKey, argPackageDeps, argPackageDepKeys, argSrcDirs,
    -- argIncludeDirs, argDepIncludeDirs,
    -- argConcat, argConcatPath, argConcatSpace,
    -- argPairs, argPrefix, argPrefixPath,
    -- argPackageConstraints,
Andrey Mokhov's avatar
Andrey Mokhov committed
13
14
    ) where

15
16
17
18
19
import Base hiding (Args, arg, args)
import Oracles hiding (not)
import Expression

-- A single argument
20
arg :: String -> Settings
Andrey Mokhov's avatar
Andrey Mokhov committed
21
22
23
24
arg = append . return

argM :: Action String -> Settings
argM = appendM . fmap return
25
26

-- A list of arguments
27
args :: [String] -> Settings
Andrey Mokhov's avatar
Andrey Mokhov committed
28
args = append
29

30
argConfig :: String -> Settings
Andrey Mokhov's avatar
Andrey Mokhov committed
31
argConfig = appendM . fmap return . askConfig
32

33
argConfigList :: String -> Settings
Andrey Mokhov's avatar
Andrey Mokhov committed
34
argConfigList = appendM . fmap words . askConfig
35
36
37
38

stagedKey :: Stage -> String -> String
stagedKey stage key = key ++ "-stage" ++ show stage

39
argStagedConfig :: String -> Settings
40
41
42
43
argStagedConfig key = do
    stage <- asks getStage
    argConfig (stagedKey stage key)

44
argStagedConfigList :: String -> Settings
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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
argStagedConfigList key = do
    stage <- asks getStage
    argConfigList (stagedKey stage key)

-- packageData :: Arity -> String -> Settings
-- packageData arity key =
--     return $ EnvironmentParameter $ PackageData arity key Nothing Nothing

-- -- Accessing key value pairs from package-data.mk files
-- argPackageKey :: Settings
-- argPackageKey = packageData Single "PACKAGE_KEY"

-- argPackageDeps :: Settings
-- argPackageDeps = packageData Multiple "DEPS"

-- argPackageDepKeys :: Settings
-- argPackageDepKeys = packageData Multiple "DEP_KEYS"

-- argSrcDirs :: Settings
-- argSrcDirs = packageData Multiple "HS_SRC_DIRS"

-- argIncludeDirs :: Settings
-- argIncludeDirs = packageData Multiple "INCLUDE_DIRS"

-- argDepIncludeDirs :: Settings
-- argDepIncludeDirs = packageData Multiple "DEP_INCLUDE_DIRS_SINGLE_QUOTED"

-- argPackageConstraints :: Packages -> Settings
-- argPackageConstraints = return . EnvironmentParameter . PackageConstraints

-- -- Concatenate arguments: arg1 ++ arg2 ++ ...
-- argConcat :: Settings -> Settings
-- argConcat = return . Fold Concat

-- -- </>-concatenate arguments: arg1 </> arg2 </> ...
-- argConcatPath :: Settings -> Settings
-- argConcatPath = return . Fold ConcatPath

-- -- Concatene arguments (space separated): arg1 ++ " " ++ arg2 ++ ...
-- argConcatSpace :: Settings -> Settings
-- argConcatSpace = return . Fold ConcatSpace

-- -- An ordered list of pairs of arguments: prefix |> arg1, prefix |> arg2, ...
-- argPairs :: String -> Settings -> Settings
-- argPairs prefix settings = settings >>= (arg prefix |>) . return

-- -- An ordered list of prefixed arguments: prefix ++ arg1, prefix ++ arg2, ...
-- argPrefix :: String -> Settings -> Settings
-- argPrefix prefix = fmap (Fold Concat . (arg prefix |>) . return)

-- -- An ordered list of prefixed arguments: prefix </> arg1, prefix </> arg2, ...
-- argPrefixPath :: String -> Settings -> Settings
-- argPrefixPath prefix = fmap (Fold ConcatPath . (arg prefix |>) . return)