From ad1b3a97d47a5a77545f9cfd02f4046a4d7fa52d Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 12 Mar 2016 16:26:43 +0100 Subject: [PATCH] RFC/Solver split (v2) --- .../Client/BuildReports/Storage.hs | 2 +- .../Distribution/Client/Configure.hs | 6 +- .../Distribution/Client/Dependency.hs | 12 +- .../Distribution/Client/Dependency/TopDown.hs | 10 +- .../Client/Dependency/TopDown/Constraints.hs | 4 +- .../Client/Dependency/TopDown/Types.hs | 2 +- .../Distribution/Client/Dependency/Types.hs | 217 +------------- cabal-install/Distribution/Client/Fetch.hs | 2 +- cabal-install/Distribution/Client/Freeze.hs | 2 +- .../Distribution/Client/IndexUtils.hs | 4 +- cabal-install/Distribution/Client/Init.hs | 2 +- .../Distribution/Client/Init/Heuristics.hs | 2 +- cabal-install/Distribution/Client/Install.hs | 6 +- .../Distribution/Client/InstallPlan.hs | 4 +- cabal-install/Distribution/Client/List.hs | 2 +- .../Distribution/Client/PlanIndex.hs | 4 +- cabal-install/Distribution/Client/Targets.hs | 4 +- cabal-install/Distribution/Client/Types.hs | 145 +++------- cabal-install/cabal-install.cabal | 59 ++-- cabal-install/tests/UnitTests.hs | 9 +- .../Client/Dependency/Modular/DSL.hs | 10 +- .../Client/Dependency/Modular/Solver.hs | 6 +- cabal-solver/.gitignore | 2 + .../Distribution/Solver}/ComponentDeps.hs | 6 +- .../Distribution/Solver}/Modular.hs | 20 +- .../Solver}/Modular/Assignment.hs | 20 +- .../Distribution/Solver}/Modular/Builder.hs | 19 +- .../Solver}/Modular/Configured.hs | 9 +- .../Solver}/Modular/ConfiguredConversion.hs | 18 +- .../Distribution/Solver}/Modular/Cycles.hs | 10 +- .../Solver}/Modular/Dependency.hs | 11 +- .../Distribution/Solver}/Modular/Explore.hs | 18 +- .../Distribution/Solver}/Modular/Flag.hs | 6 +- .../Distribution/Solver}/Modular/Index.hs | 13 +- .../Solver}/Modular/IndexConversion.hs | 20 +- .../Solver/Modular/Internal}/LabeledGraph.hs | 2 +- .../Solver/Modular/Internal}/PSQ.hs | 2 +- .../Distribution/Solver}/Modular/Linking.hs | 20 +- .../Distribution/Solver}/Modular/Log.hs | 12 +- .../Distribution/Solver}/Modular/Message.hs | 12 +- .../Distribution/Solver}/Modular/Package.hs | 4 +- .../Solver}/Modular/Preference.hs | 21 +- .../Distribution/Solver}/Modular/Solver.hs | 32 +-- .../Distribution/Solver}/Modular/Tree.hs | 16 +- .../Distribution/Solver}/Modular/Validate.hs | 22 +- .../Distribution/Solver}/Modular/Version.hs | 2 +- .../Distribution/Solver}/PackageIndex.hs | 4 +- .../Distribution/Solver}/PackageUtils.hs | 4 +- .../Distribution/Solver}/PkgConfigDb.hs | 4 +- cabal-solver/Distribution/Solver/Types.hs | 269 ++++++++++++++++++ .../Distribution/Solver/Types/ConfiguredId.hs | 31 ++ .../Solver/Types/ConfiguredPackage.hs | 51 ++++ .../Solver/Types/OptionalStanza.hs | 36 +++ .../Solver/Types/SourcePackage.hs | 29 ++ cabal-solver/LICENSE | 34 +++ cabal-solver/Setup.hs | 2 + cabal-solver/cabal-solver.cabal | 94 ++++++ cabal-solver/tests/UnitTests.hs | 21 ++ .../Solver/Modular/Internal}/PSQ.hs | 4 +- setup-dev.sh | 5 +- 60 files changed, 832 insertions(+), 587 deletions(-) create mode 100644 cabal-solver/.gitignore rename {cabal-install/Distribution/Client => cabal-solver/Distribution/Solver}/ComponentDeps.hs (96%) rename {cabal-install/Distribution/Client/Dependency => cabal-solver/Distribution/Solver}/Modular.hs (80%) rename {cabal-install/Distribution/Client/Dependency => cabal-solver/Distribution/Solver}/Modular/Assignment.hs (91%) rename {cabal-install/Distribution/Client/Dependency => cabal-solver/Distribution/Solver}/Modular/Builder.hs (94%) rename {cabal-install/Distribution/Client/Dependency => cabal-solver/Distribution/Solver}/Modular/Configured.hs (56%) rename {cabal-install/Distribution/Client/Dependency => cabal-solver/Distribution/Solver}/Modular/ConfiguredConversion.hs (74%) rename {cabal-install/Distribution/Client/Dependency => cabal-solver/Distribution/Solver}/Modular/Cycles.hs (91%) rename {cabal-install/Distribution/Client/Dependency => cabal-solver/Distribution/Solver}/Modular/Dependency.hs (98%) rename {cabal-install/Distribution/Client/Dependency => cabal-solver/Distribution/Solver}/Modular/Explore.hs (88%) rename {cabal-install/Distribution/Client/Dependency => cabal-solver/Distribution/Solver}/Modular/Flag.hs (92%) rename {cabal-install/Distribution/Client/Dependency => cabal-solver/Distribution/Solver}/Modular/Index.hs (84%) rename {cabal-install/Distribution/Client/Dependency => cabal-solver/Distribution/Solver}/Modular/IndexConversion.hs (95%) rename {cabal-install/Distribution/Client/Utils => cabal-solver/Distribution/Solver/Modular/Internal}/LabeledGraph.hs (98%) rename {cabal-install/Distribution/Client/Dependency/Modular => cabal-solver/Distribution/Solver/Modular/Internal}/PSQ.hs (99%) rename {cabal-install/Distribution/Client/Dependency => cabal-solver/Distribution/Solver}/Modular/Linking.hs (97%) rename {cabal-install/Distribution/Client/Dependency => cabal-solver/Distribution/Solver}/Modular/Log.hs (93%) rename {cabal-install/Distribution/Client/Dependency => cabal-solver/Distribution/Solver}/Modular/Message.hs (96%) rename {cabal-install/Distribution/Client/Dependency => cabal-solver/Distribution/Solver}/Modular/Package.hs (97%) rename {cabal-install/Distribution/Client/Dependency => cabal-solver/Distribution/Solver}/Modular/Preference.hs (97%) rename {cabal-install/Distribution/Client/Dependency => cabal-solver/Distribution/Solver}/Modular/Solver.hs (82%) rename {cabal-install/Distribution/Client/Dependency => cabal-solver/Distribution/Solver}/Modular/Tree.hs (93%) rename {cabal-install/Distribution/Client/Dependency => cabal-solver/Distribution/Solver}/Modular/Validate.hs (95%) rename {cabal-install/Distribution/Client/Dependency => cabal-solver/Distribution/Solver}/Modular/Version.hs (95%) rename {cabal-install/Distribution/Client => cabal-solver/Distribution/Solver}/PackageIndex.hs (99%) rename {cabal-install/Distribution/Client => cabal-solver/Distribution/Solver}/PackageUtils.hs (92%) rename {cabal-install/Distribution/Client => cabal-solver/Distribution/Solver}/PkgConfigDb.hs (97%) create mode 100644 cabal-solver/Distribution/Solver/Types.hs create mode 100644 cabal-solver/Distribution/Solver/Types/ConfiguredId.hs create mode 100644 cabal-solver/Distribution/Solver/Types/ConfiguredPackage.hs create mode 100644 cabal-solver/Distribution/Solver/Types/OptionalStanza.hs create mode 100644 cabal-solver/Distribution/Solver/Types/SourcePackage.hs create mode 100644 cabal-solver/LICENSE create mode 100644 cabal-solver/Setup.hs create mode 100644 cabal-solver/cabal-solver.cabal create mode 100644 cabal-solver/tests/UnitTests.hs rename {cabal-install/tests/UnitTests/Distribution/Client/Dependency/Modular => cabal-solver/tests/UnitTests/Distribution/Solver/Modular/Internal}/PSQ.hs (80%) diff --git a/cabal-install/Distribution/Client/BuildReports/Storage.hs b/cabal-install/Distribution/Client/BuildReports/Storage.hs index adbdb045b53..02d638ea2f7 100644 --- a/cabal-install/Distribution/Client/BuildReports/Storage.hs +++ b/cabal-install/Distribution/Client/BuildReports/Storage.hs @@ -28,7 +28,7 @@ import Distribution.Client.BuildReports.Anonymous (BuildReport) import Distribution.Client.Types import qualified Distribution.Client.InstallPlan as InstallPlan -import qualified Distribution.Client.ComponentDeps as CD +import qualified Distribution.Solver.ComponentDeps as CD import Distribution.Client.InstallPlan ( InstallPlan ) diff --git a/cabal-install/Distribution/Client/Configure.hs b/cabal-install/Distribution/Client/Configure.hs index e86ad21d96f..08e7639d9a4 100644 --- a/cabal-install/Distribution/Client/Configure.hs +++ b/cabal-install/Distribution/Client/Configure.hs @@ -26,8 +26,8 @@ import qualified Distribution.Client.InstallPlan as InstallPlan import Distribution.Client.InstallPlan (InstallPlan) import Distribution.Client.IndexUtils as IndexUtils ( getSourcePackages, getInstalledPackages ) -import Distribution.Client.PackageIndex ( PackageIndex, elemByPackageName ) -import Distribution.Client.PkgConfigDb (PkgConfigDb, readPkgConfigDb) +import Distribution.Solver.PackageIndex ( PackageIndex, elemByPackageName ) +import Distribution.Solver.PkgConfigDb (PkgConfigDb, readPkgConfigDb) import Distribution.Client.Setup ( ConfigExFlags(..), configureCommand, filterConfigureFlags , RepoContext(..) ) @@ -36,7 +36,7 @@ import Distribution.Client.SetupWrapper ( setupWrapper, SetupScriptOptions(..), defaultSetupScriptOptions ) import Distribution.Client.Targets ( userToPackageConstraint, userConstraintPackageName ) -import qualified Distribution.Client.ComponentDeps as CD +import qualified Distribution.Solver.ComponentDeps as CD import Distribution.Package (PackageId) import Distribution.Client.JobControl (Lock) diff --git a/cabal-install/Distribution/Client/Dependency.hs b/cabal-install/Distribution/Client/Dependency.hs index e1e0f5e9a25..6bb8fa9e88c 100644 --- a/cabal-install/Distribution/Client/Dependency.hs +++ b/cabal-install/Distribution/Client/Dependency.hs @@ -62,14 +62,14 @@ module Distribution.Client.Dependency ( import Distribution.Client.Dependency.TopDown ( topDownResolver ) -import Distribution.Client.Dependency.Modular +import Distribution.Solver.Modular ( modularResolver, SolverConfig(..) ) -import qualified Distribution.Client.PackageIndex as PackageIndex +import qualified Distribution.Solver.PackageIndex as PackageIndex import Distribution.Simple.PackageIndex (InstalledPackageIndex) import qualified Distribution.Simple.PackageIndex as InstalledPackageIndex import qualified Distribution.Client.InstallPlan as InstallPlan import Distribution.Client.InstallPlan (InstallPlan) -import Distribution.Client.PkgConfigDb (PkgConfigDb) +import Distribution.Solver.PkgConfigDb (PkgConfigDb) import Distribution.Client.Types ( SourcePackageDb(SourcePackageDb), SourcePackage(..) , ConfiguredPackage(..), ConfiguredId(..) @@ -86,8 +86,8 @@ import Distribution.Client.Dependency.Types import Distribution.Client.Sandbox.Types ( SandboxPackageInfo(..) ) import Distribution.Client.Targets -import Distribution.Client.ComponentDeps (ComponentDeps) -import qualified Distribution.Client.ComponentDeps as CD +import Distribution.Solver.ComponentDeps (ComponentDeps) +import qualified Distribution.Solver.ComponentDeps as CD import qualified Distribution.InstalledPackageInfo as Installed import Distribution.Package ( PackageName(..), PackageIdentifier(PackageIdentifier), PackageId @@ -99,7 +99,7 @@ import qualified Distribution.PackageDescription as PD , Flag(flagName), FlagName(..) ) import Distribution.PackageDescription.Configuration ( finalizePackageDescription ) -import Distribution.Client.PackageUtils +import Distribution.Solver.PackageUtils ( externalBuildDepends ) import Distribution.Version ( VersionRange, anyVersion, thisVersion, withinRange diff --git a/cabal-install/Distribution/Client/Dependency/TopDown.hs b/cabal-install/Distribution/Client/Dependency/TopDown.hs index 3d451d8e29f..c4cbe2d47e7 100644 --- a/cabal-install/Distribution/Client/Dependency/TopDown.hs +++ b/cabal-install/Distribution/Client/Dependency/TopDown.hs @@ -29,14 +29,14 @@ import Distribution.Client.Dependency.Types , PackagePreferences(..), InstalledPreference(..) , Progress(..), foldProgress ) -import qualified Distribution.Client.PackageIndex as PackageIndex +import qualified Distribution.Solver.PackageIndex as PackageIndex import qualified Distribution.Simple.PackageIndex as InstalledPackageIndex import Distribution.Simple.PackageIndex (InstalledPackageIndex) import qualified Distribution.InstalledPackageInfo as InstalledPackageInfo -import Distribution.Client.ComponentDeps +import Distribution.Solver.ComponentDeps ( ComponentDeps ) -import qualified Distribution.Client.ComponentDeps as CD -import Distribution.Client.PackageIndex +import qualified Distribution.Solver.ComponentDeps as CD +import Distribution.Solver.PackageIndex ( PackageIndex ) import Distribution.Package ( PackageName(..), PackageId, PackageIdentifier(..) @@ -45,7 +45,7 @@ import Distribution.Package , Dependency(Dependency), thisPackageVersion, simplifyDependency ) import Distribution.PackageDescription ( PackageDescription(buildDepends) ) -import Distribution.Client.PackageUtils +import Distribution.Solver.PackageUtils ( externalBuildDepends ) import Distribution.PackageDescription.Configuration ( finalizePackageDescription, flattenPackageDescription ) diff --git a/cabal-install/Distribution/Client/Dependency/TopDown/Constraints.hs b/cabal-install/Distribution/Client/Dependency/TopDown/Constraints.hs index 841dd539a31..2e74ea53b22 100644 --- a/cabal-install/Distribution/Client/Dependency/TopDown/Constraints.hs +++ b/cabal-install/Distribution/Client/Dependency/TopDown/Constraints.hs @@ -25,8 +25,8 @@ module Distribution.Client.Dependency.TopDown.Constraints ( ) where import Distribution.Client.Dependency.TopDown.Types -import qualified Distribution.Client.PackageIndex as PackageIndex -import Distribution.Client.PackageIndex +import qualified Distribution.Solver.PackageIndex as PackageIndex +import Distribution.Solver.PackageIndex ( PackageIndex ) import Distribution.Package ( PackageName, PackageId, PackageIdentifier(..) diff --git a/cabal-install/Distribution/Client/Dependency/TopDown/Types.hs b/cabal-install/Distribution/Client/Dependency/TopDown/Types.hs index 992383fe711..b4fd4976317 100644 --- a/cabal-install/Distribution/Client/Dependency/TopDown/Types.hs +++ b/cabal-install/Distribution/Client/Dependency/TopDown/Types.hs @@ -19,7 +19,7 @@ import Distribution.Client.Types , OptionalStanza, ConfiguredId(..) ) import Distribution.InstalledPackageInfo ( InstalledPackageInfo ) -import qualified Distribution.Client.ComponentDeps as CD +import qualified Distribution.Solver.ComponentDeps as CD import Distribution.Package ( PackageId, PackageIdentifier, Dependency diff --git a/cabal-install/Distribution/Client/Dependency/Types.hs b/cabal-install/Distribution/Client/Dependency/Types.hs index 3209afa3ffd..f3044ca8cf0 100644 --- a/cabal-install/Distribution/Client/Dependency/Types.hs +++ b/cabal-install/Distribution/Client/Dependency/Types.hs @@ -1,4 +1,3 @@ -{-# LANGUAGE CPP #-} {-# LANGUAGE DeriveFunctor #-} {-# LANGUAGE DeriveGeneric #-} ----------------------------------------------------------------------------- @@ -35,44 +34,14 @@ module Distribution.Client.Dependency.Types ( ) where -#if !MIN_VERSION_base(4,8,0) -import Control.Applicative - ( Applicative(..) ) -#endif -import Control.Applicative - ( Alternative(..) ) - import Data.Char ( isAlpha, toLower ) -#if !MIN_VERSION_base(4,8,0) -import Data.Monoid - ( Monoid(..) ) -#endif - -import Distribution.Client.PkgConfigDb - ( PkgConfigDb ) -import Distribution.Client.Types - ( OptionalStanza(..), SourcePackage(..), ConfiguredPackage ) +import Distribution.Solver.Types import qualified Distribution.Compat.ReadP as Parse ( pfail, munch1 ) -import Distribution.PackageDescription - ( FlagAssignment, FlagName(..) ) -import Distribution.InstalledPackageInfo - ( InstalledPackageInfo ) -import qualified Distribution.Client.PackageIndex as PackageIndex - ( PackageIndex ) -import Distribution.Simple.PackageIndex ( InstalledPackageIndex ) -import Distribution.Package - ( PackageName ) -import Distribution.Version - ( VersionRange, simplifyVersionRange ) -import Distribution.Compiler - ( CompilerInfo ) -import Distribution.System - ( Platform ) import Distribution.Text - ( Text(..), display ) + ( Text(..) ) import Text.PrettyPrint ( text ) @@ -105,89 +74,6 @@ instance Text PreSolver where "choose" -> return Choose _ -> Parse.pfail --- | A dependency resolver is a function that works out an installation plan --- given the set of installed and available packages and a set of deps to --- solve for. --- --- The reason for this interface is because there are dozens of approaches to --- solving the package dependency problem and we want to make it easy to swap --- in alternatives. --- -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 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 --- it is possible to construct conflicting constraints (eg impossible version --- range or inconsistent flag assignment). --- -data PackageConstraint - = PackageConstraintVersion PackageName VersionRange - | PackageConstraintInstalled PackageName - | PackageConstraintSource PackageName - | PackageConstraintFlags PackageName FlagAssignment - | PackageConstraintStanzas PackageName [OptionalStanza] - deriving (Eq,Show,Generic) - -instance Binary PackageConstraint - --- | Provide a textual representation of a package constraint --- for debugging purposes. --- -showPackageConstraint :: PackageConstraint -> String -showPackageConstraint (PackageConstraintVersion pn vr) = - display pn ++ " " ++ display (simplifyVersionRange vr) -showPackageConstraint (PackageConstraintInstalled pn) = - display pn ++ " installed" -showPackageConstraint (PackageConstraintSource pn) = - display pn ++ " source" -showPackageConstraint (PackageConstraintFlags pn fs) = - "flags " ++ display pn ++ " " ++ unwords (map (uncurry showFlag) fs) - where - showFlag (FlagName f) True = "+" ++ f - showFlag (FlagName f) False = "-" ++ f -showPackageConstraint (PackageConstraintStanzas pn ss) = - "stanzas " ++ display pn ++ " " ++ unwords (map showStanza ss) - where - showStanza TestStanzas = "test" - showStanza BenchStanzas = "bench" - --- | Per-package preferences on the version. It is a soft constraint that the --- 'DependencyResolver' should try to respect where possible. It consists of --- an 'InstalledPreference' which says if we prefer versions of packages --- that are already installed. It also has (possibly multiple) --- 'PackageVersionPreference's which are suggested constraints on the version --- number. The resolver should try to use package versions that satisfy --- the maximum number of the suggested version constraints. --- --- It is not specified if preferences on some packages are more important than --- others. --- -data PackagePreferences = PackagePreferences [VersionRange] - InstalledPreference - [OptionalStanza] - --- | Whether we prefer an installed version of a package or simply the latest --- version. --- -data InstalledPreference = PreferInstalled | PreferLatest - deriving Show - -- | Global policy for all packages to say if we prefer package versions that -- are already installed locally or if we just prefer the latest available. -- @@ -212,102 +98,3 @@ data PackagesPreferenceDefault = -- | PreferLatestForSelected deriving Show - --- | A type to represent the unfolding of an expensive long running --- calculation that may fail. We may get intermediate steps before the final --- result which may be used to indicate progress and\/or logging messages. --- -data Progress step fail done = Step step (Progress step fail done) - | Fail fail - | Done done - deriving Functor - --- | Consume a 'Progress' calculation. Much like 'foldr' for lists but with two --- base cases, one for a final result and one for failure. --- --- Eg to convert into a simple 'Either' result use: --- --- > foldProgress (flip const) Left Right --- -foldProgress :: (step -> a -> a) -> (fail -> a) -> (done -> a) - -> Progress step fail done -> a -foldProgress step fail done = fold - where fold (Step s p) = step s (fold p) - fold (Fail f) = fail f - fold (Done r) = done r - -instance Monad (Progress step fail) where - return = pure - p >>= f = foldProgress Step Fail f p - -instance Applicative (Progress step fail) where - pure a = Done a - p <*> x = foldProgress Step Fail (flip fmap x) p - -instance Monoid fail => Alternative (Progress step fail) where - empty = Fail mempty - p <|> q = foldProgress Step (const q) Done p - --- | 'PackageConstraint' labeled with its source. -data LabeledPackageConstraint - = LabeledPackageConstraint PackageConstraint ConstraintSource - -unlabelPackageConstraint :: LabeledPackageConstraint -> PackageConstraint -unlabelPackageConstraint (LabeledPackageConstraint pc _) = pc - --- | Source of a 'PackageConstraint'. -data ConstraintSource = - - -- | Main config file, which is ~/.cabal/config by default. - ConstraintSourceMainConfig FilePath - - -- | Sandbox config file, which is ./cabal.sandbox.config by default. - | ConstraintSourceSandboxConfig FilePath - - -- | User config file, which is ./cabal.config by default. - | ConstraintSourceUserConfig FilePath - - -- | Flag specified on the command line. - | ConstraintSourceCommandlineFlag - - -- | Target specified by the user, e.g., @cabal install package-0.1.0.0@ - -- implies @package==0.1.0.0@. - | ConstraintSourceUserTarget - - -- | Internal requirement to use installed versions of packages like ghc-prim. - | ConstraintSourceNonUpgradeablePackage - - -- | Internal requirement to use the add-source version of a package when that - -- version is installed and the source is modified. - | ConstraintSourceModifiedAddSourceDep - - -- | Internal constraint used by @cabal freeze@. - | ConstraintSourceFreeze - - -- | Constraint specified by a config file, a command line flag, or a user - -- target, when a more specific source is not known. - | ConstraintSourceConfigFlagOrTarget - - -- | The source of the constraint is not specified. - | ConstraintSourceUnknown - deriving (Eq, Show, Generic) - -instance Binary ConstraintSource - --- | Description of a 'ConstraintSource'. -showConstraintSource :: ConstraintSource -> String -showConstraintSource (ConstraintSourceMainConfig path) = - "main config " ++ path -showConstraintSource (ConstraintSourceSandboxConfig path) = - "sandbox config " ++ path -showConstraintSource (ConstraintSourceUserConfig path)= "user config " ++ path -showConstraintSource ConstraintSourceCommandlineFlag = "command line flag" -showConstraintSource ConstraintSourceUserTarget = "user target" -showConstraintSource ConstraintSourceNonUpgradeablePackage = - "non-upgradeable package" -showConstraintSource ConstraintSourceModifiedAddSourceDep = - "modified add-source dependency" -showConstraintSource ConstraintSourceFreeze = "cabal freeze" -showConstraintSource ConstraintSourceConfigFlagOrTarget = - "config file, command line flag, or user target" -showConstraintSource ConstraintSourceUnknown = "unknown source" diff --git a/cabal-install/Distribution/Client/Fetch.hs b/cabal-install/Distribution/Client/Fetch.hs index 94671692e57..91a112f3d4d 100644 --- a/cabal-install/Distribution/Client/Fetch.hs +++ b/cabal-install/Distribution/Client/Fetch.hs @@ -22,7 +22,7 @@ import Distribution.Client.Dependency import Distribution.Client.IndexUtils as IndexUtils ( getSourcePackages, getInstalledPackages ) import qualified Distribution.Client.InstallPlan as InstallPlan -import Distribution.Client.PkgConfigDb +import Distribution.Solver.PkgConfigDb ( PkgConfigDb, readPkgConfigDb ) import Distribution.Client.Setup ( GlobalFlags(..), FetchFlags(..), RepoContext(..) ) diff --git a/cabal-install/Distribution/Client/Freeze.hs b/cabal-install/Distribution/Client/Freeze.hs index 6e94cdf5026..86c1fe58dbc 100644 --- a/cabal-install/Distribution/Client/Freeze.hs +++ b/cabal-install/Distribution/Client/Freeze.hs @@ -27,7 +27,7 @@ import Distribution.Client.IndexUtils as IndexUtils import Distribution.Client.InstallPlan ( InstallPlan, PlanPackage ) import qualified Distribution.Client.InstallPlan as InstallPlan -import Distribution.Client.PkgConfigDb +import Distribution.Solver.PkgConfigDb ( PkgConfigDb, readPkgConfigDb ) import Distribution.Client.Setup ( GlobalFlags(..), FreezeFlags(..), ConfigExFlags(..) diff --git a/cabal-install/Distribution/Client/IndexUtils.hs b/cabal-install/Distribution/Client/IndexUtils.hs index 88238a54af5..1555f665ed9 100644 --- a/cabal-install/Distribution/Client/IndexUtils.hs +++ b/cabal-install/Distribution/Client/IndexUtils.hs @@ -41,8 +41,8 @@ import Distribution.Package ( PackageId, PackageIdentifier(..), PackageName(..) , Package(..), packageVersion, packageName , Dependency(Dependency) ) -import Distribution.Client.PackageIndex (PackageIndex) -import qualified Distribution.Client.PackageIndex as PackageIndex +import Distribution.Solver.PackageIndex (PackageIndex) +import qualified Distribution.Solver.PackageIndex as PackageIndex import Distribution.Simple.PackageIndex (InstalledPackageIndex) import qualified Distribution.PackageDescription.Parse as PackageDesc.Parse import Distribution.PackageDescription diff --git a/cabal-install/Distribution/Client/Init.hs b/cabal-install/Distribution/Client/Init.hs index c84dd41e9b4..c840e774db5 100644 --- a/cabal-install/Distribution/Client/Init.hs +++ b/cabal-install/Distribution/Client/Init.hs @@ -93,7 +93,7 @@ import Distribution.Simple.PackageIndex import Distribution.Text ( display, Text(..) ) -import Distribution.Client.PackageIndex +import Distribution.Solver.PackageIndex ( elemByPackageName ) import Distribution.Client.IndexUtils ( getSourcePackages ) diff --git a/cabal-install/Distribution/Client/Init/Heuristics.hs b/cabal-install/Distribution/Client/Init/Heuristics.hs index 336875ae8bd..48dcb100214 100644 --- a/cabal-install/Distribution/Client/Init/Heuristics.hs +++ b/cabal-install/Distribution/Client/Init/Heuristics.hs @@ -24,7 +24,7 @@ import Distribution.Text (simpleParse) import Distribution.Simple.Setup (Flag(..), flagToMaybe) import Distribution.ModuleName ( ModuleName, toFilePath ) -import Distribution.Client.PackageIndex +import Distribution.Solver.PackageIndex ( allPackagesByName ) import qualified Distribution.Package as P import qualified Distribution.PackageDescription as PD diff --git a/cabal-install/Distribution/Client/Install.hs b/cabal-install/Distribution/Client/Install.hs index 9bff74f658f..5f1fa0984af 100644 --- a/cabal-install/Distribution/Client/Install.hs +++ b/cabal-install/Distribution/Client/Install.hs @@ -102,13 +102,13 @@ import qualified Distribution.Client.BuildReports.Storage as BuildReports ( storeAnonymous, storeLocal, fromInstallPlan, fromPlanningFailure ) import qualified Distribution.Client.InstallSymlink as InstallSymlink ( symlinkBinaries ) -import qualified Distribution.Client.PackageIndex as SourcePackageIndex +import qualified Distribution.Solver.PackageIndex as SourcePackageIndex import qualified Distribution.Client.Win32SelfUpgrade as Win32SelfUpgrade import qualified Distribution.Client.World as World import qualified Distribution.InstalledPackageInfo as Installed import Distribution.Client.Compat.ExecutablePath import Distribution.Client.JobControl -import qualified Distribution.Client.ComponentDeps as CD +import qualified Distribution.Solver.ComponentDeps as CD import Distribution.Utils.NubList import Distribution.Simple.Compiler @@ -149,7 +149,7 @@ import Distribution.PackageDescription , FlagName(..), FlagAssignment ) import Distribution.PackageDescription.Configuration ( finalizePackageDescription ) -import Distribution.Client.PkgConfigDb +import Distribution.Solver.PkgConfigDb ( PkgConfigDb, readPkgConfigDb ) import Distribution.ParseUtils ( showPWarning ) diff --git a/cabal-install/Distribution/Client/InstallPlan.hs b/cabal-install/Distribution/Client/InstallPlan.hs index 852cc70ca59..0a34063d16d 100644 --- a/cabal-install/Distribution/Client/InstallPlan.hs +++ b/cabal-install/Distribution/Client/InstallPlan.hs @@ -60,8 +60,8 @@ import Distribution.Client.Types , GenericReadyPackage(..), fakeUnitId ) import Distribution.Version ( Version ) -import Distribution.Client.ComponentDeps (ComponentDeps) -import qualified Distribution.Client.ComponentDeps as CD +import Distribution.Solver.ComponentDeps (ComponentDeps) +import qualified Distribution.Solver.ComponentDeps as CD import Distribution.Simple.PackageIndex ( PackageIndex ) import qualified Distribution.Simple.PackageIndex as PackageIndex diff --git a/cabal-install/Distribution/Client/List.hs b/cabal-install/Distribution/Client/List.hs index c7cc04149cf..94861a29515 100644 --- a/cabal-install/Distribution/Client/List.hs +++ b/cabal-install/Distribution/Client/List.hs @@ -34,7 +34,7 @@ import Distribution.Simple.Utils import Distribution.Simple.Setup (fromFlag) import Distribution.Simple.PackageIndex (InstalledPackageIndex) import qualified Distribution.Simple.PackageIndex as InstalledPackageIndex -import qualified Distribution.Client.PackageIndex as PackageIndex +import qualified Distribution.Solver.PackageIndex as PackageIndex import Distribution.Version ( Version(..), VersionRange, withinRange, anyVersion , intersectVersionRanges, simplifyVersionRange ) diff --git a/cabal-install/Distribution/Client/PlanIndex.hs b/cabal-install/Distribution/Client/PlanIndex.hs index 236899de6ef..83f296e7fce 100644 --- a/cabal-install/Distribution/Client/PlanIndex.hs +++ b/cabal-install/Distribution/Client/PlanIndex.hs @@ -35,8 +35,8 @@ import Distribution.Package import Distribution.Version ( Version ) -import Distribution.Client.ComponentDeps (ComponentDeps) -import qualified Distribution.Client.ComponentDeps as CD +import Distribution.Solver.ComponentDeps (ComponentDeps) +import qualified Distribution.Solver.ComponentDeps as CD import Distribution.Client.Types ( PackageFixedDeps(..) ) import Distribution.Simple.PackageIndex diff --git a/cabal-install/Distribution/Client/Targets.hs b/cabal-install/Distribution/Client/Targets.hs index 580db2ac294..2a4e125da03 100644 --- a/cabal-install/Distribution/Client/Targets.hs +++ b/cabal-install/Distribution/Client/Targets.hs @@ -60,8 +60,8 @@ import Distribution.Client.Dependency.Types , LabeledPackageConstraint(..) ) import qualified Distribution.Client.World as World -import Distribution.Client.PackageIndex (PackageIndex) -import qualified Distribution.Client.PackageIndex as PackageIndex +import Distribution.Solver.PackageIndex (PackageIndex) +import qualified Distribution.Solver.PackageIndex as PackageIndex import qualified Codec.Archive.Tar as Tar import qualified Codec.Archive.Tar.Entry as Tar import qualified Distribution.Client.Tar as Tar diff --git a/cabal-install/Distribution/Client/Types.hs b/cabal-install/Distribution/Client/Types.hs index 45946d5e829..78ea5ee9624 100644 --- a/cabal-install/Distribution/Client/Types.hs +++ b/cabal-install/Distribution/Client/Types.hs @@ -16,31 +16,51 @@ -- -- Various common data types for the entire cabal-install system ----------------------------------------------------------------------------- -module Distribution.Client.Types where +module Distribution.Client.Types + ( PackageFixedDeps(..) + , ReadyPackage + , ConfiguredPackage(..) + , ConfiguredId(..) + , SourcePackage(..) + , SourcePackageDb(..) + , GenericReadyPackage(..) + , UnresolvedSourcePackage + , UnresolvedPkgLoc + , ResolvedPkgLoc + , PackageLocation(..) + , PackageDescriptionOverride + , enableStanzas + , maybeRepoRemote + , emptyRemoteRepo + , fakeUnitId + , OptionalStanza(..) + , Repo(..) + , Username(..) + , Password(..) + , RemoteRepo(..) + , BuildResult + , BuildFailure(..) + , BuildSuccess(..) + , DocsResult(..) + , TestsResult(..) + ) where import Distribution.Package ( PackageName, PackageId, Package(..) - , UnitId(..), mkUnitId - , HasUnitId(..), PackageInstalled(..) ) + , UnitId(..), HasUnitId(..), PackageInstalled(..) ) import Distribution.InstalledPackageInfo ( InstalledPackageInfo ) -import Distribution.PackageDescription - ( Benchmark(..), GenericPackageDescription(..), FlagAssignment - , TestSuite(..) ) -import Distribution.PackageDescription.Configuration - ( mapTreeData ) -import Distribution.Client.PackageIndex +import Distribution.Solver.PackageIndex ( PackageIndex ) -import Distribution.Client.ComponentDeps +import Distribution.Solver.ComponentDeps ( ComponentDeps ) -import qualified Distribution.Client.ComponentDeps as CD +import qualified Distribution.Solver.ComponentDeps as CD +import Distribution.Solver.Types import Distribution.Version ( VersionRange ) -import Distribution.Text (display) import Data.Map (Map) import Network.URI (URI(..), URIAuth(..), nullURI) -import Data.ByteString.Lazy (ByteString) import Control.Exception ( SomeException ) import GHC.Generics (Generic) @@ -77,69 +97,9 @@ class Package pkg => PackageFixedDeps pkg where instance PackageFixedDeps InstalledPackageInfo where depends = CD.fromInstalled . installedDepends - --- | In order to reuse the implementation of PackageIndex which relies on --- 'UnitId', we need to be able to synthesize these IDs prior --- to installation. Eventually, we'll move to a representation of --- 'UnitId' which can be properly computed before compilation --- (of course, it's a bit of a misnomer since the packages are not actually --- installed yet.) In any case, we'll synthesize temporary installed package --- IDs to use as keys during install planning. These should never be written --- out! Additionally, they need to be guaranteed unique within the install --- plan. -fakeUnitId :: PackageId -> UnitId -fakeUnitId = mkUnitId . (".fake."++) . display - --- | A 'ConfiguredPackage' is a not-yet-installed package along with the --- total configuration information. The configuration information is total in --- the sense that it provides all the configuration information and so the --- final configure process will be independent of the environment. --- -data ConfiguredPackage loc = ConfiguredPackage - (SourcePackage loc) -- package info, including repo - FlagAssignment -- complete flag assignment for the package - [OptionalStanza] -- list of enabled optional stanzas for the package - (ComponentDeps [ConfiguredId]) - -- set of exact dependencies (installed or source). - -- These must be consistent with the 'buildDepends' - -- in the 'PackageDescription' that you'd get by - -- applying the flag assignment and optional stanzas. - deriving (Eq, Show, Generic) - -instance Binary loc => Binary (ConfiguredPackage loc) - --- | A ConfiguredId is a package ID for a configured package. --- --- Once we configure a source package we know it's UnitId --- (at least, in principle, even if we have to fake it currently). It is still --- however useful in lots of places to also know the source ID for the package. --- We therefore bundle the two. --- --- An already installed package of course is also "configured" (all it's --- configuration parameters and dependencies have been specified). --- --- TODO: I wonder if it would make sense to promote this datatype to Cabal --- and use it consistently instead of UnitIds? -data ConfiguredId = ConfiguredId { - confSrcId :: PackageId - , confInstId :: UnitId - } - deriving (Eq, Generic) - -instance Binary ConfiguredId - -instance Show ConfiguredId where - show = show . confSrcId - -instance Package (ConfiguredPackage loc) where - packageId (ConfiguredPackage pkg _ _ _) = packageId pkg - instance PackageFixedDeps (ConfiguredPackage loc) where depends (ConfiguredPackage _ _ _ deps) = fmap (map confInstId) deps -instance HasUnitId (ConfiguredPackage loc) where - installedUnitId = fakeUnitId . packageId - -- | Like 'ConfiguredPackage', but with all dependencies guaranteed to be -- installed already, hence itself ready to be installed. data GenericReadyPackage srcpkg ipkg @@ -164,48 +124,9 @@ instance HasUnitId srcpkg => instance (Binary srcpkg, Binary ipkg) => Binary (GenericReadyPackage srcpkg ipkg) --- | A package description along with the location of the package sources. --- -data SourcePackage loc = SourcePackage { - packageInfoId :: PackageId, - packageDescription :: GenericPackageDescription, - packageSource :: loc, - packageDescrOverride :: PackageDescriptionOverride - } - deriving (Eq, Show, Generic) - -instance (Binary loc) => Binary (SourcePackage loc) - -- | Convenience alias for 'SourcePackage UnresolvedPkgLoc'. type UnresolvedSourcePackage = SourcePackage UnresolvedPkgLoc --- | We sometimes need to override the .cabal file in the tarball with --- the newer one from the package index. -type PackageDescriptionOverride = Maybe ByteString - -instance Package (SourcePackage a) where packageId = packageInfoId - -data OptionalStanza - = TestStanzas - | BenchStanzas - deriving (Eq, Ord, Enum, Bounded, Show, Generic) - -instance Binary OptionalStanza - -enableStanzas - :: [OptionalStanza] - -> GenericPackageDescription - -> GenericPackageDescription -enableStanzas stanzas gpkg = gpkg - { condBenchmarks = flagBenchmarks $ condBenchmarks gpkg - , condTestSuites = flagTests $ condTestSuites gpkg - } - where - enableTest t = t { testEnabled = TestStanzas `elem` stanzas } - enableBenchmark bm = bm { benchmarkEnabled = BenchStanzas `elem` stanzas } - flagBenchmarks = map (\(n, bm) -> (n, mapTreeData enableBenchmark bm)) - flagTests = map (\(n, t) -> (n, mapTreeData enableTest t)) - -- ------------------------------------------------------------ -- * Package locations and repositories -- ------------------------------------------------------------ diff --git a/cabal-install/cabal-install.cabal b/cabal-install/cabal-install.cabal index 3f05c4819f6..e9bb2d0b2ee 100644 --- a/cabal-install/cabal-install.cabal +++ b/cabal-install/cabal-install.cabal @@ -124,7 +124,6 @@ executable cabal Distribution.Client.BuildReports.Types Distribution.Client.BuildReports.Upload Distribution.Client.Check - Distribution.Client.ComponentDeps Distribution.Client.Config Distribution.Client.Configure Distribution.Client.Dependency @@ -132,27 +131,6 @@ executable cabal Distribution.Client.Dependency.TopDown.Constraints Distribution.Client.Dependency.TopDown.Types Distribution.Client.Dependency.Types - Distribution.Client.Dependency.Modular - Distribution.Client.Dependency.Modular.Assignment - Distribution.Client.Dependency.Modular.Builder - Distribution.Client.Dependency.Modular.Configured - Distribution.Client.Dependency.Modular.ConfiguredConversion - Distribution.Client.Dependency.Modular.Cycles - Distribution.Client.Dependency.Modular.Dependency - Distribution.Client.Dependency.Modular.Explore - Distribution.Client.Dependency.Modular.Flag - Distribution.Client.Dependency.Modular.Index - Distribution.Client.Dependency.Modular.IndexConversion - Distribution.Client.Dependency.Modular.Linking - Distribution.Client.Dependency.Modular.Log - Distribution.Client.Dependency.Modular.Message - Distribution.Client.Dependency.Modular.Package - Distribution.Client.Dependency.Modular.Preference - Distribution.Client.Dependency.Modular.PSQ - Distribution.Client.Dependency.Modular.Solver - Distribution.Client.Dependency.Modular.Tree - Distribution.Client.Dependency.Modular.Validate - Distribution.Client.Dependency.Modular.Version Distribution.Client.Exec Distribution.Client.Fetch Distribution.Client.FetchUtils @@ -175,10 +153,7 @@ executable cabal Distribution.Client.JobControl Distribution.Client.List Distribution.Client.Manpage - Distribution.Client.PackageIndex - Distribution.Client.PackageUtils Distribution.Client.ParseUtils - Distribution.Client.PkgConfigDb Distribution.Client.PlanIndex Distribution.Client.Run Distribution.Client.RebuildMonad @@ -197,7 +172,6 @@ executable cabal Distribution.Client.Update Distribution.Client.Upload Distribution.Client.Utils - Distribution.Client.Utils.LabeledGraph Distribution.Client.World Distribution.Client.Win32SelfUpgrade Distribution.Client.Compat.ExecutablePath @@ -210,22 +184,23 @@ executable cabal -- NOTE: when updating build-depends, don't forget to update version regexps -- in bootstrap.sh. build-depends: - array >= 0.4 && < 0.6, - base >= 4.5 && < 5, - binary >= 0.5 && < 0.9, - bytestring >= 0.9 && < 1, - Cabal >= 1.25 && < 1.26, - containers >= 0.4 && < 0.6, - filepath >= 1.3 && < 1.5, - hashable >= 1.0 && < 2, - HTTP >= 4000.1.5 && < 4000.4, - mtl >= 2.0 && < 3, - pretty >= 1.1 && < 1.2, - random >= 1 && < 1.2, - stm >= 2.0 && < 3, - tar >= 0.5.0.1 && < 0.6, - time >= 1.4 && < 1.7, - zlib >= 0.5.3 && < 0.7, + array >= 0.4 && < 0.6, + base >= 4.5 && < 5, + binary >= 0.5 && < 0.9, + bytestring >= 0.9 && < 1, + Cabal >= 1.25 && < 1.26, + cabal-solver >= 1.25 && < 1.26, + containers >= 0.4 && < 0.6, + filepath >= 1.3 && < 1.5, + hashable >= 1.0 && < 2, + HTTP >= 4000.1.5 && < 4000.4, + mtl >= 2.0 && < 3, + pretty >= 1.1 && < 1.2, + random >= 1 && < 1.2, + stm >= 2.0 && < 3, + tar >= 0.5.0.1 && < 0.6, + time >= 1.4 && < 1.7, + zlib >= 0.5.3 && < 0.7, hackage-security >= 0.5 && < 0.6 if flag(old-directory) diff --git a/cabal-install/tests/UnitTests.hs b/cabal-install/tests/UnitTests.hs index c67f5908cb6..f68f7903d8d 100644 --- a/cabal-install/tests/UnitTests.hs +++ b/cabal-install/tests/UnitTests.hs @@ -15,8 +15,7 @@ import Distribution.Verbosity import Distribution.Client.Compat.Time import qualified UnitTests.Distribution.Client.Compat.Time -import qualified UnitTests.Distribution.Client.Dependency.Modular.PSQ -import qualified UnitTests.Distribution.Client.Dependency.Modular.Solver +import qualified UnitTests.Distribution.Solver.Modular.Solver import qualified UnitTests.Distribution.Client.FileMonitor import qualified UnitTests.Distribution.Client.GZipUtils import qualified UnitTests.Distribution.Client.Sandbox @@ -38,10 +37,8 @@ tests mtimeChangeCalibrated = testGroup "Unit Tests" [ testGroup "UnitTests.Distribution.Client.Compat.Time" $ UnitTests.Distribution.Client.Compat.Time.tests mtimeChange - , testGroup "UnitTests.Distribution.Client.Dependency.Modular.PSQ" - UnitTests.Distribution.Client.Dependency.Modular.PSQ.tests - , testGroup "UnitTests.Distribution.Client.Dependency.Modular.Solver" - UnitTests.Distribution.Client.Dependency.Modular.Solver.tests + , testGroup "UnitTests.Distribution.Solver.Modular.Solver" + UnitTests.Distribution.Solver.Modular.Solver.tests , testGroup "UnitTests.Distribution.Client.FileMonitor" $ UnitTests.Distribution.Client.FileMonitor.tests mtimeChange , testGroup "Distribution.Client.GZipUtils" diff --git a/cabal-install/tests/UnitTests/Distribution/Client/Dependency/Modular/DSL.hs b/cabal-install/tests/UnitTests/Distribution/Client/Dependency/Modular/DSL.hs index f8bf7dce7c2..4a96d50ab73 100644 --- a/cabal-install/tests/UnitTests/Distribution/Client/Dependency/Modular/DSL.hs +++ b/cabal-install/tests/UnitTests/Distribution/Client/Dependency/Modular/DSL.hs @@ -1,6 +1,6 @@ {-# LANGUAGE RecordWildCards #-} -- | DSL for testing the modular solver -module UnitTests.Distribution.Client.Dependency.Modular.DSL ( +module UnitTests.Distribution.Solver.Modular.DSL ( ExampleDependency(..) , Dependencies(..) , ExPreference(..) @@ -35,14 +35,14 @@ import qualified Distribution.Version as C import Language.Haskell.Extension (Extension(..), Language) -- cabal-install -import Distribution.Client.ComponentDeps (ComponentDeps) +import Distribution.Solver.ComponentDeps (ComponentDeps) import Distribution.Client.Dependency import Distribution.Client.Dependency.Types import Distribution.Client.Types import qualified Distribution.Client.InstallPlan as CI.InstallPlan -import qualified Distribution.Client.PackageIndex as CI.PackageIndex -import qualified Distribution.Client.PkgConfigDb as PC -import qualified Distribution.Client.ComponentDeps as CD +import qualified Distribution.Solver.PackageIndex as CI.PackageIndex +import qualified Distribution.Solver.PkgConfigDb as PC +import qualified Distribution.Solver.ComponentDeps as CD {------------------------------------------------------------------------------- Example package database DSL diff --git a/cabal-install/tests/UnitTests/Distribution/Client/Dependency/Modular/Solver.hs b/cabal-install/tests/UnitTests/Distribution/Client/Dependency/Modular/Solver.hs index c3c3f999137..33e44d7211a 100644 --- a/cabal-install/tests/UnitTests/Distribution/Client/Dependency/Modular/Solver.hs +++ b/cabal-install/tests/UnitTests/Distribution/Client/Dependency/Modular/Solver.hs @@ -1,5 +1,5 @@ {-# LANGUAGE RecordWildCards #-} -module UnitTests.Distribution.Client.Dependency.Modular.Solver (tests) +module UnitTests.Distribution.Solver.Modular.Solver (tests) where -- base @@ -18,8 +18,8 @@ import Language.Haskell.Extension ( Extension(..) , KnownExtension(..), Language(..)) -- cabal-install -import Distribution.Client.PkgConfigDb (PkgConfigDb, pkgConfigDbFromList) -import UnitTests.Distribution.Client.Dependency.Modular.DSL +import Distribution.Solver.PkgConfigDb (PkgConfigDb, pkgConfigDbFromList) +import UnitTests.Distribution.Solver.Modular.DSL import UnitTests.Options tests :: [TF.TestTree] diff --git a/cabal-solver/.gitignore b/cabal-solver/.gitignore new file mode 100644 index 00000000000..78a51de049b --- /dev/null +++ b/cabal-solver/.gitignore @@ -0,0 +1,2 @@ +/Setup +/dist diff --git a/cabal-install/Distribution/Client/ComponentDeps.hs b/cabal-solver/Distribution/Solver/ComponentDeps.hs similarity index 96% rename from cabal-install/Distribution/Client/ComponentDeps.hs rename to cabal-solver/Distribution/Solver/ComponentDeps.hs index 85451024c20..8a4d522fa81 100644 --- a/cabal-install/Distribution/Client/ComponentDeps.hs +++ b/cabal-solver/Distribution/Solver/ComponentDeps.hs @@ -2,16 +2,16 @@ -- -- Like many others, this module is meant to be "double-imported": -- --- > import Distribution.Client.ComponentDeps ( +-- > import Distribution.Solver.ComponentDeps ( -- > Component -- > , ComponentDep -- > , ComponentDeps -- > ) --- > import qualified Distribution.Client.ComponentDeps as CD +-- > import qualified Distribution.Solver.ComponentDeps as CD {-# LANGUAGE CPP #-} {-# LANGUAGE DeriveFunctor #-} {-# LANGUAGE DeriveGeneric #-} -module Distribution.Client.ComponentDeps ( +module Distribution.Solver.ComponentDeps ( -- * Fine-grained package dependencies Component(..) , ComponentDep diff --git a/cabal-install/Distribution/Client/Dependency/Modular.hs b/cabal-solver/Distribution/Solver/Modular.hs similarity index 80% rename from cabal-install/Distribution/Client/Dependency/Modular.hs rename to cabal-solver/Distribution/Solver/Modular.hs index 3b302bbdd9d..8b35e3bd7ea 100644 --- a/cabal-install/Distribution/Client/Dependency/Modular.hs +++ b/cabal-solver/Distribution/Solver/Modular.hs @@ -1,5 +1,7 @@ -module Distribution.Client.Dependency.Modular - ( modularResolver, SolverConfig(..)) where +module Distribution.Solver.Modular + ( modularResolver + , SolverConfig(..) + ) where -- Here, we try to map between the external cabal-install solver -- interface and the internal interface that the solver actually @@ -11,19 +13,19 @@ module Distribution.Client.Dependency.Modular import Data.Map as M ( fromListWith ) -import Distribution.Client.Dependency.Modular.Assignment +import Distribution.Solver.Modular.Assignment ( toCPs ) -import Distribution.Client.Dependency.Modular.ConfiguredConversion +import Distribution.Solver.Modular.ConfiguredConversion ( convCP ) -import Distribution.Client.Dependency.Modular.IndexConversion +import Distribution.Solver.Modular.IndexConversion ( convPIs ) -import Distribution.Client.Dependency.Modular.Log +import Distribution.Solver.Modular.Log ( logToProgress ) -import Distribution.Client.Dependency.Modular.Package +import Distribution.Solver.Modular.Package ( PN ) -import Distribution.Client.Dependency.Modular.Solver +import Distribution.Solver.Modular.Solver ( SolverConfig(..), solve ) -import Distribution.Client.Dependency.Types +import Distribution.Solver.Types ( DependencyResolver , PackageConstraint(..), unlabelPackageConstraint ) import Distribution.System diff --git a/cabal-install/Distribution/Client/Dependency/Modular/Assignment.hs b/cabal-solver/Distribution/Solver/Modular/Assignment.hs similarity index 91% rename from cabal-install/Distribution/Client/Dependency/Modular/Assignment.hs rename to cabal-solver/Distribution/Solver/Modular/Assignment.hs index d13762bea5d..8e99abce66d 100644 --- a/cabal-install/Distribution/Client/Dependency/Modular/Assignment.hs +++ b/cabal-solver/Distribution/Solver/Modular/Assignment.hs @@ -1,4 +1,4 @@ -module Distribution.Client.Dependency.Modular.Assignment +module Distribution.Solver.Modular.Assignment ( Assignment(..) , FAssignment , SAssignment @@ -18,16 +18,16 @@ import Prelude hiding (pi) import Language.Haskell.Extension (Extension, Language) import Distribution.PackageDescription (FlagAssignment) -- from Cabal -import Distribution.Client.Types (OptionalStanza) -import Distribution.Client.Utils.LabeledGraph -import Distribution.Client.ComponentDeps (ComponentDeps, Component) -import qualified Distribution.Client.ComponentDeps as CD +import Distribution.Solver.Modular.Internal.LabeledGraph -import Distribution.Client.Dependency.Modular.Configured -import Distribution.Client.Dependency.Modular.Dependency -import Distribution.Client.Dependency.Modular.Flag -import Distribution.Client.Dependency.Modular.Package -import Distribution.Client.Dependency.Modular.Version +import Distribution.Solver.ComponentDeps (ComponentDeps, Component) +import qualified Distribution.Solver.ComponentDeps as CD +import Distribution.Solver.Modular.Configured +import Distribution.Solver.Modular.Dependency +import Distribution.Solver.Modular.Flag +import Distribution.Solver.Modular.Package +import Distribution.Solver.Modular.Version +import Distribution.Solver.Types.OptionalStanza -- | A (partial) package assignment. Qualified package names -- are associated with instances. diff --git a/cabal-install/Distribution/Client/Dependency/Modular/Builder.hs b/cabal-solver/Distribution/Solver/Modular/Builder.hs similarity index 94% rename from cabal-install/Distribution/Client/Dependency/Modular/Builder.hs rename to cabal-solver/Distribution/Solver/Modular/Builder.hs index 2bea5b80afe..6a08d662b57 100644 --- a/cabal-install/Distribution/Client/Dependency/Modular/Builder.hs +++ b/cabal-solver/Distribution/Solver/Modular/Builder.hs @@ -1,5 +1,5 @@ {-# LANGUAGE CPP #-} -module Distribution.Client.Dependency.Modular.Builder (buildTree) where +module Distribution.Solver.Modular.Builder (buildTree) where -- Building the search tree. -- @@ -20,15 +20,14 @@ import Data.List as L import Data.Map as M import Prelude hiding (sequence, mapM) -import Distribution.Client.Dependency.Modular.Dependency -import Distribution.Client.Dependency.Modular.Flag -import Distribution.Client.Dependency.Modular.Index -import Distribution.Client.Dependency.Modular.Package -import Distribution.Client.Dependency.Modular.PSQ (PSQ) -import qualified Distribution.Client.Dependency.Modular.PSQ as P -import Distribution.Client.Dependency.Modular.Tree - -import Distribution.Client.ComponentDeps (Component) +import Distribution.Solver.ComponentDeps (Component) +import Distribution.Solver.Modular.Dependency +import Distribution.Solver.Modular.Flag +import Distribution.Solver.Modular.Index +import Distribution.Solver.Modular.Package +import Distribution.Solver.Modular.Internal.PSQ (PSQ) +import qualified Distribution.Solver.Modular.Internal.PSQ as P +import Distribution.Solver.Modular.Tree -- | The state needed during the build phase of the search tree. data BuildState = BS { diff --git a/cabal-install/Distribution/Client/Dependency/Modular/Configured.hs b/cabal-solver/Distribution/Solver/Modular/Configured.hs similarity index 56% rename from cabal-install/Distribution/Client/Dependency/Modular/Configured.hs rename to cabal-solver/Distribution/Solver/Modular/Configured.hs index bbde5ecdae0..aa5a8123bcc 100644 --- a/cabal-install/Distribution/Client/Dependency/Modular/Configured.hs +++ b/cabal-solver/Distribution/Solver/Modular/Configured.hs @@ -1,12 +1,11 @@ -module Distribution.Client.Dependency.Modular.Configured +module Distribution.Solver.Modular.Configured ( CP(..) ) where import Distribution.PackageDescription (FlagAssignment) -- from Cabal -import Distribution.Client.Types (OptionalStanza) -import Distribution.Client.ComponentDeps (ComponentDeps) - -import Distribution.Client.Dependency.Modular.Package +import Distribution.Solver.Types.OptionalStanza +import Distribution.Solver.ComponentDeps (ComponentDeps) +import Distribution.Solver.Modular.Package -- | A configured package is a package instance together with -- a flag assignment and complete dependencies. diff --git a/cabal-install/Distribution/Client/Dependency/Modular/ConfiguredConversion.hs b/cabal-solver/Distribution/Solver/Modular/ConfiguredConversion.hs similarity index 74% rename from cabal-install/Distribution/Client/Dependency/Modular/ConfiguredConversion.hs rename to cabal-solver/Distribution/Solver/Modular/ConfiguredConversion.hs index b27d137e020..6a1bab8088c 100644 --- a/cabal-install/Distribution/Client/Dependency/Modular/ConfiguredConversion.hs +++ b/cabal-solver/Distribution/Solver/Modular/ConfiguredConversion.hs @@ -1,4 +1,4 @@ -module Distribution.Client.Dependency.Modular.ConfiguredConversion +module Distribution.Solver.Modular.ConfiguredConversion ( convCP ) where @@ -6,16 +6,16 @@ import Data.Maybe import Prelude hiding (pi) import Distribution.Package (UnitId) - -import Distribution.Client.Types -import Distribution.Client.Dependency.Types (ResolverPackage(..)) -import qualified Distribution.Client.PackageIndex as CI import qualified Distribution.Simple.PackageIndex as SI -import Distribution.Client.Dependency.Modular.Configured -import Distribution.Client.Dependency.Modular.Package - -import Distribution.Client.ComponentDeps (ComponentDeps) +import qualified Distribution.Solver.PackageIndex as CI +import Distribution.Solver.Types (ResolverPackage(..)) +import Distribution.Solver.ComponentDeps (ComponentDeps) +import Distribution.Solver.Modular.Configured +import Distribution.Solver.Modular.Package +import Distribution.Solver.Types.SourcePackage +import Distribution.Solver.Types.ConfiguredId +import Distribution.Solver.Types.ConfiguredPackage -- | Converts from the solver specific result @CP QPN@ into -- a 'ResolverPackage', which can then be converted into diff --git a/cabal-install/Distribution/Client/Dependency/Modular/Cycles.hs b/cabal-solver/Distribution/Solver/Modular/Cycles.hs similarity index 91% rename from cabal-install/Distribution/Client/Dependency/Modular/Cycles.hs rename to cabal-solver/Distribution/Solver/Modular/Cycles.hs index 7f368d24681..5b21c091f3b 100644 --- a/cabal-install/Distribution/Client/Dependency/Modular/Cycles.hs +++ b/cabal-solver/Distribution/Solver/Modular/Cycles.hs @@ -1,5 +1,5 @@ {-# LANGUAGE CPP #-} -module Distribution.Client.Dependency.Modular.Cycles ( +module Distribution.Solver.Modular.Cycles ( detectCyclesPhase ) where @@ -17,10 +17,10 @@ import qualified Data.Traversable as T import Control.Applicative ((<$>)) #endif -import Distribution.Client.Dependency.Modular.Dependency -import Distribution.Client.Dependency.Modular.Flag -import Distribution.Client.Dependency.Modular.Package -import Distribution.Client.Dependency.Modular.Tree +import Distribution.Solver.Modular.Dependency +import Distribution.Solver.Modular.Flag +import Distribution.Solver.Modular.Package +import Distribution.Solver.Modular.Tree type DetectCycles = Reader (ConflictSet QPN) diff --git a/cabal-install/Distribution/Client/Dependency/Modular/Dependency.hs b/cabal-solver/Distribution/Solver/Modular/Dependency.hs similarity index 98% rename from cabal-install/Distribution/Client/Dependency/Modular/Dependency.hs rename to cabal-solver/Distribution/Solver/Modular/Dependency.hs index b352d1e1a34..5aa41d56ba8 100644 --- a/cabal-install/Distribution/Client/Dependency/Modular/Dependency.hs +++ b/cabal-solver/Distribution/Solver/Modular/Dependency.hs @@ -1,6 +1,6 @@ {-# LANGUAGE DeriveFunctor #-} {-# LANGUAGE RecordWildCards #-} -module Distribution.Client.Dependency.Modular.Dependency ( +module Distribution.Solver.Modular.Dependency ( -- * Variables Var(..) , simplifyVar @@ -48,11 +48,10 @@ import Language.Haskell.Extension (Extension(..), Language(..)) import Distribution.Text -import Distribution.Client.Dependency.Modular.Flag -import Distribution.Client.Dependency.Modular.Package -import Distribution.Client.Dependency.Modular.Version - -import Distribution.Client.ComponentDeps (Component(..)) +import Distribution.Solver.ComponentDeps (Component(..)) +import Distribution.Solver.Modular.Flag +import Distribution.Solver.Modular.Package +import Distribution.Solver.Modular.Version {------------------------------------------------------------------------------- Variables diff --git a/cabal-install/Distribution/Client/Dependency/Modular/Explore.hs b/cabal-solver/Distribution/Solver/Modular/Explore.hs similarity index 88% rename from cabal-install/Distribution/Client/Dependency/Modular/Explore.hs rename to cabal-solver/Distribution/Solver/Modular/Explore.hs index 56dc9961dcc..e51565802ca 100644 --- a/cabal-install/Distribution/Client/Dependency/Modular/Explore.hs +++ b/cabal-solver/Distribution/Solver/Modular/Explore.hs @@ -1,4 +1,4 @@ -module Distribution.Client.Dependency.Modular.Explore +module Distribution.Solver.Modular.Explore ( backjump , backjumpAndExplore ) where @@ -7,14 +7,14 @@ import Data.Foldable as F import Data.Map as M import Data.Set as S -import Distribution.Client.Dependency.Modular.Assignment -import Distribution.Client.Dependency.Modular.Dependency -import Distribution.Client.Dependency.Modular.Log -import Distribution.Client.Dependency.Modular.Message -import Distribution.Client.Dependency.Modular.Package -import qualified Distribution.Client.Dependency.Modular.PSQ as P -import Distribution.Client.Dependency.Modular.Tree -import qualified Distribution.Client.Dependency.Types as T +import Distribution.Solver.Modular.Assignment +import Distribution.Solver.Modular.Dependency +import Distribution.Solver.Modular.Log +import Distribution.Solver.Modular.Message +import Distribution.Solver.Modular.Package +import qualified Distribution.Solver.Modular.Internal.PSQ as P +import Distribution.Solver.Modular.Tree +import qualified Distribution.Solver.Types as T -- | This function takes the variable we're currently considering and a -- list of children's logs. Each log yields either a solution or a diff --git a/cabal-install/Distribution/Client/Dependency/Modular/Flag.hs b/cabal-solver/Distribution/Solver/Modular/Flag.hs similarity index 92% rename from cabal-install/Distribution/Client/Dependency/Modular/Flag.hs rename to cabal-solver/Distribution/Solver/Modular/Flag.hs index 6eef0ad4046..afd283cbf65 100644 --- a/cabal-install/Distribution/Client/Dependency/Modular/Flag.hs +++ b/cabal-solver/Distribution/Solver/Modular/Flag.hs @@ -1,5 +1,5 @@ {-# LANGUAGE DeriveFunctor #-} -module Distribution.Client.Dependency.Modular.Flag +module Distribution.Solver.Modular.Flag ( FInfo(..) , Flag , FlagInfo @@ -20,8 +20,8 @@ import Prelude hiding (pi) import Distribution.PackageDescription hiding (Flag) -- from Cabal -import Distribution.Client.Dependency.Modular.Package -import Distribution.Client.Types (OptionalStanza(..)) +import Distribution.Solver.Modular.Package +import Distribution.Solver.Types.OptionalStanza -- | Flag name. Consists of a package instance and the flag identifier itself. data FN qpn = FN (PI qpn) Flag diff --git a/cabal-install/Distribution/Client/Dependency/Modular/Index.hs b/cabal-solver/Distribution/Solver/Modular/Index.hs similarity index 84% rename from cabal-install/Distribution/Client/Dependency/Modular/Index.hs rename to cabal-solver/Distribution/Solver/Modular/Index.hs index 3d593b0885f..746ce930926 100644 --- a/cabal-install/Distribution/Client/Dependency/Modular/Index.hs +++ b/cabal-solver/Distribution/Solver/Modular/Index.hs @@ -1,4 +1,4 @@ -module Distribution.Client.Dependency.Modular.Index +module Distribution.Solver.Modular.Index ( Index , PInfo(..) , defaultQualifyOptions @@ -9,12 +9,11 @@ import Data.List as L import Data.Map as M import Prelude hiding (pi) -import Distribution.Client.Dependency.Modular.Dependency -import Distribution.Client.Dependency.Modular.Flag -import Distribution.Client.Dependency.Modular.Package -import Distribution.Client.Dependency.Modular.Tree - -import Distribution.Client.ComponentDeps (Component) +import Distribution.Solver.ComponentDeps (Component) +import Distribution.Solver.Modular.Dependency +import Distribution.Solver.Modular.Flag +import Distribution.Solver.Modular.Package +import Distribution.Solver.Modular.Tree -- | An index contains information about package instances. This is a nested -- dictionary. Package names are mapped to instances, which in turn is mapped diff --git a/cabal-install/Distribution/Client/Dependency/Modular/IndexConversion.hs b/cabal-solver/Distribution/Solver/Modular/IndexConversion.hs similarity index 95% rename from cabal-install/Distribution/Client/Dependency/Modular/IndexConversion.hs rename to cabal-solver/Distribution/Solver/Modular/IndexConversion.hs index 8648f876a6c..e189cee8495 100644 --- a/cabal-install/Distribution/Client/Dependency/Modular/IndexConversion.hs +++ b/cabal-solver/Distribution/Solver/Modular/IndexConversion.hs @@ -1,4 +1,4 @@ -module Distribution.Client.Dependency.Modular.IndexConversion +module Distribution.Solver.Modular.IndexConversion ( convPIs ) where @@ -8,9 +8,9 @@ import Data.Maybe import Data.Monoid as Mon import Prelude hiding (pi) -import qualified Distribution.Client.PackageIndex as CI -import Distribution.Client.Types -import Distribution.Client.ComponentDeps (Component(..)) +import qualified Distribution.Solver.PackageIndex as CI +import Distribution.Solver.Types +import Distribution.Solver.ComponentDeps (Component(..)) import Distribution.Compiler import Distribution.InstalledPackageInfo as IPI import Distribution.Package -- from Cabal @@ -19,12 +19,12 @@ import Distribution.PackageDescription.Configuration as PDC import qualified Distribution.Simple.PackageIndex as SI import Distribution.System -import Distribution.Client.Dependency.Modular.Dependency as D -import Distribution.Client.Dependency.Modular.Flag as F -import Distribution.Client.Dependency.Modular.Index -import Distribution.Client.Dependency.Modular.Package -import Distribution.Client.Dependency.Modular.Tree -import Distribution.Client.Dependency.Modular.Version +import Distribution.Solver.Modular.Dependency as D +import Distribution.Solver.Modular.Flag as F +import Distribution.Solver.Modular.Index +import Distribution.Solver.Modular.Package +import Distribution.Solver.Modular.Tree +import Distribution.Solver.Modular.Version -- | Convert both the installed package index and the source package -- index into one uniform solver index. diff --git a/cabal-install/Distribution/Client/Utils/LabeledGraph.hs b/cabal-solver/Distribution/Solver/Modular/Internal/LabeledGraph.hs similarity index 98% rename from cabal-install/Distribution/Client/Utils/LabeledGraph.hs rename to cabal-solver/Distribution/Solver/Modular/Internal/LabeledGraph.hs index 1c42a1d51b7..ff32578705a 100644 --- a/cabal-install/Distribution/Client/Utils/LabeledGraph.hs +++ b/cabal-solver/Distribution/Solver/Modular/Internal/LabeledGraph.hs @@ -1,6 +1,6 @@ -- | Wrapper around Data.Graph with support for edge labels {-# LANGUAGE ScopedTypeVariables #-} -module Distribution.Client.Utils.LabeledGraph ( +module Distribution.Solver.Modular.Internal.LabeledGraph ( -- * Graphs Graph , Vertex diff --git a/cabal-install/Distribution/Client/Dependency/Modular/PSQ.hs b/cabal-solver/Distribution/Solver/Modular/Internal/PSQ.hs similarity index 99% rename from cabal-install/Distribution/Client/Dependency/Modular/PSQ.hs rename to cabal-solver/Distribution/Solver/Modular/Internal/PSQ.hs index 417832e7adb..b435c85c6e6 100644 --- a/cabal-install/Distribution/Client/Dependency/Modular/PSQ.hs +++ b/cabal-solver/Distribution/Solver/Modular/Internal/PSQ.hs @@ -1,5 +1,5 @@ {-# LANGUAGE DeriveFunctor, DeriveFoldable, DeriveTraversable #-} -module Distribution.Client.Dependency.Modular.PSQ +module Distribution.Solver.Modular.Internal.PSQ ( PSQ(..) -- Unit test needs constructor access , Degree(..) , casePSQ diff --git a/cabal-install/Distribution/Client/Dependency/Modular/Linking.hs b/cabal-solver/Distribution/Solver/Modular/Linking.hs similarity index 97% rename from cabal-install/Distribution/Client/Dependency/Modular/Linking.hs rename to cabal-solver/Distribution/Solver/Modular/Linking.hs index 1bc1c7abf9e..9f28c621c2d 100644 --- a/cabal-install/Distribution/Client/Dependency/Modular/Linking.hs +++ b/cabal-solver/Distribution/Solver/Modular/Linking.hs @@ -1,6 +1,6 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} -module Distribution.Client.Dependency.Modular.Linking ( +module Distribution.Solver.Modular.Linking ( addLinking , validateLinking ) where @@ -21,16 +21,16 @@ import qualified Data.Traversable as T import Control.Applicative #endif -import Distribution.Client.Dependency.Modular.Assignment -import Distribution.Client.Dependency.Modular.Dependency -import Distribution.Client.Dependency.Modular.Flag -import Distribution.Client.Dependency.Modular.Index -import Distribution.Client.Dependency.Modular.Package -import Distribution.Client.Dependency.Modular.Tree -import qualified Distribution.Client.Dependency.Modular.PSQ as P +import Distribution.Solver.Modular.Assignment +import Distribution.Solver.Modular.Dependency +import Distribution.Solver.Modular.Flag +import Distribution.Solver.Modular.Index +import Distribution.Solver.Modular.Package +import Distribution.Solver.Modular.Tree +import qualified Distribution.Solver.Modular.Internal.PSQ as P -import Distribution.Client.Types (OptionalStanza(..)) -import Distribution.Client.ComponentDeps (Component) +import Distribution.Solver.Types.OptionalStanza +import Distribution.Solver.ComponentDeps (Component) {------------------------------------------------------------------------------- Add linking diff --git a/cabal-install/Distribution/Client/Dependency/Modular/Log.hs b/cabal-solver/Distribution/Solver/Modular/Log.hs similarity index 93% rename from cabal-install/Distribution/Client/Dependency/Modular/Log.hs rename to cabal-solver/Distribution/Solver/Modular/Log.hs index d5ec8b84359..da01c282384 100644 --- a/cabal-install/Distribution/Client/Dependency/Modular/Log.hs +++ b/cabal-solver/Distribution/Solver/Modular/Log.hs @@ -1,4 +1,4 @@ -module Distribution.Client.Dependency.Modular.Log +module Distribution.Solver.Modular.Log ( Log , continueWith , failWith @@ -12,12 +12,12 @@ import Data.List as L import Data.Maybe (isNothing) import Data.Set as S -import Distribution.Client.Dependency.Types -- from Cabal +import Distribution.Solver.Types -- from Cabal -import Distribution.Client.Dependency.Modular.Dependency -import Distribution.Client.Dependency.Modular.Message -import Distribution.Client.Dependency.Modular.Package -import Distribution.Client.Dependency.Modular.Tree (FailReason(..)) +import Distribution.Solver.Modular.Dependency +import Distribution.Solver.Modular.Message +import Distribution.Solver.Modular.Package +import Distribution.Solver.Modular.Tree (FailReason(..)) -- | The 'Log' datatype. -- diff --git a/cabal-install/Distribution/Client/Dependency/Modular/Message.hs b/cabal-solver/Distribution/Solver/Modular/Message.hs similarity index 96% rename from cabal-install/Distribution/Client/Dependency/Modular/Message.hs rename to cabal-solver/Distribution/Solver/Modular/Message.hs index 3f22bef6e7b..5c2c93ec1c4 100644 --- a/cabal-install/Distribution/Client/Dependency/Modular/Message.hs +++ b/cabal-solver/Distribution/Solver/Modular/Message.hs @@ -1,6 +1,6 @@ {-# LANGUAGE BangPatterns #-} -module Distribution.Client.Dependency.Modular.Message ( +module Distribution.Solver.Modular.Message ( Message(..), showMessages ) where @@ -10,12 +10,12 @@ import Prelude hiding (pi) import Distribution.Text -- from Cabal -import Distribution.Client.Dependency.Modular.Dependency -import Distribution.Client.Dependency.Modular.Flag -import Distribution.Client.Dependency.Modular.Package -import Distribution.Client.Dependency.Modular.Tree +import Distribution.Solver.Modular.Dependency +import Distribution.Solver.Modular.Flag +import Distribution.Solver.Modular.Package +import Distribution.Solver.Modular.Tree ( FailReason(..), POption(..) ) -import Distribution.Client.Dependency.Types +import Distribution.Solver.Types ( ConstraintSource(..), showConstraintSource, Progress(..) ) data Message = diff --git a/cabal-install/Distribution/Client/Dependency/Modular/Package.hs b/cabal-solver/Distribution/Solver/Modular/Package.hs similarity index 97% rename from cabal-install/Distribution/Client/Dependency/Modular/Package.hs rename to cabal-solver/Distribution/Solver/Modular/Package.hs index 4fc8f7abeb9..2abb76f2465 100644 --- a/cabal-install/Distribution/Client/Dependency/Modular/Package.hs +++ b/cabal-solver/Distribution/Solver/Modular/Package.hs @@ -1,5 +1,5 @@ {-# LANGUAGE DeriveFunctor #-} -module Distribution.Client.Dependency.Modular.Package +module Distribution.Solver.Modular.Package ( I(..) , Loc(..) , PackageId @@ -26,7 +26,7 @@ import Data.List as L import Distribution.Package -- from Cabal import Distribution.Text -- from Cabal -import Distribution.Client.Dependency.Modular.Version +import Distribution.Solver.Modular.Version -- | A package name. type PN = PackageName diff --git a/cabal-install/Distribution/Client/Dependency/Modular/Preference.hs b/cabal-solver/Distribution/Solver/Modular/Preference.hs similarity index 97% rename from cabal-install/Distribution/Client/Dependency/Modular/Preference.hs rename to cabal-solver/Distribution/Solver/Modular/Preference.hs index 63dfbec1f46..e0828003358 100644 --- a/cabal-install/Distribution/Client/Dependency/Modular/Preference.hs +++ b/cabal-solver/Distribution/Solver/Modular/Preference.hs @@ -1,5 +1,5 @@ {-# LANGUAGE CPP #-} -module Distribution.Client.Dependency.Modular.Preference +module Distribution.Solver.Modular.Preference ( avoidReinstalls , deferSetupChoices , deferWeakFlagChoices @@ -29,18 +29,17 @@ import Control.Monad.Reader hiding (sequence) import Data.Map (Map) import Data.Traversable (sequence) -import Distribution.Client.Dependency.Types +import Distribution.Solver.Types ( PackageConstraint(..), LabeledPackageConstraint(..), ConstraintSource(..) , PackagePreferences(..), InstalledPreference(..) ) -import Distribution.Client.Types - ( OptionalStanza(..) ) - -import Distribution.Client.Dependency.Modular.Dependency -import Distribution.Client.Dependency.Modular.Flag -import Distribution.Client.Dependency.Modular.Package -import qualified Distribution.Client.Dependency.Modular.PSQ as P -import Distribution.Client.Dependency.Modular.Tree -import Distribution.Client.Dependency.Modular.Version +import Distribution.Solver.Types.OptionalStanza + +import Distribution.Solver.Modular.Dependency +import Distribution.Solver.Modular.Flag +import Distribution.Solver.Modular.Package +import qualified Distribution.Solver.Modular.Internal.PSQ as P +import Distribution.Solver.Modular.Tree +import Distribution.Solver.Modular.Version -- | Generic abstraction for strategies that just rearrange the package order. -- Only packages that match the given predicate are reordered. diff --git a/cabal-install/Distribution/Client/Dependency/Modular/Solver.hs b/cabal-solver/Distribution/Solver/Modular/Solver.hs similarity index 82% rename from cabal-install/Distribution/Client/Dependency/Modular/Solver.hs rename to cabal-solver/Distribution/Solver/Modular/Solver.hs index 08b9637896d..62cbc2f6c45 100644 --- a/cabal-install/Distribution/Client/Dependency/Modular/Solver.hs +++ b/cabal-solver/Distribution/Solver/Modular/Solver.hs @@ -1,4 +1,4 @@ -module Distribution.Client.Dependency.Modular.Solver +module Distribution.Solver.Modular.Solver ( SolverConfig(..) , solve ) where @@ -7,22 +7,20 @@ import Data.Map as M import Distribution.Compiler (CompilerInfo) -import Distribution.Client.PkgConfigDb (PkgConfigDb) - -import Distribution.Client.Dependency.Types - -import Distribution.Client.Dependency.Modular.Assignment -import Distribution.Client.Dependency.Modular.Builder -import Distribution.Client.Dependency.Modular.Cycles -import Distribution.Client.Dependency.Modular.Dependency -import Distribution.Client.Dependency.Modular.Explore -import Distribution.Client.Dependency.Modular.Index -import Distribution.Client.Dependency.Modular.Log -import Distribution.Client.Dependency.Modular.Message -import Distribution.Client.Dependency.Modular.Package -import qualified Distribution.Client.Dependency.Modular.Preference as P -import Distribution.Client.Dependency.Modular.Validate -import Distribution.Client.Dependency.Modular.Linking +import Distribution.Solver.PkgConfigDb (PkgConfigDb) +import Distribution.Solver.Types +import Distribution.Solver.Modular.Assignment +import Distribution.Solver.Modular.Builder +import Distribution.Solver.Modular.Cycles +import Distribution.Solver.Modular.Dependency +import Distribution.Solver.Modular.Explore +import Distribution.Solver.Modular.Index +import Distribution.Solver.Modular.Log +import Distribution.Solver.Modular.Message +import Distribution.Solver.Modular.Package +import qualified Distribution.Solver.Modular.Preference as P +import Distribution.Solver.Modular.Validate +import Distribution.Solver.Modular.Linking -- | Various options for the modular solver. data SolverConfig = SolverConfig { diff --git a/cabal-install/Distribution/Client/Dependency/Modular/Tree.hs b/cabal-solver/Distribution/Solver/Modular/Tree.hs similarity index 93% rename from cabal-install/Distribution/Client/Dependency/Modular/Tree.hs rename to cabal-solver/Distribution/Solver/Modular/Tree.hs index d170b565ccb..7534d85ffae 100644 --- a/cabal-install/Distribution/Client/Dependency/Modular/Tree.hs +++ b/cabal-solver/Distribution/Solver/Modular/Tree.hs @@ -1,5 +1,5 @@ {-# LANGUAGE DeriveFunctor, DeriveFoldable, DeriveTraversable #-} -module Distribution.Client.Dependency.Modular.Tree +module Distribution.Solver.Modular.Tree ( FailReason(..) , POption(..) , Tree(..) @@ -20,13 +20,13 @@ import Data.Foldable import Data.Traversable import Prelude hiding (foldr, mapM, sequence) -import Distribution.Client.Dependency.Modular.Dependency -import Distribution.Client.Dependency.Modular.Flag -import Distribution.Client.Dependency.Modular.Package -import Distribution.Client.Dependency.Modular.PSQ (PSQ) -import qualified Distribution.Client.Dependency.Modular.PSQ as P -import Distribution.Client.Dependency.Modular.Version -import Distribution.Client.Dependency.Types ( ConstraintSource(..) ) +import Distribution.Solver.Modular.Dependency +import Distribution.Solver.Modular.Flag +import Distribution.Solver.Modular.Package +import Distribution.Solver.Modular.Internal.PSQ (PSQ) +import qualified Distribution.Solver.Modular.Internal.PSQ as P +import Distribution.Solver.Modular.Version +import Distribution.Solver.Types ( ConstraintSource(..) ) -- | Type of the search tree. Inlining the choice nodes for now. data Tree a = diff --git a/cabal-install/Distribution/Client/Dependency/Modular/Validate.hs b/cabal-solver/Distribution/Solver/Modular/Validate.hs similarity index 95% rename from cabal-install/Distribution/Client/Dependency/Modular/Validate.hs rename to cabal-solver/Distribution/Solver/Modular/Validate.hs index 3bbcbab3fd3..a9363f82aea 100644 --- a/cabal-install/Distribution/Client/Dependency/Modular/Validate.hs +++ b/cabal-solver/Distribution/Solver/Modular/Validate.hs @@ -1,4 +1,4 @@ -module Distribution.Client.Dependency.Modular.Validate (validateTree) where +module Distribution.Solver.Modular.Validate (validateTree) where -- Validation of the tree. -- @@ -18,17 +18,17 @@ import Language.Haskell.Extension (Extension, Language) import Distribution.Compiler (CompilerInfo(..)) -import Distribution.Client.Dependency.Modular.Assignment -import Distribution.Client.Dependency.Modular.Dependency -import Distribution.Client.Dependency.Modular.Flag -import Distribution.Client.Dependency.Modular.Index -import Distribution.Client.Dependency.Modular.Package -import qualified Distribution.Client.Dependency.Modular.PSQ as P -import Distribution.Client.Dependency.Modular.Tree -import Distribution.Client.Dependency.Modular.Version (VR) +import Distribution.Solver.Modular.Assignment +import Distribution.Solver.Modular.Dependency +import Distribution.Solver.Modular.Flag +import Distribution.Solver.Modular.Index +import Distribution.Solver.Modular.Package +import qualified Distribution.Solver.Modular.Internal.PSQ as P +import Distribution.Solver.Modular.Tree +import Distribution.Solver.Modular.Version (VR) -import Distribution.Client.ComponentDeps (Component) -import Distribution.Client.PkgConfigDb (PkgConfigDb, pkgConfigPkgIsPresent) +import Distribution.Solver.ComponentDeps (Component) +import Distribution.Solver.PkgConfigDb (PkgConfigDb, pkgConfigPkgIsPresent) -- In practice, most constraints are implication constraints (IF we have made -- a number of choices, THEN we also have to ensure that). We call constraints diff --git a/cabal-install/Distribution/Client/Dependency/Modular/Version.hs b/cabal-solver/Distribution/Solver/Modular/Version.hs similarity index 95% rename from cabal-install/Distribution/Client/Dependency/Modular/Version.hs rename to cabal-solver/Distribution/Solver/Modular/Version.hs index 2bda3598aef..e7d10cf13f0 100644 --- a/cabal-install/Distribution/Client/Dependency/Modular/Version.hs +++ b/cabal-solver/Distribution/Solver/Modular/Version.hs @@ -1,4 +1,4 @@ -module Distribution.Client.Dependency.Modular.Version +module Distribution.Solver.Modular.Version ( Ver , VR , anyVR diff --git a/cabal-install/Distribution/Client/PackageIndex.hs b/cabal-solver/Distribution/Solver/PackageIndex.hs similarity index 99% rename from cabal-install/Distribution/Client/PackageIndex.hs rename to cabal-solver/Distribution/Solver/PackageIndex.hs index 6e890609b21..9d3948b0706 100644 --- a/cabal-install/Distribution/Client/PackageIndex.hs +++ b/cabal-solver/Distribution/Solver/PackageIndex.hs @@ -3,7 +3,7 @@ {-# LANGUAGE DeriveGeneric #-} ----------------------------------------------------------------------------- -- | --- Module : Distribution.Client.PackageIndex +-- Module : Distribution.Solver.PackageIndex -- Copyright : (c) David Himmelstrup 2005, -- Bjorn Bringert 2007, -- Duncan Coutts 2008 @@ -13,7 +13,7 @@ -- -- An index of packages. -- -module Distribution.Client.PackageIndex ( +module Distribution.Solver.PackageIndex ( -- * Package index data type PackageIndex, diff --git a/cabal-install/Distribution/Client/PackageUtils.hs b/cabal-solver/Distribution/Solver/PackageUtils.hs similarity index 92% rename from cabal-install/Distribution/Client/PackageUtils.hs rename to cabal-solver/Distribution/Solver/PackageUtils.hs index bd2b1df9745..98bf79f53be 100644 --- a/cabal-install/Distribution/Client/PackageUtils.hs +++ b/cabal-solver/Distribution/Solver/PackageUtils.hs @@ -1,6 +1,6 @@ ----------------------------------------------------------------------------- -- | --- Module : Distribution.Client.PackageUtils +-- Module : Distribution.Solver.PackageUtils -- Copyright : (c) Duncan Coutts 2010 -- License : BSD-like -- @@ -10,7 +10,7 @@ -- -- Various package description utils that should be in the Cabal lib ----------------------------------------------------------------------------- -module Distribution.Client.PackageUtils ( +module Distribution.Solver.PackageUtils ( externalBuildDepends, ) where diff --git a/cabal-install/Distribution/Client/PkgConfigDb.hs b/cabal-solver/Distribution/Solver/PkgConfigDb.hs similarity index 97% rename from cabal-install/Distribution/Client/PkgConfigDb.hs rename to cabal-solver/Distribution/Solver/PkgConfigDb.hs index 1e510fc0b2a..8b7a8e10c05 100644 --- a/cabal-install/Distribution/Client/PkgConfigDb.hs +++ b/cabal-solver/Distribution/Solver/PkgConfigDb.hs @@ -1,7 +1,7 @@ {-# LANGUAGE CPP #-} ----------------------------------------------------------------------------- -- | --- Module : Distribution.Client.PkgConfigDb +-- Module : Distribution.Solver.PkgConfigDb -- Copyright : (c) Iñaki García Etxebarria 2016 -- License : BSD-like -- @@ -10,7 +10,7 @@ -- -- Read the list of packages available to pkg-config. ----------------------------------------------------------------------------- -module Distribution.Client.PkgConfigDb +module Distribution.Solver.PkgConfigDb ( PkgConfigDb , readPkgConfigDb diff --git a/cabal-solver/Distribution/Solver/Types.hs b/cabal-solver/Distribution/Solver/Types.hs new file mode 100644 index 00000000000..525810d4515 --- /dev/null +++ b/cabal-solver/Distribution/Solver/Types.hs @@ -0,0 +1,269 @@ +{-# LANGUAGE CPP #-} +{-# LANGUAGE DeriveFunctor #-} +{-# LANGUAGE DeriveGeneric #-} +----------------------------------------------------------------------------- +-- | +-- Module : Distribution.Solver.Types +-- Copyright : (c) Duncan Coutts 2008 +-- License : BSD-like +-- +-- Maintainer : cabal-devel@haskell.org +-- Stability : provisional +-- Portability : portable +-- +-- Common types for dependency resolution. +----------------------------------------------------------------------------- +module Distribution.Solver.Types ( + DependencyResolver, + ResolverPackage(..), + + PackageConstraint(..), + showPackageConstraint, + PackagePreferences(..), + InstalledPreference(..), + + Progress(..), + foldProgress, + + LabeledPackageConstraint(..), + ConstraintSource(..), + unlabelPackageConstraint, + showConstraintSource, + + OptionalStanza(..), + enableStanzas, + + ConfiguredPackage(..), + fakeUnitId, + + ConfiguredId(..), + + SourcePackage(..), + PackageDescriptionOverride + + ) where + +#if !MIN_VERSION_base(4,8,0) +import Control.Applicative + ( Applicative(..) ) +#endif +import Control.Applicative + ( Alternative(..) ) + +#if !MIN_VERSION_base(4,8,0) +import Data.Monoid + ( Monoid(..) ) +#endif + +import Distribution.Solver.PkgConfigDb + ( PkgConfigDb ) +import Distribution.Solver.Types.ConfiguredPackage +import Distribution.Solver.Types.ConfiguredId +import Distribution.Solver.Types.OptionalStanza +import Distribution.Solver.Types.SourcePackage + +import Distribution.PackageDescription + ( FlagAssignment, FlagName(..) ) +import Distribution.InstalledPackageInfo + ( InstalledPackageInfo ) +import qualified Distribution.Solver.PackageIndex as PackageIndex + ( PackageIndex ) +import Distribution.Simple.PackageIndex ( InstalledPackageIndex ) +import Distribution.Package + ( PackageName ) +import Distribution.Version + ( VersionRange, simplifyVersionRange ) +import Distribution.Compiler + ( CompilerInfo ) +import Distribution.System + ( Platform ) +import Distribution.Text + ( display ) + +import GHC.Generics (Generic) +import Distribution.Compat.Binary (Binary(..)) + +import Prelude hiding (fail) + + +-- | A dependency resolver is a function that works out an installation plan +-- given the set of installed and available packages and a set of deps to +-- solve for. +-- +-- The reason for this interface is because there are dozens of approaches to +-- solving the package dependency problem and we want to make it easy to swap +-- in alternatives. +-- +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 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 +-- it is possible to construct conflicting constraints (eg impossible version +-- range or inconsistent flag assignment). +-- +data PackageConstraint + = PackageConstraintVersion PackageName VersionRange + | PackageConstraintInstalled PackageName + | PackageConstraintSource PackageName + | PackageConstraintFlags PackageName FlagAssignment + | PackageConstraintStanzas PackageName [OptionalStanza] + deriving (Eq,Show,Generic) + +instance Binary PackageConstraint + +-- | Provide a textual representation of a package constraint +-- for debugging purposes. +-- +showPackageConstraint :: PackageConstraint -> String +showPackageConstraint (PackageConstraintVersion pn vr) = + display pn ++ " " ++ display (simplifyVersionRange vr) +showPackageConstraint (PackageConstraintInstalled pn) = + display pn ++ " installed" +showPackageConstraint (PackageConstraintSource pn) = + display pn ++ " source" +showPackageConstraint (PackageConstraintFlags pn fs) = + "flags " ++ display pn ++ " " ++ unwords (map (uncurry showFlag) fs) + where + showFlag (FlagName f) True = "+" ++ f + showFlag (FlagName f) False = "-" ++ f +showPackageConstraint (PackageConstraintStanzas pn ss) = + "stanzas " ++ display pn ++ " " ++ unwords (map showStanza ss) + where + showStanza TestStanzas = "test" + showStanza BenchStanzas = "bench" + +-- | Per-package preferences on the version. It is a soft constraint that the +-- 'DependencyResolver' should try to respect where possible. It consists of +-- an 'InstalledPreference' which says if we prefer versions of packages +-- that are already installed. It also has (possibly multiple) +-- 'PackageVersionPreference's which are suggested constraints on the version +-- number. The resolver should try to use package versions that satisfy +-- the maximum number of the suggested version constraints. +-- +-- It is not specified if preferences on some packages are more important than +-- others. +-- +data PackagePreferences = PackagePreferences [VersionRange] + InstalledPreference + [OptionalStanza] + +-- | Whether we prefer an installed version of a package or simply the latest +-- version. +-- +data InstalledPreference = PreferInstalled | PreferLatest + deriving Show + +-- | A type to represent the unfolding of an expensive long running +-- calculation that may fail. We may get intermediate steps before the final +-- result which may be used to indicate progress and\/or logging messages. +-- +data Progress step fail done = Step step (Progress step fail done) + | Fail fail + | Done done + deriving Functor + +-- | Consume a 'Progress' calculation. Much like 'foldr' for lists but with two +-- base cases, one for a final result and one for failure. +-- +-- Eg to convert into a simple 'Either' result use: +-- +-- > foldProgress (flip const) Left Right +-- +foldProgress :: (step -> a -> a) -> (fail -> a) -> (done -> a) + -> Progress step fail done -> a +foldProgress step fail done = fold + where fold (Step s p) = step s (fold p) + fold (Fail f) = fail f + fold (Done r) = done r + +instance Monad (Progress step fail) where + return = pure + p >>= f = foldProgress Step Fail f p + +instance Applicative (Progress step fail) where + pure a = Done a + p <*> x = foldProgress Step Fail (flip fmap x) p + +instance Monoid fail => Alternative (Progress step fail) where + empty = Fail mempty + p <|> q = foldProgress Step (const q) Done p + +-- | 'PackageConstraint' labeled with its source. +data LabeledPackageConstraint + = LabeledPackageConstraint PackageConstraint ConstraintSource + +unlabelPackageConstraint :: LabeledPackageConstraint -> PackageConstraint +unlabelPackageConstraint (LabeledPackageConstraint pc _) = pc + +-- | Source of a 'PackageConstraint'. +data ConstraintSource = + + -- | Main config file, which is ~/.cabal/config by default. + ConstraintSourceMainConfig FilePath + + -- | Sandbox config file, which is ./cabal.sandbox.config by default. + | ConstraintSourceSandboxConfig FilePath + + -- | User config file, which is ./cabal.config by default. + | ConstraintSourceUserConfig FilePath + + -- | Flag specified on the command line. + | ConstraintSourceCommandlineFlag + + -- | Target specified by the user, e.g., @cabal install package-0.1.0.0@ + -- implies @package==0.1.0.0@. + | ConstraintSourceUserTarget + + -- | Internal requirement to use installed versions of packages like ghc-prim. + | ConstraintSourceNonUpgradeablePackage + + -- | Internal requirement to use the add-source version of a package when that + -- version is installed and the source is modified. + | ConstraintSourceModifiedAddSourceDep + + -- | Internal constraint used by @cabal freeze@. + | ConstraintSourceFreeze + + -- | Constraint specified by a config file, a command line flag, or a user + -- target, when a more specific source is not known. + | ConstraintSourceConfigFlagOrTarget + + -- | The source of the constraint is not specified. + | ConstraintSourceUnknown + deriving (Eq, Show, Generic) + +instance Binary ConstraintSource + +-- | Description of a 'ConstraintSource'. +showConstraintSource :: ConstraintSource -> String +showConstraintSource (ConstraintSourceMainConfig path) = + "main config " ++ path +showConstraintSource (ConstraintSourceSandboxConfig path) = + "sandbox config " ++ path +showConstraintSource (ConstraintSourceUserConfig path)= "user config " ++ path +showConstraintSource ConstraintSourceCommandlineFlag = "command line flag" +showConstraintSource ConstraintSourceUserTarget = "user target" +showConstraintSource ConstraintSourceNonUpgradeablePackage = + "non-upgradeable package" +showConstraintSource ConstraintSourceModifiedAddSourceDep = + "modified add-source dependency" +showConstraintSource ConstraintSourceFreeze = "cabal freeze" +showConstraintSource ConstraintSourceConfigFlagOrTarget = + "config file, command line flag, or user target" +showConstraintSource ConstraintSourceUnknown = "unknown source" diff --git a/cabal-solver/Distribution/Solver/Types/ConfiguredId.hs b/cabal-solver/Distribution/Solver/Types/ConfiguredId.hs new file mode 100644 index 00000000000..726be84859e --- /dev/null +++ b/cabal-solver/Distribution/Solver/Types/ConfiguredId.hs @@ -0,0 +1,31 @@ +{-# LANGUAGE DeriveGeneric #-} +module Distribution.Solver.Types.ConfiguredId + ( ConfiguredId(..) + ) where + +import Distribution.Compat.Binary (Binary(..)) +import GHC.Generics (Generic) +import Distribution.Package (PackageId, UnitId) + +-- | A ConfiguredId is a package ID for a configured package. +-- +-- Once we configure a source package we know it's UnitId +-- (at least, in principle, even if we have to fake it currently). It is still +-- however useful in lots of places to also know the source ID for the package. +-- We therefore bundle the two. +-- +-- An already installed package of course is also "configured" (all it's +-- configuration parameters and dependencies have been specified). +-- +-- TODO: I wonder if it would make sense to promote this datatype to Cabal +-- and use it consistently instead of UnitIds? +data ConfiguredId = ConfiguredId { + confSrcId :: PackageId + , confInstId :: UnitId + } + deriving (Eq, Generic) + +instance Binary ConfiguredId + +instance Show ConfiguredId where + show = show . confSrcId diff --git a/cabal-solver/Distribution/Solver/Types/ConfiguredPackage.hs b/cabal-solver/Distribution/Solver/Types/ConfiguredPackage.hs new file mode 100644 index 00000000000..e167c099bf0 --- /dev/null +++ b/cabal-solver/Distribution/Solver/Types/ConfiguredPackage.hs @@ -0,0 +1,51 @@ +{-# LANGUAGE DeriveGeneric #-} +module Distribution.Solver.Types.ConfiguredPackage + ( ConfiguredPackage(..) + , fakeUnitId + ) where + +import Distribution.Compat.Binary (Binary(..)) +import Distribution.Package (PackageId, UnitId, Package(..), HasUnitId(..), mkUnitId) +import Distribution.Text (display) +import Distribution.PackageDescription (FlagAssignment) +import Distribution.Solver.ComponentDeps (ComponentDeps) +import Distribution.Solver.Types.OptionalStanza +import Distribution.Solver.Types.SourcePackage +import Distribution.Solver.Types.ConfiguredId +import GHC.Generics (Generic) + +-- | A 'ConfiguredPackage' is a not-yet-installed package along with the +-- total configuration information. The configuration information is total in +-- the sense that it provides all the configuration information and so the +-- final configure process will be independent of the environment. +-- +data ConfiguredPackage loc = ConfiguredPackage + (SourcePackage loc) -- package info, including repo + FlagAssignment -- complete flag assignment for the package + [OptionalStanza] -- list of enabled optional stanzas for the package + (ComponentDeps [ConfiguredId]) + -- set of exact dependencies (installed or source). + -- These must be consistent with the 'buildDepends' + -- in the 'PackageDescription' that you'd get by + -- applying the flag assignment and optional stanzas. + deriving (Eq, Show, Generic) + +instance Binary loc => Binary (ConfiguredPackage loc) + +instance Package (ConfiguredPackage loc) where + packageId (ConfiguredPackage pkg _ _ _) = packageId pkg + +instance HasUnitId (ConfiguredPackage loc) where + installedUnitId = fakeUnitId . packageId + +-- | In order to reuse the implementation of PackageIndex which relies on +-- 'UnitId', we need to be able to synthesize these IDs prior +-- to installation. Eventually, we'll move to a representation of +-- 'UnitId' which can be properly computed before compilation +-- (of course, it's a bit of a misnomer since the packages are not actually +-- installed yet.) In any case, we'll synthesize temporary installed package +-- IDs to use as keys during install planning. These should never be written +-- out! Additionally, they need to be guaranteed unique within the install +-- plan. +fakeUnitId :: PackageId -> UnitId +fakeUnitId = mkUnitId . (".fake."++) . display diff --git a/cabal-solver/Distribution/Solver/Types/OptionalStanza.hs b/cabal-solver/Distribution/Solver/Types/OptionalStanza.hs new file mode 100644 index 00000000000..eac3e6915c0 --- /dev/null +++ b/cabal-solver/Distribution/Solver/Types/OptionalStanza.hs @@ -0,0 +1,36 @@ +{-# LANGUAGE DeriveGeneric #-} +module Distribution.Solver.Types.OptionalStanza + ( OptionalStanza(..) + , enableStanzas + ) where + +import Distribution.PackageDescription + ( GenericPackageDescription(..) + , benchmarkEnabled + , testEnabled) +import Distribution.PackageDescription.Configuration + ( mapTreeData + ) +import Distribution.Compat.Binary (Binary(..)) +import GHC.Generics (Generic) + +data OptionalStanza + = TestStanzas + | BenchStanzas + deriving (Eq, Ord, Enum, Bounded, Show, Generic) + +instance Binary OptionalStanza + +enableStanzas + :: [OptionalStanza] + -> GenericPackageDescription + -> GenericPackageDescription +enableStanzas stanzas gpkg = gpkg + { condBenchmarks = flagBenchmarks $ condBenchmarks gpkg + , condTestSuites = flagTests $ condTestSuites gpkg + } + where + enableTest t = t { testEnabled = TestStanzas `elem` stanzas } + enableBenchmark bm = bm { benchmarkEnabled = BenchStanzas `elem` stanzas } + flagBenchmarks = map (\(n, bm) -> (n, mapTreeData enableBenchmark bm)) + flagTests = map (\(n, t) -> (n, mapTreeData enableTest t)) diff --git a/cabal-solver/Distribution/Solver/Types/SourcePackage.hs b/cabal-solver/Distribution/Solver/Types/SourcePackage.hs new file mode 100644 index 00000000000..f88cf37e675 --- /dev/null +++ b/cabal-solver/Distribution/Solver/Types/SourcePackage.hs @@ -0,0 +1,29 @@ +{-# LANGUAGE DeriveGeneric #-} +module Distribution.Solver.Types.SourcePackage + ( PackageDescriptionOverride + , SourcePackage(..) + ) where + +import Distribution.Package (PackageId, Package(..)) +import Distribution.PackageDescription (GenericPackageDescription(..)) +import Distribution.Compat.Binary (Binary(..)) +import GHC.Generics (Generic) +import Data.ByteString.Lazy (ByteString) + +-- | A package description along with the location of the package sources. +-- +data SourcePackage loc = SourcePackage { + packageInfoId :: PackageId, + packageDescription :: GenericPackageDescription, + packageSource :: loc, + packageDescrOverride :: PackageDescriptionOverride + } + deriving (Eq, Show, Generic) + +instance (Binary loc) => Binary (SourcePackage loc) + +-- | We sometimes need to override the .cabal file in the tarball with +-- the newer one from the package index. +type PackageDescriptionOverride = Maybe ByteString + +instance Package (SourcePackage a) where packageId = packageInfoId diff --git a/cabal-solver/LICENSE b/cabal-solver/LICENSE new file mode 100644 index 00000000000..1193d3b8d0f --- /dev/null +++ b/cabal-solver/LICENSE @@ -0,0 +1,34 @@ +Copyright (c) 2003-2014, Isaac Jones, Simon Marlow, Martin Sjögren, + Bjorn Bringert, Krasimir Angelov, + Malcolm Wallace, Ross Patterson, Ian Lynagh, + Duncan Coutts, Thomas Schilling, + Johan Tibell, Mikhail Glushenkov +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * Neither the name of Isaac Jones nor the names of other + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/cabal-solver/Setup.hs b/cabal-solver/Setup.hs new file mode 100644 index 00000000000..9a994af677b --- /dev/null +++ b/cabal-solver/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/cabal-solver/cabal-solver.cabal b/cabal-solver/cabal-solver.cabal new file mode 100644 index 00000000000..7e7409cf8b8 --- /dev/null +++ b/cabal-solver/cabal-solver.cabal @@ -0,0 +1,94 @@ +name: cabal-solver +version: 1.25.0.0 +copyright: 2003-2006, Isaac Jones + 2005-2011, Duncan Coutts +license: BSD3 +license-file: LICENSE +author: Isaac Jones + Duncan Coutts +maintainer: cabal-devel@haskell.org +homepage: http://www.haskell.org/cabal/ +bug-reports: https://github.com/haskell/cabal/issues +synopsis: Solver used by cabal-install +description: + This is the solver used by cabal-install. +category: Distribution +cabal-version: >=1.10 +build-type: Simple + +-- XXX: Move relevant READMEs, etc. See extra-source-files for Cabal/cabal-install + +source-repository head + type: git + location: https://github.com/haskell/cabal/ + subdir: cabal-solver + +library + build-depends: + array >= 0.1 && < 0.6, + base >= 4.5 && < 5, + bytestring >= 0.9 && < 1, + Cabal >= 1.25 && < 1.26, + containers >= 0.4 && < 0.6, + mtl >= 2.0 && < 3 + + ghc-options: -Wall -fno-ignore-asserts -fwarn-tabs + + exposed-modules: + Distribution.Solver.ComponentDeps + Distribution.Solver.Modular + Distribution.Solver.Modular.Internal.LabeledGraph + Distribution.Solver.Modular.Internal.PSQ + Distribution.Solver.PackageIndex + Distribution.Solver.PkgConfigDb + Distribution.Solver.PackageUtils + Distribution.Solver.Types + Distribution.Solver.Types.ConfiguredId + Distribution.Solver.Types.ConfiguredPackage + Distribution.Solver.Types.OptionalStanza + Distribution.Solver.Types.SourcePackage + other-modules: + Distribution.Solver.Modular.Assignment + Distribution.Solver.Modular.Builder + Distribution.Solver.Modular.Configured + Distribution.Solver.Modular.ConfiguredConversion + Distribution.Solver.Modular.Dependency + Distribution.Solver.Modular.Explore + Distribution.Solver.Modular.Flag + Distribution.Solver.Modular.Index + Distribution.Solver.Modular.IndexConversion + Distribution.Solver.Modular.Linking + Distribution.Solver.Modular.Log + Distribution.Solver.Modular.Message + Distribution.Solver.Modular.Package + Distribution.Solver.Modular.Preference + Distribution.Solver.Modular.Solver + Distribution.Solver.Modular.Tree + Distribution.Solver.Modular.Validate + Distribution.Solver.Modular.Version + + default-language: Haskell2010 + -- starting with GHC 7.0, rely on {-# LANGUAGE CPP #-} instead + if !impl(ghc >= 7.0) + default-extensions: CPP + +-- Small, fast running tests. +Test-Suite unit-tests + type: exitcode-stdio-1.0 + main-is: UnitTests.hs + hs-source-dirs: tests + ghc-options: -Wall -fwarn-tabs + other-modules: + UnitTests.Distribution.Solver.Modular.Internal.PSQ + build-depends: + base, + cabal-solver, + tasty, + tasty-quickcheck, + QuickCheck >= 2.5 + + if arch(arm) + cc-options: -DCABAL_NO_THREADED + else + ghc-options: -threaded + default-language: Haskell2010 diff --git a/cabal-solver/tests/UnitTests.hs b/cabal-solver/tests/UnitTests.hs new file mode 100644 index 00000000000..032c15e3e51 --- /dev/null +++ b/cabal-solver/tests/UnitTests.hs @@ -0,0 +1,21 @@ +{-# LANGUAGE ScopedTypeVariables #-} + +module Main + where + +import Test.Tasty + +import qualified UnitTests.Distribution.Solver.Modular.Internal.PSQ + +tests :: TestTree +tests = + testGroup "Unit Tests" + [ testGroup "UnitTests.Distribution.Solver.Modular.Internal.PSQ" + UnitTests.Distribution.Solver.Modular.Internal.PSQ.tests + ] + +main :: IO () +main = do + defaultMainWithIngredients + defaultIngredients + tests diff --git a/cabal-install/tests/UnitTests/Distribution/Client/Dependency/Modular/PSQ.hs b/cabal-solver/tests/UnitTests/Distribution/Solver/Modular/Internal/PSQ.hs similarity index 80% rename from cabal-install/tests/UnitTests/Distribution/Client/Dependency/Modular/PSQ.hs rename to cabal-solver/tests/UnitTests/Distribution/Solver/Modular/Internal/PSQ.hs index b24e028a2d1..c85c8790016 100644 --- a/cabal-install/tests/UnitTests/Distribution/Client/Dependency/Modular/PSQ.hs +++ b/cabal-solver/tests/UnitTests/Distribution/Solver/Modular/Internal/PSQ.hs @@ -1,8 +1,8 @@ -module UnitTests.Distribution.Client.Dependency.Modular.PSQ ( +module UnitTests.Distribution.Solver.Modular.Internal.PSQ ( tests ) where -import Distribution.Client.Dependency.Modular.PSQ +import Distribution.Solver.Modular.Internal.PSQ import Test.Tasty import Test.Tasty.QuickCheck diff --git a/setup-dev.sh b/setup-dev.sh index f07e8a79a15..69bc1e4b0fb 100755 --- a/setup-dev.sh +++ b/setup-dev.sh @@ -32,5 +32,6 @@ setup() { } # Build -(cd ${SCRIPT_DIR}/Cabal && setup "Cabal" ) || die "Failed to build Cabal" -(cd ${SCRIPT_DIR}/cabal-install && setup "cabal-install" ../Cabal) || die "Failed to build cabal-install" +(cd ${SCRIPT_DIR}/Cabal && setup "Cabal" ) || die "Failed to build Cabal" +(cd ${SCRIPT_DIR}/cabal-solver && setup "cabal-solver" ../Cabal ) || die "Failed to build cabal-solver" +(cd ${SCRIPT_DIR}/cabal-install && setup "cabal-install" ../cabal-solver ../Cabal) || die "Failed to build cabal-install"