From 7ec9fc1ffb4b7a2cdebabf1874b9a89f355fd0bc Mon Sep 17 00:00:00 2001 From: Kazu Yamamoto Date: Wed, 10 Apr 2013 15:02:49 +0900 Subject: [PATCH] fixing #118. --- CabalApi.hs | 4 ++-- GHCApi.hs | 16 +++++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/CabalApi.hs b/CabalApi.hs index 82592f4..ee9b439 100644 --- a/CabalApi.hs +++ b/CabalApi.hs @@ -12,7 +12,7 @@ module CabalApi ( import Control.Applicative import Control.Exception (throwIO) import Data.List (intercalate) -import Data.Maybe (maybeToList, listToMaybe, fromMaybe) +import Data.Maybe (maybeToList, listToMaybe, fromJust) import Data.Set (fromList, toList) import Distribution.Package (Dependency(Dependency), PackageName(PackageName)) import Distribution.PackageDescription @@ -71,7 +71,7 @@ getGHCOptions ghcOptions binfo = ghcOptions ++ exts ++ [lang] ++ libs ++ libDirs -- Causes error, catched in the upper function. cabalBuildInfo :: GenericPackageDescription -> BuildInfo -cabalBuildInfo pd = fromMaybe emptyBuildInfo $ fromLibrary pd <|> fromExecutable pd +cabalBuildInfo pd = fromJust $ fromLibrary pd <|> fromExecutable pd where fromLibrary c = libBuildInfo . condTreeData <$> condLibrary c fromExecutable c = buildInfo . condTreeData . snd <$> listToMaybe (condExecutables c) diff --git a/GHCApi.hs b/GHCApi.hs index bdc5afa..f9a4767 100644 --- a/GHCApi.hs +++ b/GHCApi.hs @@ -1,3 +1,5 @@ +{-# LANGUAGE ScopedTypeVariables #-} + module GHCApi ( withGHC , withGHCDummyFile @@ -50,13 +52,17 @@ data Build = CabalPkg | SingleFile deriving Eq initializeFlagsWithCradle :: Options -> Cradle -> [GHCOption] -> Bool -> Ghc LogReader initializeFlagsWithCradle opt cradle ghcOptions logging - | cabal = do - (gopts,idirs,depPkgs) <- liftIO $ fromCabalFile ghcOptions cradle - initSession CabalPkg opt gopts idirs (Just depPkgs) logging - | otherwise = - initSession SingleFile opt ghcOptions importDirs Nothing logging + | cabal = withCabal `gcatch` fallback + | otherwise = withoutCabal where cabal = isJust $ cradleCabalFile cradle + withCabal = do + (gopts,idirs,depPkgs) <- liftIO $ fromCabalFile ghcOptions cradle + initSession CabalPkg opt gopts idirs (Just depPkgs) logging + withoutCabal = + initSession SingleFile opt ghcOptions importDirs Nothing logging + fallback :: SomeException -> Ghc LogReader + fallback _ = withoutCabal ----------------------------------------------------------------