Skip to content

Commit ddbdd71

Browse files
committed
Add Stage = Host | Build
1 parent a68d450 commit ddbdd71

File tree

7 files changed

+43
-19
lines changed

7 files changed

+43
-19
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ convCP :: SI.InstalledPackageIndex ->
2929
convCP iidx sidx (CP qpi fa es ds) =
3030
case qpi of
3131
-- Installed
32-
(PI qpn (I _ (Inst pi))) ->
32+
(PI qpn (I {- FIXME -} Host _ (Inst pi))) ->
3333
PreExisting $
3434
InstSolverPackage {
3535
instSolverQPN = qpn,
@@ -38,7 +38,7 @@ convCP iidx sidx (CP qpi fa es ds) =
3838
instSolverPkgExeDeps = fmap snd ds'
3939
}
4040
-- "In repo" i.e. a source package
41-
(PI qpn@(Q _path pn) (I v InRepo)) ->
41+
(PI qpn@(Q _path pn) (I {- FIXME -} Host v InRepo)) ->
4242
let pi = PackageIdentifier pn v in
4343
Configured $
4444
SolverPackage {
@@ -54,7 +54,7 @@ convCP iidx sidx (CP qpi fa es ds) =
5454
ds' = fmap (partitionEithers . map convConfId) ds
5555

5656
convConfId :: PI QPN -> Either SolverId {- is lib -} SolverId {- is exe -}
57-
convConfId (PI (Q (PackagePath _ q) pn) (I v loc)) =
57+
convConfId (PI (Q (PackagePath _ q) pn) (I _stage v loc)) =
5858
case loc of
5959
Inst pi ->
6060
Left (PreExistingId sourceId pi)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ exploreLog mbj enableBj fineGrainedConflicts (CountConflicts countConflicts) idx
268268
-- Skipping it is an optimization. If false, it returns a new conflict set
269269
-- to be merged with the previous one.
270270
couldResolveConflicts :: QPN -> POption -> S.Set CS.Conflict -> Maybe ConflictSet
271-
couldResolveConflicts currentQPN@(Q _ pn) (POption i@(I v _) _) conflicts =
271+
couldResolveConflicts currentQPN@(Q _ pn) (POption i@(I _stage v _) _) conflicts =
272272
let (PInfo deps _ _ _) = idx M.! pn M.! i
273273
qdeps = qualifyDeps currentQPN deps
274274

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,18 @@ mkIndex xs = M.map M.fromList (groupMap (L.map (\ (pn, i, pi) -> (pn, (i, pi)))
5656

5757
groupMap :: Ord a => [(a, b)] -> Map a [b]
5858
groupMap xs = M.fromListWith (flip (++)) (L.map (\ (x, y) -> (x, [y])) xs)
59+
60+
defaultQualifyOptions :: Index -> QualifyOptions
61+
defaultQualifyOptions idx = QO {
62+
qoBaseShim = or [ dep == base
63+
| -- Find all versions of base ..
64+
Just is <- [M.lookup base idx]
65+
-- .. which are installed ..
66+
, (I _ver _stage (Inst _), PInfo deps _comps _flagNfo _fr) <- M.toList is
67+
-- .. and flatten all their dependencies ..
68+
, (LDep _ (Dep (PkgComponent dep _) _ci), _comp) <- flattenFlaggedDeps deps
69+
]
70+
, qoSetupIndependent = True
71+
}
72+
where
73+
base = mkPackageName "base"

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ convIPI' (ShadowPkgs sip) idx =
8181

8282
-- | Extract/recover the package ID from an installed package info, and convert it to a solver's I.
8383
convId :: IPI.InstalledPackageInfo -> (PN, I)
84-
convId ipi = (pn, I ver $ Inst $ IPI.installedUnitId ipi)
84+
convId ipi = (pn, I {- FIXME -} Host ver $ Inst $ IPI.installedUnitId ipi)
8585
where MungedPackageId mpn ver = mungedId ipi
8686
-- HACK. See Note [Index conversion with internal libraries]
8787
pn = encodeCompatPackageName mpn
@@ -163,7 +163,7 @@ convSPI' os arch cinfo constraints strfl solveExes =
163163
convSP :: OS -> Arch -> CompilerInfo -> Map PN [LabeledPackageConstraint]
164164
-> StrongFlags -> SolveExecutables -> SourcePackage loc -> (PN, I, PInfo)
165165
convSP os arch cinfo constraints strfl solveExes (SourcePackage (PackageIdentifier pn pv) gpd _ _pl) =
166-
let i = I pv InRepo
166+
let i = I {- FIXME -} Host pv InRepo
167167
pkgConstraints = fromMaybe [] $ M.lookup pn constraints
168168
in (pn, i, convGPD os arch cinfo pkgConstraints strfl solveExes pn gpd)
169169

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{-# LANGUAGE DeriveFunctor #-}
22
module Distribution.Solver.Modular.Package
33
( I(..)
4+
, Stage(..)
45
, Loc(..)
56
, PackageId
67
, PackageIdentifier(..)
@@ -49,14 +50,22 @@ type PId = UnitId
4950
data Loc = Inst PId | InRepo
5051
deriving (Eq, Ord, Show)
5152

53+
-- | Stage. A stage in the build process.
54+
data Stage = Build | Host
55+
deriving (Eq, Ord, Show)
56+
57+
showStage :: Stage -> String
58+
showStage Build = "[build]"
59+
showStage Host = "[host ]"
60+
5261
-- | Instance. A version number and a location.
53-
data I = I Ver Loc
62+
data I = I Stage Ver Loc
5463
deriving (Eq, Ord, Show)
5564

5665
-- | String representation of an instance.
5766
showI :: I -> String
58-
showI (I v InRepo) = showVer v
59-
showI (I v (Inst uid)) = showVer v ++ "/installed" ++ extractPackageAbiHash uid
67+
showI (I s v InRepo) = showStage s ++ showVer v
68+
showI (I s v (Inst uid)) = showStage s ++ showVer v ++ "/installed" ++ extractPackageAbiHash uid
6069
where
6170
extractPackageAbiHash xs =
6271
case first reverse $ break (=='-') $ reverse (prettyShow xs) of
@@ -72,8 +81,8 @@ showPI :: PI QPN -> String
7281
showPI (PI qpn i) = showQPN qpn ++ "-" ++ showI i
7382

7483
instI :: I -> Bool
75-
instI (I _ (Inst _)) = True
76-
instI _ = False
84+
instI (I _ _ (Inst _)) = True
85+
instI _ = False
7786

7887
-- | Qualify a target package with its own name so that its dependencies are not
7988
-- required to be consistent with other targets.

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ addWeight :: (PN -> [Ver] -> POption -> Weight) -> EndoTreeTrav d c
7272
addWeight f = addWeights [f]
7373

7474
version :: POption -> Ver
75-
version (POption (I v _) _) = v
75+
version (POption (I _ v _) _) = v
7676

7777
-- | Prefer to link packages whenever possible.
7878
preferLinked :: EndoTreeTrav d c
@@ -139,8 +139,8 @@ preferPackagePreferences pcs =
139139

140140
-- Prefer installed packages over non-installed packages.
141141
installed :: POption -> Weight
142-
installed (POption (I _ (Inst _)) _) = 0
143-
installed _ = 1
142+
installed (POption (I _ _ (Inst _)) _) = 0
143+
installed _ = 1
144144

145145
-- | Traversal that tries to establish package stanza enable\/disable
146146
-- preferences. Works by reordering the branches of stanza choices.
@@ -184,7 +184,7 @@ processPackageConstraintP qpn c i (LabeledPackageConstraint (PackageConstraint s
184184
else r
185185
where
186186
go :: I -> PackageProperty -> Tree d c
187-
go (I v _) (PackagePropertyVersion vr)
187+
go (I _stage v _) (PackagePropertyVersion vr)
188188
| checkVR vr v = r
189189
| otherwise = Fail c (GlobalConstraintVersion vr src)
190190
go _ PackagePropertyInstalled
@@ -338,10 +338,10 @@ avoidReinstalls p = go
338338
| otherwise = PChoiceF qpn rdm gr cs
339339
where
340340
disableReinstalls =
341-
let installed = [ v | (_, POption (I v (Inst _)) _, _) <- W.toList cs ]
341+
let installed = [ v | (_, POption (I _stage v (Inst _)) _, _) <- W.toList cs ]
342342
in W.mapWithKey (notReinstall installed) cs
343343

344-
notReinstall vs (POption (I v InRepo) _) _ | v `elem` vs =
344+
notReinstall vs (POption (I _stage v InRepo) _) _ | v `elem` vs =
345345
Fail (varToConflictSet (P qpn)) CannotReinstall
346346
notReinstall _ _ x =
347347
x

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,14 +449,14 @@ merge (MergedDepFixed comp1 vs1 i1) (PkgDep vs2 (PkgComponent p comp2) ci@(Fixed
449449
, ( ConflictingDep vs1 (PkgComponent p comp1) (Fixed i1)
450450
, ConflictingDep vs2 (PkgComponent p comp2) ci ) )
451451

452-
merge (MergedDepFixed comp1 vs1 i@(I v _)) (PkgDep vs2 (PkgComponent p comp2) ci@(Constrained vr))
452+
merge (MergedDepFixed comp1 vs1 i@(I _stage v _)) (PkgDep vs2 (PkgComponent p comp2) ci@(Constrained vr))
453453
| checkVR vr v = Right $ MergedDepFixed comp1 vs1 i
454454
| otherwise =
455455
Left ( createConflictSetForVersionConflict p v vs1 vr vs2
456456
, ( ConflictingDep vs1 (PkgComponent p comp1) (Fixed i)
457457
, ConflictingDep vs2 (PkgComponent p comp2) ci ) )
458458

459-
merge (MergedDepConstrained vrOrigins) (PkgDep vs2 (PkgComponent p comp2) ci@(Fixed i@(I v _))) =
459+
merge (MergedDepConstrained vrOrigins) (PkgDep vs2 (PkgComponent p comp2) ci@(Fixed i@(I _stage v _))) =
460460
go vrOrigins -- I tried "reverse vrOrigins" here, but it seems to slow things down ...
461461
where
462462
go :: [VROrigin] -> Either (ConflictSet, (ConflictingDep, ConflictingDep)) MergedPkgDep

0 commit comments

Comments
 (0)