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

Commit

Permalink
Merge pull request #1615 from jneira/stack-install-dev
Browse files Browse the repository at this point in the history
Add dev target to stack install.hs
  • Loading branch information
jneira authored Jan 29, 2020
2 parents 62f38f8 + 40483ba commit dc03b0b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 18 deletions.
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

0 comments on commit dc03b0b

Please sign in to comment.