Skip to content

Commit 7c321e3

Browse files
committed
Add build package index
1 parent 02f17b1 commit 7c321e3

File tree

11 files changed

+46
-23
lines changed

11 files changed

+46
-23
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ showCP (CP qpi fa es ds) =
8080
-- | Ties the two worlds together: classic cabal-install vs. the modular
8181
-- solver. Performs the necessary translations before and after.
8282
modularResolver :: SolverConfig -> DependencyResolver loc
83-
modularResolver sc toolchains iidx sidx pkgConfigDB pprefs pcs pns = do
84-
(assignment, revdepmap) <- solve' sc toolchains idx pkgConfigDB pprefs gcs pns
83+
modularResolver sc toolchains biidx iidx sidx pkgConfigDB pprefs pcs pns = do
84+
(assignment, revdepmap) <- solve' sc toolchains (trace (showIdx idx) idx) pkgConfigDB pprefs gcs pns
8585
let cp = toCPs assignment revdepmap
8686
Step (show (vcat (map showCP cp))) $
8787
return $ postprocess assignment revdepmap
8888
where
8989
-- Indices have to be converted into solver-specific uniform index.
90-
idx = convPIs toolchains gcs (shadowPkgs sc) (strongFlags sc) (solveExecutables sc) iidx sidx
90+
idx = convPIs toolchains gcs (shadowPkgs sc) (strongFlags sc) (solveExecutables sc) biidx iidx sidx
9191
-- Constraints have to be converted into a finite map indexed by PN.
9292
gcs = M.fromListWith (++) (map pair pcs)
9393
where
@@ -97,7 +97,7 @@ modularResolver sc toolchains iidx sidx pkgConfigDB pprefs pcs pns = do
9797
-- package qualifiers, which means that linked packages become duplicates
9898
-- and can be removed.
9999
postprocess a rdm = ordNubBy nodeKey $
100-
map (convCP iidx sidx) (toCPs a rdm)
100+
map (convCP biidx iidx sidx) (toCPs a rdm)
101101

102102
-- Helper function to extract the PN from a constraint.
103103
pcName :: PackageConstraint -> PN

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,23 @@ import Distribution.Solver.Types.SolverId
1919
import Distribution.Solver.Types.SolverPackage
2020
import Distribution.Solver.Types.InstSolverPackage
2121
import Distribution.Solver.Types.SourcePackage
22+
import Control.Applicative ((<|>))
2223

2324
-- | Converts from the solver specific result @CP QPN@ into
2425
-- a 'ResolverPackage', which can then be converted into
2526
-- the install plan.
26-
convCP :: SI.InstalledPackageIndex ->
27-
CI.PackageIndex (SourcePackage loc) ->
28-
CP QPN -> ResolverPackage loc
29-
convCP iidx sidx (CP qpi fa es ds) =
27+
convCP :: SI.InstalledPackageIndex -- ^ build
28+
-> SI.InstalledPackageIndex -- ^ host
29+
-> CI.PackageIndex (SourcePackage loc)
30+
-> CP QPN -> ResolverPackage loc
31+
convCP biidx iidx sidx (CP qpi fa es ds) =
3032
case qpi of
3133
-- Installed
3234
(PI qpn (I _stage _ (Inst pi))) ->
3335
PreExisting $
3436
InstSolverPackage {
3537
instSolverQPN = qpn,
36-
instSolverPkgIPI = fromMaybe (error "convCP: lookupUnitId failed") $ SI.lookupUnitId iidx pi,
38+
instSolverPkgIPI = fromMaybe (error "convCP: lookupUnitId failed") $ (SI.lookupUnitId iidx pi) <|> (SI.lookupUnitId biidx pi),
3739
instSolverPkgLibDeps = fmap fst ds',
3840
instSolverPkgExeDeps = fmap snd ds'
3941
}

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,14 @@ import Distribution.Solver.Modular.Version
5858
-- explicitly requested.
5959
convPIs :: Toolchains -> Map PN [LabeledPackageConstraint]
6060
-> ShadowPkgs -> StrongFlags -> SolveExecutables
61-
-> SI.InstalledPackageIndex -> CI.PackageIndex (SourcePackage loc)
61+
-> SI.InstalledPackageIndex -- ^ build
62+
-> SI.InstalledPackageIndex -- ^ host
63+
-> CI.PackageIndex (SourcePackage loc)
6264
-> Index
63-
convPIs toolchains constraints sip strfl solveExes iidx sidx =
64-
mkIndex $
65-
convIPI' toolchains sip iidx ++ convSPI' toolchains constraints strfl solveExes sidx
65+
where bipis = convIPI' toolchains sip biidx
66+
hipis = convIPI' toolchains sip iidx
67+
ipis = bipis ++ hipis
68+
spis = convSPI' toolchains constraints strfl solveExes sidx
6669

6770
-- | Convert a Cabal installed package index to the simpler,
6871
-- more uniform index format of the solver.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ import Distribution.System ( Platform )
2828
-- in alternatives.
2929
--
3030
type DependencyResolver loc = Toolchains
31-
-> InstalledPackageIndex
31+
-> InstalledPackageIndex -- ^ build
32+
-> InstalledPackageIndex -- ^ host
3233
-> PackageIndex (SourcePackage loc)
3334
-> Maybe PkgConfigDb
3435
-> (PackageName -> PackagePreferences)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ planLocalPackage
464464
. setSolveExecutables (SolveExecutables False)
465465
. setSolverVerbosity verbosity
466466
$ standardInstallPolicy
467+
mempty {- build pkgs -}
467468
installedPkgIndex
468469
-- NB: We pass in an *empty* source package database,
469470
-- because cabal configure assumes that all dependencies

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ data DepResolverParams = DepResolverParams
181181
, depResolverPreferences :: [PackagePreference]
182182
, depResolverPreferenceDefault :: PackagesPreferenceDefault
183183
, depResolverInstalledPkgIndex :: InstalledPackageIndex
184+
, depResolverBuildInstalledPkgIndex :: InstalledPackageIndex
184185
, depResolverSourcePkgIndex :: PackageIndex.PackageIndex UnresolvedSourcePackage
185186
, depResolverReorderGoals :: ReorderGoals
186187
, depResolverCountConflicts :: CountConflicts
@@ -277,15 +278,17 @@ showPackagePreference (PackageStanzasPreference pn st) =
277278

278279
basicDepResolverParams
279280
:: InstalledPackageIndex
281+
-> InstalledPackageIndex
280282
-> PackageIndex.PackageIndex UnresolvedSourcePackage
281283
-> DepResolverParams
282-
basicDepResolverParams installedPkgIndex sourcePkgIndex =
284+
basicDepResolverParams buildInstalledPkgIndex installedPkgIndex sourcePkgIndex=
283285
DepResolverParams
284286
{ depResolverTargets = Set.empty
285287
, depResolverConstraints = []
286288
, depResolverPreferences = []
287289
, depResolverPreferenceDefault = PreferLatestForSelected
288290
, depResolverInstalledPkgIndex = installedPkgIndex
291+
, depResolverBuildInstalledPkgIndex = buildInstalledPkgIndex
289292
, depResolverSourcePkgIndex = sourcePkgIndex
290293
, depResolverReorderGoals = ReorderGoals False
291294
, depResolverCountConflicts = CountConflicts True
@@ -702,11 +705,13 @@ reinstallTargets params =
702705

703706
-- | A basic solver policy on which all others are built.
704707
basicInstallPolicy
705-
:: InstalledPackageIndex
708+
:: InstalledPackageIndex -- ^ Build
709+
-> InstalledPackageIndex -- ^ Host
706710
-> SourcePackageDb
707711
-> [PackageSpecifier UnresolvedSourcePackage]
708712
-> DepResolverParams
709713
basicInstallPolicy
714+
binstalledPkgIndex
710715
installedPkgIndex
711716
(SourcePackageDb sourcePkgIndex sourcePkgPrefs)
712717
pkgSpecifiers =
@@ -723,6 +728,7 @@ basicInstallPolicy
723728
. addSourcePackages
724729
[pkg | SpecificSourcePackage pkg <- pkgSpecifiers]
725730
$ basicDepResolverParams
731+
binstalledPkgIndex
726732
installedPkgIndex
727733
sourcePkgIndex
728734

@@ -731,13 +737,15 @@ basicInstallPolicy
731737
--
732738
-- It extends the 'basicInstallPolicy' with a policy on setup deps.
733739
standardInstallPolicy
734-
:: InstalledPackageIndex
740+
:: InstalledPackageIndex -- ^ Build
741+
-> InstalledPackageIndex -- ^ Host
735742
-> SourcePackageDb
736743
-> [PackageSpecifier UnresolvedSourcePackage]
737744
-> DepResolverParams
738-
standardInstallPolicy installedPkgIndex sourcePkgDb pkgSpecifiers =
745+
standardInstallPolicy binstalledPkgIndex installedPkgIndex sourcePkgDb pkgSpecifiers =
739746
addDefaultSetupDependencies mkDefaultSetupDeps $
740747
basicInstallPolicy
748+
binstalledPkgIndex
741749
installedPkgIndex
742750
sourcePkgDb
743751
pkgSpecifiers
@@ -810,6 +818,7 @@ resolveDependencies toolchains pkgConfigDB params =
810818
(PruneAfterFirstSuccess False)
811819
)
812820
toolchains
821+
binstalledPkgIndex
813822
installedPkgIndex
814823
sourcePkgIndex
815824
pkgConfigDB
@@ -823,6 +832,7 @@ resolveDependencies toolchains pkgConfigDB params =
823832
prefs
824833
defpref
825834
installedPkgIndex
835+
binstalledPkgIndex
826836
sourcePkgIndex
827837
reordGoals
828838
cntConflicts
@@ -1141,6 +1151,7 @@ resolveWithoutDependencies
11411151
prefs
11421152
defpref
11431153
installedPkgIndex
1154+
binstalledPkgIndex
11441155
sourcePkgIndex
11451156
_reorderGoals
11461157
_countConflicts

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ planPackages
220220
-- already installed. Since we want to get the source packages of
221221
-- things we might have installed (but not have the sources for).
222222
. reinstallTargets
223-
$ standardInstallPolicy installedPkgIndex sourcePkgDb pkgSpecifiers
223+
$ standardInstallPolicy mempty {-build-} installedPkgIndex sourcePkgDb pkgSpecifiers
224224

225225
includeDependencies = fromFlag (fetchDeps fetchFlags)
226226
logMsg message rest = debug verbosity message >> rest

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ planPackages
245245
in LabeledPackageConstraint pc ConstraintSourceFreeze
246246
| pkgSpecifier <- pkgSpecifiers
247247
]
248-
$ standardInstallPolicy installedPkgIndex sourcePkgDb pkgSpecifiers
248+
$ standardInstallPolicy mempty {- build -} installedPkgIndex sourcePkgDb pkgSpecifiers
249249

250250
logMsg message rest = debug verbosity message >> rest
251251

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ get verbosity repoCtxt globalFlags getFlags userTargets = do
148148
resolverParams :: SourcePackageDb -> [PackageSpecifier UnresolvedSourcePackage] -> DepResolverParams
149149
resolverParams sourcePkgDb pkgSpecifiers =
150150
-- TODO: add command-line constraint and preference args for unpack
151-
standardInstallPolicy mempty sourcePkgDb pkgSpecifiers
151+
standardInstallPolicy mempty mempty sourcePkgDb pkgSpecifiers
152152

153153
onlyPkgDescr = fromFlagOrDefault False (getOnlyPkgDescr getFlags)
154154

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,7 @@ planPackages
650650
-- doesn't understand how to install them
651651
. setSolveExecutables (SolveExecutables False)
652652
$ standardInstallPolicy
653+
mempty {- build pkgs -}
653654
installedPkgIndex
654655
sourcePkgDb
655656
pkgSpecifiers

0 commit comments

Comments
 (0)