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

Commit c845d3c

Browse files
authored
Merge pull request #1379 from jneira/cabal3-build
Add support for building with cabal-3.0.0.0
2 parents 503b4bd + 62d3422 commit c845d3c

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

install/src/Cabal.hs

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ execCabal_ = command_ [] "cabal"
2626

2727
cabalBuildData :: Action ()
2828
cabalBuildData = do
29-
execCabal_ ["new-build", "hoogle"]
30-
execCabal_ ["new-exec", "hoogle", "generate"]
29+
execCabal_ ["v2-build", "hoogle"]
30+
execCabal_ ["v2-exec", "hoogle", "generate"]
3131

3232
cabalBuildHie :: VersionNumber -> Action ()
3333
cabalBuildHie versionNumber = do
@@ -37,18 +37,26 @@ cabalBuildHie versionNumber = do
3737
error (ghcVersionNotFoundFailMsg versionNumber)
3838
Just p -> return p
3939
execCabal_
40-
["new-build", "-w", ghcPath, "--write-ghc-environment-files=never", "--max-backjumps=5000"]
40+
["v2-build", "-w", ghcPath, "--write-ghc-environment-files=never", "--max-backjumps=5000", "--disable-tests"]
4141

4242
cabalInstallHie :: VersionNumber -> Action ()
4343
cabalInstallHie versionNumber = do
4444
localBin <- getLocalBin
45-
execCabal_
46-
[ "new-install"
45+
cabalVersion <- getCabalVersion
46+
47+
let isCabal3 = checkVersion [3,0,0,0] cabalVersion
48+
installDirOpt | isCabal3 = "--installdir"
49+
| otherwise = "--symlink-bindir"
50+
installMethod | isWindowsSystem && isCabal3 = ["--install-method=copy"]
51+
| otherwise = []
52+
execCabal_ $
53+
[ "v2-install"
4754
, "--write-ghc-environment-files=never"
48-
, "--symlink-bindir=" ++ localBin
55+
, installDirOpt ++ "=" ++ localBin
4956
, "exe:hie"
5057
, "--overwrite-policy=always"
5158
]
59+
++ installMethod
5260
liftIO $ do
5361
copyFile (localBin </> "hie" <.> exe)
5462
(localBin </> "hie-" ++ versionNumber <.> exe)
@@ -66,7 +74,7 @@ installCabal = do
6674
-- install `cabal-install` if not already installed
6775
unless cabalExeOk $ execStackShake_ ["install", "cabal-install"]
6876

69-
-- | check `stack` has the required version
77+
-- | check `cabal` has the required version
7078
checkCabal :: Action ()
7179
checkCabal = do
7280
cabalVersion <- getCabalVersion
@@ -77,22 +85,25 @@ checkCabal = do
7785
getCabalVersion :: Action String
7886
getCabalVersion = trimmedStdout <$> execCabal ["--numeric-version"]
7987

80-
-- TODO: this restriction will be gone in the next release of cabal
8188
validateCabalNewInstallIsSupported :: Action ()
82-
validateCabalNewInstallIsSupported = when isWindowsSystem $ do
83-
printInStars cabalInstallNotSuportedFailMsg
84-
error cabalInstallNotSuportedFailMsg
89+
validateCabalNewInstallIsSupported = do
90+
cabalVersion <- getCabalVersion
91+
let isUnsupportedVersion =
92+
not $ checkVersion requiredCabalVersionForWindows cabalVersion
93+
when (isWindowsSystem && isUnsupportedVersion) $ do
94+
printInStars cabalInstallNotSuportedFailMsg
95+
error cabalInstallNotSuportedFailMsg
8596

86-
-- | Error message when a windows system tries to install HIE via `cabal new-install`
97+
-- | Error message when a windows system tries to install HIE via `cabal v2-install`
8798
cabalInstallNotSuportedFailMsg :: String
8899
cabalInstallNotSuportedFailMsg =
89100
"This system has been identified as a windows system.\n"
90-
++ "Unfortunately, `cabal new-install` is currently not supported on windows.\n"
91-
++ "Please use one of the stack-based targets.\n\n"
101+
++ "Unfortunately, `cabal v2-install` is supported since version "++ cabalVersion ++".\n"
102+
++ "Please upgrade your cabal executable or use one of the stack-based targets.\n\n"
92103
++ "If this system has been falsely identified, please open an issue at:\n\thttps://github.com/haskell/haskell-ide-engine\n"
104+
where cabalVersion = versionToString requiredCabalVersionForWindows
93105

94-
95-
-- | Error message when the `stack` binary is an older version
106+
-- | Error message when the `cabal` binary is an older version
96107
cabalInstallIsOldFailMsg :: String -> String
97108
cabalInstallIsOldFailMsg cabalVersion =
98109
"The `cabal` executable is outdated.\n"
@@ -106,3 +117,6 @@ cabalInstallIsOldFailMsg cabalVersion =
106117

107118
requiredCabalVersion :: RequiredVersion
108119
requiredCabalVersion = [2, 4, 1, 0]
120+
121+
requiredCabalVersionForWindows :: RequiredVersion
122+
requiredCabalVersionForWindows = [3, 0, 0, 0]

0 commit comments

Comments
 (0)