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
109 lines (104 loc) · 3.66 KB
/
SetupCmd.hs
File metadata and controls
109 lines (104 loc) · 3.66 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
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
-- | Types and functions related to Stack's @setup@ command.
module Stack.SetupCmd
( SetupCmdOpts (..)
, setupCmd
, setup
) where
import Stack.Prelude
import Stack.Runners
( ShouldReexec (..), withBuildConfig, withConfig )
import Stack.Setup ( SetupOpts (..), ensureCompilerAndMsys )
import Stack.Types.BuildConfig
( HasBuildConfig, stackYamlL, wantedCompilerVersionL )
import Stack.Types.CompilerPaths ( CompilerPaths (..) )
import Stack.Types.Config ( Config (..), HasConfig (..) )
import Stack.Types.GHCVariant ( HasGHCVariant )
import Stack.Types.Runner ( Runner )
import Stack.Types.Version ( VersionCheck (..) )
-- | Type representing command line options for the @stack setup@ command.
data SetupCmdOpts = SetupCmdOpts
{ scoCompilerVersion :: !(Maybe WantedCompiler)
, scoForceReinstall :: !Bool
, scoGHCBindistURL :: !(Maybe String)
, scoGHCJSBootOpts :: ![String]
, scoGHCJSBootClean :: !Bool
}
-- | Function underlying the @stack setup@ command.
setupCmd :: SetupCmdOpts -> RIO Runner ()
setupCmd sco@SetupCmdOpts{..} = withConfig YesReexec $ do
installGHC <- view $ configL.to configInstallGHC
if installGHC
then
withBuildConfig $ do
(wantedCompiler, compilerCheck, mstack) <-
case scoCompilerVersion of
Just v -> pure (v, MatchMinor, Nothing)
Nothing -> (,,)
<$> view wantedCompilerVersionL
<*> view (configL.to configCompilerCheck)
<*> (Just <$> view stackYamlL)
setup sco wantedCompiler compilerCheck mstack
else
prettyWarnL
[ "The"
, style Shell "--no-install-ghc"
, flow "flag is inconsistent with"
, style Shell (flow "stack setup") <> "."
, flow "No action taken."
]
setup ::
(HasBuildConfig env, HasGHCVariant env)
=> SetupCmdOpts
-> WantedCompiler
-> VersionCheck
-> Maybe (Path Abs File)
-> RIO env ()
setup SetupCmdOpts{..} wantedCompiler compilerCheck mstack = do
Config{..} <- view configL
sandboxedGhc <- cpSandboxed . fst <$> ensureCompilerAndMsys SetupOpts
{ soptsInstallIfMissing = True
, soptsUseSystem = configSystemGHC && not scoForceReinstall
, soptsWantedCompiler = wantedCompiler
, soptsCompilerCheck = compilerCheck
, soptsStackYaml = mstack
, soptsForceReinstall = scoForceReinstall
, soptsSanityCheck = True
, soptsSkipGhcCheck = False
, soptsSkipMsys = configSkipMsys
, soptsResolveMissingGHC = Nothing
, soptsGHCBindistURL = scoGHCBindistURL
}
let compiler = case wantedCompiler of
WCGhc _ -> "GHC"
WCGhcGit{} -> "GHC (built from source)"
WCGhcjs {} -> "GHCJS"
compilerHelpMsg = fillSep
[ flow "To use this"
, compiler
, flow "and packages outside of a project, consider using:"
, style Shell (flow "stack ghc") <> ","
, style Shell (flow "stack ghci") <> ","
, style Shell (flow "stack runghc") <> ","
, "or"
, style Shell (flow "stack exec") <> "."
]
if sandboxedGhc
then prettyInfoL
[ flow "Stack will use a sandboxed"
, compiler
, flow "it installed."
, compilerHelpMsg
]
else prettyInfoL
[ flow "Stack will use the"
, compiler
, flow "on your PATH. For more information on paths, see"
, style Shell (flow "stack path")
, "and"
, style Shell (flow "stack exec env") <> "."
, compilerHelpMsg
]