Skip to content

Commit 07bcb64

Browse files
committed
Add stack dev target
1 parent 0c78854 commit 07bcb64

File tree

4 files changed

+64
-35
lines changed

4 files changed

+64
-35
lines changed

install/src/Cabal.hs

+9-9
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ 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
4343
execCabal_ ["v2-build", "hoogle"]
4444
execCabal_ ["v2-exec", "hoogle", "generate"]
4545

4646
getGhcPathOfOrThrowError :: VersionNumber -> Action GhcPath
47-
getGhcPathOfOrThrowError versionNumber =
47+
getGhcPathOfOrThrowError versionNumber =
4848
getGhcPathOf versionNumber >>= \case
4949
Nothing -> do
5050
printInStars $ ghcVersionNotFoundFailMsg versionNumber
@@ -68,21 +68,21 @@ cabalInstallHie versionNumber = do
6868
, "--write-ghc-environment-files=never"
6969
, installDirOpt, localBin
7070
, "--max-backjumps=5000"
71-
, "exe:haskell-ide"
71+
, "exe:hie"
7272
, "--overwrite-policy=always"
7373
]
7474
++ installMethod
7575

76-
let minorVerExe = "haskell-ide-" ++ versionNumber <.> exe
77-
majorVerExe = "haskell-ide-" ++ dropExtension versionNumber <.> exe
76+
let minorVerExe = "hie-" ++ versionNumber <.> exe
77+
majorVerExe = "hie-" ++ dropExtension versionNumber <.> exe
7878

7979
liftIO $ do
80-
copyFile (localBin </> "haskell-ide" <.> exe) (localBin </> minorVerExe)
81-
copyFile (localBin </> "haskell-ide" <.> exe) (localBin </> majorVerExe)
80+
copyFile (localBin </> "hie" <.> exe) (localBin </> minorVerExe)
81+
copyFile (localBin </> "hie" <.> exe) (localBin </> majorVerExe)
8282

8383
printLine $ "Copied executables "
84-
++ ("haskell-ide-wrapper" <.> exe) ++ ", "
85-
++ ("haskell-ide" <.> exe) ++ ", "
84+
++ ("hie-wrapper" <.> exe) ++ ", "
85+
++ ("hie" <.> exe) ++ ", "
8686
++ majorVerExe ++ " and "
8787
++ minorVerExe
8888
++ " to " ++ localBin

install/src/Help.hs

+9-6
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ shortHelpMessage = do
5151
, cabalGhcsTarget
5252
]
5353

54-
-- | A record that specifies for each build system which versions of @haskell-ide@ can be built.
54+
-- | A record that specifies for each build system which versions of @hie@ can be built.
5555
data BuildableVersions = BuildableVersions
5656
{ stackVersions :: [VersionNumber]
5757
, cabalVersions :: [VersionNumber]
@@ -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,17 +97,17 @@ templateTarget = ("<target>", "")
9797

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

102102
buildTarget :: TargetDescription
103-
buildTarget = ("haskell-ide", "Build haskell-ide 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 haskell-ide with the latest available GHC")
106+
buildLatestTarget = ("latest", "Install hie with the latest available GHC")
107107

108108
buildDataTarget :: TargetDescription
109109
buildDataTarget =
110-
("data", "Get the required data-files for `haskell-ide` (Hoogle DB)")
110+
("data", "Get the required data-files for `hie` (Hoogle DB)")
111111

112112
-- special targets
113113

@@ -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

+11-7
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ defaultMain = do
5353
-- used for stack-based targets
5454
stackVersions <- getHieVersions
5555

56-
let versions = if isRunFromStack then stackVersions else cabalVersions
56+
let versions = if isRunFromStack then stackVersions else cabalVersions
5757

5858
let toolsVersions = BuildableVersions stackVersions cabalVersions
5959

@@ -65,7 +65,7 @@ defaultMain = do
6565
phony "submodules" updateSubmodules
6666
phony "short-help" shortHelpMessage
6767
phony "help" (helpMessage toolsVersions)
68-
68+
6969
phony "check" (if isRunFromStack then checkStack else checkCabal_)
7070

7171
phony "data" $ do
@@ -75,18 +75,22 @@ defaultMain = do
7575

7676
forM_
7777
versions
78-
(\version -> phony ("haskell-ide-" ++ version) $ do
78+
(\version -> phony ("hie-" ++ version) $ do
7979
need ["submodules"]
8080
need ["check"]
8181
if isRunFromStack then do
82-
stackBuildHie version
83-
stackInstallHie version
82+
stackInstallHieWithErrMsg (Just version)
8483
else
8584
cabalInstallHie version
8685
)
8786

88-
phony "latest" (need ["haskell-ide-" ++ latestVersion])
89-
phony "haskell-ide" (need ["data", "latest"])
87+
phony "latest" (need ["hie-" ++ latestVersion])
88+
phony "hie" (need ["data", "latest"])
89+
90+
-- stack specific targets
91+
when isRunFromStack $ do
92+
93+
phony "dev" $ stackInstallHieWithErrMsg Nothing
9094

9195
-- cabal specific targets
9296
when isRunFromCabal $ do

install/src/Stack.hs

+35-13
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,36 @@ 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
27-
let hie = "haskell-ide" <.> exe
36+
let hie = "hie" <.> exe
2837
liftIO $ do
2938
copyFile (localBinDir </> hie)
30-
(localBinDir </> "haskell-ide-" ++ versionNumber <.> exe)
39+
(localBinDir </> "hie-" ++ versionNumber <.> exe)
3140
copyFile (localBinDir </> hie)
32-
(localBinDir </> "haskell-ide-" ++ dropExtension versionNumber <.> exe)
41+
(localBinDir </> "hie-" ++ dropExtension versionNumber <.> exe)
42+
43+
getGhcVersionOfCfgFile :: String -> Action VersionNumber
44+
getGhcVersionOfCfgFile stackFile = do
45+
Stdout ghcVersion <-
46+
execStackWithCfgFile stackFile ["exec", "ghc", "--", "--numeric-version"]
47+
return $ trim ghcVersion
3348

3449
-- | check `stack` has the required version
3550
checkStack :: Action ()
@@ -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)