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

Add stack-install-cabal target and confirmation messages #1405

Merged
merged 2 commits into from
Oct 8, 2019
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
23 changes: 17 additions & 6 deletions install/src/Cabal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,20 @@ cabalInstallHie versionNumber = do
, "--overwrite-policy=always"
]
++ installMethod

let minorVerExe = "hie-" ++ versionNumber <.> exe
majorVerExe = "hie-" ++ dropExtension versionNumber <.> exe

liftIO $ do
copyFile (localBin </> "hie" <.> exe)
(localBin </> "hie-" ++ versionNumber <.> exe)
copyFile (localBin </> "hie" <.> exe)
(localBin </> "hie-" ++ dropExtension versionNumber <.> exe)
copyFile (localBin </> "hie" <.> exe) (localBin </> minorVerExe)
copyFile (localBin </> "hie" <.> exe) (localBin </> majorVerExe)

printLine $ "Copied executables "
++ ("hie-wrapper" <.> exe) ++ ", "
++ ("hie" <.> exe) ++ ", "
++ majorVerExe ++ " and "
++ minorVerExe
++ " to " ++ localBin

installCabal :: Action ()
installCabal = do
Expand All @@ -70,9 +79,11 @@ installCabal = do
c <- liftIO (findExecutable "cabal")
when (isJust c) checkCabal
return $ isJust c

-- install `cabal-install` if not already installed
unless cabalExeOk $ execStackShake_ ["install", "cabal-install"]
if cabalExeOk
then printLine "There is already a cabal executable in $PATH with the required minimum version."
else execStackShake_ ["install", "cabal-install"]

-- | check `cabal` has the required version
checkCabal :: Action ()
Expand Down
8 changes: 8 additions & 0 deletions install/src/Help.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Env
import Print
import Version
import BuildSystem
import Cabal

printUsage :: Action ()
printUsage = do
Expand Down Expand Up @@ -83,6 +84,7 @@ helpMessage versions@BuildableVersions {..} = do
, stackTarget buildAllTarget
, stackTarget buildDataTarget
]
++ (if isRunFromStack then [stackTarget installCabalTarget] else [])
++ map (stackTarget . hieTarget) stackVersions

cabalTargets =
Expand Down Expand Up @@ -136,6 +138,12 @@ cabalGhcsTarget =
, "Show all GHC versions that can be installed via `cabal-build` and `cabal-build-all`."
)

installCabalTarget :: TargetDescription
installCabalTarget =
( "install-cabal"
, "Install the cabal executable. It will install the required minimum version for hie (currently " ++ versionToString requiredCabalVersion ++ ") if it isn't already present in $PATH"
)

-- | Creates a message of the form "a, b, c and d", where a,b,c,d are GHC versions.
-- If there is no GHC in the list of `hieVersions`
allVersionMessage :: [String] -> String
Expand Down
1 change: 1 addition & 0 deletions install/src/HieInstall.hs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ defaultMain = do
)

-- stack specific targets
when isRunFromStack (phony "stack-install-cabal" (need ["cabal"]))
fendor marked this conversation as resolved.
Show resolved Hide resolved
phony "stack-build" (need (reverse $ map ("stack-hie-" ++) hieVersions))
phony "stack-build-all" (need ["build-data", "build"])
phony "stack-build-data" $ do
Expand Down