diff --git a/Language/Haskell/GhcMod/GhcPkg.hs b/Language/Haskell/GhcMod/GhcPkg.hs index 4418830..f5ca4b0 100644 --- a/Language/Haskell/GhcMod/GhcPkg.hs +++ b/Language/Haskell/GhcMod/GhcPkg.hs @@ -19,6 +19,7 @@ import Prelude import Language.Haskell.GhcMod.Types import Language.Haskell.GhcMod.Monad.Types import Language.Haskell.GhcMod.CabalHelper +import Language.Haskell.GhcMod.PathsAndFiles ghcVersion :: Int ghcVersion = read cProjectVersionInt @@ -59,7 +60,16 @@ ghcDbOpt (PackageDb pkgDb) getPackageCachePaths :: IOish m => FilePath -> GhcModT m [FilePath] getPackageCachePaths sysPkgCfg = do - pkgDbStack <- getPackageDbStack + crdl <- cradle + pkgDbStack <- if isJust $ cradleCabalFile crdl + then do + getPackageDbStack + else do + mdb <- liftIO $ getSandboxDb $ cradleRootDir crdl + return $ case mdb of + Just db -> [db] + Nothing -> [GlobalDb, UserDb] + catMaybes <$> (liftIO . resolvePackageConfig sysPkgCfg) `mapM` pkgDbStack -- TODO: use PkgConfRef diff --git a/Language/Haskell/GhcMod/PathsAndFiles.hs b/Language/Haskell/GhcMod/PathsAndFiles.hs index c344c8f..085cf52 100644 --- a/Language/Haskell/GhcMod/PathsAndFiles.hs +++ b/Language/Haskell/GhcMod/PathsAndFiles.hs @@ -29,7 +29,7 @@ import Data.Traversable hiding (mapM) import Distribution.Helper (buildPlatform) import System.Directory import System.FilePath -import System.IO.Unsafe +import System.Process import Language.Haskell.GhcMod.Types import Language.Haskell.GhcMod.Error @@ -78,13 +78,14 @@ getSandboxDb :: FilePath -> IO (Maybe GhcPkgDb) getSandboxDb d = do mConf <- traverse readFile =<< mightExist (d "cabal.sandbox.config") - return $ PackageDb . fixPkgDbVer <$> (extractSandboxDbDir =<< mConf) + bp <- buildPlatform readProcess + return $ PackageDb . fixPkgDbVer bp <$> (extractSandboxDbDir =<< mConf) where - fixPkgDbVer dir = - case takeFileName dir == ghcSandboxPkgDbDir of + fixPkgDbVer bp dir = + case takeFileName dir == ghcSandboxPkgDbDir bp of True -> dir - False -> takeDirectory dir ghcSandboxPkgDbDir + False -> takeDirectory dir ghcSandboxPkgDbDir bp -- | Extract the sandbox package db directory from the cabal.sandbox.config -- file. Exception is thrown if the sandbox config file is broken. @@ -190,12 +191,9 @@ setupConfigPath = "dist/setup-config" -- localBuildInfoFile defaultDistPref macrosHeaderPath :: FilePath macrosHeaderPath = "dist/build/autogen/cabal_macros.h" -ghcSandboxPkgDbDir :: String -ghcSandboxPkgDbDir = - cabalBuildPlatform ++ "-ghc-" ++ cProjectVersion ++ "-packages.conf.d" - -cabalBuildPlatform :: String -cabalBuildPlatform = unsafePerformIO $ buildPlatform +ghcSandboxPkgDbDir :: String -> String +ghcSandboxPkgDbDir buildPlatf = do + buildPlatf ++ "-ghc-" ++ cProjectVersion ++ "-packages.conf.d" packageCache :: String packageCache = "package.cache"