Add migration guide for #9718 (#10578)
[cabal.git] / Cabal / src / Distribution / Backpack / PreExistingComponent.hs
blob0fba79bcb87e73125f731bc58e592cdaccd57d8e
1 -- | See <https://github.com/ezyang/ghc-proposals/blob/backpack/proposals/0000-backpack.rst>
2 module Distribution.Backpack.PreExistingComponent
3 ( PreExistingComponent (..)
4 , ConfiguredPromisedComponent (..)
5 , ipiToPreExistingComponent
6 ) where
8 import Distribution.Compat.Prelude
9 import Prelude ()
11 import Distribution.Backpack
12 import Distribution.Backpack.ModuleShape
13 import Distribution.Package
14 import Distribution.Types.ComponentName
15 import Distribution.Types.MungedPackageId
17 import qualified Data.Map as Map
18 import Distribution.InstalledPackageInfo (InstalledPackageInfo)
19 import qualified Distribution.InstalledPackageInfo as Installed
20 import Distribution.Types.AnnotatedId
22 -- | A /promised/ component.
24 -- These components are promised to @configure@ but are not yet built.
26 -- In other words this is 'PreExistingComponent' which doesn't yet exist.
27 data ConfiguredPromisedComponent = ConfiguredPromisedComponent
28 { pr_pkgname :: PackageName
29 , pr_cid :: AnnotatedId ComponentId
32 instance Package ConfiguredPromisedComponent where
33 packageId = packageId . pr_cid
35 -- | Stripped down version of 'LinkedComponent' for things
36 -- we don't need to know how to build.
37 data PreExistingComponent = PreExistingComponent
38 { pc_pkgname :: PackageName
39 -- ^ The actual name of the package. This may DISAGREE with 'pc_pkgid'
40 -- for internal dependencies: e.g., an internal component @lib@ may be
41 -- munged to @z-pkg-z-lib@, but we still want to use it when we see
42 -- @lib@ in @build-depends@
43 , pc_compname :: ComponentName
44 -- ^ The actual name of the component.
45 , pc_munged_id :: MungedPackageId
46 , pc_uid :: UnitId
47 , pc_cid :: ComponentId
48 , pc_open_uid :: OpenUnitId
49 , pc_shape :: ModuleShape
52 -- | Convert an 'InstalledPackageInfo' into a 'PreExistingComponent',
53 -- which was brought into scope under the 'PackageName' (important for
54 -- a package qualified reference.)
55 ipiToPreExistingComponent :: InstalledPackageInfo -> PreExistingComponent
56 ipiToPreExistingComponent ipi =
57 PreExistingComponent
58 { pc_pkgname = packageName ipi
59 , pc_compname = CLibName $ Installed.sourceLibName ipi
60 , pc_munged_id = mungedId ipi
61 , pc_uid = Installed.installedUnitId ipi
62 , pc_cid = Installed.installedComponentId ipi
63 , pc_open_uid =
64 IndefFullUnitId
65 (Installed.installedComponentId ipi)
66 (Map.fromList (Installed.instantiatedWith ipi))
67 , pc_shape = shapeInstalledPackage ipi
70 instance HasMungedPackageId PreExistingComponent where
71 mungedId = pc_munged_id
73 instance Package PreExistingComponent where
74 packageId pec = PackageIdentifier (pc_pkgname pec) v
75 where
76 MungedPackageId _ v = pc_munged_id pec
78 instance HasUnitId PreExistingComponent where
79 installedUnitId = pc_uid