Commit b85602dc authored by Andrey Mokhov's avatar Andrey Mokhov
Browse files

Add docs, minor revision

parent 46a00614
-----------------------------------------------------------------------------
-- |
-- Module : Hadrian.Haskell.Cabal
-- Copyright : (c) Andrey Mokhov 2014-2017
-- License : MIT (see the file LICENSE)
-- Maintainer : andrey.mokhov@gmail.com
-- Stability : experimental
--
-- Basic functionality for extracting Haskell package metadata stored in
-- @.cabal@ files.
-----------------------------------------------------------------------------
module Hadrian.Haskell.Cabal (readCabal, cabalNameVersion, cabalDependencies) where
import Development.Shake
......@@ -8,28 +19,28 @@ import Distribution.Text
import Distribution.Types.CondTree
import Distribution.Verbosity
-- TODO: Track the values?
-- | Read a given @.cabal@ file and return the 'GenericPackageDescription'.
-- | Read a given @.cabal@ file and return the 'GenericPackageDescription'. The
-- @.cabal@ file is tracked.
readCabal :: FilePath -> Action GenericPackageDescription
readCabal cabal = do
need [cabal]
liftIO $ readGenericPackageDescription silent cabal
-- | Read a given @.cabal@ file and return the package name and version.
-- | Read a given @.cabal@ file and return the package name and version. The
-- @.cabal@ file is tracked.
cabalNameVersion :: FilePath -> Action (String, String)
cabalNameVersion cabal = do
identifier <- package . packageDescription <$> readCabal cabal
return (unPackageName $ pkgName identifier, display $ pkgVersion identifier)
-- | Read a given @.cabal@ file and return the package dependencies.
-- | Read a given @.cabal@ file and return the package dependencies. The
-- @.cabal@ file is tracked.
cabalDependencies :: FilePath -> Action [String]
cabalDependencies cabal = do
gpd <- readCabal cabal
let depsLib = collectDeps $ condLibrary gpd
depsExes = map (collectDeps . Just . snd) $ condExecutables gpd
deps = concat $ depsLib : depsExes
return $ [ unPackageName name | Dependency name _ <- deps ]
let libDeps = collectDeps (condLibrary gpd)
exeDeps = map (collectDeps . Just . snd) (condExecutables gpd)
return [ unPackageName p | Dependency p _ <- concat (libDeps : exeDeps) ]
collectDeps :: Maybe (CondTree v [Dependency] a) -> [Dependency]
collectDeps Nothing = []
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment