@@ -15,14 +15,23 @@ import Version
15
15
import Print
16
16
import Env
17
17
18
- stackBuildHie :: VersionNumber -> Action ()
19
- stackBuildHie versionNumber = execStackWithGhc_ versionNumber [" build" ]
20
- `actionOnException` liftIO (putStrLn stackBuildFailMsg)
18
+ stackInstallHieWithErrMsg :: Maybe VersionNumber -> Action ()
19
+ stackInstallHieWithErrMsg mbVersionNumber =
20
+ stackInstallHie mbVersionNumber
21
+ `actionOnException` liftIO (putStrLn stackBuildFailMsg)
21
22
22
23
-- | copy the built binaries into the localBinDir
23
- stackInstallHie :: VersionNumber -> Action ()
24
- stackInstallHie versionNumber = do
25
- execStackWithGhc_ versionNumber [" install" ]
24
+ stackInstallHie :: Maybe VersionNumber -> Action ()
25
+ stackInstallHie mbVersionNumber = do
26
+ versionNumber <-
27
+ case mbVersionNumber of
28
+ Nothing -> do
29
+ execStackWithCfgFile_ " stack.yaml" [" install" ]
30
+ getGhcVersionOfCfgFile " stack.yaml"
31
+ Just vn -> do
32
+ execStackWithGhc_ vn [" install" ]
33
+ return vn
34
+
26
35
localBinDir <- getLocalBin
27
36
let hie = " hie" <.> exe
28
37
liftIO $ do
@@ -31,6 +40,12 @@ stackInstallHie versionNumber = do
31
40
copyFile (localBinDir </> hie)
32
41
(localBinDir </> " hie-" ++ dropExtension versionNumber <.> exe)
33
42
43
+ getGhcVersionOfCfgFile :: String -> Action VersionNumber
44
+ getGhcVersionOfCfgFile stackFile = do
45
+ Stdout ghcVersion <-
46
+ execStackWithCfgFile stackFile [" exec" , " ghc" , " --" , " --numeric-version" ]
47
+ return $ trim ghcVersion
48
+
34
49
-- | check `stack` has the required version
35
50
checkStack :: Action ()
36
51
checkStack = do
@@ -53,14 +68,21 @@ stackBuildData = do
53
68
54
69
-- | Execute a stack command for a specified ghc, discarding the output
55
70
execStackWithGhc_ :: VersionNumber -> [String ] -> Action ()
56
- execStackWithGhc_ versionNumber args = do
57
- let stackFile = " stack-" ++ versionNumber ++ " .yaml"
58
- command_ [] " stack" ((" --stack-yaml=" ++ stackFile) : args)
71
+ execStackWithGhc_ = execStackWithGhc
59
72
60
73
-- | Execute a stack command for a specified ghc
61
74
execStackWithGhc :: CmdResult r => VersionNumber -> [String ] -> Action r
62
75
execStackWithGhc versionNumber args = do
63
76
let stackFile = " stack-" ++ versionNumber ++ " .yaml"
77
+ execStackWithCfgFile stackFile args
78
+
79
+ -- | Execute a stack command for a specified stack.yaml file, discarding the output
80
+ execStackWithCfgFile_ :: String -> [String ] -> Action ()
81
+ execStackWithCfgFile_ = execStackWithCfgFile
82
+
83
+ -- | Execute a stack command for a specified stack.yaml file
84
+ execStackWithCfgFile :: CmdResult r => String -> [String ] -> Action r
85
+ execStackWithCfgFile stackFile args =
64
86
command [] " stack" ((" --stack-yaml=" ++ stackFile) : args)
65
87
66
88
-- | Execute a stack command with the same resolver as the build script
@@ -69,7 +91,7 @@ execStackShake args = command [] "stack" ("--stack-yaml=install/shake.yaml" : ar
69
91
70
92
-- | Execute a stack command with the same resolver as the build script, discarding the output
71
93
execStackShake_ :: [String ] -> Action ()
72
- execStackShake_ args = command_ [] " stack " ( " --stack-yaml=install/shake.yaml " : args)
94
+ execStackShake_ = execStackShake
73
95
74
96
75
97
-- | Error message when the `stack` binary is an older version
0 commit comments