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