@@ -34,6 +34,8 @@ import Distribution.Solver.Types.PackageConstraint
3434import qualified Distribution.Solver.Types.PackageIndex as CI
3535import Distribution.Solver.Types.Settings
3636import Distribution.Solver.Types.SourcePackage
37+ import Distribution.Solver.Types.Stage (Stage (.. ), Staged (.. ))
38+ import qualified Distribution.Solver.Types.Stage as Stage
3739
3840import Distribution.Solver.Modular.Dependency as D
3941import Distribution.Solver.Modular.Flag as F
@@ -53,21 +55,27 @@ import Distribution.Solver.Modular.Version
5355-- resolving these situations. However, the right thing to do is to
5456-- fix the problem there, so for now, shadowing is only activated if
5557-- explicitly requested.
56- convPIs :: OS -> Arch -> CompilerInfo -> Map PN [LabeledPackageConstraint ]
57- -> ShadowPkgs -> StrongFlags -> SolveExecutables
58- -> SI. InstalledPackageIndex -> CI. PackageIndex (SourcePackage loc )
59- -> Index
60- convPIs os arch comp constraints sip strfl solveExes iidx sidx =
58+ convPIs
59+ :: Staged (CompilerInfo , Platform )
60+ -> Map PN [LabeledPackageConstraint ]
61+ -> ShadowPkgs
62+ -> StrongFlags
63+ -> SolveExecutables
64+ -> Staged SI. InstalledPackageIndex
65+ -> CI. PackageIndex (SourcePackage loc )
66+ -> Index
67+ convPIs toolchains' constraints sip strfl solveExes iidx sidx =
6168 mkIndex $
62- convIPI' sip iidx ++ convSPI' os arch comp constraints strfl solveExes sidx
69+ convIPI' sip iidx ++ convSPI' toolchains' constraints strfl solveExes sidx
6370
6471-- | Convert a Cabal installed package index to the simpler,
6572-- more uniform index format of the solver.
66- convIPI' :: ShadowPkgs -> SI. InstalledPackageIndex -> [(PN , I , PInfo )]
67- convIPI' (ShadowPkgs sip) idx =
73+ convIPI' :: ShadowPkgs -> Staged SI. InstalledPackageIndex -> [(PN , I , PInfo )]
74+ convIPI' (ShadowPkgs sip) =
75+ Stage. foldMapWithKey $ \ stage idx ->
6876 -- apply shadowing whenever there are multiple installed packages with
6977 -- the same version
70- [ maybeShadow (convIP idx pkg)
78+ [ maybeShadow (convIP stage idx pkg)
7179 -- IMPORTANT to get internal libraries. See
7280 -- Note [Index conversion with internal libraries]
7381 | (_, pkgs) <- SI. allPackagesBySourcePackageIdAndLibName idx
@@ -80,16 +88,16 @@ convIPI' (ShadowPkgs sip) idx =
8088 shadow x = x
8189
8290-- | Extract/recover the package ID from an installed package info, and convert it to a solver's I.
83- convId :: IPI. InstalledPackageInfo -> (PN , I )
84- convId ipi = (pn, I ver $ Inst $ IPI. installedUnitId ipi)
91+ convId :: Stage -> IPI. InstalledPackageInfo -> (PN , I )
92+ convId stage ipi = (pn, I stage ver $ Inst $ IPI. installedUnitId ipi)
8593 where MungedPackageId mpn ver = mungedId ipi
8694 -- HACK. See Note [Index conversion with internal libraries]
8795 pn = encodeCompatPackageName mpn
8896
8997-- | Convert a single installed package into the solver-specific format.
90- convIP :: SI. InstalledPackageIndex -> IPI. InstalledPackageInfo -> (PN , I , PInfo )
91- convIP idx ipi =
92- case traverse (convIPId (DependencyReason pn M. empty S. empty) comp idx) (IPI. depends ipi) of
98+ convIP :: Stage -> SI. InstalledPackageIndex -> IPI. InstalledPackageInfo -> (PN , I , PInfo )
99+ convIP stage idx ipi =
100+ case traverse (convIPId stage (DependencyReason pn M. empty S. empty) comp idx) (IPI. depends ipi) of
93101 Left u -> (pn, i, PInfo [] M. empty M. empty (Just (Broken u)))
94102 Right fds -> (pn, i, PInfo fds components M. empty Nothing )
95103 where
@@ -101,7 +109,7 @@ convIP idx ipi =
101109 , compIsBuildable = IsBuildable True
102110 }
103111
104- (pn, i) = convId ipi
112+ (pn, i) = convId stage ipi
105113
106114 -- 'sourceLibName' is unreliable, but for now we only really use this for
107115 -- primary libs anyways
@@ -141,29 +149,48 @@ convIP idx ipi =
141149-- May return Nothing if the package can't be found in the index. That
142150-- indicates that the original package having this dependency is broken
143151-- and should be ignored.
144- convIPId :: DependencyReason PN -> Component -> SI. InstalledPackageIndex -> UnitId -> Either UnitId (FlaggedDep PN )
145- convIPId dr comp idx ipid =
152+ convIPId :: Stage -> DependencyReason PN -> Component -> SI. InstalledPackageIndex -> UnitId -> Either UnitId (FlaggedDep PN )
153+ convIPId stage dr comp idx ipid =
146154 case SI. lookupUnitId idx ipid of
147155 Nothing -> Left ipid
148- Just ipi -> let (pn, i) = convId ipi
149- name = ExposedLib LMainLibName -- TODO: Handle sub-libraries.
156+ Just ipi -> let (pn, i) = convId stage ipi
157+ name = ExposedLib LMainLibName -- TODO: Handle sub-libraries.
150158 in Right (D. Simple (LDep dr (Dep (PkgComponent pn name) (Fixed i))) comp)
151159 -- NB: something we pick up from the
152160 -- InstalledPackageIndex is NEVER an executable
153161
154162-- | Convert a cabal-install source package index to the simpler,
155163-- more uniform index format of the solver.
156- convSPI' :: OS -> Arch -> CompilerInfo -> Map PN [LabeledPackageConstraint ]
157- -> StrongFlags -> SolveExecutables
158- -> CI. PackageIndex (SourcePackage loc ) -> [(PN , I , PInfo )]
159- convSPI' os arch cinfo constraints strfl solveExes =
160- L. map (convSP os arch cinfo constraints strfl solveExes) . CI. allPackages
164+ -- NOTE: The package description of source package can depent on the platform
165+ -- and compiler version. Here we decide to convert a single source package
166+ -- into multiple index entries, one for each stage, where the conditionals are
167+ -- resolved. This choice might incour in high memory consumption and it might
168+ -- be worth looking for a different approach.
169+ convSPI'
170+ :: Staged (CompilerInfo , Platform )
171+ -> Map PN [LabeledPackageConstraint ]
172+ -> StrongFlags
173+ -> SolveExecutables
174+ -> CI. PackageIndex (SourcePackage loc )
175+ -> [(PN , I , PInfo )]
176+ convSPI' toolchains constraints strfl solveExes sidx =
177+ Stage. foldMapWithKey (\ stage (cinfo, Platform arch os) ->
178+ L. map (convSP stage os arch cinfo constraints strfl solveExes) (CI. allPackages sidx)
179+ ) toolchains
161180
162181-- | Convert a single source package into the solver-specific format.
163- convSP :: OS -> Arch -> CompilerInfo -> Map PN [LabeledPackageConstraint ]
164- -> StrongFlags -> SolveExecutables -> SourcePackage loc -> (PN , I , PInfo )
165- convSP os arch cinfo constraints strfl solveExes (SourcePackage (PackageIdentifier pn pv) gpd _ _pl) =
166- let i = I pv InRepo
182+ convSP
183+ :: Stage
184+ -> OS
185+ -> Arch
186+ -> CompilerInfo
187+ -> Map PN [LabeledPackageConstraint ]
188+ -> StrongFlags
189+ -> SolveExecutables
190+ -> SourcePackage loc
191+ -> (PN , I , PInfo )
192+ convSP stage os arch cinfo constraints strfl solveExes (SourcePackage (PackageIdentifier pn pv) gpd _ _pl) =
193+ let i = I stage pv InRepo
167194 pkgConstraints = fromMaybe [] $ M. lookup pn constraints
168195 in (pn, i, convGPD os arch cinfo pkgConstraints strfl solveExes pn gpd)
169196
0 commit comments