@@ -15,14 +15,23 @@ import Version
1515import Print
1616import Env
1717
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)
2122
2223-- | 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+
2635 localBinDir <- getLocalBin
2736 let hie = " hie" <.> exe
2837 liftIO $ do
@@ -31,6 +40,12 @@ stackInstallHie versionNumber = do
3140 copyFile (localBinDir </> hie)
3241 (localBinDir </> " hie-" ++ dropExtension versionNumber <.> exe)
3342
43+ getGhcVersionOfCfgFile :: String -> Action VersionNumber
44+ getGhcVersionOfCfgFile stackFile = do
45+ Stdout ghcVersion <-
46+ execStackWithCfgFile stackFile [" exec" , " ghc" , " --" , " --numeric-version" ]
47+ return $ trim ghcVersion
48+
3449-- | check `stack` has the required version
3550checkStack :: Action ()
3651checkStack = do
@@ -53,14 +68,21 @@ stackBuildData = do
5368
5469-- | Execute a stack command for a specified ghc, discarding the output
5570execStackWithGhc_ :: VersionNumber -> [String ] -> Action ()
56- execStackWithGhc_ versionNumber args = do
57- let stackFile = " stack-" ++ versionNumber ++ " .yaml"
58- command_ [] " stack" ((" --stack-yaml=" ++ stackFile) : args)
71+ execStackWithGhc_ = execStackWithGhc
5972
6073-- | Execute a stack command for a specified ghc
6174execStackWithGhc :: CmdResult r => VersionNumber -> [String ] -> Action r
6275execStackWithGhc versionNumber args = do
6376 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 =
6486 command [] " stack" ((" --stack-yaml=" ++ stackFile) : args)
6587
6688-- | 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
6991
7092-- | Execute a stack command with the same resolver as the build script, discarding the output
7193execStackShake_ :: [String ] -> Action ()
72- execStackShake_ args = command_ [] " stack " ( " --stack-yaml=install/shake.yaml " : args)
94+ execStackShake_ = execStackShake
7395
7496
7597-- | Error message when the `stack` binary is an older version
0 commit comments