From 8e4d2cec213a02a171c9b35d343f1571239db0fd Mon Sep 17 00:00:00 2001 From: Kazu Yamamoto Date: Thu, 19 Sep 2013 16:21:48 +0900 Subject: [PATCH] Obsoleting fromCabalFile. --- Language/Haskell/GhcMod/CabalApi.hs | 17 ++++------------- Language/Haskell/GhcMod/Debug.hs | 14 ++++++++++---- Language/Haskell/GhcMod/GHCApi.hs | 8 +++++--- Language/Haskell/GhcMod/Internal.hs | 2 +- 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/Language/Haskell/GhcMod/CabalApi.hs b/Language/Haskell/GhcMod/CabalApi.hs index c37bd38..270a654 100644 --- a/Language/Haskell/GhcMod/CabalApi.hs +++ b/Language/Haskell/GhcMod/CabalApi.hs @@ -1,7 +1,7 @@ {-# LANGUAGE OverloadedStrings #-} module Language.Haskell.GhcMod.CabalApi ( - fromCabalFile + getCompilerOptions , parseCabalFile , cabalAllBuildInfo , cabalDependPackages @@ -33,24 +33,15 @@ import System.FilePath ---------------------------------------------------------------- --- | Parsing a cabal file in 'Cradle' and returns --- options for GHC, include directories for modules and --- package names of dependency. -fromCabalFile :: [GHCOption] -> Cradle -> IO CompilerOptions -fromCabalFile ghcopts cradle = - parseCabalFile cfile >>= cookInfo ghcopts cradle - where - Just cfile = cradleCabalFile cradle - -cookInfo :: [GHCOption] -> Cradle -> PackageDescription -> IO CompilerOptions -cookInfo ghcopts cradle cabal = do +getCompilerOptions :: [GHCOption] -> Cradle -> PackageDescription -> IO CompilerOptions +getCompilerOptions ghcopts cradle pkgDesc = do gopts <- getGHCOptions ghcopts cdir $ head buildInfos return $ CompilerOptions gopts idirs depPkgs where wdir = cradleCurrentDir cradle Just cdir = cradleCabalDir cradle Just cfile = cradleCabalFile cradle - buildInfos = cabalAllBuildInfo cabal + buildInfos = cabalAllBuildInfo pkgDesc idirs = includeDirectories cdir wdir $ cabalSourceDirs buildInfos depPkgs = removeThem problematicPackages $ removeMe cfile $ cabalDependPackages buildInfos diff --git a/Language/Haskell/GhcMod/Debug.hs b/Language/Haskell/GhcMod/Debug.hs index 4dc6d64..946e223 100644 --- a/Language/Haskell/GhcMod/Debug.hs +++ b/Language/Haskell/GhcMod/Debug.hs @@ -31,9 +31,9 @@ debug :: Options debug opt cradle ver fileName = do CompilerOptions gopts incDir pkgs <- if cabal then - liftIO $ fromCabalFile (ghcOpts opt) cradle ||> return (CompilerOptions (ghcOpts opt) [] []) + liftIO (fromCabalFile ||> return simpleCompilerOption) else - return (CompilerOptions (ghcOpts opt) [] []) + return simpleCompilerOption [fast] <- do void $ initializeFlagsWithCradle opt cradle gopts True setTargetFiles [fileName] @@ -49,5 +49,11 @@ debug opt cradle ver fileName = do ] where currentDir = cradleCurrentDir cradle - cabal = isJust $ cradleCabalFile cradle - cabalFile = fromMaybe "" $ cradleCabalFile cradle + mCabalFile = cradleCabalFile cradle + cabal = isJust mCabalFile + cabalFile = fromMaybe "" mCabalFile + origGopts = ghcOpts opt + simpleCompilerOption = CompilerOptions origGopts [] [] + fromCabalFile = parseCabalFile file >>= getCompilerOptions origGopts cradle + where + file = fromJust mCabalFile diff --git a/Language/Haskell/GhcMod/GHCApi.hs b/Language/Haskell/GhcMod/GHCApi.hs index 22fa21d..d0ea353 100644 --- a/Language/Haskell/GhcMod/GHCApi.hs +++ b/Language/Haskell/GhcMod/GHCApi.hs @@ -16,7 +16,7 @@ import Control.Applicative import Control.Exception import Control.Monad import CoreMonad -import Data.Maybe (isJust) +import Data.Maybe (isJust,fromJust) import DynFlags import Exception import GHC @@ -65,9 +65,11 @@ initializeFlagsWithCradle opt cradle ghcopts logging | cabal = withCabal |||> withoutCabal | otherwise = withoutCabal where - cabal = isJust $ cradleCabalFile cradle + mCradleFile = cradleCabalFile cradle + cabal = isJust mCradleFile withCabal = do - compOpts <- liftIO $ fromCabalFile ghcopts cradle + pkgDesc <- liftIO $ parseCabalFile $ fromJust mCradleFile + compOpts <- liftIO $ getCompilerOptions ghcopts cradle pkgDesc initSession CabalPkg opt compOpts logging withoutCabal = initSession SingleFile opt compOpts logging diff --git a/Language/Haskell/GhcMod/Internal.hs b/Language/Haskell/GhcMod/Internal.hs index ede6db8..6991f1a 100644 --- a/Language/Haskell/GhcMod/Internal.hs +++ b/Language/Haskell/GhcMod/Internal.hs @@ -8,7 +8,7 @@ module Language.Haskell.GhcMod.Internal ( , IncludeDir , CompilerOptions(..) -- * Cabal API - , fromCabalFile + , getCompilerOptions , parseCabalFile , cabalAllBuildInfo , cabalDependPackages