@@ -23,14 +23,16 @@ import System.Info ( os
2323 , arch
2424 )
2525
26- import Data.List ( dropWhileEnd )
26+ import Data.List ( dropWhileEnd
27+ , intersperse
28+ )
2729import Data.Char ( isSpace )
2830
2931type VersionNumber = String
3032type GhcPath = String
3133
3234-- | 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.
3436hieVersions :: [VersionNumber ]
3537hieVersions =
3638 [" 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
6264 phony " test" (forM_ hieVersions test)
6365 phony " build-copy-compiler-tool" $ forM_ hieVersions buildCopyCompilerTool
6466
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)
7069
7170 forM_
7271 hieVersions
@@ -148,14 +147,14 @@ buildHie :: VersionNumber -> Action ()
148147buildHie versionNumber = do
149148 when (versionNumber `elem` [" hie-8.2.2" , " hie-8.2.1" ])
150149 $ execStackWithYaml_ versionNumber [" install" , " happy" ]
151- ( execStackWithYaml_ versionNumber [" build" ]) `actionOnException`
152- liftIO (putStrLn buildFailMsg)
150+ execStackWithYaml_ versionNumber [" build" ]
151+ `actionOnException` liftIO (putStrLn buildFailMsg)
153152
154153buildFailMsg :: String
155154buildFailMsg =
156- let starsLine = " \n ****************************************************************** \n "
157- in
158- starsLine
155+ let starsLine
156+ = " \n ****************************************************************** \n "
157+ in starsLine
159158 ++ " building failed, "
160159 ++ " try running `stack clean` and restart the build\n "
161160 ++ " if this does not work, open an issue at \n "
@@ -187,36 +186,59 @@ buildDoc versionNumber = do
187186
188187helpMessage :: Action ()
189188helpMessage = do
190- let out = liftIO . putStrLn
191189 scriptName <- liftIO getProgName
192190 out " "
193191 out " Usage:"
194- out (" stack " <> scriptName <> " <target>" )
192+ out' (" stack " <> scriptName <> " <target>" )
195193 out " "
196194 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
219196 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
220242
221243execStackWithYaml_ :: VersionNumber -> [String ] -> Action ()
222244execStackWithYaml_ versionNumber args = do
0 commit comments