Skip to content

Commit 075b2a6

Browse files
committed
More toolchain threading
1 parent 672e511 commit 075b2a6

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

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

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import Distribution.Types.MungedPackageName -- from Cabal
2424
import Distribution.PackageDescription -- from Cabal
2525
import Distribution.PackageDescription.Configuration
2626
import qualified Distribution.Simple.PackageIndex as SI
27+
import Distribution.Simple.Compiler (compilerId)
2728
import Distribution.System
2829

2930
import Distribution.Solver.Types.ComponentDeps
@@ -61,15 +62,15 @@ convPIs :: Toolchains -> Map PN [LabeledPackageConstraint]
6162
-> Index
6263
convPIs toolchains constraints sip strfl solveExes iidx sidx =
6364
mkIndex $
64-
convIPI' sip iidx ++ convSPI' toolchains constraints strfl solveExes sidx
65+
convIPI' toolchains sip iidx ++ convSPI' toolchains constraints strfl solveExes sidx
6566

6667
-- | Convert a Cabal installed package index to the simpler,
6768
-- more uniform index format of the solver.
68-
convIPI' :: ShadowPkgs -> SI.InstalledPackageIndex -> [(PN, I, PInfo)]
69-
convIPI' (ShadowPkgs sip) idx =
69+
convIPI' :: Toolchains -> ShadowPkgs -> SI.InstalledPackageIndex -> [(PN, I, PInfo)]
70+
convIPI' toolchains (ShadowPkgs sip) idx =
7071
-- apply shadowing whenever there are multiple installed packages with
7172
-- the same version
72-
[ maybeShadow (convIP idx pkg)
73+
[ maybeShadow (convIP toolchains idx pkg)
7374
-- IMPORTANT to get internal libraries. See
7475
-- Note [Index conversion with internal libraries]
7576
| (_, pkgs) <- SI.allPackagesBySourcePackageIdAndLibName idx
@@ -82,16 +83,20 @@ convIPI' (ShadowPkgs sip) idx =
8283
shadow x = x
8384

8485
-- | Extract/recover the package ID from an installed package info, and convert it to a solver's I.
85-
convId :: IPI.InstalledPackageInfo -> (PN, I)
86-
convId ipi = (pn, I {- FIXME -} Host ver $ Inst $ IPI.installedUnitId ipi)
86+
convId :: Toolchains -> IPI.InstalledPackageInfo -> (PN, I)
87+
convId toolchains ipi = (pn, I stage ver $ Inst $ IPI.installedUnitId ipi)
8788
where MungedPackageId mpn ver = mungedId ipi
8889
-- HACK. See Note [Index conversion with internal libraries]
8990
pn = encodeCompatPackageName mpn
91+
stage = case IPI.pkgCompiler ipi of
92+
Just c | c == compilerId (toolchainCompiler (buildToolchain toolchains)) -> Build
93+
Just c | c == compilerId (toolchainCompiler (hostToolchain toolchains)) -> Host
94+
_ -> error "convId: unhandled compiler"
9095

9196
-- | Convert a single installed package into the solver-specific format.
92-
convIP :: SI.InstalledPackageIndex -> IPI.InstalledPackageInfo -> (PN, I, PInfo)
93-
convIP idx ipi =
94-
case traverse (convIPId (DependencyReason pn M.empty S.empty) comp idx) (IPI.depends ipi) of
97+
convIP :: Toolchains -> SI.InstalledPackageIndex -> IPI.InstalledPackageInfo -> (PN, I, PInfo)
98+
convIP toolchains idx ipi =
99+
case traverse (convIPId toolchains (DependencyReason pn M.empty S.empty) comp idx) (IPI.depends ipi) of
95100
Left u -> (pn, i, PInfo [] M.empty M.empty (Just (Broken u)))
96101
Right fds -> (pn, i, PInfo fds components M.empty Nothing)
97102
where
@@ -103,7 +108,7 @@ convIP idx ipi =
103108
, compIsBuildable = IsBuildable True
104109
}
105110

106-
(pn, i) = convId ipi
111+
(pn, i) = convId toolchains ipi
107112

108113
-- 'sourceLibName' is unreliable, but for now we only really use this for
109114
-- primary libs anyways
@@ -143,11 +148,11 @@ convIP idx ipi =
143148
-- May return Nothing if the package can't be found in the index. That
144149
-- indicates that the original package having this dependency is broken
145150
-- and should be ignored.
146-
convIPId :: DependencyReason PN -> Component -> SI.InstalledPackageIndex -> UnitId -> Either UnitId (FlaggedDep PN)
147-
convIPId dr comp idx ipid =
151+
convIPId :: Toolchains -> DependencyReason PN -> Component -> SI.InstalledPackageIndex -> UnitId -> Either UnitId (FlaggedDep PN)
152+
convIPId toolchains dr comp idx ipid =
148153
case SI.lookupUnitId idx ipid of
149154
Nothing -> Left ipid
150-
Just ipi -> let (pn, i) = convId ipi
155+
Just ipi -> let (pn, i) = convId toolchains ipi
151156
name = ExposedLib LMainLibName -- TODO: Handle sub-libraries.
152157
in Right (D.Simple (LDep dr (Dep (PkgComponent pn name) (Fixed i))) comp)
153158
-- NB: something we pick up from the

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ rebuildInstallPlan
801801
foldProgress logMsg (pure . Left) (pure . Right) $
802802
planPackages
803803
verbosity
804-
(hostToolchain toolchains) -- FIXME: this should be `toolchains`.
804+
toolchains
805805
solverSettings
806806
(installedPackages <> hinstalledPkgIndex <> binstalledPkgIndex)
807807
sourcePkgDb

0 commit comments

Comments
 (0)