-
Notifications
You must be signed in to change notification settings - Fork 22
/
Build.hs
executable file
·182 lines (160 loc) · 4.83 KB
/
Build.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/usr/bin/env stack
-- stack --install-ghc runghc --package shake-0.16.4 --stack-yaml stack.yaml
import Development.Shake
import Development.Shake.FilePath
import System.Directory
opts =
shakeOptions
{ shakeFiles = ".shake"
, shakeVersion = "1.0"
, shakeVerbosity = Normal
, shakeThreads = 1
}
data Doc = Lab
main :: IO ()
main =
getDirectoryFilesIO "samples" ["/*.lhs", "/*.hs"] >>= \allSamps ->
getDirectoryFilesIO "src" ["//*.hs"] >>= \allSrc ->
shakeArgs opts $ do
want ["all"]
"all"
~> need ["pdf", "md", "gentags", "install", "exe"]
"pdf"
~> need
[ "renders" </> takeFileName f -<.> ".pdf"
| f <- allSamps
, takeExtension f == ".lhs"
]
"md"
~> need
[ "renders" </> takeFileName f -<.> ".md"
| f <- allSamps
, takeExtension f == ".lhs"
]
"exe"
~> need (map (\f -> "samples-exe" </> dropExtension f) allSamps)
"haddocks" ~> do
need $ ("src" </>) <$> allSrc
cmd "jle-git-haddocks"
"install" ~> do
need $ ("src" </>) <$> allSrc
cmd "stack install"
"install-profile" ~> do
need $ ("src" </>) <$> allSrc
cmd "stack install --profile"
"gentags"
~> need ["tags", "TAGS"]
["renders/*.pdf", "renders/*.md"] |%> \f -> do
let src = "samples" </> takeFileName f -<.> "lhs"
need [src]
liftIO $ createDirectoryIfMissing True "renders"
cmd
"pandoc"
"-V geometry:margin=1in"
"-V fontfamily:palatino,cmtt"
"-V links-as-notes"
"-s"
"--highlight-style tango"
"--reference-links"
"--reference-location block"
"-o"
f
src
"samples-exe/*" %> \f -> do
need ["install"]
[src] <- getDirectoryFiles "samples" $ (takeFileName f <.>) <$> ["hs", "lhs"]
liftIO $ do
createDirectoryIfMissing True "samples-exe"
createDirectoryIfMissing True ".build"
removeFilesAfter "samples" ["/*.o"]
cmd
"stack ghc"
"--stack-yaml stack.yaml"
"--package finite-typelits"
"--package hmatrix-backprop"
"--package hmatrix-vector-sized"
"--package microlens-th"
"--package mnist-idx"
"--package mwc-random"
"--package one-liner"
"--package one-liner-instances"
"--package random"
"--package singletons"
"--package split"
"--package vector-sized"
"--"
("samples" </> src)
"-o"
f
"-hidir .build"
"-Wall"
"-O2"
"profile" ~> do
need $ do
s <- ["manual", "bp-lens", "bp-hkd", "hybrid"]
e <- ["prof.html", "svg"]
return $ "bench-prof/bench-" ++ s <.> e
"bench-prof/bench" %> \f -> do
let src = "bench" </> takeFileName f <.> ".hs"
need ["install-profile", src]
unit $
cmd
"stack install"
"--profile"
"--stack-yaml stack.yaml"
[ "lens"
, "hmatrix"
, "one-liner-instances"
, "split"
, "criterion"
]
unit $
cmd
"stack ghc"
"--profile"
"--stack-yaml stack.yaml"
src
"--"
"-o"
f
"-hidir .build"
"-O2"
"-prof"
"-fexternal-interpreter"
"bench-prof/bench-*.prof" %> \f -> do
need ["bench-prof/bench"]
let b = drop 6 $ takeBaseName f
unit $
cmd
"./bench-prof/bench"
("gradient/" ++ b)
"+RTS"
"-p"
cmd "mv" "bench.prof" f
"**/*.prof.html" %> \f -> do
let src = f -<.> ""
need [src]
cmd "profiteur" src
"**/*.prof.folded" %> \f -> do
let src = f -<.> ""
need [src]
Stdout out <- cmd "cat" [src]
cmd
(Stdin out)
(FileStdout f)
"ghc-prof-flamegraph"
"bench-prof/*.svg" %> \f -> do
let src = f -<.> "prof.folded"
need [src]
cmd
(FileStdout f)
"flamegraph.pl"
"--width 2000"
src
["tags", "TAGS"] &%> \_ -> do
need (("src" </>) <$> allSrc)
cmd "hasktags" "src/"
"clean" ~> do
unit $ cmd "stack clean"
removeFilesAfter ".shake" ["//*"]
removeFilesAfter ".build" ["//*"]