Skip to content

Commit 90cb80c

Browse files
committed
SolverId changes
add solverId function
1 parent 395aaf1 commit 90cb80c

File tree

5 files changed

+35
-21
lines changed

5 files changed

+35
-21
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
@@ -60,9 +60,9 @@ convCP iidx sidx (CP qpi fa es ds) =
6060
ds' = fmap (partitionEithers . map convConfId) ds
6161

6262
convConfId :: PI QPN -> Either SolverId {- is lib -} SolverId {- is exe -}
63-
convConfId (PI (Q (PackagePath _ q) pn) (I _ v loc)) =
63+
convConfId (PI (Q (PackagePath _ q) pn) (I stage v loc)) =
6464
case loc of
65-
Inst pi -> Left (PreExistingId sourceId pi)
65+
Inst pi -> Left (PreExistingId stage sourceId pi)
6666
_otherwise
6767
| QualExe _ pn' <- q
6868
-- NB: the dependencies of the executable are also
@@ -71,7 +71,7 @@ convConfId (PI (Q (PackagePath _ q) pn) (I _ v loc)) =
7171
-- at the actual thing. Fortunately for us, I was
7272
-- silly and didn't allow arbitrarily nested build-tools
7373
-- dependencies, so a shallow check works.
74-
, pn == pn' -> Right (PlannedId sourceId)
75-
| otherwise -> Left (PlannedId sourceId)
74+
, pn == pn' -> Right (PlannedId stage sourceId)
75+
| otherwise -> Left (PlannedId stage sourceId)
7676
where
7777
sourceId = PackageIdentifier pn v

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

Lines changed: 12 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
, dumpResolverPackage
@@ -13,6 +15,7 @@ import Prelude ()
1315
import Distribution.Solver.Types.InstSolverPackage
1416
import Distribution.Solver.Types.SolverId
1517
import Distribution.Solver.Types.SolverPackage
18+
import Distribution.Solver.Types.PackagePath (QPN)
1619
import qualified Distribution.Solver.Types.ComponentDeps as CD
1720

1821
import Distribution.Compat.Graph (IsNode(..))
@@ -36,6 +39,14 @@ instance Package (ResolverPackage loc) where
3639
packageId (PreExisting ipkg) = packageId ipkg
3740
packageId (Configured spkg) = packageId spkg
3841

42+
solverId :: ResolverPackage loc -> SolverId
43+
solverId (PreExisting ipkg) = PreExistingId (instSolverStage ipkg) (packageId ipkg) (installedUnitId ipkg)
44+
solverId (Configured spkg) = PlannedId (solverPkgStage spkg) (packageId spkg)
45+
46+
solverQPN :: ResolverPackage loc -> QPN
47+
solverQPN (PreExisting ipkg) = instSolverQPN ipkg
48+
solverQPN (Configured spkg) = solverPkgQPN spkg
49+
3950
resolverPackageLibDeps :: ResolverPackage loc -> CD.ComponentDeps [SolverId]
4051
resolverPackageLibDeps (PreExisting ipkg) = instSolverPkgLibDeps ipkg
4152
resolverPackageLibDeps (Configured spkg) = solverPkgLibDeps spkg
@@ -46,8 +57,7 @@ resolverPackageExeDeps (Configured spkg) = solverPkgExeDeps spkg
4657

4758
instance IsNode (ResolverPackage loc) where
4859
type Key (ResolverPackage loc) = SolverId
49-
nodeKey (PreExisting ipkg) = PreExistingId (packageId ipkg) (installedUnitId ipkg)
50-
nodeKey (Configured spkg) = PlannedId (packageId spkg)
60+
nodeKey = solverId
5161
-- Use dependencies for ALL components
5262
nodeNeighbors pkg =
5363
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/InstallPlan.hs

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

564564
-- The error below shouldn't happen, since mapDep should only
565565
-- be called on neighbor SolverId, which must have all been done
566566
-- already by the reverse top-sort (we assume the graph is not broken).
567567
--
568568
-- FIXME: stage is ignored
569-
mapDep _ ipiMap (PreExistingId _pid uid)
569+
mapDep _ ipiMap (PreExistingId _stage _pid uid)
570570
| Just pkgs <- Map.lookup uid ipiMap = pkgs
571571
| otherwise = error ("fromSolverInstallPlan: PreExistingId " ++ prettyShow uid)
572-
mapDep pidMap _ (PlannedId pid)
572+
mapDep pidMap _ (PlannedId _stage pid)
573573
| Just pkgs <- Map.lookup pid pidMap = pkgs
574574
| otherwise = error ("fromSolverInstallPlan: PlannedId " ++ prettyShow pid)
575575

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ module Distribution.Client.ProjectPlanning
9595
, binDirectories
9696
, storePackageInstallDirs
9797
, storePackageInstallDirs'
98-
98+
9999
-- * Re-exports for backward compatibility
100100
, programDbSignature
101101

@@ -2380,11 +2380,12 @@ elaborateInstallPlan
23802380

23812381
pkgsToBuildInplaceOnly :: Set PackageId
23822382
pkgsToBuildInplaceOnly =
2383-
Set.fromList $
2384-
map packageId $
2385-
SolverInstallPlan.reverseDependencyClosure
2386-
solverPlan
2387-
(map PlannedId (Set.toList pkgsLocalToProject))
2383+
Set.fromList [
2384+
packageId pkg
2385+
| stage <- Stage.stages
2386+
, let solverIds = [PlannedId stage pkgId | pkgId <- Set.toList pkgsLocalToProject]
2387+
, pkg <- SolverInstallPlan.reverseDependencyClosure solverPlan solverIds
2388+
]
23882389

23892390
isLocalToProject :: Package pkg => pkg -> Bool
23902391
isLocalToProject pkg =

0 commit comments

Comments
 (0)