Refactoring Cabal stuff.
This commit is contained in:
parent
561bb38900
commit
7761691795
4
Cabal.hs
4
Cabal.hs
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
module Cabal (initializeGHC, getDirs, fromCabal) where
|
module Cabal (initializeGHC, getDirs, fromCabal) where
|
||||||
|
|
||||||
import CabalApi (cabalParseFile, cabalBuildInfo, cabalDependPackages)
|
import CabalApi
|
||||||
import Control.Applicative
|
import Control.Applicative
|
||||||
import Control.Exception
|
import Control.Exception
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
@ -47,7 +47,7 @@ fromCabal ghcOptions = do
|
|||||||
idirs = case hsSourceDirs of
|
idirs = case hsSourceDirs of
|
||||||
[] -> [cdir,owdir]
|
[] -> [cdir,owdir]
|
||||||
dirs -> map (cdir </>) dirs ++ [owdir]
|
dirs -> map (cdir </>) dirs ++ [owdir]
|
||||||
let depPkgs = removeMe cfile $ cabalDependPackages cabal
|
let depPkgs = removeMe cfile $ cabalAllDependPackages cabal
|
||||||
return (gopts,idirs,depPkgs)
|
return (gopts,idirs,depPkgs)
|
||||||
|
|
||||||
removeMe :: FilePath -> [String] -> [String]
|
removeMe :: FilePath -> [String] -> [String]
|
||||||
|
45
CabalApi.hs
45
CabalApi.hs
@ -1,19 +1,19 @@
|
|||||||
module CabalApi (
|
module CabalApi (
|
||||||
cabalParseFile
|
cabalParseFile
|
||||||
, cabalBuildInfo
|
, cabalBuildInfo
|
||||||
, cabalDependPackages
|
, cabalAllDependPackages
|
||||||
, getBuildInfos
|
, cabalAllExtentions
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Applicative
|
import Control.Applicative
|
||||||
|
import Data.Maybe (fromJust, maybeToList, catMaybes)
|
||||||
import Data.Maybe (fromJust, maybeToList)
|
|
||||||
import Data.Set (fromList, toList)
|
import Data.Set (fromList, toList)
|
||||||
|
|
||||||
import Distribution.Package (Dependency(Dependency), PackageName(PackageName))
|
import Distribution.Package (Dependency(Dependency), PackageName(PackageName))
|
||||||
import Distribution.PackageDescription
|
import Distribution.PackageDescription
|
||||||
import Distribution.PackageDescription.Parse (readPackageDescription)
|
import Distribution.PackageDescription.Parse (readPackageDescription)
|
||||||
|
import Distribution.Text (display)
|
||||||
import Distribution.Verbosity (silent)
|
import Distribution.Verbosity (silent)
|
||||||
|
import Language.Haskell.Extension (Extension(..))
|
||||||
|
|
||||||
----------------------------------------------------------------
|
----------------------------------------------------------------
|
||||||
|
|
||||||
@ -33,24 +33,38 @@ cabalBuildInfo pd = fromJust $ fromLibrary pd <|> fromExecutable pd
|
|||||||
|
|
||||||
----------------------------------------------------------------
|
----------------------------------------------------------------
|
||||||
|
|
||||||
cabalDependPackages :: GenericPackageDescription -> [String]
|
cabalAllDependPackages :: GenericPackageDescription -> [String]
|
||||||
cabalDependPackages = uniqueAndSort . map getDependencyPackageName . allDependsOfDescription
|
cabalAllDependPackages pd = uniqueAndSort pkgs
|
||||||
where
|
where
|
||||||
uniqueAndSort = toList . fromList
|
pkgs = map getDependencyPackageName $ cabalAllDependency pd
|
||||||
|
|
||||||
allDependsOfDescription :: GenericPackageDescription -> [Dependency]
|
cabalAllDependency :: GenericPackageDescription -> [Dependency]
|
||||||
allDependsOfDescription = fromPackageDescription getDeps getDeps getDeps getDeps
|
cabalAllDependency = fromPackageDescription getDeps getDeps getDeps getDeps
|
||||||
where
|
where
|
||||||
getDeps :: [Tree a] -> [Dependency]
|
getDeps :: [Tree a] -> [Dependency]
|
||||||
getDeps = concatMap condTreeConstraints
|
getDeps = concatMap condTreeConstraints
|
||||||
|
|
||||||
getDependencyPackageName :: Dependency -> String
|
getDependencyPackageName :: Dependency -> String
|
||||||
getDependencyPackageName (Dependency (PackageName n) _) = n
|
getDependencyPackageName (Dependency (PackageName nm) _) = nm
|
||||||
|
|
||||||
----------------------------------------------------------------
|
----------------------------------------------------------------
|
||||||
|
|
||||||
getBuildInfos :: GenericPackageDescription -> [BuildInfo]
|
cabalAllExtentions :: GenericPackageDescription -> [String]
|
||||||
getBuildInfos = fromPackageDescription f1 f2 f3 f4
|
cabalAllExtentions pd = uniqueAndSort exts
|
||||||
|
where
|
||||||
|
buildInfos = cabalAllBuildInfos pd
|
||||||
|
eexts = concatMap oldExtensions buildInfos
|
||||||
|
++ concatMap defaultExtensions buildInfos
|
||||||
|
exts = catMaybes $ map getExtensionName eexts
|
||||||
|
|
||||||
|
getExtensionName :: Extension -> Maybe String
|
||||||
|
getExtensionName (EnableExtension nm) = Just (display nm)
|
||||||
|
getExtensionName _ = Nothing
|
||||||
|
|
||||||
|
----------------------------------------------------------------
|
||||||
|
|
||||||
|
cabalAllBuildInfos :: GenericPackageDescription -> [BuildInfo]
|
||||||
|
cabalAllBuildInfos = fromPackageDescription f1 f2 f3 f4
|
||||||
where
|
where
|
||||||
f1 = map (libBuildInfo . condTreeData)
|
f1 = map (libBuildInfo . condTreeData)
|
||||||
f2 = map (buildInfo . condTreeData)
|
f2 = map (buildInfo . condTreeData)
|
||||||
@ -73,3 +87,8 @@ fromPackageDescription f1 f2 f3 f4 pd = lib ++ exe ++ tests ++ bench
|
|||||||
exe = f2 . map snd . condExecutables $ pd
|
exe = f2 . map snd . condExecutables $ pd
|
||||||
tests = f3 . map snd . condTestSuites $ pd
|
tests = f3 . map snd . condTestSuites $ pd
|
||||||
bench = f4 . map snd . condBenchmarks $ pd
|
bench = f4 . map snd . condBenchmarks $ pd
|
||||||
|
|
||||||
|
----------------------------------------------------------------
|
||||||
|
|
||||||
|
uniqueAndSort :: [String] -> [String]
|
||||||
|
uniqueAndSort = toList . fromList
|
||||||
|
@ -6,9 +6,9 @@ import CabalApi
|
|||||||
|
|
||||||
spec :: Spec
|
spec :: Spec
|
||||||
spec = do
|
spec = do
|
||||||
describe "cabalDependPackages" $ do
|
describe "cabalAllDependPackages" $ do
|
||||||
it "extracts dependent packages" $ do
|
it "extracts dependent packages" $ do
|
||||||
pkgs <- cabalDependPackages <$> cabalParseFile "test/data/cabalapi.cabal"
|
pkgs <- cabalAllDependPackages <$> cabalParseFile "test/data/cabalapi.cabal"
|
||||||
pkgs `shouldBe` ["Cabal","base","containers","convertible","directory","filepath","ghc","ghc-paths","ghc-syb-utils","hlint","hspec","io-choice","old-time","process","regex-posix","syb","time","transformers"]
|
pkgs `shouldBe` ["Cabal","base","containers","convertible","directory","filepath","ghc","ghc-paths","ghc-syb-utils","hlint","hspec","io-choice","old-time","process","regex-posix","syb","time","transformers"]
|
||||||
|
|
||||||
describe "cabalBuildInfo" $ do
|
describe "cabalBuildInfo" $ do
|
||||||
|
Loading…
Reference in New Issue
Block a user