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

Move Dependency and it's show and parser into Package module

Rather than having it in Version and its parser elsewhere.
The Package module already imports the Version module which exports the
VersionRange type.
parent d28e1b90
...@@ -44,6 +44,10 @@ module Distribution.Package ( ...@@ -44,6 +44,10 @@ module Distribution.Package (
PackageIdentifier(..), PackageIdentifier(..),
showPackageId, parsePackageId, parsePackageName, showPackageId, parsePackageId, parsePackageName,
-- * Package dependencies
Dependency(..),
showDependency, parseDependency,
-- * Package classes -- * Package classes
Package(..), packageName, packageVersion, Package(..), packageName, packageVersion,
PackageFixedDeps(..), PackageFixedDeps(..),
...@@ -51,6 +55,8 @@ module Distribution.Package ( ...@@ -51,6 +55,8 @@ module Distribution.Package (
import Distribution.Version import Distribution.Version
import Distribution.Compat.ReadP as ReadP import Distribution.Compat.ReadP as ReadP
import qualified Text.PrettyPrint as Pretty
import Text.PrettyPrint ((<+>))
import Data.Char ( isDigit, isAlphaNum ) import Data.Char ( isDigit, isAlphaNum )
import Data.List ( intersperse ) import Data.List ( intersperse )
...@@ -84,6 +90,24 @@ parsePackageId = do ...@@ -84,6 +90,24 @@ parsePackageId = do
v <- (ReadP.char '-' >> parseVersion) <++ return (Version [] []) v <- (ReadP.char '-' >> parseVersion) <++ return (Version [] [])
return PackageIdentifier{pkgName=n,pkgVersion=v} return PackageIdentifier{pkgName=n,pkgVersion=v}
-- ------------------------------------------------------------
-- * Package dependencies
-- ------------------------------------------------------------
data Dependency = Dependency String VersionRange
deriving (Read, Show, Eq)
showDependency :: Dependency -> Pretty.Doc
showDependency (Dependency name ver) =
Pretty.text name <+> Pretty.text (showVersionRange ver)
parseDependency :: ReadP r Dependency
parseDependency = do name <- parsePackageName
skipSpaces
ver <- parseVersionRange <++ return AnyVersion
skipSpaces
return $ Dependency name ver
-- | Class of things that can be identified by a 'PackageIdentifier' -- | Class of things that can be identified by a 'PackageIdentifier'
-- --
-- Types in this class are all notions of a package. This allows us to have -- Types in this class are all notions of a package. This allows us to have
......
...@@ -79,10 +79,11 @@ import Data.List (nub) ...@@ -79,10 +79,11 @@ import Data.List (nub)
import Data.Monoid (Monoid(mempty, mappend)) import Data.Monoid (Monoid(mempty, mappend))
import Text.PrettyPrint.HughesPJ import Text.PrettyPrint.HughesPJ
import Distribution.Package (PackageIdentifier(PackageIdentifier), Package(..)) import Distribution.Package
( PackageIdentifier(PackageIdentifier), Dependency, Package(..) )
import Distribution.Version (Version(Version), VersionRange(AnyVersion)) import Distribution.Version (Version(Version), VersionRange(AnyVersion))
import Distribution.License (License(AllRightsReserved)) import Distribution.License (License(AllRightsReserved))
import Distribution.Version (Dependency, showVersionRange) import Distribution.Version (showVersionRange)
import Distribution.Compiler (CompilerFlavor, showCompilerFlavor) import Distribution.Compiler (CompilerFlavor, showCompilerFlavor)
import Distribution.System (OS, showOS, Arch, showArch) import Distribution.System (OS, showOS, Arch, showArch)
import Distribution.Simple.Utils (currentDir) import Distribution.Simple.Utils (currentDir)
......
...@@ -48,7 +48,7 @@ module Distribution.PackageDescription.Configuration ( ...@@ -48,7 +48,7 @@ module Distribution.PackageDescription.Configuration (
freeVars, freeVars,
) where ) where
import Distribution.Package (Package) import Distribution.Package (Package, Dependency(..))
import Distribution.PackageDescription import Distribution.PackageDescription
( GenericPackageDescription(..), PackageDescription(..) ( GenericPackageDescription(..), PackageDescription(..)
, Library(..), Executable(..), BuildInfo(..) , Library(..), Executable(..), BuildInfo(..)
...@@ -56,8 +56,7 @@ import Distribution.PackageDescription ...@@ -56,8 +56,7 @@ import Distribution.PackageDescription
import Distribution.Simple.PackageIndex (PackageIndex) import Distribution.Simple.PackageIndex (PackageIndex)
import qualified Distribution.Simple.PackageIndex as PackageIndex import qualified Distribution.Simple.PackageIndex as PackageIndex
import Distribution.Version import Distribution.Version
( Version(..), Dependency(..), VersionRange(..) ( Version(..), VersionRange(..), withinRange, parseVersionRange )
, withinRange, parseVersionRange )
import Distribution.Compiler (CompilerFlavor, readCompilerFlavor) import Distribution.Compiler (CompilerFlavor, readCompilerFlavor)
import Distribution.System import Distribution.System
( OS, readOS, Arch, readArch ) ( OS, readOS, Arch, readArch )
......
...@@ -71,9 +71,11 @@ import Distribution.ParseUtils ...@@ -71,9 +71,11 @@ import Distribution.ParseUtils
import Distribution.PackageDescription import Distribution.PackageDescription
import Distribution.Package import Distribution.Package
( PackageIdentifier(..), packageName, packageVersion ( PackageIdentifier(..), packageName, packageVersion
, parsePackageName ) , parsePackageName
import Distribution.Version (Dependency, showVersion, parseVersion, , Dependency(..), showDependency, parseDependency )
showVersionRange, parseVersionRange, isAnyVersion) import Distribution.Version
( showVersion, parseVersion
, showVersionRange, parseVersionRange, isAnyVersion )
import Distribution.Verbosity (Verbosity) import Distribution.Verbosity (Verbosity)
import Distribution.Compiler (CompilerFlavor(..)) import Distribution.Compiler (CompilerFlavor(..))
import Distribution.PackageDescription.Configuration (parseCondition, freeVars) import Distribution.PackageDescription.Configuration (parseCondition, freeVars)
......
...@@ -49,11 +49,11 @@ module Distribution.ParseUtils ( ...@@ -49,11 +49,11 @@ module Distribution.ParseUtils (
Field(..), fName, lineNo, Field(..), fName, lineNo,
FieldDescr(..), ppField, ppFields, readFields, FieldDescr(..), ppField, ppFields, readFields,
parseFilePathQ, parseTokenQ, parseFilePathQ, parseTokenQ,
parseModuleNameQ, parseDependency, parseBuildTool, parsePkgconfigDependency, parseModuleNameQ, parseBuildTool, parsePkgconfigDependency,
parseOptVersion, parsePackageNameQ, parseVersionRangeQ, parseOptVersion, parsePackageNameQ, parseVersionRangeQ,
parseTestedWithQ, parseLicenseQ, parseExtensionQ, parseTestedWithQ, parseLicenseQ, parseExtensionQ,
parseSepList, parseCommaList, parseOptCommaList, parseSepList, parseCommaList, parseOptCommaList,
showFilePath, showToken, showTestedWith, showDependency, showFreeText, showFilePath, showToken, showTestedWith, showFreeText,
field, simpleField, listField, commaListField, optsField, liftField, field, simpleField, listField, commaListField, optsField, liftField,
parseReadS, parseReadSQ, parseQuoted, parseBool, parseReadS, parseReadSQ, parseQuoted, parseBool,
...@@ -63,7 +63,7 @@ module Distribution.ParseUtils ( ...@@ -63,7 +63,7 @@ module Distribution.ParseUtils (
import Distribution.Compiler (CompilerFlavor) import Distribution.Compiler (CompilerFlavor)
import Distribution.License import Distribution.License
import Distribution.Version import Distribution.Version
import Distribution.Package ( parsePackageName ) import Distribution.Package ( parsePackageName, Dependency(..) )
import Distribution.Compat.ReadP as ReadP hiding (get) import Distribution.Compat.ReadP as ReadP hiding (get)
import Distribution.Simple.Utils (intercalate) import Distribution.Simple.Utils (intercalate)
import Language.Haskell.Extension (Extension) import Language.Haskell.Extension (Extension)
...@@ -517,13 +517,6 @@ parseBuildToolName = do ns <- sepBy1 component (ReadP.char '-') ...@@ -517,13 +517,6 @@ parseBuildToolName = do ns <- sepBy1 component (ReadP.char '-')
cs <- munch1 (\c -> isAlphaNum c || isSymbol c && c /= '-') cs <- munch1 (\c -> isAlphaNum c || isSymbol c && c /= '-')
if all isDigit cs then pfail else return cs if all isDigit cs then pfail else return cs
parseDependency :: ReadP r Dependency
parseDependency = do name <- parsePackageNameQ
skipSpaces
ver <- parseVersionRangeQ <++ return AnyVersion
skipSpaces
return $ Dependency name ver
-- pkg-config allows versions and other letters in package names, -- pkg-config allows versions and other letters in package names,
-- eg "gtk+-2.0" is a valid pkg-config package _name_. -- eg "gtk+-2.0" is a valid pkg-config package _name_.
-- It then has a package version number like 2.10.13 -- It then has a package version number like 2.10.13
...@@ -607,9 +600,6 @@ showToken str ...@@ -607,9 +600,6 @@ showToken str
showTestedWith :: (CompilerFlavor,VersionRange) -> Doc showTestedWith :: (CompilerFlavor,VersionRange) -> Doc
showTestedWith (compiler,version) = text (show compiler ++ " " ++ showVersionRange version) showTestedWith (compiler,version) = text (show compiler ++ " " ++ showVersionRange version)
showDependency :: Dependency -> Doc
showDependency (Dependency name ver) = text name <+> text (showVersionRange ver)
-- | Pretty-print free-format text, ensuring that it is vertically aligned, -- | Pretty-print free-format text, ensuring that it is vertically aligned,
-- and with blank lines replaced by dots for correct re-parsing. -- and with blank lines replaced by dots for correct re-parsing.
showFreeText :: String -> Doc showFreeText :: String -> Doc
......
...@@ -59,7 +59,8 @@ import Distribution.Simple.Compiler ...@@ -59,7 +59,8 @@ import Distribution.Simple.Compiler
, unsupportedExtensions, PackageDB(..) ) , unsupportedExtensions, PackageDB(..) )
import Distribution.Package import Distribution.Package
( PackageIdentifier(PackageIdentifier), packageVersion, Package(..) ( PackageIdentifier(PackageIdentifier), packageVersion, Package(..)
, showPackageId, parsePackageId ) , showPackageId, parsePackageId
, Dependency(..), showDependency )
import Distribution.InstalledPackageInfo import Distribution.InstalledPackageInfo
( InstalledPackageInfo, emptyInstalledPackageInfo ) ( InstalledPackageInfo, emptyInstalledPackageInfo )
import qualified Distribution.InstalledPackageInfo as InstalledPackageInfo import qualified Distribution.InstalledPackageInfo as InstalledPackageInfo
...@@ -74,8 +75,6 @@ import Distribution.PackageDescription.Configuration ...@@ -74,8 +75,6 @@ import Distribution.PackageDescription.Configuration
( finalizePackageDescription ) ( finalizePackageDescription )
import Distribution.PackageDescription.Check import Distribution.PackageDescription.Check
( PackageCheck(..), checkPackage, checkPackageFiles ) ( PackageCheck(..), checkPackage, checkPackageFiles )
import Distribution.ParseUtils
( showDependency )
import Distribution.Compat.ReadP import Distribution.Compat.ReadP
( readP_to_S ) ( readP_to_S )
import Distribution.Simple.Program import Distribution.Simple.Program
...@@ -102,7 +101,7 @@ import Distribution.Simple.Register ...@@ -102,7 +101,7 @@ import Distribution.Simple.Register
import Distribution.System import Distribution.System
( OS(..), buildOS, buildArch ) ( OS(..), buildOS, buildArch )
import Distribution.Version import Distribution.Version
( Version(..), Dependency(..), VersionRange(..), showVersion, readVersion ( Version(..), VersionRange(..), showVersion, readVersion
, showVersionRange, orLaterVersion, withinRange ) , showVersionRange, orLaterVersion, withinRange )
import Distribution.Verbosity import Distribution.Verbosity
( Verbosity, lessVerbose ) ( Verbosity, lessVerbose )
......
...@@ -53,8 +53,9 @@ import Data.Maybe (isNothing) ...@@ -53,8 +53,9 @@ import Data.Maybe (isNothing)
import Distribution.Package import Distribution.Package
( PackageIdentifier, Package(..), packageName, packageVersion ( PackageIdentifier, Package(..), packageName, packageVersion
, PackageFixedDeps(..) ) , Dependency(Dependency), PackageFixedDeps(..) )
import Distribution.Version (Version, Dependency(Dependency), withinRange) import Distribution.Version
( Version, withinRange )
import Distribution.Simple.Utils (lowercase, equating, comparing, isInfixOf) import Distribution.Simple.Utils (lowercase, equating, comparing, isInfixOf)
-- | The collection of information about packages from one or more 'PackageDB's. -- | The collection of information about packages from one or more 'PackageDB's.
......
...@@ -56,9 +56,6 @@ module Distribution.Version ( ...@@ -56,9 +56,6 @@ module Distribution.Version (
parseVersionRange, parseVersionRange,
isAnyVersion, isAnyVersion,
-- * Dependencies
Dependency(..),
) where ) where
import Data.Version ( Version(..), showVersion ) import Data.Version ( Version(..), showVersion )
...@@ -154,13 +151,6 @@ showVersionRange (UnionVersionRanges r1 r2) ...@@ -154,13 +151,6 @@ showVersionRange (UnionVersionRanges r1 r2)
showVersionRange (IntersectVersionRanges r1 r2) showVersionRange (IntersectVersionRanges r1 r2)
= showVersionRange r1 ++ "&&" ++ showVersionRange r2 = showVersionRange r1 ++ "&&" ++ showVersionRange r2
-- ------------------------------------------------------------
-- * Package dependencies
-- ------------------------------------------------------------
data Dependency = Dependency String VersionRange
deriving (Read, Show, Eq)
-- ------------------------------------------------------------ -- ------------------------------------------------------------
-- * Parsing -- * Parsing
-- ------------------------------------------------------------ -- ------------------------------------------------------------
......
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