From 34f1347385ec2c58d4f2cc766f3b829e08fd8455 Mon Sep 17 00:00:00 2001 From: fendor Date: Sun, 3 Feb 2019 11:36:53 +0100 Subject: [PATCH 01/19] First draft of cabal targets --- install.hs | 162 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 119 insertions(+), 43 deletions(-) diff --git a/install.hs b/install.hs index e0587fbae..c6e46fdfb 100755 --- a/install.hs +++ b/install.hs @@ -49,33 +49,54 @@ main = do unsetEnv "GHC_PACKAGE_PATH" shakeArgs shakeOptions { shakeFiles = "_build" } $ do want ["help"] - phony "ghc" $ do - ghc <- getGhcPath - command_ [] ghc ["--version"] - liftIO $ putStrLn "GHC" + -- general purpose targets phony "submodules" updateSubmodules - phony "cabal" (getGhcPath >>= installCabal) + phony "cabal" (getGhcPath mostRecentHieVersion >>= installCabal) phony "all" helpMessage phony "help" helpMessage + phony "dist" buildDist + + -- stack specific targets phony "build" (need (reverse $ map ("hie-" ++) hieVersions)) phony "build-all" (need ["build"] >> need ["build-docs"]) - phony "dist" buildDist phony "build-docs" (need (reverse $ map ("build-doc-hie-" ++) hieVersions)) - phony "test" (forM_ hieVersions test) + phony "test" (forM_ hieVersions stackTest) phony "build-copy-compiler-tool" $ forM_ hieVersions buildCopyCompilerTool - - forM_ hieVersions - (\version -> phony ("build-doc-hie-" ++ version) $ buildDoc version) - + forM_ + hieVersions + (\version -> phony ("build-doc-hie-" ++ version) $ stackBuildDoc version) forM_ hieVersions (\version -> phony ("hie-" ++ version) $ do need ["submodules"] need ["cabal"] - buildHie version - installHie version + stackBuildHie version + stackInstallHie version + ) + + -- cabal specific targets + phony "cabal-build" (need (reverse $ map ("cabal-hie-" ++) hieVersions)) + phony "cabal-build-all" (need ["cabal-build"] >> need ["cabal-build-docs"]) + phony "cabal-build-docs" + (need (reverse $ map ("cabal-build-doc-hie-" ++) hieVersions)) + phony "cabal-test" (forM_ hieVersions stackTest) + forM_ + hieVersions + (\version -> phony ("cabal-build-doc-hie-" ++ version) $ do + configureCabal version + cabalBuildDoc version + ) + forM_ + hieVersions + (\version -> phony ("cabal-hie-" ++ version) $ do + need ["submodules"] + need ["cabal"] + configureCabal version + cabalBuildHie + cabalInstallHie version ) + -- macos specific targets phony "icu-macos-fix" (need ["icu-macos-fix-install"] >> need ["icu-macos-fix-build"]) phony "icu-macos-fix-install" (command_ [] "brew" ["install", "icu4c"]) @@ -99,7 +120,7 @@ buildDist = do withTempDir (\temporaryDir -> do forM_ hieVersions $ \hieVersion -> do - buildHie hieVersion + stackBuildHie hieVersion -- after building `hie` copy it to the temporary folder localInstallRoot <- getLocalInstallRoot hieVersion copyFile' (localInstallRoot "bin" hie) @@ -137,16 +158,39 @@ updateSubmodules = do command_ [] "git" ["submodule", "sync", "--recursive"] command_ [] "git" ["submodule", "update", "--init", "--recursive"] + +configureCabal :: VersionNumber -> Action () +configureCabal versionNumber = do + ghcPath <- getGhcPath versionNumber + execCabal_ ["new-configure", "-w", ghcPath] + +cabalBuildHie :: Action () +cabalBuildHie = execCabal_ ["new-build"] + +cabalInstallHie :: VersionNumber -> Action () +cabalInstallHie versionNumber = do + localInstallBin <- getLocalBin versionNumber + execCabal_ ["new-install", "exe:hie", "--symlink-bindir", localInstallBin] + +cabalBuildDoc :: VersionNumber -> Action () +cabalBuildDoc versionNumber = do + configureCabal versionNumber + execCabal_ ["new-exec", "hoogle", "generate"] + +cabalTest :: VersionNumber -> Action () +cabalTest versionNumber = do + configureCabal versionNumber + execCabal_ ["new-test"] + installCabal :: GhcPath -> Action () installCabal ghc = do execStack_ ["install", "cabal-install"] execCabal_ ["update"] execCabal_ ["install", "Cabal-2.4.1.0", "--with-compiler=" ++ ghc] -buildHie :: VersionNumber -> Action () -buildHie versionNumber = do - when (versionNumber `elem` ["hie-8.2.2", "hie-8.2.1"]) - $ execStackWithYaml_ versionNumber ["install", "happy"] +stackBuildHie :: VersionNumber -> Action () +stackBuildHie versionNumber = do + execStackWithYaml_ versionNumber ["install", "happy"] execStackWithYaml_ versionNumber ["build"] `actionOnException` liftIO (putStrLn buildFailMsg) @@ -161,10 +205,10 @@ buildFailMsg = ++ "https://github.com/haskell/haskell-ide-engine" ++ starsLine -installHie :: VersionNumber -> Action () -installHie versionNumber = do +stackInstallHie :: VersionNumber -> Action () +stackInstallHie versionNumber = do execStackWithYaml_ versionNumber ["install"] - localBinDir <- getLocalBin + localBinDir <- getLocalBin versionNumber localInstallRoot <- getLocalInstallRoot versionNumber let hie = "hie" <.> exe copyFile' (localInstallRoot "bin" hie) @@ -176,11 +220,11 @@ buildCopyCompilerTool :: VersionNumber -> Action () buildCopyCompilerTool versionNumber = execStackWithYaml_ versionNumber ["build", "--copy-compiler-tool"] -test :: VersionNumber -> Action () -test versionNumber = execStackWithYaml_ versionNumber ["test"] +stackTest :: VersionNumber -> Action () +stackTest versionNumber = execStackWithYaml_ versionNumber ["test"] -buildDoc :: VersionNumber -> Action () -buildDoc versionNumber = do +stackBuildDoc :: VersionNumber -> Action () +stackBuildDoc versionNumber = do execStackWithYaml_ versionNumber ["install", "hoogle"] execStackWithYaml_ versionNumber ["exec", "hoogle", "generate"] @@ -209,9 +253,17 @@ helpMessage = do target ++ replicate (space - length target) ' ' ++ msg -- |Target for a specific ghc version - hieTarget :: String -> (String, String) - hieTarget version = - ("hie-" ++ version, "Builds hie for GHC version " ++ version ++ " only") + stackHieTarget :: String -> (String, String) + stackHieTarget version = + ( "hie-" ++ version + , "Builds hie for GHC version " ++ version ++ " only with stack" + ) + -- |Target for a specific ghc version + cabalHieTarget :: String -> (String, String) + cabalHieTarget version = + ( "cabal-hie-" ++ version + , "Builds hie for GHC version " ++ version ++ " only with cabal new-build" + ) allVersionMessage :: String allVersionMessage = @@ -219,8 +271,19 @@ helpMessage = do lastVersion = last msg in concat $ (init $ init msg) ++ [" and ", lastVersion] + -- All targets the shake file supports + targets = generalTargets ++ stackTargets ++ cabalTargets ++ macosTargets + -- All targets with their respective help message. - targets = + generalTargets = + [ ("help" , "Show help") + , ("cabal", "NOTE 3: This is needed for stack only projects too") + , ("dist", "Creates a tarball containing all the hie binaries") + ] + + macosTargets = [("icu-macos-fix", "Fixes icu related problems in MacOS")] + + stackTargets = [ ( "build" , "Builds hie for all supported GHC versions (" ++ allVersionMessage @@ -229,16 +292,28 @@ helpMessage = do , ( "build-all" , "Builds hie and hoogle databases for all supported GHC versions" ) - , ("cabal", "NOTE 3: This is needed for stack only projects too") , ( "build-docs" , "Builds the Hoogle database for all supported GHC versions" ) - , ("test" , "Runs hie tests") - , ("icu-macos-fix", "Fixes icu related problems in MacOS") - , ("dist", "Creates a tarball containing all the hie binaries") - , ("help" , "Show help") + , ("test", "Runs hie tests with stack") + ] + ++ map stackHieTarget hieVersions + + cabalTargets = + [ ( "cabal-build" + , "Builds hie with cabal for all supported GHC versions (" + ++ allVersionMessage + ++ ")" + ) + , ( "cabal-build-all" + , "Builds hie and hoogle databases for all supported GHC versions with cabal" + ) + , ( "cabal-build-docs" + , "Builds the Hoogle database for all supported GHC versions with cabal" + ) + , ("cabal-test", "Runs hie tests with cabal") ] - ++ map hieTarget hieVersions + ++ map cabalHieTarget hieVersions execStackWithYaml_ :: VersionNumber -> [String] -> Action () execStackWithYaml_ versionNumber args = do @@ -259,11 +334,11 @@ execStack_ = command_ [] "stack" execCabal_ :: [String] -> Action () execCabal_ = command_ [] "cabal" --- |Get the path to the GHC compiler executable linked to the local `stack.yaml` --- Equal to the command `stack path --compiler-exe` -getGhcPath :: Action GhcPath -getGhcPath = do - Stdout ghc' <- execStack ["path", "--compiler-exe"] +-- |Get the path to the GHC compiler executable linked to the local `stack-$GHCVER.yaml` +-- Equal to the command `stack path --stack-yaml $stack-yaml --compiler-exe` +getGhcPath :: VersionNumber -> Action GhcPath +getGhcPath hieVersion = do + Stdout ghc' <- execStackWithYaml hieVersion ["path", "--compiler-exe"] return $ trim ghc' -- |Read the local install root of the stack project specified by the VersionNumber @@ -278,9 +353,10 @@ getLocalInstallRoot hieVersion = do -- |Get the local binary path of stack. -- Equal to the command `stack path --local-bin` -getLocalBin :: Action FilePath -getLocalBin = do - Stdout stackLocalDir' <- execStack ["path", "--local-bin"] +getLocalBin :: VersionNumber -> Action FilePath +getLocalBin versionNumber = do + Stdout stackLocalDir' <- execStackWithYaml versionNumber + ["path", "--local-bin"] return $ trim stackLocalDir' -- |Trim the end of a string From e11d278f01628623ed1c0614de5abc4eb5218fea Mon Sep 17 00:00:00 2001 From: fendor Date: Tue, 12 Feb 2019 16:44:43 +0100 Subject: [PATCH 02/19] Discover installed GHCs and show them Also updates the target `cabal-build` to only build hie for versions that are installed --- install.hs | 116 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 89 insertions(+), 27 deletions(-) diff --git a/install.hs b/install.hs index c6e46fdfb..0c2d2a7ed 100755 --- a/install.hs +++ b/install.hs @@ -4,6 +4,7 @@ --install-ghc runghc --package shake + --package directory --package tar --package zlib -} @@ -16,6 +17,7 @@ import Development.Shake import Development.Shake.Command import Development.Shake.FilePath import Control.Monad +import System.Directory ( findExecutable ) import System.Environment ( getProgName , unsetEnv ) @@ -51,11 +53,23 @@ main = do want ["help"] -- general purpose targets phony "submodules" updateSubmodules - phony "cabal" (getGhcPath mostRecentHieVersion >>= installCabal) + phony "cabal" (getStackGhcPath mostRecentHieVersion >>= installCabal) phony "all" helpMessage phony "help" helpMessage phony "dist" buildDist + phony "cabal-ghcs" $ do + ghcPaths <- findInstalledGhcs + let + msg = + "Found the following GHC paths: \n" + ++ unlines + (map (\(version, path) -> "ghc-" ++ version ++ ": " ++ path) + ghcPaths + ) + liftIO $ putStrLn $ embedInStars msg + + -- stack specific targets phony "build" (need (reverse $ map ("hie-" ++) hieVersions)) phony "build-all" (need ["build"] >> need ["build-docs"]) @@ -75,11 +89,18 @@ main = do ) -- cabal specific targets - phony "cabal-build" (need (reverse $ map ("cabal-hie-" ++) hieVersions)) + phony "cabal-build" $ do + ghcPaths <- findInstalledGhcs + let ghcVersions = map fst ghcPaths + need (reverse $ map ("cabal-hie-" ++) ghcVersions) + phony "cabal-build-all" (need ["cabal-build"] >> need ["cabal-build-docs"]) - phony "cabal-build-docs" - (need (reverse $ map ("cabal-build-doc-hie-" ++) hieVersions)) - phony "cabal-test" (forM_ hieVersions stackTest) + phony "cabal-build-docs" $ do + ghcPaths <- findInstalledGhcs + let ghcVersions = map fst ghcPaths + need (reverse $ map ("cabal-hie-" ++) ghcVersions) + + -- phony "cabal-test" (forM_ hieVersions stackTest) forM_ hieVersions (\version -> phony ("cabal-build-doc-hie-" ++ version) $ do @@ -158,12 +179,27 @@ updateSubmodules = do command_ [] "git" ["submodule", "sync", "--recursive"] command_ [] "git" ["submodule", "update", "--init", "--recursive"] - configureCabal :: VersionNumber -> Action () configureCabal versionNumber = do - ghcPath <- getGhcPath versionNumber + ghcPath' <- getGhcPath versionNumber + ghcPath <- case ghcPath' of + Nothing -> do + liftIO $ putStrLn $ embedInStars (ghcVersionNotFound versionNumber) + error (ghcVersionNotFound versionNumber) + Just p -> return p execCabal_ ["new-configure", "-w", ghcPath] +findInstalledGhcs :: Action [(VersionNumber, GhcPath)] +findInstalledGhcs = foldM + (\found version -> do + path <- getGhcPath version + case path of + Nothing -> return found + Just p -> return $ (version, p) : found + ) + [] + hieVersions + cabalBuildHie :: Action () cabalBuildHie = execCabal_ ["new-build"] @@ -196,14 +232,11 @@ stackBuildHie versionNumber = do buildFailMsg :: String buildFailMsg = - let starsLine - = "\n******************************************************************\n" - in starsLine - ++ "building failed, " - ++ "try running `stack clean` and restart the build\n" - ++ "if this does not work, open an issue at \n" - ++ "https://github.com/haskell/haskell-ide-engine" - ++ starsLine + embedInStars + $ "building failed, " + ++ "try running `stack clean` and restart the build\n" + ++ "if this does not work, open an issue at \n" + ++ "https://github.com/haskell/haskell-ide-engine" stackInstallHie :: VersionNumber -> Action () stackInstallHie versionNumber = do @@ -300,16 +333,17 @@ helpMessage = do ++ map stackHieTarget hieVersions cabalTargets = - [ ( "cabal-build" - , "Builds hie with cabal for all supported GHC versions (" - ++ allVersionMessage - ++ ")" + [ ( "cabal-ghcs" + , "Show all GHC versions that can be installed via `cabal-build` and `cabal-build-all`." ) + , ( "cabal-build" + , "Builds hie with cabal with all installed GHCs. Target `cabal-ghcs` shows all GHC versions that will be installed" + ) , ( "cabal-build-all" - , "Builds hie and hoogle databases for all supported GHC versions with cabal" + , "Builds hie and hoogle databases for all installed GHC versions with cabal" ) , ( "cabal-build-docs" - , "Builds the Hoogle database for all supported GHC versions with cabal" + , "Builds the Hoogle database for all installed GHC versions with cabal" ) , ("cabal-test", "Runs hie tests with cabal") ] @@ -334,12 +368,28 @@ execStack_ = command_ [] "stack" execCabal_ :: [String] -> Action () execCabal_ = command_ [] "cabal" --- |Get the path to the GHC compiler executable linked to the local `stack-$GHCVER.yaml` --- Equal to the command `stack path --stack-yaml $stack-yaml --compiler-exe` -getGhcPath :: VersionNumber -> Action GhcPath -getGhcPath hieVersion = do - Stdout ghc' <- execStackWithYaml hieVersion ["path", "--compiler-exe"] - return $ trim ghc' +-- |Get the path to the GHC compiler executable linked to the local `stack-$GHCVER.yaml`. +-- Equal to the command `stack path --stack-yaml $stack-yaml --compiler-exe`. +-- This might install a GHC if it is not already installed, thus, might fail if stack fails to install the GHC. +getStackGhcPath :: VersionNumber -> Action GhcPath +getStackGhcPath ghcVersion = do + Stdout ghc <- execStackWithYaml ghcVersion ["path", "--compiler-exe"] + return $ trim ghc + +-- |Get the path to a GHC that has the version specified by `VersionNumber` +-- If no such GHC can be found, Nothing is returned. +getGhcPath :: VersionNumber -> Action (Maybe GhcPath) +getGhcPath ghcVersion = do + pathMay <- liftIO $ findExecutable ("ghc-" ++ ghcVersion) + case pathMay of + Nothing -> do + noPrefixPathMay <- liftIO $ findExecutable "ghc" + case noPrefixPathMay of + Nothing -> return Nothing + Just p -> do + Stdout version <- command [] p ["--numeric-version"] + if ghcVersion == trim version then return $ Just p else return Nothing + p -> return p -- |Read the local install root of the stack project specified by the VersionNumber -- Returns the filepath of the local install root. @@ -362,3 +412,15 @@ getLocalBin versionNumber = do -- |Trim the end of a string trim :: String -> String trim = dropWhileEnd isSpace + +-- |Embed a string within two lines of stars to improve readability. +embedInStars :: String -> String +embedInStars str = + let starsLine + = "\n******************************************************************\n" + in starsLine <> str <> starsLine + +-- |No suitable ghc version has been found. +ghcVersionNotFound :: VersionNumber -> String +ghcVersionNotFound versionNumber = + "No GHC with version " <> versionNumber <> " has been found." From c5c498d43538f4f5cd275e9c7094397104644d43 Mon Sep 17 00:00:00 2001 From: fendor Date: Sun, 17 Feb 2019 19:09:57 +0100 Subject: [PATCH 03/19] Remove generation of ghc environment file --- install.hs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/install.hs b/install.hs index 0c2d2a7ed..3d24ae187 100755 --- a/install.hs +++ b/install.hs @@ -98,12 +98,13 @@ main = do phony "cabal-build-docs" $ do ghcPaths <- findInstalledGhcs let ghcVersions = map fst ghcPaths - need (reverse $ map ("cabal-hie-" ++) ghcVersions) + need (reverse $ map ("cabal-build-doc-hie-" ++) ghcVersions) -- phony "cabal-test" (forM_ hieVersions stackTest) forM_ hieVersions (\version -> phony ("cabal-build-doc-hie-" ++ version) $ do + need ["submodules"] configureCabal version cabalBuildDoc version ) @@ -111,7 +112,6 @@ main = do hieVersions (\version -> phony ("cabal-hie-" ++ version) $ do need ["submodules"] - need ["cabal"] configureCabal version cabalBuildHie cabalInstallHie version @@ -187,7 +187,7 @@ configureCabal versionNumber = do liftIO $ putStrLn $ embedInStars (ghcVersionNotFound versionNumber) error (ghcVersionNotFound versionNumber) Just p -> return p - execCabal_ ["new-configure", "-w", ghcPath] + execCabal_ ["new-configure", "-w", ghcPath, "--write-ghc-environment-files=never"] findInstalledGhcs :: Action [(VersionNumber, GhcPath)] findInstalledGhcs = foldM @@ -201,12 +201,12 @@ findInstalledGhcs = foldM hieVersions cabalBuildHie :: Action () -cabalBuildHie = execCabal_ ["new-build"] +cabalBuildHie = execCabal_ ["new-build", "--write-ghc-environment-files=never"] cabalInstallHie :: VersionNumber -> Action () cabalInstallHie versionNumber = do - localInstallBin <- getLocalBin versionNumber - execCabal_ ["new-install", "exe:hie", "--symlink-bindir", localInstallBin] + execCabal_ ["new-install", "--write-ghc-environment-files=never", "exe:hie", "--overwrite-policy=always"] + execCabal_ ["new-install", "--write-ghc-environment-files=never", "exe:hie", "--overwrite-policy=always", "--program-suffix=-" ++ versionNumber] cabalBuildDoc :: VersionNumber -> Action () cabalBuildDoc versionNumber = do @@ -423,4 +423,5 @@ embedInStars str = -- |No suitable ghc version has been found. ghcVersionNotFound :: VersionNumber -> String ghcVersionNotFound versionNumber = - "No GHC with version " <> versionNumber <> " has been found." + "No GHC with version " <> versionNumber <> " has been found.\n" + <> "Either install a fitting GHC, use the stack targets or modify the PATH variable accordingly." From 4c8fc0df9af50f38bc42f4388372bbc97cd1df90 Mon Sep 17 00:00:00 2001 From: fendor Date: Mon, 18 Feb 2019 16:11:10 +0100 Subject: [PATCH 04/19] Fix order of hie linking with cabal --- install.hs | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/install.hs b/install.hs index 3d24ae187..b43e2f77c 100755 --- a/install.hs +++ b/install.hs @@ -92,13 +92,13 @@ main = do phony "cabal-build" $ do ghcPaths <- findInstalledGhcs let ghcVersions = map fst ghcPaths - need (reverse $ map ("cabal-hie-" ++) ghcVersions) + need (map ("cabal-hie-" ++) ghcVersions) phony "cabal-build-all" (need ["cabal-build"] >> need ["cabal-build-docs"]) phony "cabal-build-docs" $ do ghcPaths <- findInstalledGhcs let ghcVersions = map fst ghcPaths - need (reverse $ map ("cabal-build-doc-hie-" ++) ghcVersions) + need (map ("cabal-build-doc-hie-" ++) ghcVersions) -- phony "cabal-test" (forM_ hieVersions stackTest) forM_ @@ -187,7 +187,8 @@ configureCabal versionNumber = do liftIO $ putStrLn $ embedInStars (ghcVersionNotFound versionNumber) error (ghcVersionNotFound versionNumber) Just p -> return p - execCabal_ ["new-configure", "-w", ghcPath, "--write-ghc-environment-files=never"] + execCabal_ + ["new-configure", "-w", ghcPath, "--write-ghc-environment-files=never"] findInstalledGhcs :: Action [(VersionNumber, GhcPath)] findInstalledGhcs = foldM @@ -205,8 +206,19 @@ cabalBuildHie = execCabal_ ["new-build", "--write-ghc-environment-files=never"] cabalInstallHie :: VersionNumber -> Action () cabalInstallHie versionNumber = do - execCabal_ ["new-install", "--write-ghc-environment-files=never", "exe:hie", "--overwrite-policy=always"] - execCabal_ ["new-install", "--write-ghc-environment-files=never", "exe:hie", "--overwrite-policy=always", "--program-suffix=-" ++ versionNumber] + execCabal_ + [ "new-install" + , "--write-ghc-environment-files=never" + , "exe:hie" + , "--overwrite-policy=always" + ] + execCabal_ + [ "new-install" + , "--write-ghc-environment-files=never" + , "exe:hie" + , "--overwrite-policy=always" + , "--program-suffix=-" ++ versionNumber + ] cabalBuildDoc :: VersionNumber -> Action () cabalBuildDoc versionNumber = do @@ -423,5 +435,7 @@ embedInStars str = -- |No suitable ghc version has been found. ghcVersionNotFound :: VersionNumber -> String ghcVersionNotFound versionNumber = - "No GHC with version " <> versionNumber <> " has been found.\n" - <> "Either install a fitting GHC, use the stack targets or modify the PATH variable accordingly." + "No GHC with version " + <> versionNumber + <> " has been found.\n" + <> "Either install a fitting GHC, use the stack targets or modify the PATH variable accordingly." From 5cc1e85a040605846dad7d0467219339376b8c00 Mon Sep 17 00:00:00 2001 From: fendor Date: Mon, 18 Feb 2019 17:28:24 +0100 Subject: [PATCH 05/19] Change linking to always link to 'local-bin-path' --- install.hs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/install.hs b/install.hs index b43e2f77c..755205046 100755 --- a/install.hs +++ b/install.hs @@ -206,19 +206,16 @@ cabalBuildHie = execCabal_ ["new-build", "--write-ghc-environment-files=never"] cabalInstallHie :: VersionNumber -> Action () cabalInstallHie versionNumber = do + localBin <- getLocalBin execCabal_ [ "new-install" , "--write-ghc-environment-files=never" + , "--symlink-bindir=" ++ localBin , "exe:hie" , "--overwrite-policy=always" ] - execCabal_ - [ "new-install" - , "--write-ghc-environment-files=never" - , "exe:hie" - , "--overwrite-policy=always" - , "--program-suffix=-" ++ versionNumber - ] + copyFile' (localBin "hie" <.> exe) (localBin "hie-" ++ versionNumber <.> exe) + copyFile' (localBin "hie" <.> exe) (localBin "hie-" ++ dropExtension versionNumber <.> exe) cabalBuildDoc :: VersionNumber -> Action () cabalBuildDoc versionNumber = do @@ -253,7 +250,7 @@ buildFailMsg = stackInstallHie :: VersionNumber -> Action () stackInstallHie versionNumber = do execStackWithYaml_ versionNumber ["install"] - localBinDir <- getLocalBin versionNumber + localBinDir <- getLocalBin localInstallRoot <- getLocalInstallRoot versionNumber let hie = "hie" <.> exe copyFile' (localInstallRoot "bin" hie) @@ -415,10 +412,10 @@ getLocalInstallRoot hieVersion = do -- |Get the local binary path of stack. -- Equal to the command `stack path --local-bin` -getLocalBin :: VersionNumber -> Action FilePath -getLocalBin versionNumber = do - Stdout stackLocalDir' <- execStackWithYaml versionNumber - ["path", "--local-bin"] +getLocalBin :: Action FilePath +getLocalBin = do + Stdout stackLocalDir' <- execStack + ["path", "--stack-yaml=shake.yaml", "--local-bin"] return $ trim stackLocalDir' -- |Trim the end of a string From c11878d799277c45aad23d4f8cd78277242a99d8 Mon Sep 17 00:00:00 2001 From: fendor Date: Tue, 19 Feb 2019 13:23:54 +0100 Subject: [PATCH 06/19] Update help message of target cabal --- install.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.hs b/install.hs index cd5a70b14..aefb15152 100755 --- a/install.hs +++ b/install.hs @@ -348,7 +348,7 @@ helpMessage = do -- All targets with their respective help message. generalTargets = [ ("help" , "Show help") - , ("cabal", "NOTE 3: This is needed for stack only projects too") + , ("cabal", "Makes sure that Cabal the lib is available for cabal-helper-wapper, to speed up project start") , ("dist", "Creates a tarball containing all the hie binaries") ] From 218cef9337016e978120df0b1483578767e85523 Mon Sep 17 00:00:00 2001 From: fendor Date: Tue, 19 Feb 2019 13:24:54 +0100 Subject: [PATCH 07/19] Execute cabal-test only for installed GHCs --- install.hs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/install.hs b/install.hs index aefb15152..82e36df3e 100755 --- a/install.hs +++ b/install.hs @@ -107,7 +107,9 @@ main = do phony "cabal-test" $ do need ["submodules"] need ["cabal"] - forM_ hieVersions cabalTest + ghcPaths <- findInstalledGhcs + let ghcVersions = map fst ghcPaths + forM_ ghcVersions cabalTest -- phony "cabal-test" (forM_ hieVersions stackTest) forM_ @@ -347,8 +349,10 @@ helpMessage = do -- All targets with their respective help message. generalTargets = - [ ("help" , "Show help") - , ("cabal", "Makes sure that Cabal the lib is available for cabal-helper-wapper, to speed up project start") + [ ("help", "Show help") + , ( "cabal" + , "Makes sure that Cabal the lib is available for cabal-helper-wapper, to speed up project start" + ) , ("dist", "Creates a tarball containing all the hie binaries") ] From f446ee5d7ea5a9da721e7f23f4bebff322b2f65c Mon Sep 17 00:00:00 2001 From: fendor Date: Sun, 24 Feb 2019 21:06:44 +0100 Subject: [PATCH 08/19] Improve cabal-target API and add documentation --- install.hs | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/install.hs b/install.hs index 82e36df3e..a47a14d41 100755 --- a/install.hs +++ b/install.hs @@ -117,7 +117,6 @@ main = do (\version -> phony ("cabal-build-doc-" ++ version) $ do need ["submodules"] need ["cabal"] - configureCabal version cabalBuildDoc version ) forM_ @@ -125,8 +124,7 @@ main = do (\version -> phony ("cabal-hie-" ++ version) $ do need ["submodules"] need ["cabal"] - configureCabal version - cabalBuildHie + cabalBuildHie version cabalInstallHie version ) @@ -214,8 +212,10 @@ findInstalledGhcs = foldM [] hieVersions -cabalBuildHie :: Action () -cabalBuildHie = execCabal_ ["new-build", "--write-ghc-environment-files=never"] +cabalBuildHie :: VersionNumber -> Action () +cabalBuildHie versionNumber = do + configureCabal versionNumber + execCabal_ ["new-build", "--write-ghc-environment-files=never"] cabalInstallHie :: VersionNumber -> Action () cabalInstallHie versionNumber = do @@ -338,11 +338,16 @@ helpMessage = do ++ " only with cabal" ) - allVersionMessage :: String - allVersionMessage = - let msg = intersperse ", " hieVersions - lastVersion = last msg - in concat $ (init $ init msg) ++ [" and ", lastVersion] + -- | Creates a message of the form "a, b, c and d", where a,b,c,d are GHC versions. + -- If there is no GHC in the list of `hieVersions` + allVersionMessage :: [String] -> String + allVersionMessage wordList = case wordList of + [] -> "" + [a] -> show a + (a : as) -> + let msg = intersperse ", " wordList + lastVersion = last msg + in concat $ (init $ init msg) ++ [" and ", lastVersion] -- All targets the shake file supports targets = generalTargets ++ stackTargets ++ cabalTargets ++ macosTargets @@ -361,7 +366,7 @@ helpMessage = do stackTargets = [ ( "build" , "Builds hie for all supported GHC versions (" - ++ allVersionMessage + ++ allVersionMessage hieVersions ++ ")" ) , ( "build-all" @@ -393,7 +398,6 @@ helpMessage = do ++ map cabalHieTarget hieVersions ++ map cabalBuildDocTarget hieVersions - execStackWithYaml_ :: VersionNumber -> [String] -> Action () execStackWithYaml_ versionNumber args = do let stackFile = "stack-" ++ versionNumber ++ ".yaml" @@ -423,6 +427,9 @@ getStackGhcPath ghcVersion = do -- |Get the path to a GHC that has the version specified by `VersionNumber` -- If no such GHC can be found, Nothing is returned. +-- First, it is checked whether there is a GHC with the name `ghc-$VersionNumber`. +-- If this yields no result, it is checked, whether the numeric-version of the `ghc` +-- command fits to the desired version. getGhcPath :: VersionNumber -> Action (Maybe GhcPath) getGhcPath ghcVersion = do pathMay <- liftIO $ findExecutable ("ghc-" ++ ghcVersion) @@ -458,14 +465,14 @@ getLocalBin = do trim :: String -> String trim = dropWhileEnd isSpace --- |Embed a string within two lines of stars to improve readability. +-- |Embed a string within two lines of stars to improve perceivability and, thus, readability. embedInStars :: String -> String embedInStars str = let starsLine = "\n******************************************************************\n" in starsLine <> str <> starsLine --- |No suitable ghc version has been found. +-- |No suitable ghc version has been found. Show a message. ghcVersionNotFound :: VersionNumber -> String ghcVersionNotFound versionNumber = "No GHC with version " From e39f4b0a04b751ec4440cddf571deedf64a376b0 Mon Sep 17 00:00:00 2001 From: fendor Date: Sun, 24 Feb 2019 21:14:55 +0100 Subject: [PATCH 09/19] Install hoogle executable before generating documentation --- install.hs | 1 + 1 file changed, 1 insertion(+) diff --git a/install.hs b/install.hs index a47a14d41..44946ea04 100755 --- a/install.hs +++ b/install.hs @@ -235,6 +235,7 @@ cabalInstallHie versionNumber = do cabalBuildDoc :: VersionNumber -> Action () cabalBuildDoc versionNumber = do configureCabal versionNumber + execCabal_ ["new-install", "hoogle"] execCabal_ ["new-exec", "hoogle", "generate"] cabalTest :: VersionNumber -> Action () From 76e9b4d290c0fdd464faacd485669a22f671f576 Mon Sep 17 00:00:00 2001 From: fendor Date: Sun, 24 Feb 2019 21:25:53 +0100 Subject: [PATCH 10/19] Remove unused/unknown shake.yaml field 'extra-packages' --- shake.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/shake.yaml b/shake.yaml index 9f87ba09d..23c912f7b 100644 --- a/shake.yaml +++ b/shake.yaml @@ -3,8 +3,5 @@ resolver: lts-12.25 # GHC 8.4.4 packages: - . -extra-packages: -- shake-0.17.4 - nix: packages: [ zlib ] From 9feb9c496ec3f58bcce99dcbb8db48337ec861bf Mon Sep 17 00:00:00 2001 From: fendor Date: Wed, 27 Feb 2019 12:20:39 +0100 Subject: [PATCH 11/19] Throw an error if cabal target executed on windows --- install.hs | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/install.hs b/install.hs index 44946ea04..04f6e6b43 100755 --- a/install.hs +++ b/install.hs @@ -92,26 +92,19 @@ main = do stackInstallHie version ) - -- cabal specific targets - phony "cabal-build" $ do - ghcPaths <- findInstalledGhcs - let ghcVersions = map fst ghcPaths - need (map ("cabal-hie-" ++) ghcVersions) + ghcPaths <- findInstalledGhcs + let ghcVersions = map fst ghcPaths - phony "cabal-build-all" (need ["cabal-build-docs", "cabal-build"]) - phony "cabal-build-docs" $ do - ghcPaths <- findInstalledGhcs - let ghcVersions = map fst ghcPaths - need (map ("cabal-build-doc-" ++) ghcVersions) + -- cabal specific targets + phony "cabal-build" (need (map ("cabal-hie-" ++) ghcVersions)) + phony "cabal-build-all" (need ["cabal-build-docs", "cabal-build"]) + phony "cabal-build-docs" (need (map ("cabal-build-doc-" ++) ghcVersions)) phony "cabal-test" $ do need ["submodules"] need ["cabal"] - ghcPaths <- findInstalledGhcs - let ghcVersions = map fst ghcPaths forM_ ghcVersions cabalTest - -- phony "cabal-test" (forM_ hieVersions stackTest) forM_ hieVersions (\version -> phony ("cabal-build-doc-" ++ version) $ do @@ -122,6 +115,7 @@ main = do forM_ hieVersions (\version -> phony ("cabal-hie-" ++ version) $ do + validateCabalNewInstallIsSupported need ["submodules"] need ["cabal"] cabalBuildHie version @@ -190,6 +184,11 @@ updateSubmodules = do command_ [] "git" ["submodule", "sync", "--recursive"] command_ [] "git" ["submodule", "update", "--init", "--recursive"] +validateCabalNewInstallIsSupported :: Action () +validateCabalNewInstallIsSupported = when (os `elem` ["mingw32", "win32"]) $ do + liftIO $ putStrLn $ embedInStars cabalInstallNotSuported + error cabalInstallNotSuported + configureCabal :: VersionNumber -> Action () configureCabal versionNumber = do ghcPath' <- getGhcPath versionNumber @@ -480,3 +479,11 @@ ghcVersionNotFound versionNumber = <> versionNumber <> " has been found.\n" <> "Either install a fitting GHC, use the stack targets or modify the PATH variable accordingly." + +-- | Error message when a windows system tries to install HIE via `cabal new-install` +cabalInstallNotSuported :: String +cabalInstallNotSuported = + "This system has been identified as a windows system.\n" + ++ "Unfortunately, `cabal new-install` is currently not supported on windows.\n" + ++ "Please use one of the stack-based targets.\n\n" + ++ "If this system has been falsely identified, please open an issue at https://github.com/haskell/haskell-ide-engine\n" From 99621c9fa3f95d0b5508ab83334ad2ec21c6ee56 Mon Sep 17 00:00:00 2001 From: fendor Date: Wed, 27 Feb 2019 23:17:43 +0100 Subject: [PATCH 12/19] Fix type error in install.hs --- install.hs | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/install.hs b/install.hs index 04f6e6b43..c2d1e2381 100755 --- a/install.hs +++ b/install.hs @@ -49,6 +49,10 @@ main :: IO () main = do -- unset GHC_PACKAGE_PATH for cabal unsetEnv "GHC_PACKAGE_PATH" + + ghcPaths <- findInstalledGhcs + let ghcVersions = map fst ghcPaths + shakeArgs shakeOptions { shakeFiles = "_build" } $ do want ["help"] -- general purpose targets @@ -59,7 +63,6 @@ main = do phony "dist" buildDist phony "cabal-ghcs" $ do - ghcPaths <- findInstalledGhcs let msg = "Found the following GHC paths: \n" @@ -92,9 +95,6 @@ main = do stackInstallHie version ) - ghcPaths <- findInstalledGhcs - let ghcVersions = map fst ghcPaths - -- cabal specific targets phony "cabal-build" (need (map ("cabal-hie-" ++) ghcVersions)) phony "cabal-build-all" (need ["cabal-build-docs", "cabal-build"]) @@ -191,7 +191,7 @@ validateCabalNewInstallIsSupported = when (os `elem` ["mingw32", "win32"]) $ do configureCabal :: VersionNumber -> Action () configureCabal versionNumber = do - ghcPath' <- getGhcPath versionNumber + ghcPath' <- liftIO $ getGhcPath versionNumber ghcPath <- case ghcPath' of Nothing -> do liftIO $ putStrLn $ embedInStars (ghcVersionNotFound versionNumber) @@ -200,7 +200,7 @@ configureCabal versionNumber = do execCabal_ ["new-configure", "-w", ghcPath, "--write-ghc-environment-files=never"] -findInstalledGhcs :: Action [(VersionNumber, GhcPath)] +findInstalledGhcs :: IO [(VersionNumber, GhcPath)] findInstalledGhcs = foldM (\found version -> do path <- getGhcPath version @@ -252,15 +252,7 @@ stackBuildHie :: VersionNumber -> Action () stackBuildHie versionNumber = do execStackWithYaml_ versionNumber ["install", "happy"] execStackWithYaml_ versionNumber ["build"] - `actionOnException` liftIO (putStrLn buildFailMsg) - -buildFailMsg :: String -buildFailMsg = - embedInStars - $ "building failed, " - ++ "try running `stack clean` and restart the build\n" - ++ "if this does not work, open an issue at \n" - ++ "https://github.com/haskell/haskell-ide-engine" + `actionOnException` liftIO (putStrLn stackBuildFailMsg) stackInstallHie :: VersionNumber -> Action () stackInstallHie versionNumber = do @@ -430,16 +422,16 @@ getStackGhcPath ghcVersion = do -- First, it is checked whether there is a GHC with the name `ghc-$VersionNumber`. -- If this yields no result, it is checked, whether the numeric-version of the `ghc` -- command fits to the desired version. -getGhcPath :: VersionNumber -> Action (Maybe GhcPath) +getGhcPath :: VersionNumber -> IO (Maybe GhcPath) getGhcPath ghcVersion = do - pathMay <- liftIO $ findExecutable ("ghc-" ++ ghcVersion) + pathMay <- findExecutable ("ghc-" ++ ghcVersion) case pathMay of Nothing -> do - noPrefixPathMay <- liftIO $ findExecutable "ghc" + noPrefixPathMay <- findExecutable "ghc" case noPrefixPathMay of Nothing -> return Nothing Just p -> do - Stdout version <- command [] p ["--numeric-version"] + Stdout version <- cmd p ["--numeric-version"] :: IO (Stdout String) if ghcVersion == trim version then return $ Just p else return Nothing p -> return p @@ -472,6 +464,15 @@ embedInStars str = = "\n******************************************************************\n" in starsLine <> str <> starsLine +-- |Stack build fails message +stackBuildFailMsg :: String +stackBuildFailMsg = + embedInStars + $ "Building failed, " + ++ "Try running `stack clean` and restart the build\n" + ++ "If this does not work, open an issue at \n" + ++ "\thttps://github.com/haskell/haskell-ide-engine" + -- |No suitable ghc version has been found. Show a message. ghcVersionNotFound :: VersionNumber -> String ghcVersionNotFound versionNumber = From 4df099d579506b4e092a75b73f38074cf95bd482 Mon Sep 17 00:00:00 2001 From: fendor Date: Wed, 27 Feb 2019 23:18:28 +0100 Subject: [PATCH 13/19] Reformat error message --- install.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.hs b/install.hs index c2d1e2381..23493fed4 100755 --- a/install.hs +++ b/install.hs @@ -487,4 +487,4 @@ cabalInstallNotSuported = "This system has been identified as a windows system.\n" ++ "Unfortunately, `cabal new-install` is currently not supported on windows.\n" ++ "Please use one of the stack-based targets.\n\n" - ++ "If this system has been falsely identified, please open an issue at https://github.com/haskell/haskell-ide-engine\n" + ++ "If this system has been falsely identified, please open an issue at:\n\thttps://github.com/haskell/haskell-ide-engine\n" From 9f03297933db2f63076a538f043996f941f59dcb Mon Sep 17 00:00:00 2001 From: fendor Date: Thu, 28 Feb 2019 17:45:37 +0100 Subject: [PATCH 14/19] Update README to mention cabal-new-build based installs --- README.md | 113 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 90 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 760868d46..c41239315 100644 --- a/README.md +++ b/README.md @@ -18,29 +18,54 @@ This project aims to be __the universal interface__ to __a growing number of Has __We are currently focusing on using the [Language Server Protocol](https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md) as the interface via which we talk to clients.__ -- [Haskell IDE Engine](#haskell-ide-engine) - - [Features](#features) - - [Installation](#installation) - - [stack on Linux](#installation-with-stack-on-linux) - - [stack on Windows](#installation-with-stack-on-windows) - - [macOS](#installation-on-macos) - - [Nix](#installation-with-nix) - - [ArchLinux](#installation-on-archlinux) - - [Shake](#installation-with-shake) - - [Configuration](#configuration) - - [Editor Integration](#editor-integration) - - Using HIE with [VS Code](#using-hie-with-vs-code), [Sublime Text](#using-hie-with-sublime-text), [Vim/Neovim](#using-hie-with-vim-or-neovim), [Atom](#using-hie-with-atom), [Oni](#using-hie-with-oni), [Emacs](#using-hie-with-emacs), [Spacemacs](#using-hie-with-spacemacs) or [Spacemacs+Nix](#using-hie-with-spacemacs-on-nix-based-projects) - - [Docs on hover/completion](#docs-on-hovercompletion) - - [Contributing](#contributing) - - [Planned Features](#planned-features) - - [This is *not* yet another `ghc-mod` or `ide-backend` project](#this-is-not-yet-another-ghc-mod-or-ide-backend-project) - - [It's time to join the project!](#its-time-to-join-the-project) - - [Architecture](#architecture) - - [1. BIOS layer](#1-bios-layer) - - [2. Plugin layer](#2-plugin-layer) - - [3. IDE interfacing layer](#3-ide-interfacing-layer) - - [Documentation](#documentation) - - [Troubleshooting](#troubleshooting) +- [Haskell IDE Engine (HIE)](#haskell-ide-engine-hie) + - [Features](#features) + - [Installation](#installation) + - [Installation with Nix](#installation-with-nix) + - [Installation on ArchLinux](#installation-on-archlinux) + - [Installation from source](#installation-from-source) + - [Linux pre-requirements](#linux-pre-requirements) + - [Windows: long paths (optional)](#windows-long-paths-optional) + - [Download the source code](#download-the-source-code) + - [Choose your GHC version](#choose-your-ghc-version) + - [Install a specific GHC version 8.2.1 - 8.6.3](#install-a-specific-ghc-version-821---863) + - [For GHC 8.0.2](#for-ghc-802) + - [Install *all* available GHC versions](#install-all-available-ghc-versions) + - [Installation with Shake](#installation-with-shake) + - [Install specific GHC Version with Shake](#install-specific-ghc-version-with-shake) + - [Install *all* available GHC versions with Shake](#install-all-available-ghc-versions-with-shake) + - [Configuration](#configuration) + - [Editor Integration](#editor-integration) + - [Using HIE with VS Code](#using-hie-with-vs-code) + - [Using VS Code with Nix](#using-vs-code-with-nix) + - [Using HIE with Sublime Text](#using-hie-with-sublime-text) + - [Using HIE with Vim or Neovim](#using-hie-with-vim-or-neovim) + - [vim-plug](#vim-plug) + - [Vim 8.0](#vim-80) + - [Sample `~/.vimrc`](#sample-vimrc) + - [Using HIE with Atom](#using-hie-with-atom) + - [Using HIE with Emacs](#using-hie-with-emacs) + - [Using HIE with Spacemacs](#using-hie-with-spacemacs) + - [Using HIE with Spacemacs on Nix Based Projects](#using-hie-with-spacemacs-on-nix-based-projects) + - [Using HIE with Oni](#using-hie-with-oni) + - [Docs on hover/completion](#docs-on-hovercompletion) + - [Contributing](#contributing) + - [Planned Features](#planned-features) + - [This is *not* yet another `ghc-mod` or `ide-backend` project](#this-is-not-yet-another-ghc-mod-or-ide-backend-project) + - [It's time to join the project!](#its-time-to-join-the-project) + - [Architecture](#architecture) + - [1. BIOS layer](#1-bios-layer) + - [2. Plugin layer](#2-plugin-layer) + - [3. IDE interfacing layer](#3-ide-interfacing-layer) + - [Documentation](#documentation) + - [Troubleshooting](#troubleshooting) + - [DYLD on macOS](#dyld-on-macos) + - [macOS: Got error while installing GHC 8.6.1 or 8.6.2 - dyld: Library not loaded: /usr/local/opt/gmp/lib/libgmp.10.dylib](#macos-got-error-while-installing-ghc-861-or-862---dyld-library-not-loaded-usrlocaloptgmpliblibgmp10dylib) + - [macOS: Got error while processing diagnostics: unable to load package `integer-gmp-1.0.2.0`](#macos-got-error-while-processing-diagnostics-unable-to-load-package-integer-gmp-1020) + - [cannot satisfy -package-id \](#cannot-satisfy--package-id-package) + - [Is \ base-x?](#is-package-base-x) + - [Is there a hash (#) after \?](#is-there-a-hash--after-package) + - [Otherwise](#otherwise) ## Features @@ -284,6 +309,36 @@ stack ./install.hs hie-8.4.4 stack ./install.hs build-doc-8.4.4 ``` +The Haskell IDE Engine can also be built with `cabal new-build` instead of `stack build`. +This has the advantage that you can decide how the GHC versions have been installed. +However, this approach does currently not work for windows due to a missing feature upstream. +To see what GHC versions are available, the command `stack install.hs cabal-ghcs` can be used. +It will list all GHC versions that are on the path and their respective installation directory. +If you think, this list is incomplete, you can try to modify the PATH variable, such that the executables can be found. +Note, that the targets `cabal-build`, `cabal-build-docs` and `cabal-build-all` depend on the found GHC versions. +They install Haskell IDE Engine only for the found GHC versions. + +An example output is: + +```bash +> stack install.hs cabal-ghcs +****************************************************************** +Found the following GHC paths: +ghc-8.4.4: /opt/bin/ghc-8.4.4 +ghc-8.6.2: /opt/bin/ghc-8.6.2 + +****************************************************************** +``` + +If your desired ghc has been found, you use it to install Haskell IDE Engine. + +```bash +stack install.hs cabal-hie-8.4.4 +stack install.hs cabal-build-doc-8.4.4 +``` + +In general, targets that use `cabal` instead of `stack` are prefixed with `cabal-*` and identical to their counterpart. + #### Install *all* available GHC versions with Shake *Warning*: Requires 20+ GB of space and potentially more than 2 hours to install, so please be patient! @@ -307,6 +362,18 @@ Then add to VS Code user settings. +To install HIE only for those GHC versions that are present on your system, you use: + +```bash +stack ./install.hs cabal-build-all +``` + +This wil: + +- install Haskell Ide Engine for GHC versions that have been found on your path +- name them as expected by the VS Code plugin +- build local hoogle docs for each version + ## Configuration There are some settings that can be configured via a `settings.json` file: From fc32ea66a7cbf7e749d9b171d2481caac28ea0b6 Mon Sep 17 00:00:00 2001 From: fendor Date: Thu, 28 Feb 2019 22:56:41 +0100 Subject: [PATCH 15/19] Bump shake.yaml to GHC 8.6.2 This way we no longer have to rely on the nightly resolver located in stack.yaml and only one resolver is downloaded if HIE is to be installed via cabal-new-build --- shake.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shake.yaml b/shake.yaml index 23c912f7b..2eeb71009 100644 --- a/shake.yaml +++ b/shake.yaml @@ -1,5 +1,5 @@ # Used to provide a different environment for the shake build script -resolver: lts-12.25 # GHC 8.4.4 +resolver: nightly-2018-12-17 # GHC 8.6.2 packages: - . From 5906fe54ec11e8c83ea4ad56c31f93a0214b4541 Mon Sep 17 00:00:00 2001 From: fendor Date: Thu, 28 Feb 2019 22:57:37 +0100 Subject: [PATCH 16/19] Shorter help message to ease visual burden --- install.hs | 170 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 111 insertions(+), 59 deletions(-) diff --git a/install.hs b/install.hs index 23493fed4..fb0dd22dc 100755 --- a/install.hs +++ b/install.hs @@ -54,11 +54,12 @@ main = do let ghcVersions = map fst ghcPaths shakeArgs shakeOptions { shakeFiles = "_build" } $ do - want ["help"] + want ["short-help"] -- general purpose targets phony "submodules" updateSubmodules phony "cabal" (getStackGhcPath mostRecentHieVersion >>= installCabal) - phony "all" helpMessage + phony "short-help" shortHelpMessage + phony "all" shortHelpMessage phony "help" helpMessage phony "dist" buildDist @@ -244,7 +245,7 @@ cabalTest versionNumber = do installCabal :: GhcPath -> Action () installCabal ghc = do - execStack_ ["install", "cabal-install"] + execStack_ ["install", "--stack-yaml=shake.yaml", "cabal-install"] execCabal_ ["update"] execCabal_ ["install", "Cabal-2.4.1.0", "--with-compiler=" ++ ghc] @@ -277,76 +278,73 @@ stackBuildDoc versionNumber = do execStackWithYaml_ versionNumber ["install", "hoogle"] execStackWithYaml_ versionNumber ["exec", "hoogle", "generate"] -helpMessage :: Action () -helpMessage = do +shortHelpMessage :: Action () +shortHelpMessage = do + let out = liftIO . putStrLn scriptName <- liftIO getProgName out "" out "Usage:" out' ("stack " <> scriptName <> " ") out "" out "Targets:" - mapM_ (out' . showTarget) targets + mapM_ (out' . showTarget spaces) targets out "" where - out = liftIO . putStrLn - out' = out . (" " ++) - -- |Number of spaces the target name including whitespace should have. - -- At least twenty, maybe more if target names are long. At most length of the longest target plus five. - space :: Int - space = maximum (20 : map ((+ 5) . length . fst) targets) - - -- |Show a target. - -- Concatenates the target with its help message and inserts whitespace between them. - showTarget :: (String, String) -> String - showTarget (target, msg) = - target ++ replicate (space - length target) ' ' ++ msg - - -- |Target for a specific ghc version - stackHieTarget :: String -> (String, String) - stackHieTarget version = - ( "hie-" ++ version - , "Builds hie for GHC version " ++ version ++ " only with stack" - ) - -- |Target for a specific ghc version - cabalHieTarget :: String -> (String, String) - cabalHieTarget version = - ( "cabal-hie-" ++ version - , "Builds hie for GHC version " ++ version ++ " only with cabal new-build" - ) + out = liftIO . putStrLn + out' = out . (" " ++) - stackBuildDocTarget :: VersionNumber -> (String, String) - stackBuildDocTarget version = - ( "build-doc-" ++ version - , "Builds the Hoogle database for GHC version " - ++ version - ++ " only with stack" - ) + spaces = space targets + targets = + [ ("help", "Show help message including all targets") + , ( "build" + , "Builds hie for all supported GHC versions (" + ++ allVersionMessage hieVersions + ++ ")" + ) + , ( "build-all" + , "Builds hie and hoogle databases for all supported GHC versions" + ) + , stackHieTarget mostRecentHieVersion + , stackBuildDocTarget mostRecentHieVersion + , stackHieTarget "8.4.4" + , stackBuildDocTarget "8.4.4" + , emptyTarget + , ( "cabal-ghcs" + , "Show all GHC versions that can be installed via `cabal-build` and `cabal-build-all`." + ) + , ("cabal-build", "Builds hie with cabal with all installed GHCs.") + , ( "cabal-build-all" + , "Builds hie and hoogle databases for all installed GHC versions with cabal" + ) + , cabalHieTarget mostRecentHieVersion + , cabalBuildDocTarget mostRecentHieVersion + , cabalHieTarget "8.4.4" + , cabalBuildDocTarget "8.4.4" + ] - cabalBuildDocTarget :: VersionNumber -> (String, String) - cabalBuildDocTarget version = - ( "cabal-build-doc-" ++ version - , "Builds the Hoogle database for GHC version " - ++ version - ++ " only with cabal" - ) - -- | Creates a message of the form "a, b, c and d", where a,b,c,d are GHC versions. - -- If there is no GHC in the list of `hieVersions` - allVersionMessage :: [String] -> String - allVersionMessage wordList = case wordList of - [] -> "" - [a] -> show a - (a : as) -> - let msg = intersperse ", " wordList - lastVersion = last msg - in concat $ (init $ init msg) ++ [" and ", lastVersion] +helpMessage :: Action () +helpMessage = do + scriptName <- liftIO getProgName + out "" + out "Usage:" + out' ("stack " <> scriptName <> " ") + out "" + out "Targets:" + mapM_ (out' . showTarget spaces) targets + out "" + where + out = liftIO . putStrLn + out' = out . (" " ++) + spaces = space targets -- All targets the shake file supports + targets :: [(String, String)] targets = generalTargets ++ stackTargets ++ cabalTargets ++ macosTargets -- All targets with their respective help message. generalTargets = - [ ("help", "Show help") + [ ("help", "Show help message including all targets") , ( "cabal" , "Makes sure that Cabal the lib is available for cabal-helper-wapper, to speed up project start" ) @@ -376,9 +374,7 @@ helpMessage = do [ ( "cabal-ghcs" , "Show all GHC versions that can be installed via `cabal-build` and `cabal-build-all`." ) - , ( "cabal-build" - , "Builds hie with cabal with all installed GHCs. Target `cabal-ghcs` shows all GHC versions that will be installed" - ) + , ("cabal-build", "Builds hie with cabal with all installed GHCs.") , ( "cabal-build-all" , "Builds hie and hoogle databases for all installed GHC versions with cabal" ) @@ -390,6 +386,62 @@ helpMessage = do ++ map cabalHieTarget hieVersions ++ map cabalBuildDocTarget hieVersions +-- | Empty target. Purpose is to introduce a newline between the tagets +emptyTarget :: (String, String) +emptyTarget = ("", "") + +-- |Number of spaces the target name including whitespace should have. +-- At least twenty, maybe more if target names are long. At most length of the longest target plus five. +space :: [(String, String)] -> Int +space phonyTargets = maximum (20 : map ((+ 5) . length . fst) phonyTargets) + +-- |Show a target. +-- Concatenates the target with its help message and inserts whitespace between them. +showTarget :: Int -> (String, String) -> String +showTarget spaces (target, msg) = + target ++ replicate (spaces - length target) ' ' ++ msg + +-- |Target for a specific ghc version +stackHieTarget :: String -> (String, String) +stackHieTarget version = + ( "hie-" ++ version + , "Builds hie for GHC version " ++ version ++ " only with stack" + ) + +-- |Target for a specific ghc version +cabalHieTarget :: String -> (String, String) +cabalHieTarget version = + ( "cabal-hie-" ++ version + , "Builds hie for GHC version " ++ version ++ " only with cabal new-build" + ) + +stackBuildDocTarget :: VersionNumber -> (String, String) +stackBuildDocTarget version = + ( "build-doc-" ++ version + , "Builds the Hoogle database for GHC version " + ++ version + ++ " only with stack" + ) + +cabalBuildDocTarget :: VersionNumber -> (String, String) +cabalBuildDocTarget version = + ( "cabal-build-doc-" ++ version + , "Builds the Hoogle database for GHC version " + ++ version + ++ " only with cabal" + ) + +-- | Creates a message of the form "a, b, c and d", where a,b,c,d are GHC versions. +-- If there is no GHC in the list of `hieVersions` +allVersionMessage :: [String] -> String +allVersionMessage wordList = case wordList of + [] -> "" + [a] -> show a + (a : as) -> + let msg = intersperse ", " wordList + lastVersion = last msg + in concat $ (init $ init msg) ++ [" and ", lastVersion] + execStackWithYaml_ :: VersionNumber -> [String] -> Action () execStackWithYaml_ versionNumber args = do let stackFile = "stack-" ++ versionNumber ++ ".yaml" From dee5a056092af971db71bc7830e9f72f0fcf750e Mon Sep 17 00:00:00 2001 From: fendor Date: Thu, 28 Feb 2019 23:01:51 +0100 Subject: [PATCH 17/19] Fix typo and more newlines between targets --- install.hs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/install.hs b/install.hs index fb0dd22dc..f66010dec 100755 --- a/install.hs +++ b/install.hs @@ -340,7 +340,14 @@ helpMessage = do spaces = space targets -- All targets the shake file supports targets :: [(String, String)] - targets = generalTargets ++ stackTargets ++ cabalTargets ++ macosTargets + targets = + generalTargets + ++ [emptyTarget] + ++ stackTargets + ++ [emptyTarget] + ++ cabalTargets + ++ [emptyTarget] + ++ macosTargets -- All targets with their respective help message. generalTargets = @@ -386,7 +393,7 @@ helpMessage = do ++ map cabalHieTarget hieVersions ++ map cabalBuildDocTarget hieVersions --- | Empty target. Purpose is to introduce a newline between the tagets +-- | Empty target. Purpose is to introduce a newline between the targets emptyTarget :: (String, String) emptyTarget = ("", "") From 591d46ebb023bdd89ef9291ecdc34044d751e5bc Mon Sep 17 00:00:00 2001 From: fendor Date: Thu, 28 Feb 2019 23:10:22 +0100 Subject: [PATCH 18/19] Introduce visual separator in help message --- install.hs | 1 + 1 file changed, 1 insertion(+) diff --git a/install.hs b/install.hs index f66010dec..681609fcf 100755 --- a/install.hs +++ b/install.hs @@ -296,6 +296,7 @@ shortHelpMessage = do spaces = space targets targets = [ ("help", "Show help message including all targets") + , emptyTarget , ( "build" , "Builds hie for all supported GHC versions (" ++ allVersionMessage hieVersions From 5ad1d7217240f605fe452a3e5b07f669230c31db Mon Sep 17 00:00:00 2001 From: fendor Date: Fri, 1 Mar 2019 11:37:55 +0100 Subject: [PATCH 19/19] Fix typo --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0954900a3..5b5fe332c 100644 --- a/README.md +++ b/README.md @@ -312,7 +312,7 @@ To see what GHC versions are available, the command `stack install.hs cabal-ghcs It will list all GHC versions that are on the path and their respective installation directory. If you think, this list is incomplete, you can try to modify the PATH variable, such that the executables can be found. Note, that the targets `cabal-build`, `cabal-build-docs` and `cabal-build-all` depend on the found GHC versions. -They install Haskell IDE Engine only for the found GHC versions. +They install Haskell IDE Engine only for the found GHC versions. An example output is: @@ -364,7 +364,7 @@ To install HIE only for those GHC versions that are present on your system, you stack ./install.hs cabal-build-all ``` -This wil: +This will: - install Haskell Ide Engine for GHC versions that have been found on your path - name them as expected by the VS Code plugin