forked from commercialhaskell/stack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetupCmd.hs
More file actions
135 lines (128 loc) · 5.12 KB
/
SetupCmd.hs
File metadata and controls
135 lines (128 loc) · 5.12 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
-- | Install GHC/GHCJS and Cabal.
module Stack.SetupCmd
( setup
, setupParser
, SetupCmdOpts(..)
) where
import Control.Applicative
import Control.Monad.Logger ()
import Control.Monad.Reader
import qualified Data.Text as T
import qualified Options.Applicative as OA
import qualified Options.Applicative.Builder.Extra as OA
import qualified Options.Applicative.Types as OA
import Path
import Stack.Prelude
import Stack.Setup
import Stack.Types.Compiler
import Stack.Types.Config
import Stack.Types.Version
data SetupCmdOpts = SetupCmdOpts
{ scoCompilerVersion :: !(Maybe (CompilerVersion 'CVWanted))
, scoForceReinstall :: !Bool
, scoUpgradeCabal :: !(Maybe UpgradeTo)
, scoSetupInfoYaml :: !String
, scoGHCBindistURL :: !(Maybe String)
, scoGHCJSBootOpts :: ![String]
, scoGHCJSBootClean :: !Bool
}
setupYamlCompatParser :: OA.Parser String
setupYamlCompatParser = stackSetupYaml <|> setupInfoYaml
where stackSetupYaml = OA.strOption (
OA.long "stack-setup-yaml"
<> OA.help "DEPRECATED: Use 'setup-info-yaml' instead"
<> OA.metavar "URL"
<> OA.hidden )
setupInfoYaml = OA.strOption (
OA.long "setup-info-yaml"
<> OA.help "Alternate URL or absolute path for stack dependencies"
<> OA.metavar "URL"
<> OA.value defaultSetupInfoYaml )
cabalUpgradeParser :: OA.Parser UpgradeTo
cabalUpgradeParser = Specific <$> version' <|> latestParser
where
versionReader = do
s <- OA.readerAsk
case parseVersion (T.pack s) of
Nothing -> OA.readerError $ "Invalid version: " ++ s
Just v -> return v
version' = OA.option versionReader (
OA.long "install-cabal"
<> OA.metavar "VERSION"
<> OA.help "Install a specific version of Cabal" )
latestParser = OA.flag' Latest (
OA.long "upgrade-cabal"
<> OA.help "DEPRECATED Install latest version of Cabal globally" )
setupParser :: OA.Parser SetupCmdOpts
setupParser = SetupCmdOpts
<$> OA.optional (OA.argument readVersion
(OA.metavar "GHC_VERSION" <>
OA.help ("Version of GHC to install, e.g. 7.10.2. " ++
"The default is to install the version implied by the resolver.")))
<*> OA.boolFlags False
"reinstall"
"reinstalling GHC, even if available (incompatible with --system-ghc)"
OA.idm
<*> OA.optional cabalUpgradeParser
<*> setupYamlCompatParser
<*> OA.optional (OA.strOption
(OA.long "ghc-bindist"
<> OA.metavar "URL"
<> OA.help "Alternate GHC binary distribution (requires custom --ghc-variant)"))
<*> OA.many (OA.strOption
(OA.long "ghcjs-boot-options"
<> OA.metavar "GHCJS_BOOT"
<> OA.help "Additional ghcjs-boot options"))
<*> OA.boolFlags True
"ghcjs-boot-clean"
"Control if ghcjs-boot should have --clean option present"
OA.idm
where
readVersion = do
s <- OA.readerAsk
case parseCompilerVersion ("ghc-" <> T.pack s) of
Nothing ->
case parseCompilerVersion (T.pack s) of
Nothing -> OA.readerError $ "Invalid version: " ++ s
Just x -> return x
Just x -> return x
setup
:: (HasConfig env, HasGHCVariant env)
=> SetupCmdOpts
-> CompilerVersion 'CVWanted
-> VersionCheck
-> Maybe (Path Abs File)
-> RIO env ()
setup SetupCmdOpts{..} wantedCompiler compilerCheck mstack = do
Config{..} <- view configL
(_, _, sandboxedGhc) <- ensureCompiler SetupOpts
{ soptsInstallIfMissing = True
, soptsUseSystem = configSystemGHC && not scoForceReinstall
, soptsWantedCompiler = wantedCompiler
, soptsCompilerCheck = compilerCheck
, soptsStackYaml = mstack
, soptsForceReinstall = scoForceReinstall
, soptsSanityCheck = True
, soptsSkipGhcCheck = False
, soptsSkipMsys = configSkipMsys
, soptsUpgradeCabal = scoUpgradeCabal
, soptsResolveMissingGHC = Nothing
, soptsSetupInfoYaml = scoSetupInfoYaml
, soptsGHCBindistURL = scoGHCBindistURL
, soptsGHCJSBootOpts = scoGHCJSBootOpts ++ ["--clean" | scoGHCJSBootClean]
}
let compiler = case wantedCompiler of
GhcVersion _ -> "GHC"
GhcjsVersion {} -> "GHCJS"
if sandboxedGhc
then logInfo $ "stack will use a sandboxed " <> compiler <> " it installed"
else logInfo $ "stack will use the " <> compiler <> " on your PATH"
logInfo "For more information on paths, see 'stack path' and 'stack exec env'"
logInfo $ "To use this " <> compiler <> " and packages outside of a project, consider using:"
logInfo "stack ghc, stack ghci, stack runghc, or stack exec"