This repository has been archived by the owner on Mar 3, 2023. It is now read-only.
forked from avh4/elm-format
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Shakefile.hs
271 lines (226 loc) · 9.46 KB
/
Shakefile.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
import Development.Shake
import Development.Shake.Command
import Development.Shake.FilePath
import Development.Shake.Util
import Control.Monad (forM_)
import qualified System.Directory
import qualified System.Info
import qualified Shakefiles.Haskell
import qualified Shakefiles.Shellcheck
import qualified Shakefiles.Dependencies
import qualified Shakefiles.Signature
import Shakefiles.Extra
main :: IO ()
main = do
shakefilesHash <- getHashedShakeVersion [ "Shakefile.hs" ]
shakeArgs shakeOptions{
shakeChange = ChangeModtimeAndDigest,
shakeColor = True,
shakeVersion = shakefilesHash
} $ do
StdoutTrim gitDescribe <- liftIO $ cmd "git" [ "describe", "--abbrev=8", "--match", "[0-9]*", "--always" ]
StdoutTrim gitSha <- liftIO $ cmd "git" [ "describe", "--always", "--match", "NOT A TAG", "--dirty" ]
let elmFormat = "_build" </> "elm-format" <.> exe
shellcheck <- Shakefiles.Dependencies.rules
want [ "test" ]
phony "test" $ need
[ "unit-tests"
, "integration-tests"
, "shellcheck"
]
phony "build" $ need [ "elm-format" ]
phony "elm-format" $ need [ elmFormat ]
phony "unit-tests" $ need
[ "_build/cabal/elm-format-lib/test.ok"
, "_build/cabal/elm-format-test-lib/test.ok"
, "_build/cabal/elm-format/test.ok"
]
phony "profile" $ need [ "_build/tests/test-files/prof.ok" ]
phony "dist" $ need [ "dist-elm-format" ]
phonyPrefix "publish-" $ \version ->
need [ "elm-format-publish-" ++ version ]
phony "clean" $ do
removeFilesAfter "dist-newstyle" [ "//*" ]
removeFilesAfter "_build" [ "//*" ]
removeFilesAfter ".shake" [ "//*" ]
removeFilesAfter "."
[ "_input.elm"
, "_input2.elm"
, "formatted.elm"
, "formatted.json"
, "_stdout.txt"
]
Shakefiles.Signature.rules
--
-- build
--
"generated/Build_elm_format.hs" %> \out -> do
alwaysRerun
writeFileChanged out $ unlines
[ "module Build_elm_format where"
, ""
, "gitDescribe :: String"
, "gitDescribe = " ++ show (gitDescribe :: String)
]
Shakefiles.Haskell.cabalProject "avh4-lib"
[ "avh4-lib/avh4-lib.cabal" ]
[ "avh4-lib/src//*.hs" ]
[]
[ "avh4-lib/test//*.hs" ]
[]
Shakefiles.Haskell.cabalProject "elm-format-markdown"
[ "elm-format-markdown/elm-format-markdown.cabal" ]
[ "elm-format-markdown/src//*.hs"
, "elm-format-markdown//*.hs"
]
[] [] []
Shakefiles.Haskell.cabalProject "elm-format-lib"
[ "elm-format-lib/elm-format-lib.cabal" ]
[ "elm-format-lib/src//*.hs" ]
[ "avh4-lib"
, "elm-format-markdown"
]
[ "elm-format-lib/test//*.hs" ]
[ "elm-format-test-lib" ]
Shakefiles.Haskell.cabalProject "elm-format-test-lib"
[ "elm-format-test-lib/elm-format-test-lib.cabal" ]
[ "elm-format-test-lib/src//*.hs" ]
[ "avh4-lib" ]
[ "elm-format-test-lib/test//*.hs" ]
[]
Shakefiles.Haskell.cabalProject "elm-format"
[ "elm-format.cabal"
, "generated/Build_elm_format.hs"
]
[ "src//*.hs" ]
[ "avh4-lib"
, "elm-format-lib"
]
[ "tests//*.hs"
, "tests//*.stdout"
, "tests//*.stderr"
]
[ "elm-format-test-lib" ]
Shakefiles.Haskell.executable elmFormat "elm-format" gitDescribe
--
-- integration tests
--
phony "integration-tests" $
need
[ "_build/run-tests.ok"
, "_build/tests/test-files/good-json.ok"
, "_build/tests/test-files/good/Elm-0.19.ok"
, "_build/tests/test-files/good/Elm-0.18.ok"
, "_build/tests/test-files/good/Elm-0.17.ok"
, "_build/tests/test-files/transform/Elm-0.19.ok"
, "_build/tests/test-files/transform/Elm-0.18.ok"
, "_build/tests/test-files/transform/Elm-0.17.ok"
, "_build/tests/test-files/bad/Elm-0.19.ok"
, "_build/tests/test-files/bad/Elm-0.18.ok"
, "_build/tests/test-files/bad/Elm-0.17.ok"
]
"_build/run-tests.ok" %> \out -> do
let script = "tests/run-tests.sh"
need [ script, elmFormat ]
testFiles <- getDirectoryFiles ""
[ "tests/test-files/good/json//*.elm"
, "tests/test-files/bad//*.elm"
, "tests/test-files/directory//*.elm"
, "tests/test-files/recursive-directory//*.elm"
, "tests/test-files/*.json"
]
need testFiles
cmd_ ("bash" <.> exe) script elmFormat
writeFile' out ""
"_build/tests/test-files/prof.ok" %> \out -> do
let oks =
[ "_build/tests/test-files/good/Elm-0.17/prof.ok"
, "_build/tests/test-files/good/Elm-0.18/prof.ok"
, "_build/tests/test-files/good/Elm-0.19/prof.ok"
]
need oks
writeFile' out (unlines oks)
-- Elm files
let elmVersions = [ "0.17", "0.18", "0.19" ]
forM_ elmVersions $ \elmVersion -> do
("_build/tests/test-files/good/Elm-" ++ elmVersion ++ ".ok") %> \out -> do
elmFiles <- getDirectoryFiles ""
[ "tests/test-files/good/Elm-" ++ elmVersion ++ "//*.elm"
]
let oks = ["_build" </> f -<.> "elm_matches" | f <- elmFiles]
need oks
writeFile' out (unlines elmFiles)
("_build/tests/test-files/good/Elm-" ++ elmVersion ++ "/prof.ok") %> \out -> do
alwaysRerun
elmFiles <- getDirectoryFiles ""
[ "tests/test-files/good/Elm-" ++ elmVersion ++ "//*.elm"
]
let oks = ["_profile" </> f -<.> (gitSha ++ ".prof") | f <- elmFiles]
need oks
writeFile' out (unlines oks)
("_profile/tests/test-files/good/Elm-" ++ elmVersion ++ "//*." ++ gitSha ++ ".prof") %> \out -> do
let source = dropDirectory1 $ dropExtensions out <.> "elm"
need [ "_build/bin/elm-format-prof", source ]
cmd_ "_build/bin/elm-format-prof" source "--output" "/dev/null" ("--elm-version=" ++ elmVersion) "+RTS" "-p" ("-po" ++ (out -<.> ""))
("_build/tests/test-files/*/Elm-" ++ elmVersion ++ "//*.elm_formatted") %> \out -> do
let source = dropDirectory1 $ out -<.> "elm"
need [ elmFormat, source ]
cmd_ elmFormat source "--output" out ("--elm-version=" ++ elmVersion)
("_build/tests/test-files/*/Elm-" ++ elmVersion ++ "//*.elm_stderr") %> \out -> do
let source = dropDirectory1 $ out -<.> "elm"
need [ elmFormat, source ]
(Stderr stderr, Exit _) <- cmd (FileStdin source) BinaryPipes elmFormat "--stdin" ("--elm-version=" ++ elmVersion)
cmd_ (FileStdout out) (Stdin stderr) BinaryPipes "tr" [ "-d", "\r" ]
("_build/tests/test-files/transform/Elm-" ++ elmVersion ++ ".ok") %> \out -> do
elmFiles <- getDirectoryFiles ""
[ "tests/test-files/transform/Elm-" ++ elmVersion ++ "//*.elm"
]
let oks = ["_build" </> f -<.> "elm_transform_matches" | f <- elmFiles, takeExtension (dropExtension f) /= ".formatted" ]
need oks
writeFile' out (unlines oks)
("_build/tests/test-files/bad/Elm-" ++ elmVersion ++ ".ok") %> \out -> do
elmFiles <- getDirectoryFiles ""
[ "tests/test-files/bad/Elm-" ++ elmVersion ++ "//*.elm"
]
let oks = ["_build" </> f -<.> "elm_bad_matches" | f <- elmFiles ]
need oks
writeFile' out (unlines elmFiles)
"_build/tests//*.elm_matches" %> \out -> do
let actual = out -<.> "elm_formatted"
let expected = dropDirectory1 $ out -<.> "elm"
need [ actual, expected ]
cmd_ "diff" "-u" actual expected
writeFile' out ""
"_build/tests//*.elm_transform_matches" %> \out -> do
let actual = out -<.> "elm_formatted"
let expected = dropDirectory1 $ out -<.> "formatted.elm"
need [ actual, expected ]
cmd_ "diff" "-u" actual expected
writeFile' out ""
"_build/tests//*.elm_bad_matches" %> \out -> do
let actual = out -<.> "elm_stderr"
let expected = dropDirectory1 $ out -<.> "output.txt"
need [ actual, expected ]
cmd_ "diff" "--strip-trailing-cr" "-u" actual expected
writeFile' out ""
-- JSON files
"_build/tests/test-files/good-json.ok" %> \out -> do
jsonFiles <- getDirectoryFiles ""
[ "tests/test-files/good//*.json"
]
let oks = ["_build" </> f -<.> "json_matches" | f <- jsonFiles]
need oks
writeFile' out (unlines jsonFiles)
"_build/tests//*.json_formatted" %> \out -> do
let source = dropDirectory1 $ out -<.> "elm"
need [ elmFormat, source ]
(Stdout rawJson) <- cmd (FileStdin source) elmFormat "--elm-version=0.19" "--stdin" "--json"
(Stdout formattedJson) <- cmd (Stdin rawJson) "jq" "--indent" "4" "--sort-keys" "--ascii-output" "."
writeFileChanged out formattedJson
"_build/tests//*.json_matches" %> \out -> do
let actual = out -<.> "json_formatted"
let expected = dropDirectory1 $ out -<.> "json"
need [ actual, expected ]
cmd_ "diff" "--strip-trailing-cr" "-u" actual expected
writeFile' out ""
Shakefiles.Shellcheck.rules shellcheck