2013-05-17 10:00:01 +09:00
|
|
|
module Language.Haskell.GhcMod.Debug (debugInfo, debug) where
|
2013-03-04 11:21:41 +09:00
|
|
|
|
|
|
|
|
import Control.Applicative
|
2013-05-09 10:09:12 +09:00
|
|
|
import Control.Exception.IOChoice
|
2013-03-13 13:17:22 +09:00
|
|
|
import Control.Monad
|
2013-03-04 11:21:41 +09:00
|
|
|
import Data.List (intercalate)
|
|
|
|
|
import Data.Maybe
|
2013-03-13 13:17:22 +09:00
|
|
|
import GHC
|
2013-05-19 01:16:37 +04:00
|
|
|
import GhcMonad (liftIO)
|
2013-05-17 10:00:01 +09:00
|
|
|
import Language.Haskell.GhcMod.CabalApi
|
|
|
|
|
import Language.Haskell.GhcMod.GHCApi
|
|
|
|
|
import Language.Haskell.GhcMod.Types
|
2013-03-04 11:21:41 +09:00
|
|
|
import Prelude
|
|
|
|
|
|
|
|
|
|
----------------------------------------------------------------
|
|
|
|
|
|
2013-05-20 14:28:56 +09:00
|
|
|
-- | Obtaining debug information.
|
|
|
|
|
debugInfo :: Options
|
|
|
|
|
-> Cradle
|
2013-09-05 14:35:28 +09:00
|
|
|
-> FilePath -- ^ A target file.
|
2013-05-20 14:28:56 +09:00
|
|
|
-> IO String
|
2013-09-20 17:15:41 +09:00
|
|
|
debugInfo opt cradle fileName = unlines <$> withGHC fileName (debug opt cradle fileName)
|
2013-03-04 11:21:41 +09:00
|
|
|
|
2013-05-20 14:28:56 +09:00
|
|
|
-- | Obtaining debug information.
|
|
|
|
|
debug :: Options
|
|
|
|
|
-> Cradle
|
2013-09-05 14:35:28 +09:00
|
|
|
-> FilePath -- ^ A target file.
|
2013-05-20 14:28:56 +09:00
|
|
|
-> Ghc [String]
|
2013-09-20 17:15:41 +09:00
|
|
|
debug opt cradle fileName = do
|
2013-09-19 15:58:50 +09:00
|
|
|
CompilerOptions gopts incDir pkgs <-
|
2013-03-04 11:21:41 +09:00
|
|
|
if cabal then
|
2013-09-19 16:21:48 +09:00
|
|
|
liftIO (fromCabalFile ||> return simpleCompilerOption)
|
2013-03-04 11:21:41 +09:00
|
|
|
else
|
2013-09-19 16:21:48 +09:00
|
|
|
return simpleCompilerOption
|
2013-05-19 01:16:37 +04:00
|
|
|
[fast] <- do
|
2013-03-13 13:17:22 +09:00
|
|
|
void $ initializeFlagsWithCradle opt cradle gopts True
|
2013-08-21 17:21:49 +09:00
|
|
|
setTargetFiles [fileName]
|
2013-04-01 15:59:53 +09:00
|
|
|
pure . canCheckFast <$> depanal [] False
|
2013-03-04 11:21:41 +09:00
|
|
|
return [
|
2013-09-20 17:15:41 +09:00
|
|
|
"Current directory: " ++ currentDir
|
2013-03-04 11:21:41 +09:00
|
|
|
, "Cabal file: " ++ cabalFile
|
2013-03-05 16:57:18 +09:00
|
|
|
, "GHC options: " ++ unwords gopts
|
|
|
|
|
, "Include directories: " ++ unwords incDir
|
2013-03-04 11:21:41 +09:00
|
|
|
, "Dependent packages: " ++ intercalate ", " pkgs
|
2013-03-04 13:11:04 +09:00
|
|
|
, "Fast check: " ++ if fast then "Yes" else "No"
|
2013-03-04 11:21:41 +09:00
|
|
|
]
|
|
|
|
|
where
|
|
|
|
|
currentDir = cradleCurrentDir cradle
|
2013-09-19 16:21:48 +09:00
|
|
|
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
|