forked from haskell/haskell-language-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHlsInstall.hs
112 lines (87 loc) · 3.38 KB
/
HlsInstall.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
module HlsInstall where
import Development.Shake
import Control.Monad
import System.Environment ( unsetEnv )
import BuildSystem
import Stack
import Cabal
import Version
import Env
import Help
defaultMain :: IO ()
defaultMain = do
-- unset GHC_PACKAGE_PATH for cabal
unsetEnv "GHC_PACKAGE_PATH"
-- used for cabal-based targets
ghcPaths <- findInstalledGhcs
let cabalVersions = map fst ghcPaths
-- used for stack-based targets
stackVersions <- getHlsVersions
let versions = if isRunFromStack then stackVersions else cabalVersions
let toolsVersions = BuildableVersions stackVersions cabalVersions
let latestVersion = last versions
shakeArgs shakeOptions { shakeFiles = "_build" } $ do
shakeOptionsRules <- getShakeOptionsRules
let verbosityArg = if isRunFromStack then Stack.getVerbosityArg else Cabal.getVerbosityArg
let args = [verbosityArg (shakeVerbosity shakeOptionsRules)]
phony "show-options" $ do
putNormal $ "Options:"
putNormal $ " Verbosity level: " ++ show (shakeVerbosity shakeOptionsRules)
want ["short-help"]
-- general purpose targets
phony "submodules" updateSubmodules
phony "short-help" shortHelpMessage
phony "help" (helpMessage toolsVersions)
phony "check" (if isRunFromStack then checkStack args else checkCabal_ args)
phony "data" $ do
need ["show-options"]
need ["submodules"]
need ["check"]
liftIO $ putStrLn "Generation of hoogle data files is disabled for now."
-- if isRunFromStack then stackBuildData args else cabalBuildData args
forM_
versions
(\version -> phony ("hls-" ++ version) $ do
need ["show-options"]
need ["submodules"]
need ["check"]
if isRunFromStack then
stackInstallHlsWithErrMsg (Just version) args
else
cabalInstallHls version args
)
unless (null versions) $ do
phony "latest" (need ["hls-" ++ latestVersion])
phony "hls" (need ["data", "latest"])
-- stack specific targets
-- Default `stack.yaml` uses ghc-8.8.2 and we can't build hls in windows
-- TODO: Enable for windows when it uses ghc-8.8.3
when isRunFromStack $
phony "dev" $ do
need ["show-options"]
stackInstallHlsWithErrMsg Nothing args
-- cabal specific targets
when isRunFromCabal $ do
-- It throws an error if there is no ghc in $PATH
checkInstalledGhcs ghcPaths
phony "ghcs" $ showInstalledGhcs ghcPaths
-- macos specific targets
phony "icu-macos-fix" $ do
need ["show-options"]
need ["icu-macos-fix-install"]
need ["icu-macos-fix-build"]
phony "icu-macos-fix-install" (command_ [] "brew" ["install", "icu4c"])
phony "icu-macos-fix-build" $ mapM_ (flip buildIcuMacosFix $ args) versions
buildIcuMacosFix :: VersionNumber -> [String] -> Action ()
buildIcuMacosFix version args = execStackWithGhc_
version $
[ "build"
, "text-icu"
, "--extra-lib-dirs=/usr/local/opt/icu4c/lib"
, "--extra-include-dirs=/usr/local/opt/icu4c/include"
] ++ args
-- | update the submodules that the project is in the state as required by the `stack.yaml` files
updateSubmodules :: Action ()
updateSubmodules = do
command_ [] "git" ["submodule", "sync"]
command_ [] "git" ["submodule", "update", "--init"]