Commit c2596226 authored by kristenk's avatar kristenk Committed by Edward Z. Yang
Browse files

Add constraints to solver DSL.

parent 8194fab5
......@@ -7,6 +7,7 @@ module UnitTests.Distribution.Solver.Modular.DSL (
, Dependencies(..)
, ExTest(..)
, ExExe(..)
, ExConstraint(..)
, ExPreference(..)
, ExampleDb
, ExampleVersionRange
......@@ -73,6 +74,7 @@ import Distribution.Solver.Types.ConstraintSource
import Distribution.Solver.Types.LabeledPackageConstraint
import Distribution.Solver.Types.OptionalStanza
import qualified Distribution.Solver.Types.PackageIndex as CI.PackageIndex
import Distribution.Solver.Types.PackageConstraint
import qualified Distribution.Solver.Types.PackagePath as P
import qualified Distribution.Solver.Types.PkgConfigDb as PC
import Distribution.Solver.Types.Settings
......@@ -167,6 +169,9 @@ exFlag :: ExampleFlagName -> [ExampleDependency] -> [ExampleDependency]
-> ExampleDependency
exFlag n t e = ExFlag n (Buildable t) (Buildable e)
data ExConstraint =
ExConstraint ConstraintScope ExampleVersionRange
data ExPreference =
ExPkgPref ExamplePkgName ExampleVersionRange
| ExStanzaPref ExamplePkgName [OptionalStanza]
......@@ -526,11 +531,12 @@ exResolve :: ExampleDb
-> AllowBootLibInstalls
-> EnableBackjumping
-> Maybe [ExampleVar]
-> [ExConstraint]
-> [ExPreference]
-> EnableAllTests
-> Progress String String CI.SolverInstallPlan.SolverInstallPlan
exResolve db exts langs pkgConfigDb targets solver mbj indepGoals reorder
allowBootLibInstalls enableBj vars prefs enableAllTests
allowBootLibInstalls enableBj vars constraints prefs enableAllTests
= resolveDependencies C.buildPlatform compiler pkgConfigDb solver params
where
defaultCompiler = C.unknownCompilerInfo C.buildCompilerId C.NoAbiTag
......@@ -550,8 +556,9 @@ exResolve db exts langs pkgConfigDb targets solver mbj indepGoals reorder
(exDbPkgs db)
| otherwise = []
targets' = fmap (\p -> NamedPackage (C.mkPackageName p) []) targets
params = addPreferences (fmap toPref prefs)
params = addConstraints (fmap toConstraint constraints)
$ addConstraints (fmap toLpc enableTests)
$ addPreferences (fmap toPref prefs)
$ setIndependentGoals indepGoals
$ setReorderGoals reorder
$ setMaxBackjumps mbj
......@@ -561,6 +568,9 @@ exResolve db exts langs pkgConfigDb targets solver mbj indepGoals reorder
$ standardInstallPolicy instIdx avaiIdx targets'
toLpc pc = LabeledPackageConstraint pc ConstraintSourceUnknown
toConstraint (ExConstraint scope v) =
toLpc $ PackageConstraint scope (PackagePropertyVersion v)
toPref (ExPkgPref n v) = PackageVersionPreference (C.mkPackageName n) v
toPref (ExStanzaPref n stanzas) = PackageStanzasPreference (C.mkPackageName n) stanzas
......
......@@ -7,6 +7,7 @@ module UnitTests.Distribution.Solver.Modular.DSL.TestCaseUtils (
, allowBootLibInstalls
, disableBackjumping
, goalOrder
, constraints
, preferences
, enableAllTests
, solverSuccess
......@@ -52,6 +53,9 @@ disableBackjumping test =
goalOrder :: [ExampleVar] -> SolverTest -> SolverTest
goalOrder order test = test { testGoalOrder = Just order }
constraints :: [ExConstraint] -> SolverTest -> SolverTest
constraints cs test = test { testConstraints = cs }
preferences :: [ExPreference] -> SolverTest -> SolverTest
preferences prefs test = test { testSoftConstraints = prefs }
......@@ -70,6 +74,7 @@ data SolverTest = SolverTest {
, testAllowBootLibInstalls :: AllowBootLibInstalls
, testEnableBackjumping :: EnableBackjumping
, testGoalOrder :: Maybe [ExampleVar]
, testConstraints :: [ExConstraint]
, testSoftConstraints :: [ExPreference]
, testDb :: ExampleDb
, testSupportedExts :: Maybe [Extension]
......@@ -160,6 +165,7 @@ mkTestExtLangPC exts langs pkgConfigDb db label targets result = SolverTest {
, testAllowBootLibInstalls = AllowBootLibInstalls False
, testEnableBackjumping = EnableBackjumping True
, testGoalOrder = Nothing
, testConstraints = []
, testSoftConstraints = []
, testDb = db
, testSupportedExts = exts
......@@ -175,7 +181,7 @@ runTest SolverTest{..} = askOption $ \(OptionShowSolverLog showSolverLog) ->
testSupportedLangs testPkgConfigDb testTargets
Modular Nothing testIndepGoals (ReorderGoals False)
testAllowBootLibInstalls testEnableBackjumping testGoalOrder
testSoftConstraints testEnableAllTests
testConstraints testSoftConstraints testEnableAllTests
printMsg msg = if showSolverLog
then putStrLn msg
else return ()
......
......@@ -108,7 +108,7 @@ solve enableBj reorder indep solver targets (TestDb db) =
-- The backjump limit prevents individual tests from using
-- too much time and memory.
(Just defaultMaxBackjumps)
indep reorder (AllowBootLibInstalls False) enableBj Nothing []
indep reorder (AllowBootLibInstalls False) enableBj Nothing [] []
(EnableAllTests True)
failure :: String -> Failure
......
Markdown is supported
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