11module Distribution.Solver.Modular.IndexConversion
2- ( convPIs
3- ) where
2+ ( convPIs
3+ ) where
44
55import Distribution.Solver.Compat.Prelude
66import Prelude ()
@@ -11,36 +11,38 @@ import qualified Distribution.Compat.NonEmptySet as NonEmptySet
1111import qualified Data.Set as S
1212
1313import qualified Distribution.InstalledPackageInfo as IPI
14- import Distribution.Compiler
15- import Distribution.Package -- from Cabal
16- import Distribution.Simple.BuildToolDepends -- from Cabal
17- import Distribution.Types.ExeDependency -- from Cabal
18- import Distribution.Types.PkgconfigDependency -- from Cabal
19- import Distribution.Types.ComponentName -- from Cabal
20- import Distribution.Types.CondTree -- from Cabal
21- import Distribution.Types.MungedPackageId -- from Cabal
22- import Distribution.Types.MungedPackageName -- from Cabal
23- import Distribution.PackageDescription -- from Cabal
24- import Distribution.PackageDescription.Configuration
14+ import Distribution.Compiler
15+ import Distribution.Package
16+ import Distribution.Simple.BuildToolDepends
17+ import Distribution.Simple.Compiler (compilerInfo )
18+ import Distribution.Types.ExeDependency
19+ import Distribution.Types.PkgconfigDependency
20+ import Distribution.Types.ComponentName
21+ import Distribution.Types.CondTree
22+ import Distribution.Types.MungedPackageId
23+ import Distribution.Types.MungedPackageName
24+ import Distribution.PackageDescription
25+ import Distribution.PackageDescription.Configuration
2526import qualified Distribution.Simple.PackageIndex as SI
26- import Distribution.System
27+ import Distribution.System
2728
28- import Distribution.Solver.Types.ComponentDeps
29- ( Component (.. ), componentNameToComponent )
29+ import Distribution.Solver.Types.ComponentDeps ( Component (.. ), componentNameToComponent )
3030import Distribution.Solver.Types.Flag
3131import Distribution.Solver.Types.LabeledPackageConstraint
3232import Distribution.Solver.Types.OptionalStanza
3333import 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.Toolchain
38+ import qualified Distribution.Solver.Types.Stage as Stage
3739
38- import Distribution.Solver.Modular.Dependency as D
39- import Distribution.Solver.Modular.Flag as F
40- import Distribution.Solver.Modular.Index
41- import Distribution.Solver.Modular.Package
42- import Distribution.Solver.Modular.Tree
43- import Distribution.Solver.Modular.Version
40+ import Distribution.Solver.Modular.Dependency as D
41+ import Distribution.Solver.Modular.Flag as F
42+ import Distribution.Solver.Modular.Index
43+ import Distribution.Solver.Modular.Package
44+ import Distribution.Solver.Modular.Tree
45+ import Distribution.Solver.Modular.Version
4446
4547-- | Convert both the installed package index and the source package
4648-- index into one uniform solver index.
@@ -53,59 +55,75 @@ 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 =
61- mkIndex $
62- convIPI' sip iidx ++ convSPI' os arch comp constraints strfl solveExes sidx
58+ convPIs
59+ :: Staged Toolchain
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 =
68+ mkIndex $ convIPI' sip iidx ++ convSPI' toolchains' constraints strfl solveExes sidx
69+ -- [ foldMap
70+ -- (\(stage, idx) -> convIPI' stage sip idx)
71+ -- (tabulate iidx)
72+ -- , foldMap
73+ -- (\(stage, Toolchain{toolchainCompiler = comp, toolchainPlatform = Platform arch os}) ->
74+ -- convSPI' stage os arch comp constraints strfl solveExes sidx
75+ -- )
76+ -- toolchains'
77+ -- ]
6378
6479-- | Convert a Cabal installed package index to the simpler,
6580-- more uniform index format of the solver.
66- convIPI' :: ShadowPkgs -> SI. InstalledPackageIndex -> [(PN , I , PInfo )]
67- convIPI' (ShadowPkgs sip) idx =
81+ convIPI' :: ShadowPkgs -> Staged SI. InstalledPackageIndex -> [(PN , I , PInfo )]
82+ convIPI' (ShadowPkgs sip) =
83+ Stage. foldMapWithKey (\ stage idx ->
6884 -- apply shadowing whenever there are multiple installed packages with
6985 -- the same version
70- [ maybeShadow (convIP idx pkg)
71- -- IMPORTANT to get internal libraries. See
72- -- Note [Index conversion with internal libraries]
73- | (_, pkgs ) <- SI. allPackagesBySourcePackageIdAndLibName idx
74- , (maybeShadow, pkg) <- zip ( id : repeat shadow) pkgs ]
86+ [ maybeShadow (convIP stage idx pkg)
87+ | -- IMPORTANT to get internal libraries. See Note [Index conversion with internal libraries]
88+ (_, pkgs) <- SI. allPackagesBySourcePackageIdAndLibName idx
89+ , (maybeShadow, pkg ) <- zip ( id : repeat shadow) pkgs
90+ ])
7591 where
76-
7792 -- shadowing is recorded in the package info
7893 shadow (pn, i, PInfo fdeps comps fds _)
7994 | sip = (pn, i, PInfo fdeps comps fds (Just Shadowed ))
80- shadow x = x
95+ shadow x = x
8196
8297-- | 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)
85- where MungedPackageId mpn ver = mungedId ipi
86- -- HACK. See Note [Index conversion with internal libraries]
87- pn = encodeCompatPackageName mpn
98+ convId :: Stage -> IPI. InstalledPackageInfo -> (PN , I )
99+ convId stage ipi = (pn, I stage ver $ Inst $ IPI. installedUnitId ipi)
100+ where
101+ MungedPackageId mpn ver = mungedId ipi
102+ -- HACK. See Note [Index conversion with internal libraries]
103+ pn = encodeCompatPackageName mpn
88104
89105-- | 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
93- Left u -> (pn, i, PInfo [] M. empty M. empty (Just (Broken u)))
94- Right fds -> (pn, i, PInfo fds components M. empty Nothing )
95- where
96- -- TODO: Handle sub-libraries and visibility.
97- components =
98- M. singleton (ExposedLib LMainLibName )
99- ComponentInfo {
100- compIsVisible = IsVisible True
101- , compIsBuildable = IsBuildable True
102- }
103-
104- (pn, i) = convId ipi
105-
106- -- 'sourceLibName' is unreliable, but for now we only really use this for
107- -- primary libs anyways
108- comp = componentNameToComponent $ CLibName $ IPI. sourceLibName ipi
106+ convIP :: Stage -> SI. InstalledPackageIndex -> IPI. InstalledPackageInfo -> (PN , I , PInfo )
107+ convIP stage idx ipi =
108+ case traverse (convIPId stage (DependencyReason pn M. empty S. empty) comp idx) (IPI. depends ipi) of
109+ Left u -> (pn, i, PInfo [] M. empty M. empty (Just (Broken u)))
110+ Right fds -> (pn, i, PInfo fds components M. empty Nothing )
111+ where
112+ -- TODO: Handle sub-libraries and visibility.
113+ components =
114+ M. singleton
115+ (ExposedLib LMainLibName )
116+ ComponentInfo
117+ { compIsVisible = IsVisible True
118+ , compIsBuildable = IsBuildable True
119+ }
120+
121+ (pn, i) = convId stage ipi
122+
123+ -- 'sourceLibName' is unreliable, but for now we only really use this for
124+ -- primary libs anyways
125+ comp = componentNameToComponent $ CLibName $ IPI. sourceLibName ipi
126+
109127-- TODO: Installed packages should also store their encapsulations!
110128
111129-- Note [Index conversion with internal libraries]
@@ -141,31 +159,51 @@ convIP idx ipi =
141159-- May return Nothing if the package can't be found in the index. That
142160-- indicates that the original package having this dependency is broken
143161-- and should be ignored.
144- convIPId :: DependencyReason PN -> Component -> SI. InstalledPackageIndex -> UnitId -> Either UnitId (FlaggedDep PN )
145- convIPId dr comp idx ipid =
162+ convIPId :: Stage -> DependencyReason PN -> Component -> SI. InstalledPackageIndex -> UnitId -> Either UnitId (FlaggedDep PN )
163+ convIPId stage dr comp idx ipid =
146164 case SI. lookupUnitId idx ipid of
147- Nothing -> Left ipid
148- Just ipi -> let (pn, i) = convId ipi
149- name = ExposedLib LMainLibName -- TODO: Handle sub-libraries.
150- in Right (D. Simple (LDep dr (Dep (PkgComponent pn name) (Fixed i))) comp)
151- -- NB: something we pick up from the
152- -- InstalledPackageIndex is NEVER an executable
165+ Nothing -> Left ipid
166+ Just ipi ->
167+ let (pn, i) = convId stage ipi
168+ name = ExposedLib LMainLibName -- TODO: Handle sub-libraries.
169+ in Right (D. Simple (LDep dr (Dep (PkgComponent pn name) (Fixed i))) comp)
170+
171+ -- NB: something we pick up from the
172+ -- InstalledPackageIndex is NEVER an executable
153173
154174-- | Convert a cabal-install source package index to the simpler,
155175-- 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
176+ convSPI'
177+ :: Staged Toolchain
178+ -> Map PN [LabeledPackageConstraint ]
179+ -> StrongFlags
180+ -> SolveExecutables
181+ -> CI. PackageIndex (SourcePackage loc )
182+ -> [(PN , I , PInfo )]
183+ convSPI' toolchains constraints strfl solveExes sidx =
184+ Stage. foldMapWithKey (\ stage toolchain ->
185+ let
186+ Platform arch os = toolchainPlatform toolchain
187+ cinfo = compilerInfo (toolchainCompiler toolchain)
188+ in
189+ L. map (convSP stage os arch cinfo constraints strfl solveExes) (CI. allPackages sidx)
190+ ) toolchains
161191
162192-- | 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
193+ convSP
194+ :: Stage
195+ -> OS
196+ -> Arch
197+ -> CompilerInfo
198+ -> Map PN [LabeledPackageConstraint ]
199+ -> StrongFlags
200+ -> SolveExecutables
201+ -> SourcePackage loc
202+ -> (PN , I , PInfo )
203+ convSP stage os arch cinfo constraints strfl solveExes (SourcePackage (PackageIdentifier pn pv) gpd _ _pl) =
204+ let i = I stage pv InRepo
167205 pkgConstraints = fromMaybe [] $ M. lookup pn constraints
168- in (pn, i, convGPD os arch cinfo pkgConstraints strfl solveExes pn gpd)
206+ in (pn, i, convGPD os arch cinfo pkgConstraints strfl solveExes pn gpd)
169207
170208-- We do not use 'flattenPackageDescription' or 'finalizePD'
171209-- from 'Distribution.PackageDescription.Configuration' here, because we
0 commit comments