Repository : ssh://darcs.haskell.org//srv/darcs/packages/Cabal On branch : master
http://hackage.haskell.org/trac/ghc/changeset/2341ba1180fbad960c085e0a1540c6460a562ebd >--------------------------------------------------------------- commit 2341ba1180fbad960c085e0a1540c6460a562ebd Author: Andres Loeh <[email protected]> Date: Thu Oct 27 19:01:52 2011 +0000 restore the index conversion utility function, but as a top-level function >--------------------------------------------------------------- cabal-install/Distribution/Client/IndexUtils.hs | 31 +++++++++++++++++++++++ 1 files changed, 31 insertions(+), 0 deletions(-) diff --git a/cabal-install/Distribution/Client/IndexUtils.hs b/cabal-install/Distribution/Client/IndexUtils.hs index b8343b0..fbcb7ae 100644 --- a/cabal-install/Distribution/Client/IndexUtils.hs +++ b/cabal-install/Distribution/Client/IndexUtils.hs @@ -13,6 +13,7 @@ module Distribution.Client.IndexUtils ( getInstalledPackages, getSourcePackages, + convert, readPackageIndexFile, parsePackageIndex, @@ -85,6 +86,36 @@ getInstalledPackages verbosity comp packageDbs conf = --FIXME: make getInstalledPackages use sensible verbosity in the first place verbosity' = lessVerbose verbosity +convert :: InstalledPackageIndex.PackageIndex -> PackageIndex InstalledPackage +convert index = PackageIndex.fromList + -- There can be multiple installed instances of each package version, + -- like when the same package is installed in the global & user dbs. + -- InstalledPackageIndex.allPackagesByName gives us the installed + -- packages with the most preferred instances first, so by picking the + -- first we should get the user one. This is almost but not quite the + -- same as what ghc does. + [ InstalledPackage ipkg (sourceDeps index ipkg) + | ipkgs <- InstalledPackageIndex.allPackagesByName index + , (ipkg:_) <- groupBy (equating packageVersion) ipkgs ] + where + -- The InstalledPackageInfo only lists dependencies by the + -- InstalledPackageId, which means we do not directly know the corresponding + -- source dependency. The only way to find out is to lookup the + -- InstalledPackageId to get the InstalledPackageInfo and look at its + -- source PackageId. But if the package is broken because it depends on + -- other packages that do not exist then we have a problem we cannot find + -- the original source package id. Instead we make up a bogus package id. + -- This should have the same effect since it should be a dependency on a + -- non-existant package. + sourceDeps index ipkg = + [ maybe (brokenPackageId depid) packageId mdep + | let depids = InstalledPackageInfo.depends ipkg + getpkg = InstalledPackageIndex.lookupInstalledPackageId index + , (depid, mdep) <- zip depids (map getpkg depids) ] + + brokenPackageId (InstalledPackageId str) = + PackageIdentifier (PackageName (str ++ "-broken")) (Version [] []) + ------------------------------------------------------------------------ -- Reading the source package index -- _______________________________________________ Cvs-libraries mailing list [email protected] http://www.haskell.org/mailman/listinfo/cvs-libraries
