Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit b46a531

Browse files
committed
Several improvements to install script
* Remove unused imports * Pass number of jobs and verbosity shake args to build tools * Use custom cabal.project-${ghcVersion} if exists * Add comments with the possible resolvers to shake.yaml
1 parent 4d04893 commit b46a531

File tree

9 files changed

+163
-130
lines changed

9 files changed

+163
-130
lines changed

install/hie-install.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: hie-install
2-
version: 0.8.0.0
2+
version: 0.8.1.0
33
synopsis: Install the haskell-ide-engine
44
license: BSD3
55
author: Many, TBD when we release

install/shake.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
# Used to provide a different environment for the shake build script
2-
resolver: lts-14.11 # GHC 8.6.5
2+
resolver: lts-13.19 # last lts with GHC 8.6.5
3+
# resolver: nightly-2020-01-31 # GHC 8.8.2
4+
# resolver: nightly-2020-01-21 # last nightly GHC 8.8.1
5+
# resolver: lts-13.19 # last lts GHC 8.6.4
6+
# resolver: lts-12.26 # last lts GHC 8.4.4
7+
# resolver: lts-12.14 # last lts GHC 8.4.3
8+
# resolver: nightly-2018-05-30 # last nightly for GHC 8.4.2
39
packages:
410
- .
511

12+
extra-deps:
13+
- shake-0.18.5
14+
# for resolvers with ghc < 8.6
15+
# - shake-0.17
16+
17+
618
nix:
719
packages: [ zlib ]
820

install/src/Cabal.hs

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,14 @@
11
{-# LANGUAGE CPP #-}
2-
32
module Cabal where
43

54
import Development.Shake
6-
import Development.Shake.Command
75
import Development.Shake.FilePath
86
import Control.Monad
9-
import Data.Maybe ( isNothing
10-
, isJust
11-
)
12-
import Control.Monad.Extra ( whenMaybe )
13-
import System.Directory ( findExecutable
14-
, copyFile
15-
)
7+
import System.Directory ( copyFile )
168

179
import Version
1810
import Print
1911
import Env
20-
import Data.Functor.Identity
2112
#if RUN_FROM_STACK
2213
import Control.Exception ( throwIO )
2314
#else
@@ -38,43 +29,48 @@ execCabal = command [] "cabal"
3829
execCabal_ :: [String] -> Action ()
3930
execCabal_ = execCabal
4031

41-
cabalBuildData :: Action ()
42-
cabalBuildData = do
43-
execCabal_ ["v2-build", "hoogle"]
44-
execCabal_ ["v2-exec", "hoogle", "generate"]
32+
cabalBuildData :: [String] -> Action ()
33+
cabalBuildData args = do
34+
execCabal_ $ ["v2-build", "hoogle"] ++ args
35+
execCabal_ $ ["v2-exec", "hoogle", "generate"] ++ args
4536

4637
getGhcPathOfOrThrowError :: VersionNumber -> Action GhcPath
47-
getGhcPathOfOrThrowError versionNumber =
38+
getGhcPathOfOrThrowError versionNumber =
4839
getGhcPathOf versionNumber >>= \case
4940
Nothing -> do
5041
printInStars $ ghcVersionNotFoundFailMsg versionNumber
5142
error (ghcVersionNotFoundFailMsg versionNumber)
5243
Just p -> return p
5344

54-
cabalInstallHie :: VersionNumber -> Action ()
55-
cabalInstallHie versionNumber = do
45+
cabalInstallHie :: VersionNumber -> [String] -> Action ()
46+
cabalInstallHie versionNumber args = do
5647
localBin <- liftIO $ getInstallDir
57-
cabalVersion <- getCabalVersion
48+
cabalVersion <- getCabalVersion args
5849
ghcPath <- getGhcPathOfOrThrowError versionNumber
5950

6051
let isCabal3 = checkVersion [3,0,0,0] cabalVersion
6152
installDirOpt | isCabal3 = "--installdir"
6253
| otherwise = "--symlink-bindir"
6354
installMethod | isWindowsSystem && isCabal3 = ["--install-method=copy"]
6455
| otherwise = []
56+
57+
projectFile <- getProjectFile versionNumber
58+
6559
execCabal_ $
6660
[ "v2-install"
6761
, "-w", ghcPath
6862
, "--write-ghc-environment-files=never"
6963
, installDirOpt, localBin
7064
, "--max-backjumps=5000"
71-
, "exe:hie"
65+
, "exe:hie", "exe:hie-wrapper"
7266
, "--overwrite-policy=always"
67+
, "--project-file=" ++ projectFile
7368
]
7469
++ installMethod
70+
++ args
7571

7672
let minorVerExe = "hie-" ++ versionNumber <.> exe
77-
majorVerExe = "hie-" ++ dropExtension versionNumber <.> exe
73+
majorVerExe = "hie-" ++ dropExtension versionNumber <.> exe
7874

7975
liftIO $ do
8076
copyFile (localBin </> "hie" <.> exe) (localBin </> minorVerExe)
@@ -87,20 +83,27 @@ cabalInstallHie versionNumber = do
8783
++ minorVerExe
8884
++ " to " ++ localBin
8985

90-
checkCabal_ :: Action ()
91-
checkCabal_ = checkCabal >> return ()
86+
getProjectFile :: VersionNumber -> Action FilePath
87+
getProjectFile ver = do
88+
existFile <- doesFileExist $ "cabal.project-" ++ ver
89+
return $ if existFile
90+
then "cabal.project-" ++ ver
91+
else "cabal.project"
92+
93+
checkCabal_ :: [String] -> Action ()
94+
checkCabal_ args = checkCabal args >> return ()
9295

9396
-- | check `cabal` has the required version
94-
checkCabal :: Action String
95-
checkCabal = do
96-
cabalVersion <- getCabalVersion
97+
checkCabal :: [String] -> Action String
98+
checkCabal args = do
99+
cabalVersion <- getCabalVersion args
97100
unless (checkVersion requiredCabalVersion cabalVersion) $ do
98101
printInStars $ cabalInstallIsOldFailMsg cabalVersion
99102
error $ cabalInstallIsOldFailMsg cabalVersion
100103
return cabalVersion
101104

102-
getCabalVersion :: Action String
103-
getCabalVersion = trimmedStdout <$> execCabal ["--numeric-version"]
105+
getCabalVersion :: [String] -> Action String
106+
getCabalVersion args = trimmedStdout <$> (execCabal $ ["--numeric-version"] ++ args)
104107

105108
-- | Error message when the `cabal` binary is an older version
106109
cabalInstallIsOldFailMsg :: String -> String
@@ -119,3 +122,21 @@ requiredCabalVersion | isWindowsSystem = requiredCabalVersionForWindows
119122

120123
requiredCabalVersionForWindows :: RequiredVersion
121124
requiredCabalVersionForWindows = [3, 0, 0, 0]
125+
126+
getVerbosityArg :: Verbosity -> String
127+
getVerbosityArg v = "-v" ++ cabalVerbosity
128+
where cabalVerbosity = case v of
129+
Silent -> "0"
130+
#if MIN_VERSION_shake(0,18,4)
131+
Error -> "0"
132+
Warn -> "1"
133+
Info -> "1"
134+
Verbose -> "2"
135+
#else
136+
Quiet -> "0"
137+
Normal -> "1"
138+
Loud -> "2"
139+
Chatty -> "2"
140+
#endif
141+
Diagnostic -> "3"
142+

install/src/Env.hs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
module Env where
22

33
import Development.Shake
4-
import Development.Shake.Command
54
import Control.Monad.IO.Class
65
import Control.Monad
76
import Development.Shake.FilePath
8-
import System.Info ( os
9-
, arch
10-
)
7+
import System.Info ( os )
118
import Data.Maybe ( isJust
12-
, isNothing
139
, mapMaybe
1410
)
1511
import System.Directory ( findExecutable

install/src/Help.hs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,18 @@
22
module Help where
33

44
import Development.Shake
5-
import Data.List ( intersperse
6-
, intercalate
7-
)
5+
import Data.List ( intercalate )
86

97
import Env
108
import Print
119
import Version
1210
import BuildSystem
13-
import Cabal
1411

1512
stackCommand :: TargetDescription -> String
16-
stackCommand target = "stack install.hs " ++ fst target
13+
stackCommand target = "stack install.hs " ++ fst target ++ " [options]"
1714

1815
cabalCommand :: TargetDescription -> String
19-
cabalCommand target = "cabal v2-run install.hs --project-file install/shake.project " ++ fst target
16+
cabalCommand target = "cabal v2-run install.hs --project-file install/shake.project -- " ++ fst target ++ " [options]"
2017

2118
buildCommand :: TargetDescription -> String
2219
buildCommand | isRunFromCabal = cabalCommand
@@ -37,7 +34,7 @@ shortHelpMessage = do
3734
printUsage
3835
printLine ""
3936
printLine "Targets:"
40-
mapM_ (printLineIndented . showTarget (spaces hieVersions)) (targets hieVersions)
37+
mapM_ (printLineIndented . showHelpItem (spaces hieVersions)) (targets hieVersions)
4138
printLine ""
4239
where
4340
spaces hieVersions = space (targets hieVersions)
@@ -68,7 +65,10 @@ helpMessage versions@BuildableVersions {..} = do
6865
printUsage
6966
printLine ""
7067
printLine "Targets:"
71-
mapM_ (printLineIndented . showTarget spaces) targets
68+
mapM_ (printLineIndented . showHelpItem spaces) targets
69+
printLine ""
70+
printLine "Options:"
71+
mapM_ (printLineIndented . showHelpItem spaces) options
7272
printLine ""
7373
where
7474
spaces = space targets
@@ -81,6 +81,11 @@ helpMessage versions@BuildableVersions {..} = do
8181
, if isRunFromCabal then [cabalGhcsTarget] else [stackDevTarget]
8282
, [macosIcuTarget]
8383
]
84+
options = [ ("-j[N], --jobs[=N]", "Allow N jobs/threads at once [default number of CPUs].")
85+
, ("-s, --silent", "Don't print anything.")
86+
, ("-q, --quiet", "Print less (pass repeatedly for even less).")
87+
, ("-V, --verbose", "Print more (pass repeatedly for even more).")
88+
]
8489

8590
-- All targets with their respective help message.
8691
generalTargets = [helpTarget]

install/src/HieInstall.hs

Lines changed: 37 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,13 @@
11
module HieInstall where
22

33
import Development.Shake
4-
import Development.Shake.Command
5-
import Development.Shake.FilePath
64
import Control.Monad
7-
import Control.Monad.IO.Class
8-
import Control.Monad.Extra ( unlessM
9-
, mapMaybeM
10-
)
11-
import Data.Maybe ( isJust )
12-
import System.Directory ( listDirectory )
135
import System.Environment ( unsetEnv )
14-
import System.Info ( os
15-
, arch
16-
)
17-
18-
import Data.Maybe ( isNothing
19-
, mapMaybe
20-
)
21-
import Data.List ( dropWhileEnd
22-
, intersperse
23-
, intercalate
24-
, sort
25-
, sortOn
26-
)
27-
import qualified Data.Text as T
28-
import Data.Char ( isSpace )
29-
import Data.Version ( parseVersion
30-
, makeVersion
31-
, showVersion
32-
)
33-
import Data.Function ( (&) )
34-
import Text.ParserCombinators.ReadP ( readP_to_S )
356

367
import BuildSystem
378
import Stack
389
import Cabal
3910
import Version
40-
import Print
4111
import Env
4212
import Help
4313

@@ -53,37 +23,53 @@ defaultMain = do
5323
-- used for stack-based targets
5424
stackVersions <- getHieVersions
5525

56-
let versions = if isRunFromStack then stackVersions else cabalVersions
26+
let versions = if isRunFromStack then stackVersions else cabalVersions
5727

5828
let toolsVersions = BuildableVersions stackVersions cabalVersions
5929

6030
let latestVersion = last versions
6131

62-
shakeArgs shakeOptions { shakeFiles = "_build" } $ do
32+
shakeArgs shakeOptions { shakeFiles = "_build", shakeThreads = 0 } $ do
33+
34+
shakeOptionsRules <- getShakeOptionsRules
35+
36+
let jobsArg = "-j" ++ show (shakeThreads shakeOptionsRules)
37+
38+
let verbosityArg = if isRunFromStack then Stack.getVerbosityArg else Cabal.getVerbosityArg
39+
40+
let args = [jobsArg, verbosityArg (shakeVerbosity shakeOptionsRules)]
41+
42+
phony "show-options" $ do
43+
putNormal $ "Options:"
44+
putNormal $ " Number of jobs: " ++ show (shakeThreads shakeOptionsRules)
45+
putNormal $ " Verbosity level: " ++ show (shakeVerbosity shakeOptionsRules)
46+
6347
want ["short-help"]
6448
-- general purpose targets
6549
phony "submodules" updateSubmodules
6650
phony "short-help" shortHelpMessage
6751
phony "help" (helpMessage toolsVersions)
68-
69-
phony "check" (if isRunFromStack then checkStack else checkCabal_)
52+
53+
phony "check" (if isRunFromStack then checkStack args else checkCabal_ args)
7054

7155
phony "data" $ do
56+
need ["show-options"]
7257
need ["submodules"]
7358
need ["check"]
74-
if isRunFromStack then stackBuildData else cabalBuildData
59+
if isRunFromStack then stackBuildData args else cabalBuildData args
7560

7661
forM_
7762
versions
7863
(\version -> phony ("hie-" ++ version) $ do
64+
need ["show-options"]
7965
need ["submodules"]
8066
need ["check"]
8167
if isRunFromStack then
82-
stackInstallHieWithErrMsg (Just version)
68+
stackInstallHieWithErrMsg (Just version) args
8369
else
84-
cabalInstallHie version
70+
cabalInstallHie version args
8571
)
86-
72+
8773
unless (null versions) $ do
8874
phony "latest" (need ["hie-" ++ latestVersion])
8975
phony "hie" (need ["data", "latest"])
@@ -92,7 +78,9 @@ defaultMain = do
9278
-- Default `stack.yaml` uses ghc-8.8.2 and we can't build hie in windows
9379
-- TODO: Enable for windows when it uses ghc-8.8.3
9480
when (isRunFromStack && not isWindowsSystem) $
95-
phony "dev" $ stackInstallHieWithErrMsg Nothing
81+
phony "dev" $ do
82+
need ["show-options"]
83+
stackInstallHieWithErrMsg Nothing args
9684

9785
-- cabal specific targets
9886
when isRunFromCabal $ do
@@ -101,20 +89,23 @@ defaultMain = do
10189
phony "ghcs" $ showInstalledGhcs ghcPaths
10290

10391
-- macos specific targets
104-
phony "icu-macos-fix"
105-
(need ["icu-macos-fix-install"] >> need ["icu-macos-fix-build"])
92+
phony "icu-macos-fix" $ do
93+
need ["show-options"]
94+
need ["icu-macos-fix-install"]
95+
need ["icu-macos-fix-build"]
96+
10697
phony "icu-macos-fix-install" (command_ [] "brew" ["install", "icu4c"])
107-
phony "icu-macos-fix-build" $ mapM_ buildIcuMacosFix versions
98+
phony "icu-macos-fix-build" $ mapM_ (flip buildIcuMacosFix $ args) versions
10899

109100

110-
buildIcuMacosFix :: VersionNumber -> Action ()
111-
buildIcuMacosFix version = execStackWithGhc_
112-
version
101+
buildIcuMacosFix :: VersionNumber -> [String] -> Action ()
102+
buildIcuMacosFix version args = execStackWithGhc_
103+
version $
113104
[ "build"
114105
, "text-icu"
115106
, "--extra-lib-dirs=/usr/local/opt/icu4c/lib"
116107
, "--extra-include-dirs=/usr/local/opt/icu4c/include"
117-
]
108+
] ++ args
118109

119110
-- | update the submodules that the project is in the state as required by the `stack.yaml` files
120111
updateSubmodules :: Action ()

0 commit comments

Comments
 (0)