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
112 lines (106 loc) · 4.18 KB
/
SetupCmd.hs
File metadata and controls
112 lines (106 loc) · 4.18 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
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}
-- | Install GHC/GHCJS and Cabal.
module Stack.SetupCmd
( setup
, setupParser
, SetupCmdOpts(..)
) where
import Control.Applicative
import Control.Monad.Logger
import Control.Monad.Reader
import Data.Monoid
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 Prelude -- silence redundant import warnings
import Stack.Setup
import Stack.Types.Compiler
import Stack.Types.Config
import Stack.Types.StackT
import Stack.Types.Version
data SetupCmdOpts = SetupCmdOpts
{ scoCompilerVersion :: !(Maybe CompilerVersion)
, scoForceReinstall :: !Bool
, scoUpgradeCabal :: !Bool
, scoSetupInfoYaml :: !String
, scoGHCBindistURL :: !(Maybe String)
}
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 )
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.boolFlags False
"upgrade-cabal"
"installing the newest version of the Cabal library globally"
OA.idm
<*> setupYamlCompatParser
<*> OA.optional (OA.strOption
(OA.long "ghc-bindist"
<> OA.metavar "URL"
<> OA.help "Alternate GHC binary distribution (requires custom --ghc-variant)"))
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
:: (StackM env m, HasConfig env, HasGHCVariant env)
=> SetupCmdOpts
-> CompilerVersion
-> VersionCheck
-> Maybe (Path Abs File)
-> m ()
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
}
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"