From 45d6b7d67ae11b05f08cc459ad07bf4dffd08ef9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gr=C3=B6ber?= Date: Sat, 7 Feb 2015 15:23:00 +0100 Subject: [PATCH] Guess right sandbox pkg-db path on ghc version mismatch If cabal.sandbox.config contains a "package-db:" declaration with the wrong path and only the ghc version is wrong, for example: ``` package-db: /.cabal-sandbox/x86_64-linux-ghc-7.8.3-packages.conf.d ``` Even though the user is using 7.10.0.20141222 `cabal repl` will correct this and pass ``` -package-db /.cabal-sandbox/x86_64-linux-ghc-7.10.0.20141222-packages.conf.d ``` to ghci, so obviously Cabal/cabal-install is doing some magic. Conflicts: Language/Haskell/GhcMod/PathsAndFiles.hs --- Language/Haskell/GhcMod/PathsAndFiles.hs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Language/Haskell/GhcMod/PathsAndFiles.hs b/Language/Haskell/GhcMod/PathsAndFiles.hs index 064d39e..88c61a0 100644 --- a/Language/Haskell/GhcMod/PathsAndFiles.hs +++ b/Language/Haskell/GhcMod/PathsAndFiles.hs @@ -1,9 +1,11 @@ {-# LANGUAGE BangPatterns, TupleSections #-} module Language.Haskell.GhcMod.PathsAndFiles where +import Config (cProjectVersion, cTargetPlatformString) import Control.Applicative import Control.Monad import Data.List +import Data.List.Split (splitOn) import Data.Char import Data.Maybe import Data.Traversable (traverse) @@ -92,7 +94,13 @@ getSandboxDb :: FilePath -- ^ Path to the cabal package root directory -> IO (Maybe FilePath) getSandboxDb d = do mConf <- traverse readFile =<< U.mightExist (d "cabal.sandbox.config") - return $ extractSandboxDbDir =<< mConf + return $ fixPkgDbVer <$> (extractSandboxDbDir =<< mConf) + + where + fixPkgDbVer dir = + case takeFileName dir == ghcSandboxPkgDbDir of + True -> dir + False -> takeDirectory dir ghcSandboxPkgDbDir -- | Extract the sandbox package db directory from the cabal.sandbox.config file. -- Exception is thrown if the sandbox config file is broken. @@ -112,5 +120,12 @@ setupConfigFile crdl = cradleRootDir crdl setupConfigPath setupConfigPath :: FilePath setupConfigPath = localBuildInfoFile defaultDistPref +ghcSandboxPkgDbDir :: String +ghcSandboxPkgDbDir = + targetPlatform ++ "-ghc-" ++ cProjectVersion ++ "-packages.conf.d" + where + targetPlatform = display buildPlatform + packageCache :: String packageCache = "package.cache" +