1{-# LANGUAGE DeriveDataTypeable #-}
2{-# LANGUAGE DeriveGeneric #-}
3{-# LANGUAGE GeneralizedNewtypeDeriving #-}
4
5-----------------------------------------------------------------------------
6-- |
7-- Module      :  Distribution.Package
8-- Copyright   :  Isaac Jones 2003-2004
9-- License     :  BSD3
10--
11-- Maintainer  :  cabal-devel@haskell.org
12-- Portability :  portable
13--
14-- Defines a package identifier along with a parser and pretty printer for it.
15-- 'PackageIdentifier's consist of a name and an exact version. It also defines
16-- a 'Dependency' data type. A dependency is a package name and a version
17-- range, like @\"foo >= 1.2 && < 2\"@.
18
19module Distribution.Package
20  ( module Distribution.Types.AbiHash
21  , module Distribution.Types.ComponentId
22  , module Distribution.Types.PackageId
23  , module Distribution.Types.UnitId
24  , module Distribution.Types.Module
25  , module Distribution.Types.PackageName
26  , module Distribution.Types.PkgconfigName
27  , module Distribution.Types.Dependency
28  , Package(..), packageName, packageVersion
29  , HasMungedPackageId(..), mungedName', mungedVersion'
30  , HasUnitId(..)
31  , PackageInstalled(..)
32  ) where
33
34import Prelude ()
35import Distribution.Compat.Prelude
36
37import Distribution.Version
38         ( Version )
39
40import Distribution.Types.AbiHash
41import Distribution.Types.ComponentId
42import Distribution.Types.Dependency
43import Distribution.Types.MungedPackageId
44import Distribution.Types.PackageId
45import Distribution.Types.UnitId
46import Distribution.Types.Module
47import Distribution.Types.MungedPackageName
48import Distribution.Types.PackageName
49import Distribution.Types.PkgconfigName
50
51-- | Class of things that have a 'PackageIdentifier'
52--
53-- Types in this class are all notions of a package. This allows us to have
54-- different types for the different phases that packages go though, from
55-- simple name\/id, package description, configured or installed packages.
56--
57-- Not all kinds of packages can be uniquely identified by a
58-- 'PackageIdentifier'. In particular, installed packages cannot, there may be
59-- many installed instances of the same source package.
60--
61class Package pkg where
62  packageId  :: pkg -> PackageIdentifier
63
64mungedName'    :: HasMungedPackageId pkg => pkg -> MungedPackageName
65mungedName'     = mungedName    . mungedId
66
67mungedVersion' :: HasMungedPackageId munged => munged -> Version
68mungedVersion'  = mungedVersion . mungedId
69
70class HasMungedPackageId pkg where
71  mungedId :: pkg -> MungedPackageId
72
73instance Package PackageIdentifier where
74  packageId = id
75
76packageName    :: Package pkg => pkg -> PackageName
77packageName     = pkgName    . packageId
78
79packageVersion :: Package pkg => pkg -> Version
80packageVersion  = pkgVersion . packageId
81
82instance HasMungedPackageId MungedPackageId where
83  mungedId = id
84
85-- | Packages that have an installed unit ID
86class Package pkg => HasUnitId pkg where
87  installedUnitId :: pkg -> UnitId
88
89-- | Class of installed packages.
90--
91-- The primary data type which is an instance of this package is
92-- 'InstalledPackageInfo', but when we are doing install plans in Cabal install
93-- we may have other, installed package-like things which contain more metadata.
94-- Installed packages have exact dependencies 'installedDepends'.
95class (HasUnitId pkg) => PackageInstalled pkg where
96  installedDepends :: pkg -> [UnitId]
97