1 {-# LANGUAGE DeriveDataTypeable #-}
2 {-# LANGUAGE DeriveGeneric #-}
3 {-# LANGUAGE FlexibleContexts #-}
4 {-# LANGUAGE ScopedTypeVariables #-}
6 module Distribution
.Types
.GenericPackageDescription
7 ( GenericPackageDescription
(..)
8 , emptyGenericPackageDescription
11 import Distribution
.Compat
.Prelude
15 import Distribution
.Compat
.Lens
as L
16 import qualified Distribution
.Types
.BuildInfo
.Lens
as L
18 import Distribution
.Types
.PackageDescription
20 import Distribution
.Package
21 import Distribution
.Types
.Benchmark
22 import Distribution
.Types
.CondTree
23 import Distribution
.Types
.ConfVar
24 import Distribution
.Types
.Executable
25 import Distribution
.Types
.Flag
26 import Distribution
.Types
.ForeignLib
27 import Distribution
.Types
.Library
28 import Distribution
.Types
.TestSuite
29 import Distribution
.Types
.UnqualComponentName
30 import Distribution
.Version
32 -- ---------------------------------------------------------------------------
33 -- The 'GenericPackageDescription' type
35 data GenericPackageDescription
= GenericPackageDescription
36 { packageDescription
:: PackageDescription
37 , gpdScannedVersion
:: Maybe Version
38 -- ^ This is a version as specified in source.
39 -- We populate this field in index reading for dummy GPDs,
40 -- only when GPD reading failed, but scanning haven't.
42 -- Cabal-the-library never produces GPDs with Just as gpdScannedVersion.
44 -- Perfectly, PackageIndex should have sum type, so we don't need to
46 , genPackageFlags
:: [PackageFlag
]
47 , condLibrary
:: Maybe (CondTree ConfVar
[Dependency
] Library
)
49 :: [ ( UnqualComponentName
50 , CondTree ConfVar
[Dependency
] Library
54 :: [ ( UnqualComponentName
55 , CondTree ConfVar
[Dependency
] ForeignLib
59 :: [ ( UnqualComponentName
60 , CondTree ConfVar
[Dependency
] Executable
64 :: [ ( UnqualComponentName
65 , CondTree ConfVar
[Dependency
] TestSuite
69 :: [ ( UnqualComponentName
70 , CondTree ConfVar
[Dependency
] Benchmark
74 deriving (Show, Eq
, Typeable
, Data
, Generic
)
76 instance Package GenericPackageDescription
where
77 packageId
= packageId
. packageDescription
79 instance Binary GenericPackageDescription
80 instance Structured GenericPackageDescription
81 instance NFData GenericPackageDescription
where rnf
= genericRnf
83 emptyGenericPackageDescription
:: GenericPackageDescription
84 emptyGenericPackageDescription
= GenericPackageDescription emptyPackageDescription Nothing
[] Nothing
[] [] [] [] []
86 -- -----------------------------------------------------------------------------
87 -- Traversal Instances
89 instance L
.HasBuildInfos GenericPackageDescription
where
90 traverseBuildInfos f
(GenericPackageDescription p v a1 x1 x2 x3 x4 x5 x6
) =
91 GenericPackageDescription
92 <$> L
.traverseBuildInfos f p
95 <*> (traverse
. traverseCondTreeBuildInfo
) f x1
96 <*> (traverse
. L
._2
. traverseCondTreeBuildInfo
) f x2
97 <*> (traverse
. L
._2
. traverseCondTreeBuildInfo
) f x3
98 <*> (traverse
. L
._2
. traverseCondTreeBuildInfo
) f x4
99 <*> (traverse
. L
._2
. traverseCondTreeBuildInfo
) f x5
100 <*> (traverse
. L
._2
. traverseCondTreeBuildInfo
) f x6
102 -- We use this traversal to keep [Dependency] field in CondTree up to date.
103 traverseCondTreeBuildInfo
105 . (Applicative f
, L
.HasBuildInfo comp
)
106 => LensLike
' f
(CondTree v
[Dependency
] comp
) L
.BuildInfo
107 traverseCondTreeBuildInfo g
= node
109 mkCondNode
:: comp
-> [CondBranch v
[Dependency
] comp
] -> CondTree v
[Dependency
] comp
110 mkCondNode comp
= CondNode comp
(view L
.targetBuildDepends comp
)
112 node
(CondNode comp _ branches
) =
114 <$> L
.buildInfo g comp
115 <*> traverse branch branches
117 branch
(CondBranch v x y
) =