Merge pull request #116 from nh2/fix-fromJust

Fix fromJust crash
This commit is contained in:
Kazu Yamamoto 2013-04-09 22:40:16 -07:00
commit b57402212a

View File

@ -12,7 +12,7 @@ module CabalApi (
import Control.Applicative
import Control.Exception (throwIO)
import Data.List (intercalate)
import Data.Maybe (fromJust, maybeToList)
import Data.Maybe (maybeToList, listToMaybe)
import Data.Set (fromList, toList)
import Distribution.Package (Dependency(Dependency), PackageName(PackageName))
import Distribution.PackageDescription
@ -71,12 +71,10 @@ getGHCOptions ghcOptions binfo = ghcOptions ++ exts ++ [lang] ++ libs ++ libDirs
-- Causes error, catched in the upper function.
cabalBuildInfo :: GenericPackageDescription -> BuildInfo
cabalBuildInfo pd = fromJust $ fromLibrary pd <|> fromExecutable pd
cabalBuildInfo pd = maybe emptyBuildInfo id $ fromLibrary pd <|> fromExecutable pd
where
fromLibrary c = libBuildInfo . condTreeData <$> condLibrary c
fromExecutable c = buildInfo . condTreeData . snd <$> toMaybe (condExecutables c)
toMaybe [] = Nothing
toMaybe (x:_) = Just x
fromExecutable c = buildInfo . condTreeData . snd <$> listToMaybe (condExecutables c)
----------------------------------------------------------------