Commit b2e5c1f9 authored by Duncan Coutts's avatar Duncan Coutts
Browse files

Move common dependency resolver types into shared module

parent 2ec49343
......@@ -25,6 +25,8 @@ import qualified Hackage.InstallPlan as InstallPlan
import Hackage.InstallPlan (InstallPlan)
import Hackage.Types
( UnresolvedDependency(..), AvailablePackage(..) )
import Hackage.Dependency.Types
( DependencyResolver )
import Distribution.Package
( PackageIdentifier(..), packageVersion, packageName
, Dependency(..), Package(..), PackageFixedDeps(..) )
......@@ -41,6 +43,9 @@ import Data.List (maximumBy)
import Data.Monoid (Monoid(mempty))
import Control.Exception (assert)
defaultResolver :: DependencyResolver a
defaultResolver = naiveResolver
resolveDependencies :: OS
-> Arch
-> CompilerId
......@@ -49,7 +54,7 @@ resolveDependencies :: OS
-> [UnresolvedDependency]
-> Either [Dependency] (InstallPlan a)
resolveDependencies os arch comp (Just installed) available deps =
dependencyResolver naiveResolver
dependencyResolver defaultResolver
os arch comp installed available deps
resolveDependencies os arch comp Nothing available deps =
......@@ -70,14 +75,6 @@ hideBasePackage :: Package p => PackageIndex p -> PackageIndex p
hideBasePackage = PackageIndex.deletePackageName "base"
. PackageIndex.deletePackageName "ghc-prim"
type DependencyResolver a = OS
-> Arch
-> CompilerId
-> PackageIndex InstalledPackageInfo
-> PackageIndex AvailablePackage
-> [UnresolvedDependency]
-> Either [Dependency] [InstallPlan.PlanPackage a]
dependencyResolver
:: DependencyResolver a
-> OS -> Arch -> CompilerId
......
......@@ -17,19 +17,16 @@ module Hackage.Dependency.Bogus (
import qualified Distribution.Simple.PackageIndex as PackageIndex
import Distribution.Simple.PackageIndex (PackageIndex)
import Distribution.InstalledPackageInfo (InstalledPackageInfo)
import qualified Hackage.InstallPlan as InstallPlan
import Hackage.Types
( UnresolvedDependency(..), AvailablePackage(..)
, ConfiguredPackage(..) )
import Hackage.Dependency.Types
( DependencyResolver )
import Distribution.Package
( PackageIdentifier(..), Dependency(..), Package(..) )
import Distribution.PackageDescription.Configuration
( finalizePackageDescription)
import Distribution.Compiler
( CompilerId )
import Distribution.System
( OS, Arch )
import Distribution.Simple.Utils (comparing)
import Data.List (maximumBy)
......@@ -39,13 +36,7 @@ import Data.List (maximumBy)
-- We need this for hugs and nhc98 which do not track installed packages.
-- We just pretend that everything is installed and hope for the best.
--
bogusResolver :: OS
-> Arch
-> CompilerId
-> PackageIndex InstalledPackageInfo
-> PackageIndex AvailablePackage
-> [UnresolvedDependency]
-> Either [Dependency] [InstallPlan.PlanPackage a]
bogusResolver :: DependencyResolver a
bogusResolver os arch comp _ available deps =
case unzipEithers (map resolveFromAvailable deps) of
(ok, []) -> Right ok
......
......@@ -24,6 +24,8 @@ import qualified Hackage.InstallPlan as InstallPlan
import Hackage.Types
( UnresolvedDependency(..), AvailablePackage(..)
, ConfiguredPackage(..) )
import Hackage.Dependency.Types
( DependencyResolver )
import Distribution.Package
( PackageIdentifier(..), Dependency(..), Package(..) )
import Distribution.PackageDescription
......@@ -44,13 +46,7 @@ import Data.List (maximumBy)
import Data.Maybe (fromMaybe)
import Data.Monoid (Monoid(mappend))
naiveResolver :: OS
-> Arch
-> CompilerId
-> PackageIndex InstalledPackageInfo
-> PackageIndex AvailablePackage
-> [UnresolvedDependency]
-> Either [Dependency] [InstallPlan.PlanPackage a]
naiveResolver :: DependencyResolver a
naiveResolver os arch comp installed available deps =
packagesToInstall installed
[ resolveDependency os arch comp installed available dep flags
......
-----------------------------------------------------------------------------
-- |
-- Module : Hackage.Dependency.Types
-- Copyright : (c) Duncan Coutts 2008
-- License : BSD-like
--
-- Maintainer : cabal-devel@haskell.org
-- Stability : provisional
-- Portability : portable
--
-- Common types for dependency resolution.
-----------------------------------------------------------------------------
module Hackage.Dependency.Types (
DependencyResolver,
) where
import Hackage.Types
( UnresolvedDependency(..), AvailablePackage(..) )
import qualified Hackage.InstallPlan as InstallPlan
import Distribution.Package
( Dependency )
import Distribution.InstalledPackageInfo
( InstalledPackageInfo )
import Distribution.Simple.PackageIndex
( PackageIndex )
import Distribution.Compiler
( CompilerId )
import Distribution.System
( OS, Arch )
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 a = OS
-> Arch
-> CompilerId
-> PackageIndex InstalledPackageInfo
-> PackageIndex AvailablePackage
-> [UnresolvedDependency]
-> Either [Dependency] [InstallPlan.PlanPackage a]
......@@ -41,6 +41,7 @@ Executable cabal
Hackage.Dependency
Hackage.Dependency.Bogus
Hackage.Dependency.Naive
Hackage.Dependency.Types
Hackage.Fetch
Hackage.HttpUtils
Hackage.IndexUtils
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment