Skip to content

Commit

Permalink
Avoid package index conversion
Browse files Browse the repository at this point in the history
Introduce

    dependencyClosure :: InstallPlan
                      -> [PackageIdentifier]
                      -> Either (PackageIndex PlanPackage) [(PlanPackage, [InstalledPackageId])]

And use this in the definition of `pruneInstallPlan` in `freeze`, to avoid
first converting an install plan from a `Cabal.PackageIndex` to a
`CabalInstall.PackageIndex`.

This resolves the first of the two irregularities mentioned in the previous
commit.
  • Loading branch information
edsko committed Mar 21, 2015
1 parent 1beba1b commit e866b5e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
18 changes: 7 additions & 11 deletions cabal-install/Distribution/Client/Freeze.hs
Expand Up @@ -34,12 +34,11 @@ import Distribution.Client.Sandbox.Types
( SandboxPackageInfo(..) )

import Distribution.Package
( Package, PackageIdentifier, packageId, packageName, packageVersion )
( Package, packageId, packageName, packageVersion )
import Distribution.Simple.Compiler
( Compiler, compilerInfo, PackageDBStack )
import Distribution.Simple.PackageIndex (InstalledPackageIndex)
import qualified Distribution.Client.PackageIndex as PackageIndex
import qualified Distribution.Client.PlanIndex as PlanIndex
import qualified Distribution.Simple.PackageIndex as PackageIndex
import Distribution.Simple.Program
( ProgramConfiguration )
import Distribution.Simple.Setup
Expand Down Expand Up @@ -141,9 +140,7 @@ planPackages verbosity comp platform mSandboxPkgInfo freezeFlags
solver
resolverParams

return $ either id
(error "planPackages: installPlan contains broken packages")
(pruneInstallPlan installPlan pkgSpecifiers)
return $ pruneInstallPlan installPlan pkgSpecifiers

where
resolverParams =
Expand Down Expand Up @@ -194,15 +191,14 @@ planPackages verbosity comp platform mSandboxPkgInfo freezeFlags
-- which are no longer required from the install plan.
pruneInstallPlan :: InstallPlan.InstallPlan
-> [PackageSpecifier SourcePackage]
-> Either [PlanPackage] [(PlanPackage, [PackageIdentifier])]
-> [PlanPackage]
pruneInstallPlan installPlan pkgSpecifiers =
mapLeft (removeSelf pkgIds . PackageIndex.allPackages) $
PlanIndex.dependencyClosure pkgIdx pkgIds
InstallPlan.dependencyClosure installPlan pkgIds
where
pkgIdx = PackageIndex.fromList $ InstallPlan.toList installPlan
pkgIds = [ packageId pkg | SpecificSourcePackage pkg <- pkgSpecifiers ]
mapLeft f (Left v) = Left $ f v
mapLeft _ (Right v) = Right v
mapLeft f (Left v) = f v
mapLeft _ (Right _) = error "planPackages: installPlan contains broken packages"
removeSelf [thisPkg] = filter (\pp -> packageId pp /= thisPkg)
removeSelf _ =
error $ "internal error: 'pruneInstallPlan' given "
Expand Down
20 changes: 19 additions & 1 deletion cabal-install/Distribution/Client/InstallPlan.hs
Expand Up @@ -44,7 +44,10 @@ module Distribution.Client.InstallPlan (
PackageProblem(..),
showPackageProblem,
problems,
configuredPackageProblems
configuredPackageProblems,

-- ** Querying the install plan
dependencyClosure,
) where

import Distribution.Client.Types
Expand Down Expand Up @@ -628,3 +631,18 @@ configuredPackageProblems platform cinfo
(enableStanzas stanzas $ packageDescription pkg) of
Right (resolvedPkg, _) -> externalBuildDepends resolvedPkg
Left _ -> error "configuredPackageInvalidDeps internal error"

-- | Compute the dependency closure of a _source_ package in a install plan
--
-- See `Distribution.Simple.dependencyClosure`
dependencyClosure :: InstallPlan
-> [PackageIdentifier]
-> Either (PackageIndex PlanPackage) [(PlanPackage, [InstalledPackageId])]
dependencyClosure installPlan pids =
PackageIndex.dependencyClosure'
(planFakeMap installPlan)
(planIndex installPlan)
(map (resolveFakeId . fakeInstalledPackageId) pids)
where
resolveFakeId :: InstalledPackageId -> InstalledPackageId
resolveFakeId ipid = Map.findWithDefault ipid ipid (planFakeMap installPlan)

0 comments on commit e866b5e

Please sign in to comment.