Commit 95eea01a authored by Duncan Coutts's avatar Duncan Coutts
Browse files

Add support for source constraints to the solver

parent 27f9895c
......@@ -320,6 +320,17 @@ addTopLevelConstraints (PackageConstraintInstalled pkg:deps) cs =
ConflictsWith conflicts ->
Fail (TopLevelInstallConstraintConflict pkg conflicts)
addTopLevelConstraints (PackageConstraintSource pkg:deps) cs =
case addTopLevelSourceConstraint pkg cs of
Satisfiable cs' pkgids ->
foldr (Step . Exclude) (addTopLevelConstraints deps cs') pkgids
Unsatisfiable ->
Fail (TopLevelInstallConstraintUnsatisfiable pkg)
ConflictsWith conflicts ->
Fail (TopLevelInstallConstraintConflict pkg conflicts)
-- | Add exclusion on available packages that cannot be configured.
--
......@@ -675,6 +686,7 @@ addPackageDependencyConstraint pkgid dep@(Dependency pkgname verrange)
constraint ver installed = ver `withinRange` verrange
&& case installedConstraint of
InstalledConstraint -> installed
SourceConstraint -> not installed
NoInstalledConstraint -> True
reason = ExcludedByPackageDependency pkgid dep installedConstraint
......@@ -700,6 +712,17 @@ addTopLevelInstalledConstraint pkgname =
reason = ExcludedByTopLevelDependency (Dependency pkgname anyVersion)
InstalledConstraint
addTopLevelSourceConstraint :: PackageName
-> Constraints
-> Satisfiable Constraints
[PackageId] ExclusionReason
addTopLevelSourceConstraint pkgname =
Constraints.constrain pkgname constraint reason
where
constraint _ver installed = not installed
reason = ExcludedByTopLevelDependency (Dependency pkgname anyVersion)
SourceConstraint
-- ------------------------------------------------------------
-- * Reasons for constraints
-- ------------------------------------------------------------
......
......@@ -70,18 +70,21 @@ instance Package UnconfiguredPackage where
instance Package SemiConfiguredPackage where
packageId (SemiConfiguredPackage p _ _) = packageId p
instance (Package installed, Package available)
=> Package (InstalledOrSource installed available) where
instance (Package installed, Package source)
=> Package (InstalledOrSource installed source) where
packageId (InstalledOnly p ) = packageId p
packageId (SourceOnly p ) = packageId p
packageId (InstalledAndSource p _) = packageId p
-- | We can have constraints on selecting just installed packages.
-- | We can have constraints on selecting just installed or just source
-- packages.
--
-- In particular, installed packages can only depend on other installed
-- packages while packages that are not yet installed but which we plan to
-- install can depend on installed or other not-yet-installed packages.
--
data InstalledConstraint = InstalledConstraint | NoInstalledConstraint
deriving Eq
data InstalledConstraint = NoInstalledConstraint
| InstalledConstraint
| SourceConstraint
deriving (Eq, Show)
......@@ -65,6 +65,7 @@ type DependencyResolver = Platform
data PackageConstraint
= PackageConstraintVersion PackageName VersionRange
| PackageConstraintInstalled PackageName
| PackageConstraintSource PackageName
| PackageConstraintFlags PackageName FlagAssignment
deriving (Show,Eq)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment