diff --git a/Cabal.hs b/Cabal.hs index fe2a33f..f907dfa 100644 --- a/Cabal.hs +++ b/Cabal.hs @@ -38,7 +38,7 @@ fromCabal :: [String] -> IO ([String], [FilePath], [String]) fromCabal ghcOptions = do (owdir,cdir,cfile) <- getDirs cabal <- cabalParseFile cfile - binfo@BuildInfo{..} <- cabalBuildInfo cabal + let binfo@BuildInfo{..} = cabalBuildInfo cabal let exts = map (("-X" ++) . display) $ usedExtensions binfo lang = maybe "-XHaskell98" (("-X" ++) . display) defaultLanguage libs = map ("-l" ++) extraLibs diff --git a/CabalApi.hs b/CabalApi.hs index 9875bc5..2d0f305 100644 --- a/CabalApi.hs +++ b/CabalApi.hs @@ -24,9 +24,8 @@ cabalParseFile :: FilePath -> IO GenericPackageDescription cabalParseFile = readPackageDescription silent -- Causes error, catched in the upper function. -cabalBuildInfo :: GenericPackageDescription -> IO BuildInfo -cabalBuildInfo pd = - return . fromJust $ fromLibrary pd <|> fromExecutable pd +cabalBuildInfo :: GenericPackageDescription -> BuildInfo +cabalBuildInfo pd = fromJust $ fromLibrary pd <|> fromExecutable pd where fromLibrary c = libBuildInfo . condTreeData <$> condLibrary c fromExecutable c = buildInfo . condTreeData . snd <$> toMaybe (condExecutables c) diff --git a/test/CabalApiSpec.hs b/test/CabalApiSpec.hs index affb56c..d17f867 100644 --- a/test/CabalApiSpec.hs +++ b/test/CabalApiSpec.hs @@ -13,6 +13,6 @@ spec = do describe "cabalBuildInfo" $ do it "extracts build info" $ do - info <- cabalParseFile "test/data/cabalapi.cabal" >>= cabalBuildInfo + info <- cabalBuildInfo <$> cabalParseFile "test/data/cabalapi.cabal" let infoStr = show info infoStr `shouldBe` "BuildInfo {buildable = True, buildTools = [], cppOptions = [], ccOptions = [], ldOptions = [], pkgconfigDepends = [], frameworks = [], cSources = [], hsSourceDirs = [], otherModules = [ModuleName [\"Browse\"],ModuleName [\"CabalApi\"],ModuleName [\"Cabal\"],ModuleName [\"CabalDev\"],ModuleName [\"Check\"],ModuleName [\"ErrMsg\"],ModuleName [\"Flag\"],ModuleName [\"GHCApi\"],ModuleName [\"GHCChoice\"],ModuleName [\"Gap\"],ModuleName [\"Info\"],ModuleName [\"Lang\"],ModuleName [\"Lint\"],ModuleName [\"List\"],ModuleName [\"Paths_ghc_mod\"],ModuleName [\"Types\"]], defaultLanguage = Nothing, otherLanguages = [], defaultExtensions = [], otherExtensions = [], oldExtensions = [], extraLibs = [], extraLibDirs = [], includeDirs = [], includes = [], installIncludes = [], options = [(GHC,[\"-Wall\"])], ghcProfOptions = [], ghcSharedOptions = [], customFieldsBI = [], targetBuildDepends = []}"