never executed always true always false
1 {-# LANGUAGE DeriveGeneric #-}
2 {-# LANGUAGE TypeFamilies #-}
3 module Distribution.Client.Types.ConfiguredPackage (
4 ConfiguredPackage (..),
5 ) where
6
7 import Distribution.Client.Compat.Prelude
8 import Prelude ()
9
10 import Distribution.Compat.Graph (IsNode (..))
11 import Distribution.Package (newSimpleUnitId, HasMungedPackageId (..), HasUnitId (..), Package (..), PackageInstalled (..), UnitId)
12 import Distribution.Types.Flag (FlagAssignment)
13 import Distribution.Types.ComponentName
14 import Distribution.Types.LibraryName (LibraryName (..))
15 import Distribution.Types.MungedPackageId (computeCompatPackageId)
16 import Distribution.Simple.Utils (ordNub)
17
18 import Distribution.Client.Types.ConfiguredId
19 import Distribution.Solver.Types.OptionalStanza (OptionalStanzaSet)
20 import Distribution.Solver.Types.PackageFixedDeps
21 import Distribution.Solver.Types.SourcePackage (SourcePackage)
22
23 import qualified Distribution.Solver.Types.ComponentDeps as CD
24
25 -- | A 'ConfiguredPackage' is a not-yet-installed package along with the
26 -- total configuration information. The configuration information is total in
27 -- the sense that it provides all the configuration information and so the
28 -- final configure process will be independent of the environment.
29 --
30 -- 'ConfiguredPackage' is assumed to not support Backpack. Only the
31 -- @v2-build@ codepath supports Backpack.
32 --
33 data ConfiguredPackage loc = ConfiguredPackage
34 { confPkgId :: InstalledPackageId
35 , confPkgSource :: SourcePackage loc -- ^ package info, including repo
36 , confPkgFlags :: FlagAssignment -- ^ complete flag assignment for the package
37 , confPkgStanzas :: OptionalStanzaSet -- ^ list of enabled optional stanzas for the package
38 , confPkgDeps :: CD.ComponentDeps [ConfiguredId]
39 -- ^ set of exact dependencies (installed or source).
40 --
41 -- These must be consistent with the 'buildDepends'
42 -- in the 'PackageDescription' that you'd get by
43 -- applying the flag assignment and optional stanzas.
44 }
45 deriving (Eq, Show, Generic)
46
47 -- | 'HasConfiguredId' indicates data types which have a 'ConfiguredId'.
48 -- This type class is mostly used to conveniently finesse between
49 -- 'ElaboratedPackage' and 'ElaboratedComponent'.
50 --
51 instance HasConfiguredId (ConfiguredPackage loc) where
52 configuredId pkg = ConfiguredId (packageId pkg) (Just (CLibName LMainLibName)) (confPkgId pkg)
53
54 -- 'ConfiguredPackage' is the legacy codepath, we are guaranteed
55 -- to never have a nontrivial 'UnitId'
56 instance PackageFixedDeps (ConfiguredPackage loc) where
57 depends = fmap (map (newSimpleUnitId . confInstId)) . confPkgDeps
58
59 instance IsNode (ConfiguredPackage loc) where
60 type Key (ConfiguredPackage loc) = UnitId
61 nodeKey = newSimpleUnitId . confPkgId
62 -- TODO: if we update ConfiguredPackage to support order-only
63 -- dependencies, need to include those here.
64 -- NB: have to deduplicate, otherwise the planner gets confused
65 nodeNeighbors = ordNub . CD.flatDeps . depends
66
67 instance (Binary loc) => Binary (ConfiguredPackage loc)
68
69
70
71
72 instance Package (ConfiguredPackage loc) where
73 packageId cpkg = packageId (confPkgSource cpkg)
74
75 instance HasMungedPackageId (ConfiguredPackage loc) where
76 mungedId cpkg = computeCompatPackageId (packageId cpkg) LMainLibName
77
78 -- Never has nontrivial UnitId
79 instance HasUnitId (ConfiguredPackage loc) where
80 installedUnitId = newSimpleUnitId . confPkgId
81
82 instance PackageInstalled (ConfiguredPackage loc) where
83 installedDepends = CD.flatDeps . depends
84
85
86