Parse *.cabal file at once in initializeGHC.
This commit is contained in:
parent
659e5421e7
commit
87cca58681
7
Cabal.hs
7
Cabal.hs
@ -2,7 +2,7 @@
|
||||
|
||||
module Cabal (initializeGHC) where
|
||||
|
||||
import CabalApi (cabalBuildInfo, cabalDependPackages)
|
||||
import CabalApi (cabalParseFile, cabalBuildInfo, cabalDependPackages)
|
||||
import Control.Applicative
|
||||
import Control.Exception
|
||||
import Control.Monad
|
||||
@ -31,7 +31,8 @@ initializeGHC opt fileName ghcOptions logging = withCabal ||> withoutCabal
|
||||
return (fileName,logReader)
|
||||
withCabal = do
|
||||
(owdir,cdir,cfile) <- liftIO getDirs
|
||||
binfo@BuildInfo{..} <- liftIO $ cabalBuildInfo cfile
|
||||
cabal <- liftIO $ cabalParseFile cfile
|
||||
binfo@BuildInfo{..} <- liftIO $ cabalBuildInfo cabal
|
||||
let exts = map (addX . Gap.extensionToString) $ usedExtensions binfo
|
||||
lang = maybe "-XHaskell98" (addX . show) defaultLanguage
|
||||
libs = map ("-l" ++) extraLibs
|
||||
@ -40,7 +41,7 @@ initializeGHC opt fileName ghcOptions logging = withCabal ||> withoutCabal
|
||||
idirs = case hsSourceDirs of
|
||||
[] -> [cdir,owdir]
|
||||
dirs -> map (cdir </>) dirs ++ [owdir]
|
||||
depPkgs <- liftIO $ cabalDependPackages cfile
|
||||
depPkgs <- liftIO $ cabalDependPackages cabal
|
||||
logReader <- initSession opt gopts idirs (Just depPkgs) logging
|
||||
return (fileName,logReader)
|
||||
addX = ("-X" ++)
|
||||
|
23
CabalApi.hs
23
CabalApi.hs
@ -1,4 +1,5 @@
|
||||
module CabalApi (
|
||||
cabalParseFile,
|
||||
cabalBuildInfo,
|
||||
cabalDependPackages
|
||||
) where
|
||||
@ -19,20 +20,19 @@ import Distribution.PackageDescription.Parse (readPackageDescription)
|
||||
|
||||
----------------------------------------------------------------
|
||||
|
||||
cabalParseFile :: FilePath -> IO GenericPackageDescription
|
||||
cabalParseFile = readPackageDescription silent
|
||||
|
||||
-- Causes error, catched in the upper function.
|
||||
cabalBuildInfo :: FilePath -> IO BuildInfo
|
||||
cabalBuildInfo file = do
|
||||
cabal <- readPackageDescription silent file
|
||||
return . fromJust $ fromLibrary cabal <|> fromExecutable cabal
|
||||
cabalBuildInfo :: GenericPackageDescription -> IO BuildInfo
|
||||
cabalBuildInfo pd = do
|
||||
return . fromJust $ 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
|
||||
|
||||
parseGenericDescription :: FilePath -> IO GenericPackageDescription
|
||||
parseGenericDescription = readPackageDescription silent
|
||||
|
||||
getDepsOfPairs :: [(a1, CondTree v [b] a)] -> [b]
|
||||
getDepsOfPairs = concatMap (condTreeConstraints . snd)
|
||||
|
||||
@ -48,9 +48,8 @@ allDependsOfDescription pd =
|
||||
getDependencyPackageName :: Dependency -> String
|
||||
getDependencyPackageName (Dependency (PackageName n) _) = n
|
||||
|
||||
cabalDependPackages :: FilePath -> IO [String]
|
||||
cabalDependPackages :: GenericPackageDescription -> IO [String]
|
||||
cabalDependPackages =
|
||||
fmap (toList . fromList
|
||||
. map getDependencyPackageName
|
||||
. allDependsOfDescription)
|
||||
. parseGenericDescription
|
||||
return . toList . fromList
|
||||
. map getDependencyPackageName
|
||||
. allDependsOfDescription
|
||||
|
Loading…
Reference in New Issue
Block a user