Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit dc03b0b

Browse files
authored
Merge pull request #1615 from jneira/stack-install-dev
Add dev target to stack install.hs
2 parents 62f38f8 + 40483ba commit dc03b0b

File tree

4 files changed

+47
-18
lines changed

4 files changed

+47
-18
lines changed

install/src/Cabal.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ execCabal :: CmdResult r => [String] -> Action r
3636
execCabal = command [] "cabal"
3737

3838
execCabal_ :: [String] -> Action ()
39-
execCabal_ = command [] "cabal"
39+
execCabal_ = execCabal
4040

4141
cabalBuildData :: Action ()
4242
cabalBuildData = do

install/src/Help.hs

+7-4
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ helpMessage versions@BuildableVersions {..} = do
7878
[emptyTarget]
7979
[ generalTargets
8080
, defaultTargets
81-
, if isRunFromCabal then [cabalGhcsTarget] else []
81+
, if isRunFromCabal then [cabalGhcsTarget] else [stackDevTarget]
8282
, [macosIcuTarget]
8383
]
8484

@@ -97,13 +97,13 @@ templateTarget = ("<target>", "")
9797

9898
hieTarget :: String -> TargetDescription
9999
hieTarget version =
100-
("hie-" ++ version, "Builds hie for GHC version " ++ version)
100+
("hie-" ++ version, "Install hie for GHC version " ++ version)
101101

102102
buildTarget :: TargetDescription
103-
buildTarget = ("hie", "Build hie with the latest available GHC and the data files")
103+
buildTarget = ("hie", "Install hie with the latest available GHC and the data files")
104104

105105
buildLatestTarget :: TargetDescription
106-
buildLatestTarget = ("latest", "Build hie with the latest available GHC")
106+
buildLatestTarget = ("latest", "Install hie with the latest available GHC")
107107

108108
buildDataTarget :: TargetDescription
109109
buildDataTarget =
@@ -122,3 +122,6 @@ cabalGhcsTarget =
122122
( "ghcs"
123123
, "Show all GHC versions that can be installed via `cabal-build`."
124124
)
125+
126+
stackDevTarget :: TargetDescription
127+
stackDevTarget = ("dev", "Install hie with the default stack.yaml")

install/src/HieInstall.hs

+7-3
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,20 @@ defaultMain = do
7878
(\version -> phony ("hie-" ++ version) $ do
7979
need ["submodules"]
8080
need ["check"]
81-
if isRunFromStack then do
82-
stackBuildHie version
83-
stackInstallHie version
81+
if isRunFromStack then do
82+
stackInstallHieWithErrMsg (Just version)
8483
else
8584
cabalInstallHie version
8685
)
8786

8887
phony "latest" (need ["hie-" ++ latestVersion])
8988
phony "hie" (need ["data", "latest"])
9089

90+
-- stack specific targets
91+
when isRunFromStack $ do
92+
93+
phony "dev" $ stackInstallHieWithErrMsg Nothing
94+
9195
-- cabal specific targets
9296
when isRunFromCabal $ do
9397

install/src/Stack.hs

+32-10
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,23 @@ import Version
1515
import Print
1616
import 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
3550
checkStack :: Action ()
3651
checkStack = do
@@ -53,14 +68,21 @@ stackBuildData = do
5368

5469
-- | Execute a stack command for a specified ghc, discarding the output
5570
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
5972

6073
-- | Execute a stack command for a specified ghc
6174
execStackWithGhc :: CmdResult r => VersionNumber -> [String] -> Action r
6275
execStackWithGhc 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
7193
execStackShake_ :: [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

Comments
 (0)