Skip to content

Parameterize SourcePackage and ConfiguredPackage on package location #3210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions cabal-install/Distribution/Client/Dependency.hs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import Distribution.Client.PkgConfigDb (PkgConfigDb)
import Distribution.Client.Types
( SourcePackageDb(SourcePackageDb), SourcePackage(..)
, ConfiguredPackage(..), ConfiguredId(..)
, UnresolvedPkgLoc
, OptionalStanza(..), enableStanzas )
import Distribution.Client.Dependency.Types
( PreSolver(..), Solver(..), DependencyResolver, ResolverPackage(..)
Expand Down Expand Up @@ -145,7 +146,7 @@ data DepResolverParams = DepResolverParams {
depResolverPreferences :: [PackagePreference],
depResolverPreferenceDefault :: PackagesPreferenceDefault,
depResolverInstalledPkgIndex :: InstalledPackageIndex,
depResolverSourcePkgIndex :: PackageIndex.PackageIndex SourcePackage,
depResolverSourcePkgIndex :: PackageIndex.PackageIndex (SourcePackage UnresolvedPkgLoc),
depResolverReorderGoals :: Bool,
depResolverIndependentGoals :: Bool,
depResolverAvoidReinstalls :: Bool,
Expand Down Expand Up @@ -207,7 +208,7 @@ showPackagePreference (PackageStanzasPreference pn st) =
display pn ++ " " ++ show st

basicDepResolverParams :: InstalledPackageIndex
-> PackageIndex.PackageIndex SourcePackage
-> PackageIndex.PackageIndex (SourcePackage UnresolvedPkgLoc)
-> DepResolverParams
basicDepResolverParams installedPkgIndex sourcePkgIndex =
DepResolverParams {
Expand Down Expand Up @@ -312,7 +313,7 @@ dontUpgradeNonUpgradeablePackages params =
. InstalledPackageIndex.lookupPackageName
(depResolverInstalledPkgIndex params)

addSourcePackages :: [SourcePackage]
addSourcePackages :: [SourcePackage UnresolvedPkgLoc]
-> DepResolverParams -> DepResolverParams
addSourcePackages pkgs params =
params {
Expand Down Expand Up @@ -381,7 +382,7 @@ removeUpperBounds allowNewer params =
where
sourcePkgIndex' = fmap relaxDeps $ depResolverSourcePkgIndex params

relaxDeps :: SourcePackage -> SourcePackage
relaxDeps :: SourcePackage UnresolvedPkgLoc -> SourcePackage UnresolvedPkgLoc
relaxDeps srcPkg = srcPkg {
packageDescription = relaxPackageDeps allowNewer
(packageDescription srcPkg)
Expand All @@ -393,15 +394,15 @@ removeUpperBounds allowNewer params =
-- 'addSourcePackages'. Otherwise, the packages inserted by
-- 'addSourcePackages' won't have upper bounds in dependencies relaxed.
--
addDefaultSetupDependencies :: (SourcePackage -> [Dependency])
addDefaultSetupDependencies :: (SourcePackage UnresolvedPkgLoc -> [Dependency])
-> DepResolverParams -> DepResolverParams
addDefaultSetupDependencies defaultSetupDeps params =
params {
depResolverSourcePkgIndex =
fmap applyDefaultSetupDeps (depResolverSourcePkgIndex params)
}
where
applyDefaultSetupDeps :: SourcePackage -> SourcePackage
applyDefaultSetupDeps :: SourcePackage UnresolvedPkgLoc -> SourcePackage UnresolvedPkgLoc
applyDefaultSetupDeps srcpkg =
srcpkg {
packageDescription = gpkgdesc {
Expand Down Expand Up @@ -431,7 +432,7 @@ reinstallTargets params =

standardInstallPolicy :: InstalledPackageIndex
-> SourcePackageDb
-> [PackageSpecifier SourcePackage]
-> [PackageSpecifier (SourcePackage UnresolvedPkgLoc)]
-> DepResolverParams
standardInstallPolicy
installedPkgIndex (SourcePackageDb sourcePkgIndex sourcePkgPrefs)
Expand Down Expand Up @@ -512,7 +513,7 @@ chooseSolver verbosity preSolver _cinfo =
info verbosity "Choosing modular solver."
return Modular

runSolver :: Solver -> SolverConfig -> DependencyResolver
runSolver :: Solver -> SolverConfig -> DependencyResolver UnresolvedPkgLoc
runSolver TopDown = const topDownResolver -- TODO: warn about unsupported options
runSolver Modular = modularResolver

Expand Down Expand Up @@ -619,7 +620,7 @@ interpretPackagesPreference selected defaultPref prefs =
validateSolverResult :: Platform
-> CompilerInfo
-> Bool
-> [ResolverPackage]
-> [ResolverPackage UnresolvedPkgLoc]
-> InstallPlan
validateSolverResult platform comp indepGoals pkgs =
case planPackagesProblems platform comp pkgs of
Expand Down Expand Up @@ -647,7 +648,7 @@ validateSolverResult platform comp indepGoals pkgs =


data PlanPackageProblem =
InvalidConfiguredPackage ConfiguredPackage [PackageProblem]
InvalidConfiguredPackage (ConfiguredPackage UnresolvedPkgLoc) [PackageProblem]

showPlanPackageProblem :: PlanPackageProblem -> String
showPlanPackageProblem (InvalidConfiguredPackage pkg packageProblems) =
Expand All @@ -657,7 +658,7 @@ showPlanPackageProblem (InvalidConfiguredPackage pkg packageProblems) =
| problem <- packageProblems ]

planPackagesProblems :: Platform -> CompilerInfo
-> [ResolverPackage]
-> [ResolverPackage UnresolvedPkgLoc]
-> [PlanPackageProblem]
planPackagesProblems platform cinfo pkgs =
[ InvalidConfiguredPackage pkg packageProblems
Expand Down Expand Up @@ -706,7 +707,7 @@ showPackageProblem (InvalidDep dep pkgid) =
-- dependencies are satisfied by the specified packages.
--
configuredPackageProblems :: Platform -> CompilerInfo
-> ConfiguredPackage -> [PackageProblem]
-> ConfiguredPackage UnresolvedPkgLoc -> [PackageProblem]
configuredPackageProblems platform cinfo
(ConfiguredPackage pkg specifiedFlags stanzas specifiedDeps') =
[ DuplicateFlag flag | ((flag,_):_) <- duplicates specifiedFlags ]
Expand Down Expand Up @@ -787,14 +788,14 @@ configuredPackageProblems platform cinfo
-- It simply means preferences for installed packages will be ignored.
--
resolveWithoutDependencies :: DepResolverParams
-> Either [ResolveNoDepsError] [SourcePackage]
-> Either [ResolveNoDepsError] [SourcePackage UnresolvedPkgLoc]
resolveWithoutDependencies (DepResolverParams targets constraints
prefs defpref installedPkgIndex sourcePkgIndex
_reorderGoals _indGoals _avoidReinstalls
_shadowing _strFlags _maxBjumps) =
collectEithers (map selectPackage targets)
where
selectPackage :: PackageName -> Either ResolveNoDepsError SourcePackage
selectPackage :: PackageName -> Either ResolveNoDepsError (SourcePackage UnresolvedPkgLoc)
selectPackage pkgname
| null choices = Left $! ResolveUnsatisfiable pkgname requiredVersions
| otherwise = Right $! maximumBy bestByPrefs choices
Expand Down
9 changes: 3 additions & 6 deletions cabal-install/Distribution/Client/Dependency/Modular.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ module Distribution.Client.Dependency.Modular
import Data.Map as M
( fromListWith )
import Distribution.Client.Dependency.Modular.Assignment
( Assignment, toCPs )
import Distribution.Client.Dependency.Modular.Dependency
( RevDepMap )
( toCPs )
import Distribution.Client.Dependency.Modular.ConfiguredConversion
( convCP )
import Distribution.Client.Dependency.Modular.IndexConversion
Expand All @@ -26,14 +24,14 @@ import Distribution.Client.Dependency.Modular.Package
import Distribution.Client.Dependency.Modular.Solver
( SolverConfig(..), solve )
import Distribution.Client.Dependency.Types
( DependencyResolver, ResolverPackage
( DependencyResolver
, PackageConstraint(..), unlabelPackageConstraint )
import Distribution.System
( Platform(..) )

-- | Ties the two worlds together: classic cabal-install vs. the modular
-- solver. Performs the necessary translations before and after.
modularResolver :: SolverConfig -> DependencyResolver
modularResolver :: SolverConfig -> DependencyResolver loc
modularResolver sc (Platform arch os) cinfo iidx sidx pkgConfigDB pprefs pcs pns =
fmap (uncurry postprocess) $ -- convert install plan
logToProgress (maxBackjumps sc) $ -- convert log format into progress format
Expand All @@ -47,7 +45,6 @@ modularResolver sc (Platform arch os) cinfo iidx sidx pkgConfigDB pprefs pcs pns
pair lpc = (pcName $ unlabelPackageConstraint lpc, [lpc])

-- Results have to be converted into an install plan.
postprocess :: Assignment -> RevDepMap -> [ResolverPackage]
postprocess a rdm = map (convCP iidx sidx) (toCPs a rdm)

-- Helper function to extract the PN from a constraint.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import Distribution.Client.ComponentDeps (ComponentDeps)
-- a 'ResolverPackage', which can then be converted into
-- the install plan.
convCP :: SI.InstalledPackageIndex ->
CI.PackageIndex SourcePackage ->
CP QPN -> ResolverPackage
CI.PackageIndex (SourcePackage loc) ->
CP QPN -> ResolverPackage loc
convCP iidx sidx (CP qpi fa es ds) =
case convPI qpi of
Left pi -> PreExisting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import Distribution.Client.Dependency.Modular.Version
-- fix the problem there, so for now, shadowing is only activated if
-- explicitly requested.
convPIs :: OS -> Arch -> CompilerInfo -> Bool -> Bool ->
SI.InstalledPackageIndex -> CI.PackageIndex SourcePackage -> Index
SI.InstalledPackageIndex -> CI.PackageIndex (SourcePackage loc) -> Index
convPIs os arch comp sip strfl iidx sidx =
mkIndex (convIPI' sip iidx ++ convSPI' os arch comp strfl sidx)

Expand Down Expand Up @@ -88,11 +88,11 @@ convIPId pn' idx ipid =
-- | Convert a cabal-install source package index to the simpler,
-- more uniform index format of the solver.
convSPI' :: OS -> Arch -> CompilerInfo -> Bool ->
CI.PackageIndex SourcePackage -> [(PN, I, PInfo)]
CI.PackageIndex (SourcePackage loc) -> [(PN, I, PInfo)]
convSPI' os arch cinfo strfl = L.map (convSP os arch cinfo strfl) . CI.allPackages

-- | Convert a single source package into the solver-specific format.
convSP :: OS -> Arch -> CompilerInfo -> Bool -> SourcePackage -> (PN, I, PInfo)
convSP :: OS -> Arch -> CompilerInfo -> Bool -> SourcePackage loc -> (PN, I, PInfo)
convSP os arch cinfo strfl (SourcePackage (PackageIdentifier pn pv) gpd _ _pl) =
let i = I pv InRepo
in (pn, i, convGPD os arch cinfo strfl (PI pn i) gpd)
Expand Down
21 changes: 11 additions & 10 deletions cabal-install/Distribution/Client/Dependency/TopDown.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Distribution.Client.Dependency.TopDown.Constraints
( Satisfiable(..) )
import Distribution.Client.Types
( SourcePackage(..), ConfiguredPackage(..)
, UnresolvedPkgLoc
, enableStanzas, ConfiguredId(..), fakeUnitId )
import Distribution.Client.Dependency.Types
( DependencyResolver, ResolverPackage(..)
Expand Down Expand Up @@ -250,7 +251,7 @@ search configure pref constraints =
-- | The main exported resolver, with string logging and failure types to fit
-- the standard 'DependencyResolver' interface.
--
topDownResolver :: DependencyResolver
topDownResolver :: DependencyResolver UnresolvedPkgLoc
topDownResolver platform cinfo installedPkgIndex sourcePkgIndex _pkgConfigDB
preferences constraints targets =
mapMessages $ topDownResolver'
Expand All @@ -268,11 +269,11 @@ topDownResolver platform cinfo installedPkgIndex sourcePkgIndex _pkgConfigDB
--
topDownResolver' :: Platform -> CompilerInfo
-> PackageIndex InstalledPackage
-> PackageIndex SourcePackage
-> PackageIndex (SourcePackage UnresolvedPkgLoc)
-> (PackageName -> PackagePreferences)
-> [PackageConstraint]
-> [PackageName]
-> Progress Log Failure [ResolverPackage]
-> Progress Log Failure [ResolverPackage UnresolvedPkgLoc]
topDownResolver' platform cinfo installedPkgIndex sourcePkgIndex
preferences constraints targets =
fmap (uncurry finalise)
Expand Down Expand Up @@ -300,7 +301,7 @@ topDownResolver' platform cinfo installedPkgIndex sourcePkgIndex
. PackageIndex.fromList
$ finaliseSelectedPackages preferences selected' constraints'

toResolverPackage :: FinalSelectedPackage -> ResolverPackage
toResolverPackage :: FinalSelectedPackage -> ResolverPackage UnresolvedPkgLoc
toResolverPackage (SelectedInstalled (InstalledPackage pkg _))
= PreExisting pkg
toResolverPackage (SelectedSource pkg) = Configured pkg
Expand Down Expand Up @@ -446,7 +447,7 @@ annotateInstalledPackages dfsNumber installed = PackageIndex.fromList
--
annotateSourcePackages :: [PackageConstraint]
-> (PackageName -> TopologicalSortNumber)
-> PackageIndex SourcePackage
-> PackageIndex (SourcePackage UnresolvedPkgLoc)
-> PackageIndex UnconfiguredPackage
annotateSourcePackages constraints dfsNumber sourcePkgIndex =
PackageIndex.fromList
Expand Down Expand Up @@ -483,7 +484,7 @@ annotateSourcePackages constraints dfsNumber sourcePkgIndex =
-- heuristic.
--
topologicalSortNumbering :: PackageIndex InstalledPackage
-> PackageIndex SourcePackage
-> PackageIndex (SourcePackage UnresolvedPkgLoc)
-> (PackageName -> TopologicalSortNumber)
topologicalSortNumbering installedPkgIndex sourcePkgIndex =
\pkgname -> let Just vertex = toVertex pkgname
Expand All @@ -510,17 +511,17 @@ topologicalSortNumbering installedPkgIndex sourcePkgIndex =
-- and looking at the names of all possible dependencies.
--
selectNeededSubset :: PackageIndex InstalledPackage
-> PackageIndex SourcePackage
-> PackageIndex (SourcePackage UnresolvedPkgLoc)
-> Set PackageName
-> (PackageIndex InstalledPackage
,PackageIndex SourcePackage)
,PackageIndex (SourcePackage UnresolvedPkgLoc))
selectNeededSubset installedPkgIndex sourcePkgIndex = select mempty mempty
where
select :: PackageIndex InstalledPackage
-> PackageIndex SourcePackage
-> PackageIndex (SourcePackage UnresolvedPkgLoc)
-> Set PackageName
-> (PackageIndex InstalledPackage
,PackageIndex SourcePackage)
,PackageIndex (SourcePackage UnresolvedPkgLoc))
select installedPkgIndex' sourcePkgIndex' remaining
| Set.null remaining = (installedPkgIndex', sourcePkgIndex')
| otherwise = select installedPkgIndex'' sourcePkgIndex'' remaining''
Expand Down
17 changes: 9 additions & 8 deletions cabal-install/Distribution/Client/Dependency/TopDown/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module Distribution.Client.Dependency.TopDown.Types where

import Distribution.Client.Types
( SourcePackage(..), ConfiguredPackage(..)
, UnresolvedPkgLoc
, OptionalStanza, ConfiguredId(..) )
import Distribution.InstalledPackageInfo
( InstalledPackageInfo )
Expand Down Expand Up @@ -44,7 +45,7 @@ data InstalledOrSource installed source

data FinalSelectedPackage
= SelectedInstalled InstalledPackage
| SelectedSource ConfiguredPackage
| SelectedSource (ConfiguredPackage UnresolvedPkgLoc)

type TopologicalSortNumber = Int

Expand All @@ -62,18 +63,18 @@ data InstalledPackageEx

data UnconfiguredPackage
= UnconfiguredPackage
SourcePackage
(SourcePackage UnresolvedPkgLoc)
!TopologicalSortNumber
FlagAssignment
[OptionalStanza]

data SemiConfiguredPackage
= SemiConfiguredPackage
SourcePackage -- package info
FlagAssignment -- total flag assignment for the package
[OptionalStanza] -- enabled optional stanzas
[Dependency] -- dependencies we end up with when we apply
-- the flag assignment
(SourcePackage UnresolvedPkgLoc) -- package info
FlagAssignment -- total flag assignment for the package
[OptionalStanza] -- enabled optional stanzas
[Dependency] -- dependencies we end up with when we apply
-- the flag assignment

instance Package InstalledPackage where
packageId (InstalledPackage pkg _) = packageId pkg
Expand Down Expand Up @@ -131,7 +132,7 @@ class Package a => PackageSourceDeps a where
instance PackageSourceDeps InstalledPackageEx where
sourceDeps (InstalledPackageEx _ _ deps) = deps

instance PackageSourceDeps ConfiguredPackage where
instance PackageSourceDeps (ConfiguredPackage loc) where
sourceDeps (ConfiguredPackage _ _ _ deps) = map confSrcId $ CD.nonSetupDeps deps

instance PackageSourceDeps InstalledPackage where
Expand Down
22 changes: 11 additions & 11 deletions cabal-install/Distribution/Client/Dependency/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -113,23 +113,23 @@ instance Text PreSolver where
-- solving the package dependency problem and we want to make it easy to swap
-- in alternatives.
--
type DependencyResolver = Platform
-> CompilerInfo
-> InstalledPackageIndex
-> PackageIndex.PackageIndex SourcePackage
-> PkgConfigDb
-> (PackageName -> PackagePreferences)
-> [LabeledPackageConstraint]
-> [PackageName]
-> Progress String String [ResolverPackage]
type DependencyResolver loc = Platform
-> CompilerInfo
-> InstalledPackageIndex
-> PackageIndex.PackageIndex (SourcePackage loc)
-> PkgConfigDb
-> (PackageName -> PackagePreferences)
-> [LabeledPackageConstraint]
-> [PackageName]
-> Progress String String [ResolverPackage loc]

-- | The dependency resolver picks either pre-existing installed packages
-- or it picks source packages along with package configuration.
--
-- This is like the 'InstallPlan.PlanPackage' but with fewer cases.
--
data ResolverPackage = PreExisting InstalledPackageInfo
| Configured ConfiguredPackage
data ResolverPackage loc = PreExisting InstalledPackageInfo
| Configured (ConfiguredPackage loc)

-- | Per-package constraints. Package constraints must be respected by the
-- solver. Multiple constraints for each package can be given, though obviously
Expand Down
4 changes: 2 additions & 2 deletions cabal-install/Distribution/Client/Fetch.hs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ planPackages :: Verbosity
-> InstalledPackageIndex
-> SourcePackageDb
-> PkgConfigDb
-> [PackageSpecifier SourcePackage]
-> IO [SourcePackage]
-> [PackageSpecifier (SourcePackage UnresolvedPkgLoc)]
-> IO [SourcePackage UnresolvedPkgLoc]
planPackages verbosity comp platform fetchFlags
installedPkgIndex sourcePkgDb pkgConfigDb pkgSpecifiers

Expand Down
Loading