forked from haskell/haskell-language-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHlsInstall.hs
101 lines (77 loc) · 2.89 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
module HlsInstall where
import Control.Monad
import Development.Shake
import System.Environment (unsetEnv)
import BuildSystem
import Cabal
import Env
import Help
import Stack
import Version
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 "short-help" shortHelpMessage
phony "help" (helpMessage toolsVersions)
phony "check" (if isRunFromStack then checkStack args else checkCabal_ args)
phony "data" $ do
need ["show-options"]
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 ["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
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