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

Move Package class to Distribution.Package

parent f08ff028
......@@ -63,6 +63,8 @@ import Distribution.ParseUtils (
import Distribution.License ( License(..) )
import Distribution.Package ( PackageIdentifier(..), showPackageId,
parsePackageId )
import qualified Distribution.Package as Package
( Package(..), PackageFixedDeps(..) )
import Distribution.Version ( Version(..), showVersion )
import Distribution.Compat.ReadP as ReadP
......@@ -107,6 +109,11 @@ data InstalledPackageInfo_ m
}
deriving (Read, Show)
instance Package.Package (InstalledPackageInfo_ str) where
packageId = package
instance Package.PackageFixedDeps (InstalledPackageInfo_ str) where
depends = depends
type InstalledPackageInfo = InstalledPackageInfo_ String
emptyInstalledPackageInfo :: InstalledPackageInfo_ m
......
......@@ -40,8 +40,13 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -}
module Distribution.Package (
-- * Package ids
PackageIdentifier(..),
showPackageId, parsePackageId, parsePackageName,
-- * Package classes
Package(..),
PackageFixedDeps(..),
) where
import Distribution.Version
......@@ -78,3 +83,25 @@ parsePackageId = do
n <- parsePackageName
v <- (ReadP.char '-' >> parseVersion) <++ return (Version [] [])
return PackageIdentifier{pkgName=n,pkgVersion=v}
-- | 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
-- different types for the different phases that packages go though, from
-- simple name\/id, package description, configured or installed packages.
--
class Package pkg where
packageId :: pkg -> PackageIdentifier
instance Package PackageIdentifier where
packageId = id
-- | Subclass of packages that have specific versioned dependencies.
--
-- So for example a not-yet-configured package has dependencies on version
-- ranges, not specific versions. A configured or an already installed package
-- depends on exact versions. Some operations or data structures (like
-- dependency graphs) only make sense on this subclass of package types.
--
class Package pkg => PackageFixedDeps pkg where
depends :: pkg -> [PackageIdentifier]
......@@ -80,7 +80,7 @@ import Data.List (nub)
import Data.Monoid (Monoid(mempty, mappend))
import Text.PrettyPrint.HughesPJ
import Distribution.Package (PackageIdentifier(PackageIdentifier))
import Distribution.Package (PackageIdentifier(..), Package(..))
import Distribution.Version (Version(Version), VersionRange(AnyVersion))
import Distribution.License (License(AllRightsReserved))
import Distribution.Version (Dependency, showVersionRange)
......@@ -128,6 +128,9 @@ data PackageDescription
}
deriving (Show, Read, Eq)
instance Package PackageDescription where
packageId = package
emptyPackageDescription :: PackageDescription
emptyPackageDescription
= PackageDescription {package = PackageIdentifier "" (Version [] []),
......@@ -412,6 +415,9 @@ data GenericPackageDescription =
}
deriving (Show)
instance Package GenericPackageDescription where
packageId = packageId . packageDescription
{-
-- XXX: I think we really want a PPrint or Pretty or ShowPretty class.
instance Show GenericPackageDescription where
......
......@@ -52,11 +52,12 @@ module Distribution.PackageDescription.Configuration (
freeVars,
) where
import Distribution.Package (Package)
import Distribution.PackageDescription
( GenericPackageDescription(..), PackageDescription(..)
, Library(..), Executable(..), BuildInfo(..)
, Flag(..), CondTree(..), ConfVar(..), ConfFlag(..), Condition(..) )
import Distribution.Simple.PackageIndex (PackageIndex, Package)
import Distribution.Simple.PackageIndex (PackageIndex)
import qualified Distribution.Simple.PackageIndex as PackageIndex
import Distribution.Version
( Version(..), Dependency(..), VersionRange(..)
......
......@@ -58,13 +58,13 @@ import Distribution.Simple.Compiler
( CompilerFlavor(..), Compiler(..), compilerVersion, showCompilerId
, unsupportedExtensions, PackageDB(..) )
import Distribution.Package
( PackageIdentifier(..), showPackageId )
( PackageIdentifier(..), showPackageId, Package(..) )
import Distribution.InstalledPackageInfo
( InstalledPackageInfo, emptyInstalledPackageInfo )
import qualified Distribution.InstalledPackageInfo as InstalledPackageInfo
( InstalledPackageInfo_(package,depends) )
import qualified Distribution.Simple.PackageIndex as PackageIndex
import Distribution.Simple.PackageIndex (PackageIndex, Package(packageId))
import Distribution.Simple.PackageIndex (PackageIndex)
import Distribution.PackageDescription as PD
( PackageDescription(..), GenericPackageDescription(..)
, Library(..), hasLibs, Executable(..), BuildInfo(..)
......@@ -199,7 +199,7 @@ configure (pkg_descr0, pbi) cfg
= do let verbosity = fromFlag (configVerbose cfg)
setupMessage verbosity "Configuring"
(package (either packageDescription id pkg_descr0))
(packageId (either packageDescription id pkg_descr0))
createDirectoryIfMissingVerbose (lessVerbose verbosity) True distPref
......@@ -262,7 +262,7 @@ configure (pkg_descr0, pbi) cfg
++ " packages\nthey depend on are missing. These broken "
++ "packages must be rebuilt\nbefore they can be used.\n"
++ unlines [ "package "
++ showPackageId (InstalledPackageInfo.package pkg)
++ showPackageId (packageId pkg)
++ " is broken due to missing package "
++ intercalate ", " (map showPackageId deps)
| (pkg, deps) <- broken ]
......
......@@ -13,10 +13,6 @@
-- An index of packages.
-----------------------------------------------------------------------------
module Distribution.Simple.PackageIndex (
-- * Package classes
Package(..),
PackageFixedDeps(..),
-- * Package index data type
PackageIndex,
......@@ -55,49 +51,11 @@ import Data.List (nubBy, group, sort, groupBy, sortBy, find)
import Data.Monoid (Monoid(..))
import Data.Maybe (isNothing)
import Distribution.Package (PackageIdentifier(..))
import Distribution.InstalledPackageInfo
( InstalledPackageInfo_ )
import qualified Distribution.InstalledPackageInfo as InstalledPackageInfo
( InstalledPackageInfo_(..) )
import Distribution.PackageDescription
( PackageDescription, GenericPackageDescription )
import qualified Distribution.PackageDescription as PackageDescription
( PackageDescription(..), GenericPackageDescription(packageDescription) )
import Distribution.Package
( PackageIdentifier(..), Package(..), PackageFixedDeps(..) )
import Distribution.Version (Version, Dependency(Dependency), withinRange)
import Distribution.Simple.Utils (lowercase, equating, comparing, isInfixOf)
-- | 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
-- different types for the different phases that packages go though, from
-- simple name\/id, package description, configured or installed packages.
--
class Package pkg where
packageId :: pkg -> PackageIdentifier
instance Package PackageIdentifier where
packageId = id
instance Package (InstalledPackageInfo_ str) where
packageId = InstalledPackageInfo.package
instance Package PackageDescription where
packageId = PackageDescription.package
instance Package GenericPackageDescription where
packageId = packageId . PackageDescription.packageDescription
-- | Subclass of packages that have specific versioned dependencies.
--
-- So for example a not-yet-configured package has dependencies on version
-- ranges, not specific versions. A configured or an already installed package
-- depends on exact versions. Some operations or data structures (like
-- dependency graphs) only make sense on this subclass of package types.
--
class Package pkg => PackageFixedDeps pkg where
depends :: pkg -> [PackageIdentifier]
instance PackageFixedDeps (InstalledPackageInfo_ str) where
depends = InstalledPackageInfo.depends
-- | The collection of information about packages from one or more 'PackageDB's.
--
-- It can be searched effeciently by package name and version.
......
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