Skip to content

Commit c213cea

Browse files
committed
feat(cabal-install, cabal-install-solver): track stage in SolverId
1 parent 4d51ab9 commit c213cea

File tree

6 files changed

+46
-22
lines changed

6 files changed

+46
-22
lines changed

cabal-install-solver/src/Distribution/Solver/Modular/ConfiguredConversion.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ convCP iidx sidx (CP qpi fa es ds) =
5757
ds' = fmap (partitionEithers . map convConfId) ds
5858

5959
convConfId :: PI QPN -> Either SolverId {- is lib -} SolverId {- is exe -}
60-
convConfId (PI (Q (PackagePath _stage q) pn) (I _stage' v loc)) =
60+
convConfId (PI (Q (PackagePath _stage q) pn) (I stage v loc)) =
6161
case loc of
62-
Inst pi -> Left (PreExistingId sourceId pi)
62+
Inst pi -> Left (PreExistingId stage sourceId pi)
6363
_otherwise
6464
| QualExe _ pn' <- q
6565
-- NB: the dependencies of the executable are also
@@ -68,7 +68,7 @@ convConfId (PI (Q (PackagePath _stage q) pn) (I _stage' v loc)) =
6868
-- at the actual thing. Fortunately for us, I was
6969
-- silly and didn't allow arbitrarily nested build-tools
7070
-- dependencies, so a shallow check works.
71-
, pn == pn' -> Right (PlannedId sourceId)
72-
| otherwise -> Left (PlannedId sourceId)
71+
, pn == pn' -> Right (PlannedId stage sourceId)
72+
| otherwise -> Left (PlannedId stage sourceId)
7373
where
7474
sourceId = PackageIdentifier pn v

cabal-install-solver/src/Distribution/Solver/Types/ResolverPackage.hs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
{-# LANGUAGE DeriveGeneric #-}
33
module Distribution.Solver.Types.ResolverPackage
44
( ResolverPackage(..)
5+
, solverId
6+
, solverQPN
57
, resolverPackageLibDeps
68
, resolverPackageExeDeps
79
) where
@@ -12,6 +14,7 @@ import Prelude ()
1214
import Distribution.Solver.Types.InstSolverPackage
1315
import Distribution.Solver.Types.SolverId
1416
import Distribution.Solver.Types.SolverPackage
17+
import Distribution.Solver.Types.PackagePath (QPN)
1518
import qualified Distribution.Solver.Types.ComponentDeps as CD
1619

1720
import Distribution.Compat.Graph (IsNode(..))
@@ -34,6 +37,14 @@ instance Package (ResolverPackage loc) where
3437
packageId (PreExisting ipkg) = packageId ipkg
3538
packageId (Configured spkg) = packageId spkg
3639

40+
solverId :: ResolverPackage loc -> SolverId
41+
solverId (PreExisting ipkg) = PreExistingId (instSolverStage ipkg) (packageId ipkg) (installedUnitId ipkg)
42+
solverId (Configured spkg) = PlannedId (solverPkgStage spkg) (packageId spkg)
43+
44+
solverQPN :: ResolverPackage loc -> QPN
45+
solverQPN (PreExisting ipkg) = instSolverQPN ipkg
46+
solverQPN (Configured spkg) = solverPkgQPN spkg
47+
3748
resolverPackageLibDeps :: ResolverPackage loc -> CD.ComponentDeps [SolverId]
3849
resolverPackageLibDeps (PreExisting ipkg) = instSolverPkgLibDeps ipkg
3950
resolverPackageLibDeps (Configured spkg) = solverPkgLibDeps spkg
@@ -44,8 +55,8 @@ resolverPackageExeDeps (Configured spkg) = solverPkgExeDeps spkg
4455

4556
instance IsNode (ResolverPackage loc) where
4657
type Key (ResolverPackage loc) = SolverId
47-
nodeKey (PreExisting ipkg) = PreExistingId (packageId ipkg) (installedUnitId ipkg)
48-
nodeKey (Configured spkg) = PlannedId (packageId spkg)
58+
nodeKey = solverId
59+
4960
-- Use dependencies for ALL components
5061
nodeNeighbors pkg =
5162
ordNub $ CD.flatDeps (resolverPackageLibDeps pkg) ++

cabal-install-solver/src/Distribution/Solver/Types/SolverId.hs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@ import Prelude ()
1010

1111
import Distribution.Package (PackageId, Package(..), UnitId)
1212
import Distribution.Pretty (Pretty (..))
13-
import Text.PrettyPrint (parens)
13+
import Distribution.Solver.Types.Stage (Stage)
14+
15+
import Text.PrettyPrint (colon, punctuate, text)
16+
1417

1518
-- | The solver can produce references to existing packages or
1619
-- packages we plan to install. Unlike 'ConfiguredId' we don't
1720
-- yet know the 'UnitId' for planned packages, because it's
1821
-- not the solver's job to compute them.
1922
--
20-
data SolverId = PreExistingId { solverSrcId :: PackageId, solverInstId :: UnitId }
21-
| PlannedId { solverSrcId :: PackageId }
23+
data SolverId = PreExistingId { solverStage :: Stage, solverSrcId :: PackageId, solverInstId :: UnitId }
24+
| PlannedId { solverStage :: Stage, solverSrcId :: PackageId }
2225
deriving (Eq, Ord, Generic)
2326

2427
instance Binary SolverId
@@ -31,5 +34,5 @@ instance Package SolverId where
3134
packageId = solverSrcId
3235

3336
instance Pretty SolverId where
34-
pretty (PreExistingId pkg unitId) = pretty pkg <+> parens (pretty unitId)
35-
pretty (PlannedId pkg) = pretty pkg
37+
pretty (PreExistingId stage pkg unitId) = mconcat $ punctuate colon $ [pretty stage, pretty pkg, text "installed", pretty unitId]
38+
pretty (PlannedId stage pkg) = mconcat $ punctuate colon $ [pretty stage, pretty pkg, text "planned"]

cabal-install/src/Distribution/Client/Freeze.hs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ import Distribution.Solver.Types.ConstraintSource
5151
import Distribution.Solver.Types.LabeledPackageConstraint
5252
import Distribution.Solver.Types.OptionalStanza
5353
import Distribution.Solver.Types.PkgConfigDb
54+
import Distribution.Solver.Types.ResolverPackage (solverId)
5455
import Distribution.Solver.Types.SolverId
56+
import Distribution.Solver.Types.SolverPackage (SolverPackage (..))
5557
import qualified Distribution.Solver.Types.Stage as Stage
5658

5759
import Distribution.Client.Errors
@@ -285,9 +287,15 @@ pruneInstallPlan installPlan pkgSpecifiers =
285287
removeSelf pkgIds $
286288
SolverInstallPlan.dependencyClosure installPlan pkgIds
287289
where
290+
-- Get the source packages from the (specific) package specifiers.
291+
srcpkgs :: [UnresolvedSourcePackage]
292+
srcpkgs = [pkg | SpecificSourcePackage pkg <- pkgSpecifiers]
293+
-- Get the 'SolverId's of the packages we are freezing.
294+
pkgIds :: [SolverId]
288295
pkgIds =
289-
[ PlannedId (packageId pkg)
290-
| SpecificSourcePackage pkg <- pkgSpecifiers
296+
[ solverId (SolverInstallPlan.Configured pkg)
297+
| SolverInstallPlan.Configured pkg <- SolverInstallPlan.toList installPlan
298+
, solverPkgSource pkg `elem` srcpkgs
291299
]
292300
removeSelf [thisPkg] = filter (\pp -> packageId pp /= packageId thisPkg)
293301
removeSelf _ =

cabal-install/src/Distribution/Client/InstallPlan.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -557,19 +557,20 @@ fromSolverInstallPlanWithProgress f plan = do
557557
pkgs' <- f (mapDep pidMap ipiMap) pkg
558558
let (pidMap', ipiMap') =
559559
case nodeKey pkg of
560-
PreExistingId _ uid -> (pidMap, Map.insert uid pkgs' ipiMap)
561-
PlannedId pid -> (Map.insert pid pkgs' pidMap, ipiMap)
560+
-- FIXME: stage is ignored
561+
PreExistingId _stage _ uid -> (pidMap, Map.insert uid pkgs' ipiMap)
562+
PlannedId _stage pid -> (Map.insert pid pkgs' pidMap, ipiMap)
562563
return (pidMap', ipiMap', pkgs' ++ pkgs)
563564

564565
-- The error below shouldn't happen, since mapDep should only
565566
-- be called on neighbor SolverId, which must have all been done
566567
-- already by the reverse top-sort (we assume the graph is not broken).
567568
--
568569
-- FIXME: stage is ignored
569-
mapDep _ ipiMap (PreExistingId _pid uid)
570+
mapDep _ ipiMap (PreExistingId _stage _pid uid)
570571
| Just pkgs <- Map.lookup uid ipiMap = pkgs
571572
| otherwise = error ("fromSolverInstallPlan: PreExistingId " ++ prettyShow uid)
572-
mapDep pidMap _ (PlannedId pid)
573+
mapDep pidMap _ (PlannedId _stage pid)
573574
| Just pkgs <- Map.lookup pid pidMap = pkgs
574575
| otherwise = error ("fromSolverInstallPlan: PlannedId " ++ prettyShow pid)
575576

cabal-install/src/Distribution/Client/ProjectPlanning.hs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2455,11 +2455,12 @@ elaborateInstallPlan
24552455

24562456
pkgsToBuildInplaceOnly :: Set PackageId
24572457
pkgsToBuildInplaceOnly =
2458-
Set.fromList $
2459-
map packageId $
2460-
SolverInstallPlan.reverseDependencyClosure
2461-
solverPlan
2462-
(map PlannedId (Set.toList pkgsLocalToProject))
2458+
Set.fromList
2459+
[ packageId pkg
2460+
| stage <- stages
2461+
, let solverIds = [PlannedId stage pkgId | pkgId <- Set.toList pkgsLocalToProject]
2462+
, pkg <- SolverInstallPlan.reverseDependencyClosure solverPlan solverIds
2463+
]
24632464

24642465
isLocalToProject :: Package pkg => pkg -> Bool
24652466
isLocalToProject pkg =

0 commit comments

Comments
 (0)