From 3212557fe62f33d4086c1c55b2fd5c0b6d88a175 Mon Sep 17 00:00:00 2001 From: jneira Date: Wed, 29 Jan 2020 10:05:58 +0100 Subject: [PATCH 1/2] Add dev target --- install/src/Cabal.hs | 2 +- install/src/Help.hs | 11 ++++++---- install/src/HieInstall.hs | 10 ++++++--- install/src/Stack.hs | 43 ++++++++++++++++++++++++++++++--------- 4 files changed, 48 insertions(+), 18 deletions(-) diff --git a/install/src/Cabal.hs b/install/src/Cabal.hs index 5ae3dcb30..171cb7667 100644 --- a/install/src/Cabal.hs +++ b/install/src/Cabal.hs @@ -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 diff --git a/install/src/Help.hs b/install/src/Help.hs index c0f600bc6..a512f2593 100644 --- a/install/src/Help.hs +++ b/install/src/Help.hs @@ -78,7 +78,7 @@ helpMessage versions@BuildableVersions {..} = do [emptyTarget] [ generalTargets , defaultTargets - , if isRunFromCabal then [cabalGhcsTarget] else [] + , if isRunFromCabal then [cabalGhcsTarget] else [stackDevTarget] , [macosIcuTarget] ] @@ -97,13 +97,13 @@ templateTarget = ("", "") 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 = @@ -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") \ No newline at end of file diff --git a/install/src/HieInstall.hs b/install/src/HieInstall.hs index b0e723ac3..bb6f36883 100644 --- a/install/src/HieInstall.hs +++ b/install/src/HieInstall.hs @@ -78,9 +78,8 @@ 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 ) @@ -88,6 +87,11 @@ defaultMain = do 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 diff --git a/install/src/Stack.hs b/install/src/Stack.hs index c33db4432..2aff1d791 100644 --- a/install/src/Stack.hs +++ b/install/src/Stack.hs @@ -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 @@ -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 @@ -53,14 +68,22 @@ 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_ stackFile args = + command_ [] "stack" (("--stack-yaml=" ++ stackFile) : args) + +-- | 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 @@ -69,7 +92,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 From 40483ba367d648d2cb9770035f7d9b9396a2eb6d Mon Sep 17 00:00:00 2001 From: jneira Date: Wed, 29 Jan 2020 10:09:52 +0100 Subject: [PATCH 2/2] Remove duplication --- install/src/Stack.hs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/install/src/Stack.hs b/install/src/Stack.hs index 2aff1d791..ec8aabcd0 100644 --- a/install/src/Stack.hs +++ b/install/src/Stack.hs @@ -78,8 +78,7 @@ execStackWithGhc versionNumber args = do -- | Execute a stack command for a specified stack.yaml file, discarding the output execStackWithCfgFile_ :: String -> [String] -> Action () -execStackWithCfgFile_ stackFile args = - command_ [] "stack" (("--stack-yaml=" ++ stackFile) : args) +execStackWithCfgFile_ = execStackWithCfgFile -- | Execute a stack command for a specified stack.yaml file execStackWithCfgFile :: CmdResult r => String -> [String] -> Action r