module Distribution.Types.Dependency
( Dependency(..)
, depPkgName
, depVerRange
, thisPackageVersion
, notThisPackageVersion
, simplifyDependency
) where
import Prelude ()
import Distribution.Compat.Prelude
import Distribution.Version ( VersionRange, thisVersion
, notThisVersion, anyVersion
, simplifyVersionRange )
import qualified Distribution.Compat.ReadP as Parse
import Distribution.Compat.ReadP
import Distribution.Text
import Distribution.Package
import Text.PrettyPrint ((<+>))
data Dependency = Dependency PackageName VersionRange
deriving (Generic, Read, Show, Eq, Typeable, Data)
depPkgName :: Dependency -> PackageName
depPkgName (Dependency pn _) = pn
depVerRange :: Dependency -> VersionRange
depVerRange (Dependency _ vr) = vr
instance Binary Dependency
instance NFData Dependency where rnf = genericRnf
instance Text Dependency where
disp (Dependency name ver) =
disp name <+> disp ver
parse = do name <- parse
Parse.skipSpaces
ver <- parse <++ return anyVersion
Parse.skipSpaces
return (Dependency name ver)
thisPackageVersion :: PackageIdentifier -> Dependency
thisPackageVersion (PackageIdentifier n v) =
Dependency n (thisVersion v)
notThisPackageVersion :: PackageIdentifier -> Dependency
notThisPackageVersion (PackageIdentifier n v) =
Dependency n (notThisVersion v)
simplifyDependency :: Dependency -> Dependency
simplifyDependency (Dependency name range) =
Dependency name (simplifyVersionRange range)