Skip to content

Commit a155ab7

Browse files
committed
wip: pass qualified package name into the SolverInstallPlan
1 parent 57376aa commit a155ab7

File tree

6 files changed

+42
-22
lines changed

6 files changed

+42
-22
lines changed

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import Data.Maybe
66
import Prelude hiding (pi)
77
import Data.Either (partitionEithers)
88

9-
import Distribution.Package (UnitId, packageId)
10-
119
import qualified Distribution.Simple.PackageIndex as SI
1210

1311
import Distribution.Solver.Modular.Configured
@@ -29,36 +27,38 @@ convCP :: SI.InstalledPackageIndex ->
2927
CI.PackageIndex (SourcePackage loc) ->
3028
CP QPN -> ResolverPackage loc
3129
convCP iidx sidx (CP qpi fa es ds) =
32-
case convPI qpi of
33-
Left pi -> PreExisting $
30+
case qpi of
31+
-- Installed
32+
(PI qpn (I _ (Inst pi))) ->
33+
PreExisting $
3434
InstSolverPackage {
35-
instSolverPkgIPI = fromJust $ SI.lookupUnitId iidx pi,
35+
instSolverQPN = qpn,
36+
instSolverPkgIPI = fromMaybe (error "convCP: lookupUnitId failed") $ SI.lookupUnitId iidx pi,
3637
instSolverPkgLibDeps = fmap fst ds',
3738
instSolverPkgExeDeps = fmap snd ds'
3839
}
39-
Right pi -> Configured $
40+
-- "In repo" i.e. a source package
41+
(PI qpn@(Q _path pn) (I v InRepo)) ->
42+
let pi = PackageIdentifier pn v in
43+
Configured $
4044
SolverPackage {
41-
solverPkgSource = srcpkg,
45+
solverPkgQPN = qpn,
46+
solverPkgSource = fromMaybe (error "convCP: lookupPackageId failed") $ CI.lookupPackageId sidx pi,
4247
solverPkgFlags = fa,
4348
solverPkgStanzas = es,
4449
solverPkgLibDeps = fmap fst ds',
4550
solverPkgExeDeps = fmap snd ds'
4651
}
47-
where
48-
srcpkg = fromMaybe (error "convCP: lookupPackageId failed") $ CI.lookupPackageId sidx pi
4952
where
5053
ds' :: ComponentDeps ([SolverId] {- lib -}, [SolverId] {- exe -})
5154
ds' = fmap (partitionEithers . map convConfId) ds
5255

53-
convPI :: PI QPN -> Either UnitId PackageId
54-
convPI (PI _ (I _ (Inst pi))) = Left pi
55-
convPI pi = Right (packageId (either id id (convConfId pi)))
56-
5756
convConfId :: PI QPN -> Either SolverId {- is lib -} SolverId {- is exe -}
5857
convConfId (PI (Q (PackagePath _ q) pn) (I v loc)) =
5958
case loc of
60-
Inst pi -> Left (PreExistingId sourceId pi)
61-
_otherwise
59+
Inst pi ->
60+
Left (PreExistingId sourceId pi)
61+
InRepo
6262
| QualExe _ pn' <- q
6363
-- NB: the dependencies of the executable are also
6464
-- qualified. So the way to tell if this is an executable
@@ -67,6 +67,6 @@ convConfId (PI (Q (PackagePath _ q) pn) (I v loc)) =
6767
-- silly and didn't allow arbitrarily nested build-tools
6868
-- dependencies, so a shallow check works.
6969
, pn == pn' -> Right (PlannedId sourceId)
70-
| otherwise -> Left (PlannedId sourceId)
70+
| otherwise -> Left (PlannedId sourceId)
7171
where
7272
sourceId = PackageIdentifier pn v

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Prelude ()
88

99
import Distribution.Package ( Package(..), HasMungedPackageId(..), HasUnitId(..) )
1010
import Distribution.Solver.Types.ComponentDeps ( ComponentDeps )
11+
import Distribution.Solver.Types.PackagePath (QPN)
1112
import Distribution.Solver.Types.SolverId
1213
import Distribution.Types.MungedPackageId
1314
import Distribution.Types.PackageId
@@ -17,6 +18,7 @@ import Distribution.InstalledPackageInfo (InstalledPackageInfo)
1718
-- | An 'InstSolverPackage' is a pre-existing installed package
1819
-- specified by the dependency solver.
1920
data InstSolverPackage = InstSolverPackage {
21+
instSolverQPN :: QPN,
2022
instSolverPkgIPI :: InstalledPackageInfo,
2123
instSolverPkgLibDeps :: ComponentDeps [SolverId],
2224
instSolverPkgExeDeps :: ComponentDeps [SolverId]

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{-# LANGUAGE FlexibleInstances #-}
2+
{-# LANGUAGE DeriveGeneric #-}
13
module Distribution.Solver.Types.PackagePath
24
( PackagePath(..)
35
, Namespace(..)
@@ -18,7 +20,10 @@ import qualified Text.PrettyPrint as Disp
1820
-- | A package path consists of a namespace and a package path inside that
1921
-- namespace.
2022
data PackagePath = PackagePath Namespace Qualifier
21-
deriving (Eq, Ord, Show)
23+
deriving (Eq, Ord, Show, Generic)
24+
25+
instance Binary PackagePath
26+
instance Structured PackagePath
2227

2328
-- | Top-level namespace
2429
--
@@ -30,7 +35,10 @@ data Namespace =
3035

3136
-- | A namespace for a specific build target
3237
| Independent PackageName
33-
deriving (Eq, Ord, Show)
38+
deriving (Eq, Ord, Show, Generic)
39+
40+
instance Binary Namespace
41+
instance Structured Namespace
3442

3543
-- | Pretty-prints a namespace. The result is either empty or
3644
-- ends in a period, so it can be prepended onto a qualifier.
@@ -68,7 +76,10 @@ data Qualifier =
6876
-- tracked only @pn2@, that would require us to pick only one
6977
-- version of an executable over the entire install plan.)
7078
| QualExe PackageName PackageName
71-
deriving (Eq, Ord, Show)
79+
deriving (Eq, Ord, Show, Generic)
80+
81+
instance Binary Qualifier
82+
instance Structured Qualifier
7283

7384
-- | Pretty-prints a qualifier. The result is either empty or
7485
-- ends in a period, so it can be prepended onto a package name.
@@ -87,11 +98,14 @@ dispQualifier (QualBase pn) = pretty pn <<>> Disp.text "."
8798

8899
-- | A qualified entity. Pairs a package path with the entity.
89100
data Qualified a = Q PackagePath a
90-
deriving (Eq, Ord, Show)
101+
deriving (Eq, Ord, Show, Generic)
91102

92103
-- | Qualified package name.
93104
type QPN = Qualified PackageName
94105

106+
instance Binary (Qualified PackageName)
107+
instance Structured (Qualified PackageName)
108+
95109
-- | Pretty-prints a qualified package name.
96110
dispQPN :: QPN -> Disp.Doc
97111
dispQPN (Q (PackagePath ns qual) pn) =

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Distribution.Package ( Package(..) )
1010
import Distribution.PackageDescription ( FlagAssignment )
1111
import Distribution.Solver.Types.ComponentDeps ( ComponentDeps )
1212
import Distribution.Solver.Types.OptionalStanza
13+
import Distribution.Solver.Types.PackagePath (QPN)
1314
import Distribution.Solver.Types.SolverId
1415
import Distribution.Solver.Types.SourcePackage
1516

@@ -21,6 +22,7 @@ import Distribution.Solver.Types.SourcePackage
2122
-- but for symmetry we have the parameter. (Maybe it can be removed.)
2223
--
2324
data SolverPackage loc = SolverPackage {
25+
solverPkgQPN :: QPN,
2426
solverPkgSource :: SourcePackage loc,
2527
solverPkgFlags :: FlagAssignment,
2628
solverPkgStanzas :: OptionalStanzaSet,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ configuredPackageProblems
10231023
configuredPackageProblems
10241024
platform
10251025
cinfo
1026-
(SolverPackage pkg specifiedFlags stanzas specifiedDeps0 _specifiedExeDeps') =
1026+
(SolverPackage _qpn pkg specifiedFlags stanzas specifiedDeps0 _specifiedExeDeps') =
10271027
[ DuplicateFlag flag
10281028
| flag <- PD.findDuplicateFlagAssignments specifiedFlags
10291029
]

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1685,7 +1685,7 @@ elaborateInstallPlan
16851685
:: (SolverId -> [ElaboratedPlanPackage])
16861686
-> SolverPackage UnresolvedPkgLoc
16871687
-> LogProgress [ElaboratedConfiguredPackage]
1688-
elaborateSolverToComponents mapDep spkg@(SolverPackage _ _ _ deps0 exe_deps0) =
1688+
elaborateSolverToComponents mapDep spkg@(SolverPackage qpn _ _ _ deps0 exe_deps0) =
16891689
case mkComponentsGraph (elabEnabledSpec elab0) pd of
16901690
Right g -> do
16911691
let src_comps = componentsGraphToList g
@@ -2075,6 +2075,7 @@ elaborateInstallPlan
20752075
elaborateSolverToPackage
20762076
pkgWhyNotPerComponent
20772077
pkg@( SolverPackage
2078+
qpn
20782079
(SourcePackage pkgid _gpd _srcloc _descOverride)
20792080
_flags
20802081
_stanzas
@@ -2178,6 +2179,7 @@ elaborateInstallPlan
21782179
-> (ElaboratedConfiguredPackage, LogProgress ())
21792180
elaborateSolverToCommon
21802181
pkg@( SolverPackage
2182+
qpn
21812183
(SourcePackage pkgid gdesc srcloc descOverride)
21822184
flags
21832185
stanzas

0 commit comments

Comments
 (0)