-
Notifications
You must be signed in to change notification settings - Fork 5
/
Setup.hs
134 lines (119 loc) · 4.18 KB
/
Setup.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
module Main (main) where
import Control.Monad
( unless
, when
)
import Data.Maybe
( fromJust
, fromMaybe
)
import qualified Distribution.PackageDescription as PD
import Distribution.Simple
( Args
, UserHooks
, buildHook
, confHook
, defaultMainWithHooks
, postClean
, postConf
, preConf
, simpleUserHooks
)
import Distribution.Simple.LocalBuildInfo
( LocalBuildInfo
, configFlags
, localPkgDescr
)
import Distribution.Simple.Setup
( BuildFlags
, CleanFlags
, ConfigFlags
, buildVerbosity
, cleanVerbosity
, configConfigurationsFlags
, configVerbosity
, fromFlag
)
import Distribution.Simple.Utils (rawSystemExit)
import System.Directory
( doesDirectoryExist
, getCurrentDirectory
, removeDirectoryRecursive
)
main :: IO ()
main = defaultMainWithHooks simpleUserHooks {
preConf = volarePreConf,
confHook = volareConfHook,
postConf = volarePostConf,
buildHook = volareBuildHook,
postClean = volarePostClean
}
volarePreConf :: Args ->
ConfigFlags ->
IO PD.HookedBuildInfo
volarePreConf args flags = do
buildInfo <- preConf simpleUserHooks args flags
let glibcxx = fromMaybe False $ PD.lookupFlagAssignment (PD.mkFlagName "glibcxx") $ configConfigurationsFlags flags
macros = if glibcxx then
" GLIBCXX=1"
else
""
rawSystemExit (fromFlag $ configVerbosity flags) "/bin/sh" ["-c", "cd msm && make" ++ macros]
return buildInfo
volareConfHook :: (PD.GenericPackageDescription, PD.HookedBuildInfo) ->
ConfigFlags ->
IO LocalBuildInfo
volareConfHook (description, buildInfo) flags = do
localBuildInfo <- confHook simpleUserHooks (description, buildInfo) flags
let packageDescription = localPkgDescr localBuildInfo
library = fromJust $ PD.library packageDescription
libraryBuildInfo = PD.libBuildInfo library
dir <- getCurrentDirectory
return localBuildInfo {
localPkgDescr = packageDescription {
PD.library = Just $ library {
PD.libBuildInfo = libraryBuildInfo {
PD.includeDirs = (dir ++ "/msm"):PD.includeDirs libraryBuildInfo,
PD.extraLibDirs = (dir ++ "/msm/lib"):PD.extraLibDirs libraryBuildInfo
}
}
}
}
volarePostConf :: Args ->
ConfigFlags ->
PD.PackageDescription ->
LocalBuildInfo ->
IO ()
volarePostConf args flags description localBuildInfo = do
rawSystemExit (fromFlag $ configVerbosity flags) "npm" ["install"]
rawSystemExit (fromFlag $ configVerbosity flags) "npx" ["grunt", "bower:install"]
postConf simpleUserHooks args flags description localBuildInfo
volareBuildHook :: PD.PackageDescription ->
LocalBuildInfo ->
UserHooks ->
BuildFlags ->
IO ()
volareBuildHook description localBuildInfo hooks flags = do
let f = configConfigurationsFlags $ configFlags localBuildInfo
dev = fromMaybe False (PD.lookupFlagAssignment (PD.mkFlagName "dev") f) || fromMaybe False (PD.lookupFlagAssignment (PD.mkFlagName "library-only") f)
unless dev $
rawSystemExit (fromFlag $ buildVerbosity flags) "npx" ["grunt", "build"]
buildHook simpleUserHooks description localBuildInfo hooks flags
volarePostClean :: Args ->
CleanFlags ->
PD.PackageDescription ->
() ->
IO ()
volarePostClean args flags description _ = do
rawSystemExit (fromFlag $ cleanVerbosity flags) "/bin/sh" ["-c", "cd msm && make clean"]
b <- doesDirectoryExist "node_modules"
when b $
rawSystemExit (fromFlag $ cleanVerbosity flags) "npx" ["grunt", "clean"]
safeRemoveDirectory "node_modules"
postClean simpleUserHooks args flags description ()
safeRemoveDirectory :: FilePath ->
IO ()
safeRemoveDirectory path = do
b <- doesDirectoryExist path
when b $
removeDirectoryRecursive path