Commit b9ce4337 authored by Duncan Coutts's avatar Duncan Coutts Committed by Francesco Gazzetta

Move PackageSpecifier into common Types module

It's currently in the old Targets module, but we'll need it in the
new-build code too soon, and it's not really that closely related to
targets, so it makes sense to have it live in the common Types module.
parent c6f8d1b0
......@@ -71,6 +71,7 @@ import Distribution.Client.SolverInstallPlan (SolverInstallPlan)
import qualified Distribution.Client.SolverInstallPlan as SolverInstallPlan
import Distribution.Client.Types
( SourcePackageDb(SourcePackageDb)
, PackageSpecifier(..), pkgSpecifierTarget, pkgSpecifierConstraints
, UnresolvedPkgLoc, UnresolvedSourcePackage
, AllowNewer(..), AllowOlder(..), RelaxDeps(..), RelaxedDep(..)
, RelaxDepScope(..), RelaxDepMod(..), RelaxDepSubject(..), isRelaxDeps
......@@ -80,7 +81,6 @@ import Distribution.Client.Dependency.Types
, PackagesPreferenceDefault(..) )
import Distribution.Client.Sandbox.Types
( SandboxPackageInfo(..) )
import Distribution.Client.Targets
import Distribution.Package
( PackageName, mkPackageName, PackageIdentifier(PackageIdentifier), PackageId
, Package(..), packageName, packageVersion )
......
......@@ -47,10 +47,9 @@ import qualified Distribution.Solver.Types.PackageIndex as PackageIndex
import Distribution.Solver.Types.SourcePackage
import Distribution.Client.Types
( SourcePackageDb(..)
, UnresolvedSourcePackage )
( SourcePackageDb(..), PackageSpecifier(..), UnresolvedSourcePackage )
import Distribution.Client.Targets
( UserTarget, resolveUserTargets, PackageSpecifier(..) )
( UserTarget, resolveUserTargets )
import Distribution.Client.Setup
( GlobalFlags(..), ListFlags(..), InfoFlags(..)
, RepoContext(..) )
......
......@@ -18,11 +18,6 @@ module Distribution.Client.Targets (
UserTarget(..),
readUserTargets,
-- * Package specifiers
PackageSpecifier(..),
pkgSpecifierTarget,
pkgSpecifierConstraints,
-- * Resolving user targets to package specifiers
resolveUserTargets,
......@@ -60,11 +55,9 @@ import Distribution.Package
, PackageIdentifier(..), packageName, packageVersion )
import Distribution.Types.Dependency
import Distribution.Client.Types
( PackageLocation(..)
, ResolvedPkgLoc, UnresolvedSourcePackage )
( PackageLocation(..), ResolvedPkgLoc, UnresolvedSourcePackage
, PackageSpecifier(..) )
import Distribution.Solver.Types.ConstraintSource
import Distribution.Solver.Types.LabeledPackageConstraint
import Distribution.Solver.Types.OptionalStanza
import Distribution.Solver.Types.PackageConstraint
import Distribution.Solver.Types.PackagePath
......@@ -170,46 +163,6 @@ data UserTarget =
deriving (Show,Eq)
-- ------------------------------------------------------------
-- * Package specifier
-- ------------------------------------------------------------
-- | A fully or partially resolved reference to a package.
--
data PackageSpecifier pkg =
-- | A partially specified reference to a package (either source or
-- installed). It is specified by package name and optionally some
-- required properties. Use a dependency resolver to pick a specific
-- package satisfying these properties.
--
NamedPackage PackageName [PackageProperty]
-- | A fully specified source package.
--
| SpecificSourcePackage pkg
deriving (Eq, Show, Generic)
instance Binary pkg => Binary (PackageSpecifier pkg)
pkgSpecifierTarget :: Package pkg => PackageSpecifier pkg -> PackageName
pkgSpecifierTarget (NamedPackage name _) = name
pkgSpecifierTarget (SpecificSourcePackage pkg) = packageName pkg
pkgSpecifierConstraints :: Package pkg
=> PackageSpecifier pkg -> [LabeledPackageConstraint]
pkgSpecifierConstraints (NamedPackage name props) = map toLpc props
where
toLpc prop = LabeledPackageConstraint
(PackageConstraint (scopeToplevel name) prop)
ConstraintSourceUserTarget
pkgSpecifierConstraints (SpecificSourcePackage pkg) =
[LabeledPackageConstraint pc ConstraintSourceUserTarget]
where
pc = PackageConstraint
(ScopeTarget $ packageName pkg)
(PackagePropertyVersion $ thisVersion (packageVersion pkg))
-- ------------------------------------------------------------
-- * Parsing and checking user targets
-- ------------------------------------------------------------
......
......@@ -25,13 +25,14 @@ import Distribution.Client.Compat.Prelude
import Distribution.Package
( Package(..), HasMungedPackageId(..), HasUnitId(..)
, PackageIdentifier(..), PackageInstalled(..), newSimpleUnitId )
, PackageIdentifier(..), packageVersion, packageName
, PackageInstalled(..), newSimpleUnitId )
import Distribution.InstalledPackageInfo
( InstalledPackageInfo, installedComponentId, sourceComponentName )
import Distribution.PackageDescription
( FlagAssignment )
import Distribution.Version
( VersionRange, nullVersion )
( VersionRange, nullVersion, thisVersion )
import Distribution.Types.ComponentId
( ComponentId )
import Distribution.Types.MungedPackageId
......@@ -51,7 +52,10 @@ import Distribution.Solver.Types.PackageIndex
import qualified Distribution.Solver.Types.ComponentDeps as CD
import Distribution.Solver.Types.ComponentDeps
( ComponentDeps )
import Distribution.Solver.Types.ConstraintSource
import Distribution.Solver.Types.LabeledPackageConstraint
import Distribution.Solver.Types.OptionalStanza
import Distribution.Solver.Types.PackageConstraint
import Distribution.Solver.Types.PackageFixedDeps
import Distribution.Solver.Types.SourcePackage
import Distribution.Compat.Graph (IsNode(..))
......@@ -211,6 +215,48 @@ type ReadyPackage = GenericReadyPackage (ConfiguredPackage UnresolvedPkgLoc)
-- | Convenience alias for 'SourcePackage UnresolvedPkgLoc'.
type UnresolvedSourcePackage = SourcePackage UnresolvedPkgLoc
-- ------------------------------------------------------------
-- * Package specifier
-- ------------------------------------------------------------
-- | A fully or partially resolved reference to a package.
--
data PackageSpecifier pkg =
-- | A partially specified reference to a package (either source or
-- installed). It is specified by package name and optionally some
-- required properties. Use a dependency resolver to pick a specific
-- package satisfying these properties.
--
NamedPackage PackageName [PackageProperty]
-- | A fully specified source package.
--
| SpecificSourcePackage pkg
deriving (Eq, Show, Generic)
instance Binary pkg => Binary (PackageSpecifier pkg)
pkgSpecifierTarget :: Package pkg => PackageSpecifier pkg -> PackageName
pkgSpecifierTarget (NamedPackage name _) = name
pkgSpecifierTarget (SpecificSourcePackage pkg) = packageName pkg
pkgSpecifierConstraints :: Package pkg
=> PackageSpecifier pkg -> [LabeledPackageConstraint]
pkgSpecifierConstraints (NamedPackage name props) = map toLpc props
where
toLpc prop = LabeledPackageConstraint
(PackageConstraint (scopeToplevel name) prop)
ConstraintSourceUserTarget
pkgSpecifierConstraints (SpecificSourcePackage pkg) =
[LabeledPackageConstraint pc ConstraintSourceUserTarget]
where
pc = PackageConstraint
(ScopeTarget $ packageName pkg)
(PackagePropertyVersion $ thisVersion (packageVersion pkg))
-- ------------------------------------------------------------
-- * Package locations and repositories
-- ------------------------------------------------------------
......
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