module Distribution.Backpack.PreExistingComponent (
PreExistingComponent(..),
ipiToPreExistingComponent,
) where
import Prelude ()
import Distribution.Compat.Prelude
import Distribution.Backpack.ModuleShape
import Distribution.Backpack
import Distribution.Types.ComponentId
import Distribution.Types.MungedPackageId
import Distribution.Types.PackageId
import Distribution.Types.UnitId
import Distribution.Types.ComponentName
import Distribution.Types.PackageName
import Distribution.Package
import qualified Data.Map as Map
import qualified Distribution.InstalledPackageInfo as Installed
import Distribution.InstalledPackageInfo (InstalledPackageInfo)
data PreExistingComponent
= PreExistingComponent {
pc_pkgname :: PackageName,
pc_compname :: ComponentName,
pc_munged_id :: MungedPackageId,
pc_uid :: UnitId,
pc_cid :: ComponentId,
pc_open_uid :: OpenUnitId,
pc_shape :: ModuleShape
}
ipiToPreExistingComponent :: InstalledPackageInfo -> PreExistingComponent
ipiToPreExistingComponent ipi =
PreExistingComponent {
pc_pkgname = packageName ipi,
pc_compname = CLibName $ Installed.sourceLibName ipi,
pc_munged_id = mungedId ipi,
pc_uid = Installed.installedUnitId ipi,
pc_cid = Installed.installedComponentId ipi,
pc_open_uid =
IndefFullUnitId (Installed.installedComponentId ipi)
(Map.fromList (Installed.instantiatedWith ipi)),
pc_shape = shapeInstalledPackage ipi
}
instance HasMungedPackageId PreExistingComponent where
mungedId = pc_munged_id
instance Package PreExistingComponent where
packageId pec = PackageIdentifier (pc_pkgname pec) v
where MungedPackageId _ v = pc_munged_id pec
instance HasUnitId PreExistingComponent where
installedUnitId = pc_uid