Commit 832f5f7f authored by Francesco Gazzetta's avatar Francesco Gazzetta

Add a PackageVersionConstraint type

Dependency is used in two seemingly related but now incompatible ways:

* As a dependency specification ("I want this component from this package,
  version range xy")
* As a constraint ("Package p must be in version range xy")

This commit begins to separate the two concepts.
parent 4fac7e15
......@@ -369,6 +369,7 @@ library
Distribution.Types.VersionRange
Distribution.Types.VersionInterval
Distribution.Types.GivenComponent
Distribution.Types.PackageVersionConstraint
Distribution.Utils.Generic
Distribution.Utils.NubList
Distribution.Utils.ShortText
......
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
module Distribution.Types.PackageVersionConstraint
( PackageVersionConstraint(..)
) where
import Prelude ()
import Distribution.Compat.Prelude
import qualified Distribution.Compat.ReadP as Parse
import Distribution.Text
import Distribution.Pretty
import Text.PrettyPrint ((<+>))
import Distribution.Types.VersionRange
import Distribution.Types.PackageName
-- | A version constraint on a package. Different from 'ExeDependency' and
-- 'Dependency' since it does not specify the need for a component, not even
-- the main library.
-- There are a few places in the codebase where 'Dependency' is used where
-- 'PackageVersionConstraint' should be used instead (#5570).
data PackageVersionConstraint = PackageVersionConstraint PackageName VersionRange
deriving (Generic, Read, Show, Eq, Typeable, Data)
instance Binary PackageVersionConstraint
instance NFData PackageVersionConstraint where rnf = genericRnf
instance Pretty PackageVersionConstraint where
pretty (PackageVersionConstraint name ver) = pretty name <+> pretty ver
instance Text PackageVersionConstraint where
parse = do name <- parse
Parse.skipSpaces
ver <- parse Parse.<++ return anyVersion
Parse.skipSpaces
return (PackageVersionConstraint name ver)
......@@ -63,9 +63,11 @@ import Distribution.Simple.PackageIndex
import Distribution.Package
( Package(..), packageName, PackageId )
import Distribution.Types.Dependency
( Dependency(..), thisPackageVersion )
( thisPackageVersion )
import Distribution.Types.GivenComponent
( GivenComponent(..) )
import Distribution.Types.PackageVersionConstraint
( PackageVersionConstraint(..) )
import qualified Distribution.PackageDescription as PkgDesc
import Distribution.PackageDescription.Parsec
( readGenericPackageDescription )
......@@ -278,7 +280,7 @@ checkConfigExFlags verbosity installedPkgIndex sourcePkgIndex flags = do
where
unknownConstraints = filter (unknown . userConstraintPackageName . fst) $
configExConstraints flags
unknownPreferences = filter (unknown . \(Dependency name _ _) -> name) $
unknownPreferences = filter (unknown . \(PackageVersionConstraint name _) -> name) $
configPreferences flags
unknown pkg = null (lookupPackageName installedPkgIndex pkg)
&& not (elemByPackageName sourcePkgIndex pkg)
......@@ -325,7 +327,7 @@ planLocalPackage verbosity comp platform configFlags configExFlags
. addPreferences
-- preferences from the config file or command line
[ PackageVersionPreference name ver
| Dependency name ver _ <- configPreferences configExFlags ]
| PackageVersionConstraint name ver <- configPreferences configExFlags ]
. addConstraints
-- version constraints from the config file or command line
......
......@@ -142,9 +142,11 @@ import Distribution.Package
, Package(..), HasMungedPackageId(..), HasUnitId(..)
, UnitId )
import Distribution.Types.Dependency
( Dependency(..), thisPackageVersion )
( thisPackageVersion )
import Distribution.Types.GivenComponent
( GivenComponent(..) )
import Distribution.Types.PackageVersionConstraint
( PackageVersionConstraint(..) )
import Distribution.Types.MungedPackageId
import qualified Distribution.PackageDescription as PackageDescription
import Distribution.PackageDescription
......@@ -407,7 +409,7 @@ planPackages verbosity comp platform mSandboxPkgInfo solver
. addPreferences
-- preferences from the config file or command line
[ PackageVersionPreference name ver
| Dependency name ver _ <- configPreferences configExFlags ]
| PackageVersionConstraint name ver <- configPreferences configExFlags ]
. addConstraints
-- version constraints from the config file or command line
......
......@@ -82,7 +82,8 @@ import Distribution.Solver.Types.PackageConstraint
import Distribution.Package
( PackageName, PackageId, packageId, UnitId )
import Distribution.Types.Dependency
import Distribution.Types.PackageVersionConstraint
( PackageVersionConstraint(..) )
import Distribution.System
( Platform )
import Distribution.Types.GenericPackageDescription
......@@ -638,7 +639,7 @@ data ProjectPackageLocation =
| ProjectPackageLocalTarball FilePath
| ProjectPackageRemoteTarball URI
| ProjectPackageRemoteRepo SourceRepo
| ProjectPackageNamed Dependency
| ProjectPackageNamed PackageVersionConstraint
deriving Show
......@@ -992,7 +993,7 @@ fetchAndReadSourcePackages verbosity distDirLayout
let pkgsNamed =
[ NamedPackage pkgname [PackagePropertyVersion verrange]
| ProjectPackageNamed (Dependency pkgname verrange _) <- pkgLocations ]
| ProjectPackageNamed (PackageVersionConstraint pkgname verrange) <- pkgLocations ]
return $ concat
[ pkgsLocalDirectory
......
......@@ -80,6 +80,8 @@ import Distribution.Client.ParseUtils
import Distribution.Simple.Command
( CommandUI(commandOptions), ShowOrParseArgs(..)
, OptionField, option, reqArg' )
import Distribution.Types.PackageVersionConstraint
( PackageVersionConstraint )
import qualified Data.Map as Map
------------------------------------------------------------------
......@@ -99,7 +101,7 @@ data LegacyProjectConfig = LegacyProjectConfig {
legacyPackages :: [String],
legacyPackagesOptional :: [String],
legacyPackagesRepo :: [SourceRepo],
legacyPackagesNamed :: [Dependency],
legacyPackagesNamed :: [PackageVersionConstraint],
legacySharedConfig :: LegacySharedConfig,
legacyAllConfig :: LegacyPackageConfig,
......
......@@ -37,7 +37,8 @@ import Distribution.Solver.Types.ConstraintSource
import Distribution.Package
( PackageName, PackageId, UnitId )
import Distribution.Types.Dependency
import Distribution.Types.PackageVersionConstraint
( PackageVersionConstraint )
import Distribution.Version
( Version )
import Distribution.System
......@@ -105,7 +106,7 @@ data ProjectConfig
projectPackagesRepo :: [SourceRepo],
-- | Packages in this project from hackage repositories.
projectPackagesNamed :: [Dependency],
projectPackagesNamed :: [PackageVersionConstraint],
-- See respective types for an explanation of what these
-- values are about:
......@@ -181,7 +182,7 @@ data ProjectConfigShared
-- solver configuration
projectConfigConstraints :: [(UserConstraint, ConstraintSource)],
projectConfigPreferences :: [Dependency],
projectConfigPreferences :: [PackageVersionConstraint],
projectConfigCabalVersion :: Flag Version, --TODO: [required eventually] unused
projectConfigSolver :: Flag PreSolver,
projectConfigAllowOlder :: Maybe AllowOlder,
......@@ -361,7 +362,7 @@ data SolverSettings
solverSettingRemoteRepos :: [RemoteRepo], -- ^ Available Hackage servers.
solverSettingLocalRepos :: [FilePath],
solverSettingConstraints :: [(UserConstraint, ConstraintSource)],
solverSettingPreferences :: [Dependency],
solverSettingPreferences :: [PackageVersionConstraint],
solverSettingFlagAssignment :: FlagAssignment, -- ^ For all local packages
solverSettingFlagAssignments :: Map PackageName FlagAssignment,
solverSettingCabalVersion :: Maybe Version, --TODO: [required eventually] unused
......
......@@ -115,6 +115,7 @@ import Distribution.Types.ComponentName
import Distribution.Types.LibraryName
import Distribution.Types.GivenComponent
(GivenComponent(..))
import Distribution.Types.PackageVersionConstraint
import Distribution.Types.PkgconfigDependency
import Distribution.Types.UnqualComponentName
import Distribution.System
......@@ -988,7 +989,7 @@ planPackages verbosity comp platform solver SolverSettings{..}
. addPreferences
-- preferences from the config file or command line
[ PackageVersionPreference name ver
| Dependency name ver _ <- solverSettingPreferences ]
| PackageVersionConstraint name ver <- solverSettingPreferences ]
. addConstraints
-- version constraints from the config file or command line
......
......@@ -114,6 +114,8 @@ import Distribution.Package
import Distribution.Types.Dependency
import Distribution.Types.GivenComponent
( GivenComponent(..) )
import Distribution.Types.PackageVersionConstraint
( PackageVersionConstraint(..) )
import Distribution.Types.UnqualComponentName
( unqualComponentNameToPackageName )
import Distribution.PackageDescription
......@@ -636,7 +638,7 @@ configCompilerAux' configFlags =
data ConfigExFlags = ConfigExFlags {
configCabalVersion :: Flag Version,
configExConstraints:: [(UserConstraint, ConstraintSource)],
configPreferences :: [Dependency],
configPreferences :: [PackageVersionConstraint],
configSolver :: Flag PreSolver,
configAllowNewer :: Maybe AllowNewer,
configAllowOlder :: Maybe AllowOlder
......
......@@ -22,6 +22,7 @@ import Control.Monad
import Distribution.Version
import Distribution.Types.Dependency
import Distribution.Types.PackageVersionConstraint
import Distribution.Types.UnqualComponentName
import Distribution.Types.LibraryName
import Distribution.Package
......@@ -123,6 +124,9 @@ instance Arbitrary PackageName where
instance Arbitrary Dependency where
arbitrary = Dependency <$> arbitrary <*> arbitrary <*> fmap getNonMEmpty arbitrary
instance Arbitrary PackageVersionConstraint where
arbitrary = PackageVersionConstraint <$> arbitrary <*> arbitrary
instance Arbitrary UnqualComponentName where
-- same rules as package names
arbitrary = packageNameToUnqualComponentName <$> arbitrary
......
......@@ -24,6 +24,7 @@ import qualified Distribution.Compat.ReadP as Parse
import Distribution.Simple.Utils
import Distribution.Simple.Program.Types
import Distribution.Simple.Program.Db
import Distribution.Types.PackageVersionConstraint
import Distribution.Client.Types
import Distribution.Client.Dependency.Types
......@@ -166,7 +167,7 @@ prop_roundtrip_printparse_all config =
prop_roundtrip_printparse_packages :: [PackageLocationString]
-> [PackageLocationString]
-> [SourceRepo]
-> [Dependency]
-> [PackageVersionConstraint]
-> Bool
prop_roundtrip_printparse_packages pkglocstrs1 pkglocstrs2 repos named =
roundtrip_printparse
......
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