@@ -23,14 +23,16 @@ import System.Info ( os
23
23
, arch
24
24
)
25
25
26
- import Data.List ( dropWhileEnd )
26
+ import Data.List ( dropWhileEnd
27
+ , intersperse
28
+ )
27
29
import Data.Char ( isSpace )
28
30
29
31
type VersionNumber = String
30
32
type GhcPath = String
31
33
32
34
-- | Defines all different hie versions that are buildable.
33
- -- If they are edited,
35
+ -- If they are edited, make sure to maintain the order of the versions.
34
36
hieVersions :: [VersionNumber ]
35
37
hieVersions =
36
38
[" 8.2.1" , " 8.2.2" , " 8.4.2" , " 8.4.3" , " 8.4.4" , " 8.6.1" , " 8.6.2" , " 8.6.3" ]
@@ -62,11 +64,8 @@ main = do
62
64
phony " test" (forM_ hieVersions test)
63
65
phony " build-copy-compiler-tool" $ forM_ hieVersions buildCopyCompilerTool
64
66
65
- forM_
66
- hieVersions
67
- (\ version -> phony (" build-doc-hie-" ++ version) $ do
68
- buildDoc version
69
- )
67
+ forM_ hieVersions
68
+ (\ version -> phony (" build-doc-hie-" ++ version) $ buildDoc version)
70
69
71
70
forM_
72
71
hieVersions
@@ -148,14 +147,14 @@ buildHie :: VersionNumber -> Action ()
148
147
buildHie versionNumber = do
149
148
when (versionNumber `elem` [" hie-8.2.2" , " hie-8.2.1" ])
150
149
$ execStackWithYaml_ versionNumber [" install" , " happy" ]
151
- ( execStackWithYaml_ versionNumber [" build" ]) `actionOnException`
152
- liftIO (putStrLn buildFailMsg)
150
+ execStackWithYaml_ versionNumber [" build" ]
151
+ `actionOnException` liftIO (putStrLn buildFailMsg)
153
152
154
153
buildFailMsg :: String
155
154
buildFailMsg =
156
- let starsLine = " \n ****************************************************************** \n "
157
- in
158
- starsLine
155
+ let starsLine
156
+ = " \n ****************************************************************** \n "
157
+ in starsLine
159
158
++ " building failed, "
160
159
++ " try running `stack clean` and restart the build\n "
161
160
++ " if this does not work, open an issue at \n "
@@ -187,36 +186,59 @@ buildDoc versionNumber = do
187
186
188
187
helpMessage :: Action ()
189
188
helpMessage = do
190
- let out = liftIO . putStrLn
191
189
scriptName <- liftIO getProgName
192
190
out " "
193
191
out " Usage:"
194
- out (" stack " <> scriptName <> " <target>" )
192
+ out' (" stack " <> scriptName <> " <target>" )
195
193
out " "
196
194
out " Targets:"
197
- out
198
- " build Builds hie for all supported GHC versions (8.2.1, 8.2.2, 8.4.2, 8.4.3, 8.4.4, 8.6.1, 8.6.2 and 8.6.3)"
199
- out
200
- " build-all Builds hie and hoogle databases for all supported GHC versions"
201
- out " hie-8.2.1 Builds hie for GHC version 8.2.1 only"
202
- out " hie-8.2.2 Builds hie for GHC version 8.2.2 only"
203
- out " hie-8.4.2 Builds hie for GHC version 8.4.2 only"
204
- out " hie-8.4.3 Builds hie for GHC version 8.4.3 only"
205
- out " hie-8.4.4 Builds hie for GHC version 8.4.4 only"
206
- out " hie-8.6.1 Builds hie for GHC version 8.6.1 only"
207
- out " hie-8.6.2 Builds hie for GHC version 8.6.2 only"
208
- out " hie-8.6.3 Builds hie for GHC version 8.6.3 only"
209
- out " submodules Updates local git submodules"
210
- out
211
- " cabal NOTE 3: This is needed for stack only projects too"
212
- out
213
- " build-docs Builds the Hoogle database for all supported GHC versions"
214
- out " test Runs hie tests"
215
- out " icu-macos-fix Fixes icu related problems in MacOS"
216
- out
217
- " dist Creates a tarball containing all the hie binaries"
218
- out " help Show help"
195
+ mapM_ (out' . showTarget) targets
219
196
out " "
197
+ where
198
+ out = liftIO . putStrLn
199
+ out' = out . (" " ++ )
200
+ -- | Number of spaces the target name including whitespace should have.
201
+ -- At least twenty, maybe more if target names are long. At most length of the longest target plus five.
202
+ space :: Int
203
+ space = maximum (20 : map ((+ 5 ) . length . fst ) targets)
204
+
205
+ -- | Show a target.
206
+ -- Concatenates the target with its help message and inserts whitespace between them.
207
+ showTarget :: (String , String ) -> String
208
+ showTarget (target, msg) =
209
+ target ++ replicate (space - length target) ' ' ++ msg
210
+
211
+ -- | Target for a specific ghc version
212
+ hieTarget :: String -> (String , String )
213
+ hieTarget version =
214
+ (" hie-" ++ version, " Builds hie for GHC version " ++ version ++ " only" )
215
+
216
+ allVersionMessage :: String
217
+ allVersionMessage =
218
+ let msg = intersperse " , " hieVersions
219
+ lastVersion = last msg
220
+ in concat $ (init $ init msg) ++ [" and " , lastVersion]
221
+
222
+ -- All targets with their respective help message.
223
+ targets =
224
+ [ ( " build"
225
+ , " Builds hie for all supported GHC versions ("
226
+ ++ allVersionMessage
227
+ ++ " )"
228
+ )
229
+ , ( " build-all"
230
+ , " Builds hie and hoogle databases for all supported GHC versions"
231
+ )
232
+ , (" cabal" , " NOTE 3: This is needed for stack only projects too" )
233
+ , ( " build-docs"
234
+ , " Builds the Hoogle database for all supported GHC versions"
235
+ )
236
+ , (" test" , " Runs hie tests" )
237
+ , (" icu-macos-fix" , " Fixes icu related problems in MacOS" )
238
+ , (" dist" , " Creates a tarball containing all the hie binaries" )
239
+ , (" help" , " Show help" )
240
+ ]
241
+ ++ map hieTarget hieVersions
220
242
221
243
execStackWithYaml_ :: VersionNumber -> [String ] -> Action ()
222
244
execStackWithYaml_ versionNumber args = do
0 commit comments