From ca229c3be1644c44b10b4ceec70341fd16270d12 Mon Sep 17 00:00:00 2001 From: Kazu Yamamoto Date: Sun, 3 Mar 2013 15:47:03 +0900 Subject: [PATCH] Merging Cabal to CabalApi. --- Cabal.hs | 41 ----------------------------------------- CabalApi.hs | 38 +++++++++++++++++++++++++++++++++++++- GHCApi.hs | 2 +- ghc-mod.cabal | 1 - 4 files changed, 38 insertions(+), 44 deletions(-) delete mode 100644 Cabal.hs diff --git a/Cabal.hs b/Cabal.hs deleted file mode 100644 index f373200..0000000 --- a/Cabal.hs +++ /dev/null @@ -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 diff --git a/CabalApi.hs b/CabalApi.hs index b2fd58e..abe0f2a 100644 --- a/CabalApi.hs +++ b/CabalApi.hs @@ -1,5 +1,8 @@ +{-# LANGUAGE OverloadedStrings, RecordWildCards #-} + module CabalApi ( - cabalParseFile + fromCabal + , cabalParseFile , cabalBuildInfo , cabalAllDependPackages , cabalAllExtentions @@ -14,10 +17,43 @@ import Distribution.PackageDescription.Parse (readPackageDescription) import Distribution.Text (display) import Distribution.Verbosity (silent) import Language.Haskell.Extension (Extension(..)) +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 + +---------------------------------------------------------------- + cabalParseFile :: FilePath -> IO GenericPackageDescription cabalParseFile = readPackageDescription silent diff --git a/GHCApi.hs b/GHCApi.hs index 972e764..df89ebe 100644 --- a/GHCApi.hs +++ b/GHCApi.hs @@ -1,6 +1,6 @@ module GHCApi where -import Cabal +import CabalApi import Control.Applicative import Control.Exception import CoreMonad diff --git a/ghc-mod.cabal b/ghc-mod.cabal index 59c11c3..d79963a 100644 --- a/ghc-mod.cabal +++ b/ghc-mod.cabal @@ -36,7 +36,6 @@ Executable ghc-mod Default-Language: Haskell2010 Main-Is: GHCMod.hs Other-Modules: Browse - Cabal CabalApi Check Cradle