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

Add dev target to stack install.hs #1615

Merged
merged 2 commits into from
Jan 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion install/src/Cabal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ execCabal :: CmdResult r => [String] -> Action r
execCabal = command [] "cabal"

execCabal_ :: [String] -> Action ()
execCabal_ = command [] "cabal"
execCabal_ = execCabal

cabalBuildData :: Action ()
cabalBuildData = do
Expand Down
11 changes: 7 additions & 4 deletions install/src/Help.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ helpMessage versions@BuildableVersions {..} = do
[emptyTarget]
[ generalTargets
, defaultTargets
, if isRunFromCabal then [cabalGhcsTarget] else []
, if isRunFromCabal then [cabalGhcsTarget] else [stackDevTarget]
, [macosIcuTarget]
]

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

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

buildTarget :: TargetDescription
buildTarget = ("hie", "Build hie with the latest available GHC and the data files")
buildTarget = ("hie", "Install hie with the latest available GHC and the data files")

buildLatestTarget :: TargetDescription
buildLatestTarget = ("latest", "Build hie with the latest available GHC")
buildLatestTarget = ("latest", "Install hie with the latest available GHC")

buildDataTarget :: TargetDescription
buildDataTarget =
Expand All @@ -122,3 +122,6 @@ cabalGhcsTarget =
( "ghcs"
, "Show all GHC versions that can be installed via `cabal-build`."
)

stackDevTarget :: TargetDescription
stackDevTarget = ("dev", "Install hie with the default stack.yaml")
10 changes: 7 additions & 3 deletions install/src/HieInstall.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,20 @@ defaultMain = do
(\version -> phony ("hie-" ++ version) $ do
need ["submodules"]
need ["check"]
if isRunFromStack then do
stackBuildHie version
stackInstallHie version
if isRunFromStack then do
stackInstallHieWithErrMsg (Just version)
else
cabalInstallHie version
)

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

-- stack specific targets
when isRunFromStack $ do

phony "dev" $ stackInstallHieWithErrMsg Nothing

-- cabal specific targets
when isRunFromCabal $ do

Expand Down
42 changes: 32 additions & 10 deletions install/src/Stack.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,23 @@ import Version
import Print
import Env

stackBuildHie :: VersionNumber -> Action ()
stackBuildHie versionNumber = execStackWithGhc_ versionNumber ["build"]
`actionOnException` liftIO (putStrLn stackBuildFailMsg)
stackInstallHieWithErrMsg :: Maybe VersionNumber -> Action ()
stackInstallHieWithErrMsg mbVersionNumber =
stackInstallHie mbVersionNumber
`actionOnException` liftIO (putStrLn stackBuildFailMsg)

-- | copy the built binaries into the localBinDir
stackInstallHie :: VersionNumber -> Action ()
stackInstallHie versionNumber = do
execStackWithGhc_ versionNumber ["install"]
stackInstallHie :: Maybe VersionNumber -> Action ()
stackInstallHie mbVersionNumber = do
versionNumber <-
case mbVersionNumber of
Nothing -> do
execStackWithCfgFile_ "stack.yaml" ["install"]
getGhcVersionOfCfgFile "stack.yaml"
Just vn -> do
execStackWithGhc_ vn ["install"]
return vn

localBinDir <- getLocalBin
let hie = "hie" <.> exe
liftIO $ do
Expand All @@ -31,6 +40,12 @@ stackInstallHie versionNumber = do
copyFile (localBinDir </> hie)
(localBinDir </> "hie-" ++ dropExtension versionNumber <.> exe)

getGhcVersionOfCfgFile :: String -> Action VersionNumber
getGhcVersionOfCfgFile stackFile = do
Stdout ghcVersion <-
execStackWithCfgFile stackFile ["exec", "ghc", "--", "--numeric-version"]
return $ trim ghcVersion

-- | check `stack` has the required version
checkStack :: Action ()
checkStack = do
Expand All @@ -53,14 +68,21 @@ stackBuildData = do

-- | Execute a stack command for a specified ghc, discarding the output
execStackWithGhc_ :: VersionNumber -> [String] -> Action ()
execStackWithGhc_ versionNumber args = do
let stackFile = "stack-" ++ versionNumber ++ ".yaml"
command_ [] "stack" (("--stack-yaml=" ++ stackFile) : args)
execStackWithGhc_ = execStackWithGhc

-- | Execute a stack command for a specified ghc
execStackWithGhc :: CmdResult r => VersionNumber -> [String] -> Action r
execStackWithGhc versionNumber args = do
let stackFile = "stack-" ++ versionNumber ++ ".yaml"
execStackWithCfgFile stackFile args

-- | Execute a stack command for a specified stack.yaml file, discarding the output
execStackWithCfgFile_ :: String -> [String] -> Action ()
execStackWithCfgFile_ = execStackWithCfgFile

-- | Execute a stack command for a specified stack.yaml file
execStackWithCfgFile :: CmdResult r => String -> [String] -> Action r
execStackWithCfgFile stackFile args =
command [] "stack" (("--stack-yaml=" ++ stackFile) : args)

-- | Execute a stack command with the same resolver as the build script
Expand All @@ -69,7 +91,7 @@ execStackShake args = command [] "stack" ("--stack-yaml=install/shake.yaml" : ar

-- | Execute a stack command with the same resolver as the build script, discarding the output
execStackShake_ :: [String] -> Action ()
execStackShake_ args = command_ [] "stack" ("--stack-yaml=install/shake.yaml" : args)
execStackShake_ = execStackShake


-- | Error message when the `stack` binary is an older version
Expand Down