Merging Cabal to CabalApi.
This commit is contained in:
parent
a393f8a971
commit
ca229c3be1
41
Cabal.hs
41
Cabal.hs
@ -1,41 +0,0 @@
|
|||||||
{-# LANGUAGE OverloadedStrings, RecordWildCards #-}
|
|
||||||
|
|
||||||
module Cabal (fromCabal) where
|
|
||||||
|
|
||||||
import CabalApi
|
|
||||||
import Distribution.PackageDescription (BuildInfo(..), usedExtensions)
|
|
||||||
import Distribution.Text (display)
|
|
||||||
import System.FilePath
|
|
||||||
import Types
|
|
||||||
|
|
||||||
----------------------------------------------------------------
|
|
||||||
|
|
||||||
fromCabal :: [GHCOption]
|
|
||||||
-> Cradle
|
|
||||||
-> IO ([GHCOption]
|
|
||||||
,[IncludeDir]
|
|
||||||
,[Package]
|
|
||||||
,[LangExt])
|
|
||||||
fromCabal ghcOptions cradle = do
|
|
||||||
cabal <- cabalParseFile cfile
|
|
||||||
let binfo@BuildInfo{..} = cabalBuildInfo cabal
|
|
||||||
let exts = map (("-X" ++) . display) $ usedExtensions binfo
|
|
||||||
lang = maybe "-XHaskell98" (("-X" ++) . display) defaultLanguage
|
|
||||||
libs = map ("-l" ++) extraLibs
|
|
||||||
libDirs = map ("-L" ++) extraLibDirs
|
|
||||||
gopts = ghcOptions ++ exts ++ [lang] ++ libs ++ libDirs
|
|
||||||
idirs = case hsSourceDirs of
|
|
||||||
[] -> [cdir,owdir]
|
|
||||||
dirs -> map (cdir </>) dirs ++ [owdir]
|
|
||||||
let depPkgs = removeMe cfile $ cabalAllDependPackages cabal
|
|
||||||
hdrExts = cabalAllExtentions cabal
|
|
||||||
return (gopts,idirs,depPkgs,hdrExts)
|
|
||||||
where
|
|
||||||
owdir = cradleCurrentDir cradle
|
|
||||||
Just cdir = cradleCabalDir cradle
|
|
||||||
Just cfile = cradleCabalDir cradle
|
|
||||||
|
|
||||||
removeMe :: FilePath -> [String] -> [String]
|
|
||||||
removeMe cabalfile = filter (/= me)
|
|
||||||
where
|
|
||||||
me = dropExtension $ takeFileName cabalfile
|
|
38
CabalApi.hs
38
CabalApi.hs
@ -1,5 +1,8 @@
|
|||||||
|
{-# LANGUAGE OverloadedStrings, RecordWildCards #-}
|
||||||
|
|
||||||
module CabalApi (
|
module CabalApi (
|
||||||
cabalParseFile
|
fromCabal
|
||||||
|
, cabalParseFile
|
||||||
, cabalBuildInfo
|
, cabalBuildInfo
|
||||||
, cabalAllDependPackages
|
, cabalAllDependPackages
|
||||||
, cabalAllExtentions
|
, cabalAllExtentions
|
||||||
@ -14,10 +17,43 @@ import Distribution.PackageDescription.Parse (readPackageDescription)
|
|||||||
import Distribution.Text (display)
|
import Distribution.Text (display)
|
||||||
import Distribution.Verbosity (silent)
|
import Distribution.Verbosity (silent)
|
||||||
import Language.Haskell.Extension (Extension(..))
|
import Language.Haskell.Extension (Extension(..))
|
||||||
|
import System.FilePath
|
||||||
import Types
|
import Types
|
||||||
|
|
||||||
----------------------------------------------------------------
|
----------------------------------------------------------------
|
||||||
|
|
||||||
|
fromCabal :: [GHCOption]
|
||||||
|
-> Cradle
|
||||||
|
-> IO ([GHCOption]
|
||||||
|
,[IncludeDir]
|
||||||
|
,[Package]
|
||||||
|
,[LangExt])
|
||||||
|
fromCabal ghcOptions cradle = do
|
||||||
|
cabal <- cabalParseFile cfile
|
||||||
|
let binfo@BuildInfo{..} = cabalBuildInfo cabal
|
||||||
|
let exts = map (("-X" ++) . display) $ usedExtensions binfo
|
||||||
|
lang = maybe "-XHaskell98" (("-X" ++) . display) defaultLanguage
|
||||||
|
libs = map ("-l" ++) extraLibs
|
||||||
|
libDirs = map ("-L" ++) extraLibDirs
|
||||||
|
gopts = ghcOptions ++ exts ++ [lang] ++ libs ++ libDirs
|
||||||
|
idirs = case hsSourceDirs of
|
||||||
|
[] -> [cdir,owdir]
|
||||||
|
dirs -> map (cdir </>) dirs ++ [owdir]
|
||||||
|
let depPkgs = removeMe cfile $ cabalAllDependPackages cabal
|
||||||
|
hdrExts = cabalAllExtentions cabal
|
||||||
|
return (gopts,idirs,depPkgs,hdrExts)
|
||||||
|
where
|
||||||
|
owdir = cradleCurrentDir cradle
|
||||||
|
Just cdir = cradleCabalDir cradle
|
||||||
|
Just cfile = cradleCabalDir cradle
|
||||||
|
|
||||||
|
removeMe :: FilePath -> [String] -> [String]
|
||||||
|
removeMe cabalfile = filter (/= me)
|
||||||
|
where
|
||||||
|
me = dropExtension $ takeFileName cabalfile
|
||||||
|
|
||||||
|
----------------------------------------------------------------
|
||||||
|
|
||||||
cabalParseFile :: FilePath -> IO GenericPackageDescription
|
cabalParseFile :: FilePath -> IO GenericPackageDescription
|
||||||
cabalParseFile = readPackageDescription silent
|
cabalParseFile = readPackageDescription silent
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
module GHCApi where
|
module GHCApi where
|
||||||
|
|
||||||
import Cabal
|
import CabalApi
|
||||||
import Control.Applicative
|
import Control.Applicative
|
||||||
import Control.Exception
|
import Control.Exception
|
||||||
import CoreMonad
|
import CoreMonad
|
||||||
|
@ -36,7 +36,6 @@ Executable ghc-mod
|
|||||||
Default-Language: Haskell2010
|
Default-Language: Haskell2010
|
||||||
Main-Is: GHCMod.hs
|
Main-Is: GHCMod.hs
|
||||||
Other-Modules: Browse
|
Other-Modules: Browse
|
||||||
Cabal
|
|
||||||
CabalApi
|
CabalApi
|
||||||
Check
|
Check
|
||||||
Cradle
|
Cradle
|
||||||
|
Loading…
Reference in New Issue
Block a user