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 {
PreExistingComponent -> PackageName
pc_pkgname :: PackageName,
PreExistingComponent -> ComponentName
pc_compname :: ComponentName,
PreExistingComponent -> MungedPackageId
pc_munged_id :: MungedPackageId,
PreExistingComponent -> UnitId
pc_uid :: UnitId,
PreExistingComponent -> ComponentId
pc_cid :: ComponentId,
PreExistingComponent -> OpenUnitId
pc_open_uid :: OpenUnitId,
PreExistingComponent -> ModuleShape
pc_shape :: ModuleShape
}
ipiToPreExistingComponent :: InstalledPackageInfo -> PreExistingComponent
ipiToPreExistingComponent :: InstalledPackageInfo -> PreExistingComponent
ipiToPreExistingComponent InstalledPackageInfo
ipi =
PreExistingComponent :: PackageName
-> ComponentName
-> MungedPackageId
-> UnitId
-> ComponentId
-> OpenUnitId
-> ModuleShape
-> PreExistingComponent
PreExistingComponent {
pc_pkgname :: PackageName
pc_pkgname = InstalledPackageInfo -> PackageName
forall pkg. Package pkg => pkg -> PackageName
packageName InstalledPackageInfo
ipi,
pc_compname :: ComponentName
pc_compname = LibraryName -> ComponentName
CLibName (LibraryName -> ComponentName) -> LibraryName -> ComponentName
forall a b. (a -> b) -> a -> b
$ InstalledPackageInfo -> LibraryName
Installed.sourceLibName InstalledPackageInfo
ipi,
pc_munged_id :: MungedPackageId
pc_munged_id = InstalledPackageInfo -> MungedPackageId
forall pkg. HasMungedPackageId pkg => pkg -> MungedPackageId
mungedId InstalledPackageInfo
ipi,
pc_uid :: UnitId
pc_uid = InstalledPackageInfo -> UnitId
Installed.installedUnitId InstalledPackageInfo
ipi,
pc_cid :: ComponentId
pc_cid = InstalledPackageInfo -> ComponentId
Installed.installedComponentId InstalledPackageInfo
ipi,
pc_open_uid :: OpenUnitId
pc_open_uid =
ComponentId -> OpenModuleSubst -> OpenUnitId
IndefFullUnitId (InstalledPackageInfo -> ComponentId
Installed.installedComponentId InstalledPackageInfo
ipi)
([(ModuleName, OpenModule)] -> OpenModuleSubst
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList (InstalledPackageInfo -> [(ModuleName, OpenModule)]
Installed.instantiatedWith InstalledPackageInfo
ipi)),
pc_shape :: ModuleShape
pc_shape = InstalledPackageInfo -> ModuleShape
shapeInstalledPackage InstalledPackageInfo
ipi
}
instance HasMungedPackageId PreExistingComponent where
mungedId :: PreExistingComponent -> MungedPackageId
mungedId = PreExistingComponent -> MungedPackageId
pc_munged_id
instance Package PreExistingComponent where
packageId :: PreExistingComponent -> PackageIdentifier
packageId PreExistingComponent
pec = PackageName -> Version -> PackageIdentifier
PackageIdentifier (PreExistingComponent -> PackageName
pc_pkgname PreExistingComponent
pec) Version
v
where MungedPackageId MungedPackageName
_ Version
v = PreExistingComponent -> MungedPackageId
pc_munged_id PreExistingComponent
pec
instance HasUnitId PreExistingComponent where
installedUnitId :: PreExistingComponent -> UnitId
installedUnitId = PreExistingComponent -> UnitId
pc_uid