{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}

-----------------------------------------------------------------------------
-- |
-- Module      :  Distribution.Types.PackageDescription
-- Copyright   :  Isaac Jones 2003-2005
-- License     :  BSD3
--
-- Maintainer  :  cabal-devel@haskell.org
-- Portability :  portable
--
-- This defines the data structure for the @.cabal@ file format. There are
-- several parts to this structure. It has top level info and then 'Library',
-- 'Executable', 'TestSuite', and 'Benchmark' sections each of which have
-- associated 'BuildInfo' data that's used to build the library, exe, test, or
-- benchmark.  To further complicate things there is both a 'PackageDescription'
-- and a 'GenericPackageDescription'. This distinction relates to cabal
-- configurations. When we initially read a @.cabal@ file we get a
-- 'GenericPackageDescription' which has all the conditional sections.
-- Before actually building a package we have to decide
-- on each conditional. Once we've done that we get a 'PackageDescription'.
-- It was done this way initially to avoid breaking too much stuff when the
-- feature was introduced. It could probably do with being rationalised at some
-- point to make it simpler.

module Distribution.Types.PackageDescription (
    PackageDescription(..),
    specVersion,
    specVersion',
    license,
    license',
    buildType,
    emptyPackageDescription,
    hasPublicLib,
    hasLibs,
    allLibraries,
    withLib,
    hasExes,
    withExe,
    hasTests,
    withTest,
    hasBenchmarks,
    withBenchmark,
    hasForeignLibs,
    withForeignLib,
    allBuildInfo,
    enabledBuildInfos,
    allBuildDepends,
    enabledBuildDepends,
    updatePackageDescription,
    pkgComponents,
    pkgBuildableComponents,
    enabledComponents,
    lookupComponent,
    getComponent,
  ) where

import Prelude ()
import Distribution.Compat.Prelude

import Control.Monad ((<=<))

-- lens
import qualified Distribution.Types.BuildInfo.Lens  as L
import Distribution.Types.Library
import Distribution.Types.TestSuite
import Distribution.Types.Executable
import Distribution.Types.Benchmark
import Distribution.Types.ForeignLib

import Distribution.Types.Component
import Distribution.Types.ComponentRequestedSpec
import Distribution.Types.Dependency
import Distribution.Types.PackageId
import Distribution.Types.ComponentName
import Distribution.Types.PackageName
import Distribution.Types.UnqualComponentName
import Distribution.Types.SetupBuildInfo
import Distribution.Types.BuildInfo
import Distribution.Types.BuildType
import Distribution.Types.SourceRepo
import Distribution.Types.HookedBuildInfo

import Distribution.Compiler
import Distribution.License
import Distribution.Package
import Distribution.Version

import qualified Distribution.SPDX as SPDX

-- -----------------------------------------------------------------------------
-- The PackageDescription type

-- | This data type is the internal representation of the file @pkg.cabal@.
-- It contains two kinds of information about the package: information
-- which is needed for all packages, such as the package name and version, and
-- information which is needed for the simple build system only, such as
-- the compiler options and library name.
--
data PackageDescription
    =  PackageDescription {
        -- the following are required by all packages:

        -- | The version of the Cabal spec that this package description uses.
        -- For historical reasons this is specified with a version range but
        -- only ranges of the form @>= v@ make sense. We are in the process of
        -- transitioning to specifying just a single version, not a range.
        -- See also 'specVersion'.
        PackageDescription -> Either Version VersionRange
specVersionRaw :: Either Version VersionRange,
        PackageDescription -> PackageIdentifier
package        :: PackageIdentifier,
        PackageDescription -> Either License License
licenseRaw     :: Either SPDX.License License,
        PackageDescription -> [FilePath]
licenseFiles   :: [FilePath],
        PackageDescription -> FilePath
copyright      :: String,
        PackageDescription -> FilePath
maintainer     :: String,
        PackageDescription -> FilePath
author         :: String,
        PackageDescription -> FilePath
stability      :: String,
        PackageDescription -> [(CompilerFlavor, VersionRange)]
testedWith     :: [(CompilerFlavor,VersionRange)],
        PackageDescription -> FilePath
homepage       :: String,
        PackageDescription -> FilePath
pkgUrl         :: String,
        PackageDescription -> FilePath
bugReports     :: String,
        PackageDescription -> [SourceRepo]
sourceRepos    :: [SourceRepo],
        PackageDescription -> FilePath
synopsis       :: String, -- ^A one-line summary of this package
        PackageDescription -> FilePath
description    :: String, -- ^A more verbose description of this package
        PackageDescription -> FilePath
category       :: String,
        PackageDescription -> [(FilePath, FilePath)]
customFieldsPD :: [(String,String)], -- ^Custom fields starting
                                             -- with x-, stored in a
                                             -- simple assoc-list.

        -- | The original @build-type@ value as parsed from the
        -- @.cabal@ file without defaulting. See also 'buildType'.
        --
        -- @since 2.2
        PackageDescription -> Maybe BuildType
buildTypeRaw   :: Maybe BuildType,
        PackageDescription -> Maybe SetupBuildInfo
setupBuildInfo :: Maybe SetupBuildInfo,
        -- components
        PackageDescription -> Maybe Library
library        :: Maybe Library,
        PackageDescription -> [Library]
subLibraries   :: [Library],
        PackageDescription -> [Executable]
executables    :: [Executable],
        PackageDescription -> [ForeignLib]
foreignLibs    :: [ForeignLib],
        PackageDescription -> [TestSuite]
testSuites     :: [TestSuite],
        PackageDescription -> [Benchmark]
benchmarks     :: [Benchmark],
        -- files
        PackageDescription -> [FilePath]
dataFiles      :: [FilePath],
        PackageDescription -> FilePath
dataDir        :: FilePath,
        PackageDescription -> [FilePath]
extraSrcFiles  :: [FilePath],
        PackageDescription -> [FilePath]
extraTmpFiles  :: [FilePath],
        PackageDescription -> [FilePath]
extraDocFiles  :: [FilePath]
    }
    deriving ((forall x. PackageDescription -> Rep PackageDescription x)
-> (forall x. Rep PackageDescription x -> PackageDescription)
-> Generic PackageDescription
forall x. Rep PackageDescription x -> PackageDescription
forall x. PackageDescription -> Rep PackageDescription x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PackageDescription x -> PackageDescription
$cfrom :: forall x. PackageDescription -> Rep PackageDescription x
Generic, Int -> PackageDescription -> ShowS
[PackageDescription] -> ShowS
PackageDescription -> FilePath
(Int -> PackageDescription -> ShowS)
-> (PackageDescription -> FilePath)
-> ([PackageDescription] -> ShowS)
-> Show PackageDescription
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [PackageDescription] -> ShowS
$cshowList :: [PackageDescription] -> ShowS
show :: PackageDescription -> FilePath
$cshow :: PackageDescription -> FilePath
showsPrec :: Int -> PackageDescription -> ShowS
$cshowsPrec :: Int -> PackageDescription -> ShowS
Show, ReadPrec [PackageDescription]
ReadPrec PackageDescription
Int -> ReadS PackageDescription
ReadS [PackageDescription]
(Int -> ReadS PackageDescription)
-> ReadS [PackageDescription]
-> ReadPrec PackageDescription
-> ReadPrec [PackageDescription]
-> Read PackageDescription
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PackageDescription]
$creadListPrec :: ReadPrec [PackageDescription]
readPrec :: ReadPrec PackageDescription
$creadPrec :: ReadPrec PackageDescription
readList :: ReadS [PackageDescription]
$creadList :: ReadS [PackageDescription]
readsPrec :: Int -> ReadS PackageDescription
$creadsPrec :: Int -> ReadS PackageDescription
Read, PackageDescription -> PackageDescription -> Bool
(PackageDescription -> PackageDescription -> Bool)
-> (PackageDescription -> PackageDescription -> Bool)
-> Eq PackageDescription
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PackageDescription -> PackageDescription -> Bool
$c/= :: PackageDescription -> PackageDescription -> Bool
== :: PackageDescription -> PackageDescription -> Bool
$c== :: PackageDescription -> PackageDescription -> Bool
Eq, Typeable, Typeable PackageDescription
DataType
Constr
Typeable PackageDescription
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g)
    -> PackageDescription
    -> c PackageDescription)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c PackageDescription)
-> (PackageDescription -> Constr)
-> (PackageDescription -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c PackageDescription))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c PackageDescription))
-> ((forall b. Data b => b -> b)
    -> PackageDescription -> PackageDescription)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> PackageDescription -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> PackageDescription -> r)
-> (forall u.
    (forall d. Data d => d -> u) -> PackageDescription -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> PackageDescription -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> PackageDescription -> m PackageDescription)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> PackageDescription -> m PackageDescription)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> PackageDescription -> m PackageDescription)
-> Data PackageDescription
PackageDescription -> DataType
PackageDescription -> Constr
(forall b. Data b => b -> b)
-> PackageDescription -> PackageDescription
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> PackageDescription
-> c PackageDescription
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PackageDescription
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u.
Int -> (forall d. Data d => d -> u) -> PackageDescription -> u
forall u. (forall d. Data d => d -> u) -> PackageDescription -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PackageDescription -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PackageDescription -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> PackageDescription -> m PackageDescription
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> PackageDescription -> m PackageDescription
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PackageDescription
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> PackageDescription
-> c PackageDescription
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c PackageDescription)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c PackageDescription)
$cPackageDescription :: Constr
$tPackageDescription :: DataType
gmapMo :: (forall d. Data d => d -> m d)
-> PackageDescription -> m PackageDescription
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> PackageDescription -> m PackageDescription
gmapMp :: (forall d. Data d => d -> m d)
-> PackageDescription -> m PackageDescription
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> PackageDescription -> m PackageDescription
gmapM :: (forall d. Data d => d -> m d)
-> PackageDescription -> m PackageDescription
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> PackageDescription -> m PackageDescription
gmapQi :: Int -> (forall d. Data d => d -> u) -> PackageDescription -> u
$cgmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> PackageDescription -> u
gmapQ :: (forall d. Data d => d -> u) -> PackageDescription -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> PackageDescription -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PackageDescription -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PackageDescription -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PackageDescription -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PackageDescription -> r
gmapT :: (forall b. Data b => b -> b)
-> PackageDescription -> PackageDescription
$cgmapT :: (forall b. Data b => b -> b)
-> PackageDescription -> PackageDescription
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c PackageDescription)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c PackageDescription)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c PackageDescription)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c PackageDescription)
dataTypeOf :: PackageDescription -> DataType
$cdataTypeOf :: PackageDescription -> DataType
toConstr :: PackageDescription -> Constr
$ctoConstr :: PackageDescription -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PackageDescription
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PackageDescription
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> PackageDescription
-> c PackageDescription
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> PackageDescription
-> c PackageDescription
$cp1Data :: Typeable PackageDescription
Data)

instance Binary PackageDescription

instance NFData PackageDescription where rnf :: PackageDescription -> ()
rnf = PackageDescription -> ()
forall a. (Generic a, GNFData (Rep a)) => a -> ()
genericRnf

instance Package PackageDescription where
  packageId :: PackageDescription -> PackageIdentifier
packageId = PackageDescription -> PackageIdentifier
package

-- | The version of the Cabal spec that this package should be interpreted
-- against.
--
-- Historically we used a version range but we are switching to using a single
-- version. Currently we accept either. This function converts into a single
-- version by ignoring upper bounds in the version range.
--
specVersion :: PackageDescription -> Version
specVersion :: PackageDescription -> Version
specVersion = Either Version VersionRange -> Version
specVersion' (Either Version VersionRange -> Version)
-> (PackageDescription -> Either Version VersionRange)
-> PackageDescription
-> Version
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PackageDescription -> Either Version VersionRange
specVersionRaw

-- |
--
-- @since 2.2.0.0
specVersion' :: Either Version VersionRange -> Version
specVersion' :: Either Version VersionRange -> Version
specVersion' (Left Version
version) = Version
version
specVersion' (Right VersionRange
versionRange) = case VersionRange -> [VersionInterval]
asVersionIntervals VersionRange
versionRange of
    []                            -> [Int] -> Version
mkVersion [Int
0]
    ((LowerBound Version
version Bound
_, UpperBound
_):[VersionInterval]
_) -> Version
version

-- | The SPDX 'LicenseExpression' of the package.
--
-- @since 2.2.0.0
license :: PackageDescription -> SPDX.License
license :: PackageDescription -> License
license = Either License License -> License
license' (Either License License -> License)
-> (PackageDescription -> Either License License)
-> PackageDescription
-> License
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PackageDescription -> Either License License
licenseRaw

-- | See 'license'.
--
-- @since 2.2.0.0
license' :: Either SPDX.License License -> SPDX.License
license' :: Either License License -> License
license' = (License -> License)
-> (License -> License) -> Either License License -> License
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either License -> License
forall a. a -> a
id License -> License
licenseToSPDX

-- | The effective @build-type@ after applying defaulting rules.
--
-- The original @build-type@ value parsed is stored in the
-- 'buildTypeRaw' field.  However, the @build-type@ field is optional
-- and can therefore be empty in which case we need to compute the
-- /effective/ @build-type@. This function implements the following
-- defaulting rules:
--
--  * For @cabal-version:2.0@ and below, default to the @Custom@
--    build-type unconditionally.
--
--  * Otherwise, if a @custom-setup@ stanza is defined, default to
--    the @Custom@ build-type; else default to @Simple@ build-type.
--
-- @since 2.2
buildType :: PackageDescription -> BuildType
buildType :: PackageDescription -> BuildType
buildType PackageDescription
pkg
  | PackageDescription -> Version
specVersion PackageDescription
pkg Version -> Version -> Bool
forall a. Ord a => a -> a -> Bool
>= [Int] -> Version
mkVersion [Int
2,Int
1]
    = BuildType -> Maybe BuildType -> BuildType
forall a. a -> Maybe a -> a
fromMaybe BuildType
newDefault (PackageDescription -> Maybe BuildType
buildTypeRaw PackageDescription
pkg)
  | Bool
otherwise -- cabal-version < 2.1
    = BuildType -> Maybe BuildType -> BuildType
forall a. a -> Maybe a -> a
fromMaybe BuildType
Custom (PackageDescription -> Maybe BuildType
buildTypeRaw PackageDescription
pkg)
  where
    newDefault :: BuildType
newDefault | Maybe SetupBuildInfo -> Bool
forall a. Maybe a -> Bool
isNothing (PackageDescription -> Maybe SetupBuildInfo
setupBuildInfo PackageDescription
pkg) = BuildType
Simple
               | Bool
otherwise                      = BuildType
Custom

emptyPackageDescription :: PackageDescription
emptyPackageDescription :: PackageDescription
emptyPackageDescription
    =  PackageDescription :: Either Version VersionRange
-> PackageIdentifier
-> Either License License
-> [FilePath]
-> FilePath
-> FilePath
-> FilePath
-> FilePath
-> [(CompilerFlavor, VersionRange)]
-> FilePath
-> FilePath
-> FilePath
-> [SourceRepo]
-> FilePath
-> FilePath
-> FilePath
-> [(FilePath, FilePath)]
-> Maybe BuildType
-> Maybe SetupBuildInfo
-> Maybe Library
-> [Library]
-> [Executable]
-> [ForeignLib]
-> [TestSuite]
-> [Benchmark]
-> [FilePath]
-> FilePath
-> [FilePath]
-> [FilePath]
-> [FilePath]
-> PackageDescription
PackageDescription {
                      package :: PackageIdentifier
package      = PackageName -> Version -> PackageIdentifier
PackageIdentifier (FilePath -> PackageName
mkPackageName FilePath
"")
                                                       Version
nullVersion,
                      licenseRaw :: Either License License
licenseRaw   = License -> Either License License
forall a b. b -> Either a b
Right License
UnspecifiedLicense, -- TODO:
                      licenseFiles :: [FilePath]
licenseFiles = [],
                      specVersionRaw :: Either Version VersionRange
specVersionRaw = VersionRange -> Either Version VersionRange
forall a b. b -> Either a b
Right VersionRange
anyVersion,
                      buildTypeRaw :: Maybe BuildType
buildTypeRaw = Maybe BuildType
forall a. Maybe a
Nothing,
                      copyright :: FilePath
copyright    = FilePath
"",
                      maintainer :: FilePath
maintainer   = FilePath
"",
                      author :: FilePath
author       = FilePath
"",
                      stability :: FilePath
stability    = FilePath
"",
                      testedWith :: [(CompilerFlavor, VersionRange)]
testedWith   = [],
                      homepage :: FilePath
homepage     = FilePath
"",
                      pkgUrl :: FilePath
pkgUrl       = FilePath
"",
                      bugReports :: FilePath
bugReports   = FilePath
"",
                      sourceRepos :: [SourceRepo]
sourceRepos  = [],
                      synopsis :: FilePath
synopsis     = FilePath
"",
                      description :: FilePath
description  = FilePath
"",
                      category :: FilePath
category     = FilePath
"",
                      customFieldsPD :: [(FilePath, FilePath)]
customFieldsPD = [],
                      setupBuildInfo :: Maybe SetupBuildInfo
setupBuildInfo = Maybe SetupBuildInfo
forall a. Maybe a
Nothing,
                      library :: Maybe Library
library      = Maybe Library
forall a. Maybe a
Nothing,
                      subLibraries :: [Library]
subLibraries = [],
                      foreignLibs :: [ForeignLib]
foreignLibs  = [],
                      executables :: [Executable]
executables  = [],
                      testSuites :: [TestSuite]
testSuites   = [],
                      benchmarks :: [Benchmark]
benchmarks   = [],
                      dataFiles :: [FilePath]
dataFiles    = [],
                      dataDir :: FilePath
dataDir      = FilePath
"",
                      extraSrcFiles :: [FilePath]
extraSrcFiles = [],
                      extraTmpFiles :: [FilePath]
extraTmpFiles = [],
                      extraDocFiles :: [FilePath]
extraDocFiles = []
                     }

-- ---------------------------------------------------------------------------
-- The Library type

-- | Does this package have a buildable PUBLIC library?
hasPublicLib :: PackageDescription -> Bool
hasPublicLib :: PackageDescription -> Bool
hasPublicLib PackageDescription
p =
    case PackageDescription -> Maybe Library
library PackageDescription
p of
        Just Library
lib -> BuildInfo -> Bool
buildable (Library -> BuildInfo
libBuildInfo Library
lib)
        Maybe Library
Nothing  -> Bool
False

-- | Does this package have any libraries?
hasLibs :: PackageDescription -> Bool
hasLibs :: PackageDescription -> Bool
hasLibs PackageDescription
p = (Library -> Bool) -> [Library] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (BuildInfo -> Bool
buildable (BuildInfo -> Bool) -> (Library -> BuildInfo) -> Library -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Library -> BuildInfo
libBuildInfo) (PackageDescription -> [Library]
allLibraries PackageDescription
p)

allLibraries :: PackageDescription -> [Library]
allLibraries :: PackageDescription -> [Library]
allLibraries PackageDescription
p = Maybe Library -> [Library]
forall a. Maybe a -> [a]
maybeToList (PackageDescription -> Maybe Library
library PackageDescription
p) [Library] -> [Library] -> [Library]
forall a. [a] -> [a] -> [a]
++ PackageDescription -> [Library]
subLibraries PackageDescription
p

-- | If the package description has a buildable library section,
-- call the given function with the library build info as argument.
-- You probably want 'withLibLBI' if you have a 'LocalBuildInfo',
-- see the note in
-- "Distribution.Types.ComponentRequestedSpec#buildable_vs_enabled_components"
-- for more information.
withLib :: PackageDescription -> (Library -> IO ()) -> IO ()
withLib :: PackageDescription -> (Library -> IO ()) -> IO ()
withLib PackageDescription
pkg_descr Library -> IO ()
f =
   [IO ()] -> IO ()
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, Monad m) =>
t (m a) -> m ()
sequence_ [Library -> IO ()
f Library
lib | Library
lib <- PackageDescription -> [Library]
allLibraries PackageDescription
pkg_descr, BuildInfo -> Bool
buildable (Library -> BuildInfo
libBuildInfo Library
lib)]

-- ---------------------------------------------------------------------------
-- The Executable type

-- |does this package have any executables?
hasExes :: PackageDescription -> Bool
hasExes :: PackageDescription -> Bool
hasExes PackageDescription
p = (Executable -> Bool) -> [Executable] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (BuildInfo -> Bool
buildable (BuildInfo -> Bool)
-> (Executable -> BuildInfo) -> Executable -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Executable -> BuildInfo
buildInfo) (PackageDescription -> [Executable]
executables PackageDescription
p)

-- | Perform the action on each buildable 'Executable' in the package
-- description.  You probably want 'withExeLBI' if you have a
-- 'LocalBuildInfo', see the note in
-- "Distribution.Types.ComponentRequestedSpec#buildable_vs_enabled_components"
-- for more information.
withExe :: PackageDescription -> (Executable -> IO ()) -> IO ()
withExe :: PackageDescription -> (Executable -> IO ()) -> IO ()
withExe PackageDescription
pkg_descr Executable -> IO ()
f =
  [IO ()] -> IO ()
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, Monad m) =>
t (m a) -> m ()
sequence_ [Executable -> IO ()
f Executable
exe | Executable
exe <- PackageDescription -> [Executable]
executables PackageDescription
pkg_descr, BuildInfo -> Bool
buildable (Executable -> BuildInfo
buildInfo Executable
exe)]

-- ---------------------------------------------------------------------------
-- The TestSuite type

-- | Does this package have any test suites?
hasTests :: PackageDescription -> Bool
hasTests :: PackageDescription -> Bool
hasTests = (TestSuite -> Bool) -> [TestSuite] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (BuildInfo -> Bool
buildable (BuildInfo -> Bool)
-> (TestSuite -> BuildInfo) -> TestSuite -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TestSuite -> BuildInfo
testBuildInfo) ([TestSuite] -> Bool)
-> (PackageDescription -> [TestSuite])
-> PackageDescription
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PackageDescription -> [TestSuite]
testSuites

-- | Perform an action on each buildable 'TestSuite' in a package.
-- You probably want 'withTestLBI' if you have a 'LocalBuildInfo', see the note in
-- "Distribution.Types.ComponentRequestedSpec#buildable_vs_enabled_components"
-- for more information.

withTest :: PackageDescription -> (TestSuite -> IO ()) -> IO ()
withTest :: PackageDescription -> (TestSuite -> IO ()) -> IO ()
withTest PackageDescription
pkg_descr TestSuite -> IO ()
f =
    [IO ()] -> IO ()
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, Monad m) =>
t (m a) -> m ()
sequence_ [ TestSuite -> IO ()
f TestSuite
test | TestSuite
test <- PackageDescription -> [TestSuite]
testSuites PackageDescription
pkg_descr, BuildInfo -> Bool
buildable (TestSuite -> BuildInfo
testBuildInfo TestSuite
test) ]

-- ---------------------------------------------------------------------------
-- The Benchmark type

-- | Does this package have any benchmarks?
hasBenchmarks :: PackageDescription -> Bool
hasBenchmarks :: PackageDescription -> Bool
hasBenchmarks = (Benchmark -> Bool) -> [Benchmark] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (BuildInfo -> Bool
buildable (BuildInfo -> Bool)
-> (Benchmark -> BuildInfo) -> Benchmark -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Benchmark -> BuildInfo
benchmarkBuildInfo) ([Benchmark] -> Bool)
-> (PackageDescription -> [Benchmark])
-> PackageDescription
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PackageDescription -> [Benchmark]
benchmarks

-- | Perform an action on each buildable 'Benchmark' in a package.
-- You probably want 'withBenchLBI' if you have a 'LocalBuildInfo', see the note in
-- "Distribution.Types.ComponentRequestedSpec#buildable_vs_enabled_components"
-- for more information.

withBenchmark :: PackageDescription -> (Benchmark -> IO ()) -> IO ()
withBenchmark :: PackageDescription -> (Benchmark -> IO ()) -> IO ()
withBenchmark PackageDescription
pkg_descr Benchmark -> IO ()
f =
    [IO ()] -> IO ()
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, Monad m) =>
t (m a) -> m ()
sequence_ [Benchmark -> IO ()
f Benchmark
bench | Benchmark
bench <- PackageDescription -> [Benchmark]
benchmarks PackageDescription
pkg_descr, BuildInfo -> Bool
buildable (Benchmark -> BuildInfo
benchmarkBuildInfo Benchmark
bench)]

-- ---------------------------------------------------------------------------
-- The ForeignLib type

-- | Does this package have any foreign libraries?
hasForeignLibs :: PackageDescription -> Bool
hasForeignLibs :: PackageDescription -> Bool
hasForeignLibs PackageDescription
p = (ForeignLib -> Bool) -> [ForeignLib] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (BuildInfo -> Bool
buildable (BuildInfo -> Bool)
-> (ForeignLib -> BuildInfo) -> ForeignLib -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ForeignLib -> BuildInfo
foreignLibBuildInfo) (PackageDescription -> [ForeignLib]
foreignLibs PackageDescription
p)

-- | Perform the action on each buildable 'ForeignLib' in the package
-- description.
withForeignLib :: PackageDescription -> (ForeignLib -> IO ()) -> IO ()
withForeignLib :: PackageDescription -> (ForeignLib -> IO ()) -> IO ()
withForeignLib PackageDescription
pkg_descr ForeignLib -> IO ()
f =
  [IO ()] -> IO ()
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, Monad m) =>
t (m a) -> m ()
sequence_ [ ForeignLib -> IO ()
f ForeignLib
flib
            | ForeignLib
flib <- PackageDescription -> [ForeignLib]
foreignLibs PackageDescription
pkg_descr
            , BuildInfo -> Bool
buildable (ForeignLib -> BuildInfo
foreignLibBuildInfo ForeignLib
flib)
            ]

-- ---------------------------------------------------------------------------
-- The BuildInfo type

-- | All 'BuildInfo' in the 'PackageDescription':
-- libraries, executables, test-suites and benchmarks.
--
-- Useful for implementing package checks.
allBuildInfo :: PackageDescription -> [BuildInfo]
allBuildInfo :: PackageDescription -> [BuildInfo]
allBuildInfo PackageDescription
pkg_descr = [ BuildInfo
bi | Library
lib <- PackageDescription -> [Library]
allLibraries PackageDescription
pkg_descr
                               , let bi :: BuildInfo
bi = Library -> BuildInfo
libBuildInfo Library
lib ]
                       [BuildInfo] -> [BuildInfo] -> [BuildInfo]
forall a. [a] -> [a] -> [a]
++ [ BuildInfo
bi | ForeignLib
flib <- PackageDescription -> [ForeignLib]
foreignLibs PackageDescription
pkg_descr
                               , let bi :: BuildInfo
bi = ForeignLib -> BuildInfo
foreignLibBuildInfo ForeignLib
flib ]
                       [BuildInfo] -> [BuildInfo] -> [BuildInfo]
forall a. [a] -> [a] -> [a]
++ [ BuildInfo
bi | Executable
exe <- PackageDescription -> [Executable]
executables PackageDescription
pkg_descr
                               , let bi :: BuildInfo
bi = Executable -> BuildInfo
buildInfo Executable
exe ]
                       [BuildInfo] -> [BuildInfo] -> [BuildInfo]
forall a. [a] -> [a] -> [a]
++ [ BuildInfo
bi | TestSuite
tst <- PackageDescription -> [TestSuite]
testSuites PackageDescription
pkg_descr
                               , let bi :: BuildInfo
bi = TestSuite -> BuildInfo
testBuildInfo TestSuite
tst ]
                       [BuildInfo] -> [BuildInfo] -> [BuildInfo]
forall a. [a] -> [a] -> [a]
++ [ BuildInfo
bi | Benchmark
tst <- PackageDescription -> [Benchmark]
benchmarks PackageDescription
pkg_descr
                               , let bi :: BuildInfo
bi = Benchmark -> BuildInfo
benchmarkBuildInfo Benchmark
tst ]

-- | Return all of the 'BuildInfo's of enabled components, i.e., all of
-- the ones that would be built if you run @./Setup build@.
enabledBuildInfos :: PackageDescription -> ComponentRequestedSpec -> [BuildInfo]
enabledBuildInfos :: PackageDescription -> ComponentRequestedSpec -> [BuildInfo]
enabledBuildInfos PackageDescription
pkg ComponentRequestedSpec
enabled =
    [ Component -> BuildInfo
componentBuildInfo Component
comp
    | Component
comp <- PackageDescription -> ComponentRequestedSpec -> [Component]
enabledComponents PackageDescription
pkg ComponentRequestedSpec
enabled ]


-- ------------------------------------------------------------
-- * Utils
-- ------------------------------------------------------------

-- | Get the combined build-depends entries of all components.
allBuildDepends :: PackageDescription -> [Dependency]
allBuildDepends :: PackageDescription -> [Dependency]
allBuildDepends = BuildInfo -> [Dependency]
targetBuildDepends (BuildInfo -> [Dependency])
-> (PackageDescription -> [BuildInfo])
-> PackageDescription
-> [Dependency]
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< PackageDescription -> [BuildInfo]
allBuildInfo

-- | Get the combined build-depends entries of all enabled components, per the
-- given request spec.
enabledBuildDepends :: PackageDescription -> ComponentRequestedSpec -> [Dependency]
enabledBuildDepends :: PackageDescription -> ComponentRequestedSpec -> [Dependency]
enabledBuildDepends PackageDescription
spec ComponentRequestedSpec
pd = BuildInfo -> [Dependency]
targetBuildDepends (BuildInfo -> [Dependency]) -> [BuildInfo] -> [Dependency]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< PackageDescription -> ComponentRequestedSpec -> [BuildInfo]
enabledBuildInfos PackageDescription
spec ComponentRequestedSpec
pd


updatePackageDescription :: HookedBuildInfo -> PackageDescription -> PackageDescription
updatePackageDescription :: HookedBuildInfo -> PackageDescription -> PackageDescription
updatePackageDescription (Maybe BuildInfo
mb_lib_bi, [(UnqualComponentName, BuildInfo)]
exe_bi) PackageDescription
p
    = PackageDescription
p{ executables :: [Executable]
executables = [(UnqualComponentName, BuildInfo)] -> [Executable] -> [Executable]
updateExecutables [(UnqualComponentName, BuildInfo)]
exe_bi    (PackageDescription -> [Executable]
executables PackageDescription
p)
       , library :: Maybe Library
library     = Maybe BuildInfo -> Maybe Library -> Maybe Library
updateLibrary     Maybe BuildInfo
mb_lib_bi (PackageDescription -> Maybe Library
library     PackageDescription
p) }
    where
      updateLibrary :: Maybe BuildInfo -> Maybe Library -> Maybe Library
      updateLibrary :: Maybe BuildInfo -> Maybe Library -> Maybe Library
updateLibrary (Just BuildInfo
bi) (Just Library
lib) = Library -> Maybe Library
forall a. a -> Maybe a
Just (Library
lib{libBuildInfo :: BuildInfo
libBuildInfo = BuildInfo
bi BuildInfo -> BuildInfo -> BuildInfo
forall a. Monoid a => a -> a -> a
`mappend` Library -> BuildInfo
libBuildInfo Library
lib})
      updateLibrary Maybe BuildInfo
Nothing   Maybe Library
mb_lib     = Maybe Library
mb_lib
      updateLibrary (Just BuildInfo
_)  Maybe Library
Nothing    = Maybe Library
forall a. Maybe a
Nothing

      updateExecutables :: [(UnqualComponentName, BuildInfo)] -- ^[(exeName, new buildinfo)]
        -> [Executable]                                       -- ^list of executables to update
        -> [Executable]                                       -- ^list with exeNames updated
      updateExecutables :: [(UnqualComponentName, BuildInfo)] -> [Executable] -> [Executable]
updateExecutables [(UnqualComponentName, BuildInfo)]
exe_bi' [Executable]
executables' = ((UnqualComponentName, BuildInfo) -> [Executable] -> [Executable])
-> [Executable]
-> [(UnqualComponentName, BuildInfo)]
-> [Executable]
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (UnqualComponentName, BuildInfo) -> [Executable] -> [Executable]
updateExecutable [Executable]
executables' [(UnqualComponentName, BuildInfo)]
exe_bi'

      updateExecutable :: (UnqualComponentName, BuildInfo) -- ^(exeName, new buildinfo)
                       -> [Executable]                     -- ^list of executables to update
                       -> [Executable]                     -- ^list with exeName updated
      updateExecutable :: (UnqualComponentName, BuildInfo) -> [Executable] -> [Executable]
updateExecutable (UnqualComponentName, BuildInfo)
_                 []         = []
      updateExecutable exe_bi' :: (UnqualComponentName, BuildInfo)
exe_bi'@(UnqualComponentName
name,BuildInfo
bi) (Executable
exe:[Executable]
exes)
        | Executable -> UnqualComponentName
exeName Executable
exe UnqualComponentName -> UnqualComponentName -> Bool
forall a. Eq a => a -> a -> Bool
== UnqualComponentName
name = Executable
exe{buildInfo :: BuildInfo
buildInfo = BuildInfo
bi BuildInfo -> BuildInfo -> BuildInfo
forall a. Monoid a => a -> a -> a
`mappend` Executable -> BuildInfo
buildInfo Executable
exe} Executable -> [Executable] -> [Executable]
forall a. a -> [a] -> [a]
: [Executable]
exes
        | Bool
otherwise           = Executable
exe Executable -> [Executable] -> [Executable]
forall a. a -> [a] -> [a]
: (UnqualComponentName, BuildInfo) -> [Executable] -> [Executable]
updateExecutable (UnqualComponentName, BuildInfo)
exe_bi' [Executable]
exes

-- -----------------------------------------------------------------------------
-- Source-representation of buildable components

-- | All the components in the package.
--
pkgComponents :: PackageDescription -> [Component]
pkgComponents :: PackageDescription -> [Component]
pkgComponents PackageDescription
pkg =
    [ Library -> Component
CLib  Library
lib | Library
lib <- PackageDescription -> [Library]
allLibraries PackageDescription
pkg ]
 [Component] -> [Component] -> [Component]
forall a. [a] -> [a] -> [a]
++ [ ForeignLib -> Component
CFLib ForeignLib
flib | ForeignLib
flib <- PackageDescription -> [ForeignLib]
foreignLibs PackageDescription
pkg ]
 [Component] -> [Component] -> [Component]
forall a. [a] -> [a] -> [a]
++ [ Executable -> Component
CExe  Executable
exe | Executable
exe <- PackageDescription -> [Executable]
executables PackageDescription
pkg ]
 [Component] -> [Component] -> [Component]
forall a. [a] -> [a] -> [a]
++ [ TestSuite -> Component
CTest TestSuite
tst | TestSuite
tst <- PackageDescription -> [TestSuite]
testSuites  PackageDescription
pkg ]
 [Component] -> [Component] -> [Component]
forall a. [a] -> [a] -> [a]
++ [ Benchmark -> Component
CBench Benchmark
bm | Benchmark
bm  <- PackageDescription -> [Benchmark]
benchmarks  PackageDescription
pkg ]

-- | A list of all components in the package that are buildable,
-- i.e., were not marked with @buildable: False@.  This does NOT
-- indicate if we are actually going to build the component,
-- see 'enabledComponents' instead.
--
-- @since 2.0.0.2
--
pkgBuildableComponents :: PackageDescription -> [Component]
pkgBuildableComponents :: PackageDescription -> [Component]
pkgBuildableComponents = (Component -> Bool) -> [Component] -> [Component]
forall a. (a -> Bool) -> [a] -> [a]
filter Component -> Bool
componentBuildable ([Component] -> [Component])
-> (PackageDescription -> [Component])
-> PackageDescription
-> [Component]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PackageDescription -> [Component]
pkgComponents

-- | A list of all components in the package that are enabled.
--
-- @since 2.0.0.2
--
enabledComponents :: PackageDescription -> ComponentRequestedSpec -> [Component]
enabledComponents :: PackageDescription -> ComponentRequestedSpec -> [Component]
enabledComponents PackageDescription
pkg ComponentRequestedSpec
enabled = (Component -> Bool) -> [Component] -> [Component]
forall a. (a -> Bool) -> [a] -> [a]
filter (ComponentRequestedSpec -> Component -> Bool
componentEnabled ComponentRequestedSpec
enabled) ([Component] -> [Component]) -> [Component] -> [Component]
forall a b. (a -> b) -> a -> b
$ PackageDescription -> [Component]
pkgBuildableComponents PackageDescription
pkg

lookupComponent :: PackageDescription -> ComponentName -> Maybe Component
lookupComponent :: PackageDescription -> ComponentName -> Maybe Component
lookupComponent PackageDescription
pkg (CLibName LibraryName
name) =
    (Library -> Component) -> Maybe Library -> Maybe Component
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Library -> Component
CLib (Maybe Library -> Maybe Component)
-> Maybe Library -> Maybe Component
forall a b. (a -> b) -> a -> b
$ (Library -> Bool) -> [Library] -> Maybe Library
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find ((LibraryName
name LibraryName -> LibraryName -> Bool
forall a. Eq a => a -> a -> Bool
==) (LibraryName -> Bool)
-> (Library -> LibraryName) -> Library -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Library -> LibraryName
libName) (PackageDescription -> [Library]
allLibraries PackageDescription
pkg)
lookupComponent PackageDescription
pkg (CFLibName UnqualComponentName
name) =
    (ForeignLib -> Component) -> Maybe ForeignLib -> Maybe Component
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ForeignLib -> Component
CFLib (Maybe ForeignLib -> Maybe Component)
-> Maybe ForeignLib -> Maybe Component
forall a b. (a -> b) -> a -> b
$ (ForeignLib -> Bool) -> [ForeignLib] -> Maybe ForeignLib
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find ((UnqualComponentName
name UnqualComponentName -> UnqualComponentName -> Bool
forall a. Eq a => a -> a -> Bool
==) (UnqualComponentName -> Bool)
-> (ForeignLib -> UnqualComponentName) -> ForeignLib -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ForeignLib -> UnqualComponentName
foreignLibName) (PackageDescription -> [ForeignLib]
foreignLibs PackageDescription
pkg)
lookupComponent PackageDescription
pkg (CExeName UnqualComponentName
name) =
    (Executable -> Component) -> Maybe Executable -> Maybe Component
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Executable -> Component
CExe (Maybe Executable -> Maybe Component)
-> Maybe Executable -> Maybe Component
forall a b. (a -> b) -> a -> b
$ (Executable -> Bool) -> [Executable] -> Maybe Executable
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find ((UnqualComponentName
name UnqualComponentName -> UnqualComponentName -> Bool
forall a. Eq a => a -> a -> Bool
==) (UnqualComponentName -> Bool)
-> (Executable -> UnqualComponentName) -> Executable -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Executable -> UnqualComponentName
exeName) (PackageDescription -> [Executable]
executables PackageDescription
pkg)
lookupComponent PackageDescription
pkg (CTestName UnqualComponentName
name) =
    (TestSuite -> Component) -> Maybe TestSuite -> Maybe Component
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap TestSuite -> Component
CTest (Maybe TestSuite -> Maybe Component)
-> Maybe TestSuite -> Maybe Component
forall a b. (a -> b) -> a -> b
$ (TestSuite -> Bool) -> [TestSuite] -> Maybe TestSuite
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find ((UnqualComponentName
name UnqualComponentName -> UnqualComponentName -> Bool
forall a. Eq a => a -> a -> Bool
==) (UnqualComponentName -> Bool)
-> (TestSuite -> UnqualComponentName) -> TestSuite -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TestSuite -> UnqualComponentName
testName) (PackageDescription -> [TestSuite]
testSuites PackageDescription
pkg)
lookupComponent PackageDescription
pkg (CBenchName UnqualComponentName
name) =
    (Benchmark -> Component) -> Maybe Benchmark -> Maybe Component
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Benchmark -> Component
CBench (Maybe Benchmark -> Maybe Component)
-> Maybe Benchmark -> Maybe Component
forall a b. (a -> b) -> a -> b
$ (Benchmark -> Bool) -> [Benchmark] -> Maybe Benchmark
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find ((UnqualComponentName
name UnqualComponentName -> UnqualComponentName -> Bool
forall a. Eq a => a -> a -> Bool
==) (UnqualComponentName -> Bool)
-> (Benchmark -> UnqualComponentName) -> Benchmark -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Benchmark -> UnqualComponentName
benchmarkName) (PackageDescription -> [Benchmark]
benchmarks PackageDescription
pkg)

getComponent :: PackageDescription -> ComponentName -> Component
getComponent :: PackageDescription -> ComponentName -> Component
getComponent PackageDescription
pkg ComponentName
cname =
    case PackageDescription -> ComponentName -> Maybe Component
lookupComponent PackageDescription
pkg ComponentName
cname of
      Just Component
cpnt -> Component
cpnt
      Maybe Component
Nothing   -> Component
forall a. a
missingComponent
  where
    missingComponent :: a
missingComponent =
      FilePath -> a
forall a. HasCallStack => FilePath -> a
error (FilePath -> a) -> FilePath -> a
forall a b. (a -> b) -> a -> b
$ FilePath
"internal error: the package description contains no "
           FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ FilePath
"component corresponding to " FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ ComponentName -> FilePath
forall a. Show a => a -> FilePath
show ComponentName
cname

-- -----------------------------------------------------------------------------
-- Traversal Instances

instance L.HasBuildInfos PackageDescription where
  traverseBuildInfos :: LensLike
  f PackageDescription PackageDescription BuildInfo BuildInfo
traverseBuildInfos BuildInfo -> f BuildInfo
f (PackageDescription Either Version VersionRange
a1 PackageIdentifier
a2 Either License License
a3 [FilePath]
a4 FilePath
a5 FilePath
a6 FilePath
a7 FilePath
a8 [(CompilerFlavor, VersionRange)]
a9 FilePath
a10 FilePath
a11 FilePath
a12 [SourceRepo]
a13 FilePath
a14 FilePath
a15 FilePath
a16 [(FilePath, FilePath)]
a17 Maybe BuildType
a18 Maybe SetupBuildInfo
a19
                                   Maybe Library
x1 [Library]
x2 [Executable]
x3 [ForeignLib]
x4 [TestSuite]
x5 [Benchmark]
x6
                                   [FilePath]
a20 FilePath
a21 [FilePath]
a22 [FilePath]
a23 [FilePath]
a24) =
    Either Version VersionRange
-> PackageIdentifier
-> Either License License
-> [FilePath]
-> FilePath
-> FilePath
-> FilePath
-> FilePath
-> [(CompilerFlavor, VersionRange)]
-> FilePath
-> FilePath
-> FilePath
-> [SourceRepo]
-> FilePath
-> FilePath
-> FilePath
-> [(FilePath, FilePath)]
-> Maybe BuildType
-> Maybe SetupBuildInfo
-> Maybe Library
-> [Library]
-> [Executable]
-> [ForeignLib]
-> [TestSuite]
-> [Benchmark]
-> [FilePath]
-> FilePath
-> [FilePath]
-> [FilePath]
-> [FilePath]
-> PackageDescription
PackageDescription Either Version VersionRange
a1 PackageIdentifier
a2 Either License License
a3 [FilePath]
a4 FilePath
a5 FilePath
a6 FilePath
a7 FilePath
a8 [(CompilerFlavor, VersionRange)]
a9 FilePath
a10 FilePath
a11 FilePath
a12 [SourceRepo]
a13 FilePath
a14 FilePath
a15 FilePath
a16 [(FilePath, FilePath)]
a17 Maybe BuildType
a18 Maybe SetupBuildInfo
a19
        (Maybe Library
 -> [Library]
 -> [Executable]
 -> [ForeignLib]
 -> [TestSuite]
 -> [Benchmark]
 -> [FilePath]
 -> FilePath
 -> [FilePath]
 -> [FilePath]
 -> [FilePath]
 -> PackageDescription)
-> f (Maybe Library)
-> f ([Library]
      -> [Executable]
      -> [ForeignLib]
      -> [TestSuite]
      -> [Benchmark]
      -> [FilePath]
      -> FilePath
      -> [FilePath]
      -> [FilePath]
      -> [FilePath]
      -> PackageDescription)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((Library -> f Library) -> Maybe Library -> f (Maybe Library)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((Library -> f Library) -> Maybe Library -> f (Maybe Library))
-> ((BuildInfo -> f BuildInfo) -> Library -> f Library)
-> (BuildInfo -> f BuildInfo)
-> Maybe Library
-> f (Maybe Library)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (BuildInfo -> f BuildInfo) -> Library -> f Library
forall a. HasBuildInfo a => Lens' a BuildInfo
L.buildInfo) BuildInfo -> f BuildInfo
f Maybe Library
x1 -- library
        f ([Library]
   -> [Executable]
   -> [ForeignLib]
   -> [TestSuite]
   -> [Benchmark]
   -> [FilePath]
   -> FilePath
   -> [FilePath]
   -> [FilePath]
   -> [FilePath]
   -> PackageDescription)
-> f [Library]
-> f ([Executable]
      -> [ForeignLib]
      -> [TestSuite]
      -> [Benchmark]
      -> [FilePath]
      -> FilePath
      -> [FilePath]
      -> [FilePath]
      -> [FilePath]
      -> PackageDescription)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((Library -> f Library) -> [Library] -> f [Library]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((Library -> f Library) -> [Library] -> f [Library])
-> ((BuildInfo -> f BuildInfo) -> Library -> f Library)
-> (BuildInfo -> f BuildInfo)
-> [Library]
-> f [Library]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (BuildInfo -> f BuildInfo) -> Library -> f Library
forall a. HasBuildInfo a => Lens' a BuildInfo
L.buildInfo) BuildInfo -> f BuildInfo
f [Library]
x2 -- sub libraries
        f ([Executable]
   -> [ForeignLib]
   -> [TestSuite]
   -> [Benchmark]
   -> [FilePath]
   -> FilePath
   -> [FilePath]
   -> [FilePath]
   -> [FilePath]
   -> PackageDescription)
-> f [Executable]
-> f ([ForeignLib]
      -> [TestSuite]
      -> [Benchmark]
      -> [FilePath]
      -> FilePath
      -> [FilePath]
      -> [FilePath]
      -> [FilePath]
      -> PackageDescription)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((Executable -> f Executable) -> [Executable] -> f [Executable]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((Executable -> f Executable) -> [Executable] -> f [Executable])
-> ((BuildInfo -> f BuildInfo) -> Executable -> f Executable)
-> (BuildInfo -> f BuildInfo)
-> [Executable]
-> f [Executable]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (BuildInfo -> f BuildInfo) -> Executable -> f Executable
forall a. HasBuildInfo a => Lens' a BuildInfo
L.buildInfo) BuildInfo -> f BuildInfo
f [Executable]
x3 -- executables
        f ([ForeignLib]
   -> [TestSuite]
   -> [Benchmark]
   -> [FilePath]
   -> FilePath
   -> [FilePath]
   -> [FilePath]
   -> [FilePath]
   -> PackageDescription)
-> f [ForeignLib]
-> f ([TestSuite]
      -> [Benchmark]
      -> [FilePath]
      -> FilePath
      -> [FilePath]
      -> [FilePath]
      -> [FilePath]
      -> PackageDescription)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((ForeignLib -> f ForeignLib) -> [ForeignLib] -> f [ForeignLib]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((ForeignLib -> f ForeignLib) -> [ForeignLib] -> f [ForeignLib])
-> ((BuildInfo -> f BuildInfo) -> ForeignLib -> f ForeignLib)
-> (BuildInfo -> f BuildInfo)
-> [ForeignLib]
-> f [ForeignLib]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (BuildInfo -> f BuildInfo) -> ForeignLib -> f ForeignLib
forall a. HasBuildInfo a => Lens' a BuildInfo
L.buildInfo) BuildInfo -> f BuildInfo
f [ForeignLib]
x4 -- foreign libs
        f ([TestSuite]
   -> [Benchmark]
   -> [FilePath]
   -> FilePath
   -> [FilePath]
   -> [FilePath]
   -> [FilePath]
   -> PackageDescription)
-> f [TestSuite]
-> f ([Benchmark]
      -> [FilePath]
      -> FilePath
      -> [FilePath]
      -> [FilePath]
      -> [FilePath]
      -> PackageDescription)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((TestSuite -> f TestSuite) -> [TestSuite] -> f [TestSuite]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((TestSuite -> f TestSuite) -> [TestSuite] -> f [TestSuite])
-> ((BuildInfo -> f BuildInfo) -> TestSuite -> f TestSuite)
-> (BuildInfo -> f BuildInfo)
-> [TestSuite]
-> f [TestSuite]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (BuildInfo -> f BuildInfo) -> TestSuite -> f TestSuite
forall a. HasBuildInfo a => Lens' a BuildInfo
L.buildInfo) BuildInfo -> f BuildInfo
f [TestSuite]
x5 -- test suites
        f ([Benchmark]
   -> [FilePath]
   -> FilePath
   -> [FilePath]
   -> [FilePath]
   -> [FilePath]
   -> PackageDescription)
-> f [Benchmark]
-> f ([FilePath]
      -> FilePath
      -> [FilePath]
      -> [FilePath]
      -> [FilePath]
      -> PackageDescription)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((Benchmark -> f Benchmark) -> [Benchmark] -> f [Benchmark]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((Benchmark -> f Benchmark) -> [Benchmark] -> f [Benchmark])
-> ((BuildInfo -> f BuildInfo) -> Benchmark -> f Benchmark)
-> (BuildInfo -> f BuildInfo)
-> [Benchmark]
-> f [Benchmark]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (BuildInfo -> f BuildInfo) -> Benchmark -> f Benchmark
forall a. HasBuildInfo a => Lens' a BuildInfo
L.buildInfo) BuildInfo -> f BuildInfo
f [Benchmark]
x6 -- benchmarks
        f ([FilePath]
   -> FilePath
   -> [FilePath]
   -> [FilePath]
   -> [FilePath]
   -> PackageDescription)
-> f [FilePath]
-> f (FilePath
      -> [FilePath] -> [FilePath] -> [FilePath] -> PackageDescription)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [FilePath] -> f [FilePath]
forall (f :: * -> *) a. Applicative f => a -> f a
pure [FilePath]
a20                      -- data files
        f (FilePath
   -> [FilePath] -> [FilePath] -> [FilePath] -> PackageDescription)
-> f FilePath
-> f ([FilePath] -> [FilePath] -> [FilePath] -> PackageDescription)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> FilePath -> f FilePath
forall (f :: * -> *) a. Applicative f => a -> f a
pure FilePath
a21                      -- data dir
        f ([FilePath] -> [FilePath] -> [FilePath] -> PackageDescription)
-> f [FilePath]
-> f ([FilePath] -> [FilePath] -> PackageDescription)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [FilePath] -> f [FilePath]
forall (f :: * -> *) a. Applicative f => a -> f a
pure [FilePath]
a22                      -- exta src files
        f ([FilePath] -> [FilePath] -> PackageDescription)
-> f [FilePath] -> f ([FilePath] -> PackageDescription)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [FilePath] -> f [FilePath]
forall (f :: * -> *) a. Applicative f => a -> f a
pure [FilePath]
a23                      -- extra temp files
        f ([FilePath] -> PackageDescription)
-> f [FilePath] -> f PackageDescription
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [FilePath] -> f [FilePath]
forall (f :: * -> *) a. Applicative f => a -> f a
pure [FilePath]
a24                      -- extra doc files