Commit 4b6e2be1 authored by Edward Z. Yang's avatar Edward Z. Yang

Add some more backwards-compatibility functions, fixes #3068.

Signed-off-by: default avatarEdward Z. Yang <ezyang@cs.stanford.edu>
parent a966c8e9
......@@ -29,6 +29,7 @@
module Distribution.InstalledPackageInfo (
InstalledPackageInfo(..),
installedComponentId,
installedPackageId,
OriginalModule(..), ExposedModule(..),
ParseResult(..), PError(..), PWarning,
emptyInstalledPackageInfo,
......@@ -41,7 +42,7 @@ module Distribution.InstalledPackageInfo (
import Distribution.ParseUtils
import Distribution.License
import Distribution.Package hiding (installedUnitId)
import Distribution.Package hiding (installedUnitId, installedPackageId)
import qualified Distribution.Package as Package
import Distribution.ModuleName
import Distribution.Version
......@@ -103,6 +104,11 @@ installedComponentId :: InstalledPackageInfo -> ComponentId
installedComponentId ipi = case installedUnitId ipi of
SimpleUnitId cid -> cid
{-# DEPRECATED installedPackageId "Use installedUnitId instead" #-}
-- | Backwards compatibility with pre-Cabal 1.23.
installedPackageId :: InstalledPackageInfo -> UnitId
installedPackageId = installedUnitId
instance Binary InstalledPackageInfo
instance Package.Package InstalledPackageInfo where
......
......@@ -42,6 +42,7 @@ module Distribution.Package (
-- * Package classes
Package(..), packageName, packageVersion,
HasUnitId(..),
installedPackageId,
PackageInstalled(..),
) where
......@@ -122,6 +123,7 @@ data ComponentId
= ComponentId String
deriving (Generic, Read, Show, Eq, Ord, Typeable, Data)
{-# DEPRECATED InstalledPackageId "Use UnitId instead" #-}
type InstalledPackageId = UnitId
instance Binary ComponentId
......@@ -214,6 +216,11 @@ instance Package PackageIdentifier where
class Package pkg => HasUnitId pkg where
installedUnitId :: pkg -> UnitId
{-# DEPRECATED installedPackageId "Use installedUnitId instead" #-}
-- | Compatibility wrapper for pre-Cabal 1.23.
installedPackageId :: HasUnitId pkg => pkg -> UnitId
installedPackageId = installedUnitId
-- | Class of installed packages.
--
-- The primary data type which is an instance of this package is
......
......@@ -59,6 +59,10 @@ module Distribution.Simple.PackageIndex (
dependencyCycles,
dependencyGraph,
moduleNameIndex,
-- * Backwards compatibility
deleteInstalledPackageId,
lookupInstalledPackageId,
) where
import Distribution.Compat.Binary
......@@ -236,8 +240,8 @@ insert pkg (PackageIndex pids pnames) =
-- | Removes a single installed package from the index.
--
deleteUnitId :: HasUnitId a
=> UnitId -> PackageIndex a
-> PackageIndex a
=> UnitId -> PackageIndex a
-> PackageIndex a
deleteUnitId ipkgid original@(PackageIndex pids pnames) =
case Map.updateLookupWithKey (\_ _ -> Nothing) ipkgid pids of
(Nothing, _) -> original
......@@ -256,6 +260,12 @@ deleteUnitId ipkgid original@(PackageIndex pids pnames) =
(\xs -> if List.null xs then Nothing else Just xs)
. List.deleteBy (\_ pkg -> installedUnitId pkg == ipkgid) undefined
-- | Backwards compatibility wrapper for pre-Cabal 1.23.
{-# DEPRECATED deleteInstalledPackageId "Use deleteUnitId instead" #-}
deleteInstalledPackageId :: HasUnitId a
=> UnitId -> PackageIndex a
-> PackageIndex a
deleteInstalledPackageId = deleteUnitId
-- | Removes all packages with this source 'PackageId' from the index.
--
......@@ -337,9 +347,15 @@ allPackagesBySourcePackageId (PackageIndex _ pnames) =
-- then we get back at most one package.
--
lookupUnitId :: PackageIndex a -> UnitId
-> Maybe a
-> Maybe a
lookupUnitId (PackageIndex pids _) pid = Map.lookup pid pids
-- | Backwards compatibility for pre Cabal-1.23.
{-# DEPRECATED lookupInstalledPackageId "Use lookupUnitId instead" #-}
lookupInstalledPackageId :: PackageIndex a -> UnitId
-> Maybe a
lookupInstalledPackageId = lookupUnitId
-- | Does a lookup by source package id (name & version).
--
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment