Copyright | (c) David Himmelstrup 2005, Bjorn Bringert 2007, Duncan Coutts 2008-2009 |
---|---|
Maintainer | cabal-devel@haskell.org |
Portability | portable |
Safe Haskell | None |
Language | Haskell98 |
An index of packages.
- type InstalledPackageIndex = PackageIndex InstalledPackageInfo
- data PackageIndex a
- type FakeMap = Map InstalledPackageId InstalledPackageId
- fromList :: PackageInstalled a => [a] -> PackageIndex a
- merge :: PackageInstalled a => PackageIndex a -> PackageIndex a -> PackageIndex a
- insert :: PackageInstalled a => a -> PackageIndex a -> PackageIndex a
- deleteInstalledPackageId :: PackageInstalled a => InstalledPackageId -> PackageIndex a -> PackageIndex a
- deleteSourcePackageId :: PackageInstalled a => PackageId -> PackageIndex a -> PackageIndex a
- deletePackageName :: PackageInstalled a => PackageName -> PackageIndex a -> PackageIndex a
- lookupInstalledPackageId :: PackageInstalled a => PackageIndex a -> InstalledPackageId -> Maybe a
- lookupSourcePackageId :: PackageInstalled a => PackageIndex a -> PackageId -> [a]
- lookupPackageId :: PackageInstalled a => PackageIndex a -> PackageId -> Maybe a
- lookupPackageName :: PackageInstalled a => PackageIndex a -> PackageName -> [(Version, [a])]
- lookupDependency :: PackageInstalled a => PackageIndex a -> Dependency -> [(Version, [a])]
- searchByName :: PackageInstalled a => PackageIndex a -> String -> SearchResult [a]
- data SearchResult a
- = None
- | Unambiguous a
- | Ambiguous [a]
- searchByNameSubstring :: PackageInstalled a => PackageIndex a -> String -> [a]
- allPackages :: PackageIndex a -> [a]
- allPackagesByName :: PackageIndex a -> [(PackageName, [a])]
- allPackagesBySourcePackageId :: PackageInstalled a => PackageIndex a -> [(PackageId, [a])]
- brokenPackages :: PackageInstalled a => PackageIndex a -> [(a, [InstalledPackageId])]
- dependencyClosure :: PackageInstalled a => PackageIndex a -> [InstalledPackageId] -> Either (PackageIndex a) [(a, [InstalledPackageId])]
- reverseDependencyClosure :: PackageInstalled a => PackageIndex a -> [InstalledPackageId] -> [a]
- topologicalOrder :: PackageInstalled a => PackageIndex a -> [a]
- reverseTopologicalOrder :: PackageInstalled a => PackageIndex a -> [a]
- dependencyInconsistencies :: PackageInstalled a => PackageIndex a -> [(PackageName, [(PackageId, Version)])]
- dependencyCycles :: PackageInstalled a => PackageIndex a -> [[a]]
- dependencyGraph :: PackageInstalled a => PackageIndex a -> (Graph, Vertex -> a, InstalledPackageId -> Maybe Vertex)
- moduleNameIndex :: InstalledPackageIndex -> Map ModuleName [InstalledPackageInfo]
- fakeLookupInstalledPackageId :: PackageInstalled a => FakeMap -> PackageIndex a -> InstalledPackageId -> Maybe a
- brokenPackages' :: PackageInstalled a => FakeMap -> PackageIndex a -> [(a, [InstalledPackageId])]
- dependencyClosure' :: PackageInstalled a => FakeMap -> PackageIndex a -> [InstalledPackageId] -> Either (PackageIndex a) [(a, [InstalledPackageId])]
- reverseDependencyClosure' :: PackageInstalled a => FakeMap -> PackageIndex a -> [InstalledPackageId] -> [a]
- dependencyInconsistencies' :: PackageInstalled a => FakeMap -> PackageIndex a -> [(PackageName, [(PackageId, Version)])]
- dependencyCycles' :: PackageInstalled a => FakeMap -> PackageIndex a -> [[a]]
- dependencyGraph' :: PackageInstalled a => FakeMap -> PackageIndex a -> (Graph, Vertex -> a, InstalledPackageId -> Maybe Vertex)
Package index data type
type InstalledPackageIndex = PackageIndex InstalledPackageInfo Source
The default package index which contains InstalledPackageInfo
. Normally
use this.
data PackageIndex a Source
The collection of information about packages from one or more PackageDB
s.
These packages generally should have an instance of PackageInstalled
Packages are uniquely identified in by their InstalledPackageId
, they can
also be efficiently looked up by package name or by name and version.
Read a => Read (PackageIndex a) Source | |
Show a => Show (PackageIndex a) Source | |
Generic (PackageIndex a) Source | |
PackageInstalled a => Monoid (PackageIndex a) Source | |
Binary a => Binary (PackageIndex a) Source | |
type Rep (PackageIndex a) Source |
type FakeMap = Map InstalledPackageId InstalledPackageId Source
Map from fake installed package IDs to real ones. See Note [FakeMap]
Creating an index
fromList :: PackageInstalled a => [a] -> PackageIndex a Source
Build an index out of a bunch of packages.
If there are duplicates by InstalledPackageId
then later ones mask earlier
ones.
Updates
merge :: PackageInstalled a => PackageIndex a -> PackageIndex a -> PackageIndex a Source
Merge two indexes.
Packages from the second mask packages from the first if they have the exact
same InstalledPackageId
.
For packages with the same source PackageId
, packages from the second are
"preferred" over those from the first. Being preferred means they are top
result when we do a lookup by source PackageId
. This is the mechanism we
use to prefer user packages over global packages.
insert :: PackageInstalled a => a -> PackageIndex a -> PackageIndex a Source
deleteInstalledPackageId :: PackageInstalled a => InstalledPackageId -> PackageIndex a -> PackageIndex a Source
Removes a single installed package from the index.
deleteSourcePackageId :: PackageInstalled a => PackageId -> PackageIndex a -> PackageIndex a Source
Removes all packages with this source PackageId
from the index.
deletePackageName :: PackageInstalled a => PackageName -> PackageIndex a -> PackageIndex a Source
Removes all packages with this (case-sensitive) name from the index.
Queries
Precise lookups
lookupInstalledPackageId :: PackageInstalled a => PackageIndex a -> InstalledPackageId -> Maybe a Source
Does a lookup by source package id (name & version).
Since multiple package DBs mask each other by InstalledPackageId
,
then we get back at most one package.
lookupSourcePackageId :: PackageInstalled a => PackageIndex a -> PackageId -> [a] Source
Does a lookup by source package id (name & version).
There can be multiple installed packages with the same source PackageId
but different InstalledPackageId
. They are returned in order of
preference, with the most preferred first.
lookupPackageId :: PackageInstalled a => PackageIndex a -> PackageId -> Maybe a Source
Convenient alias of lookupSourcePackageId
, but assuming only
one package per package ID.
lookupPackageName :: PackageInstalled a => PackageIndex a -> PackageName -> [(Version, [a])] Source
Does a lookup by source package name.
lookupDependency :: PackageInstalled a => PackageIndex a -> Dependency -> [(Version, [a])] Source
Does a lookup by source package name and a range of versions.
We get back any number of versions of the specified package name, all satisfying the version range constraint.
Case-insensitive searches
searchByName :: PackageInstalled a => PackageIndex a -> String -> SearchResult [a] Source
Does a case-insensitive search by package name.
If there is only one package that compares case-insensitively to this name then the search is unambiguous and we get back all versions of that package. If several match case-insensitively but one matches exactly then it is also unambiguous.
If however several match case-insensitively and none match exactly then we have an ambiguous result, and we get back all the versions of all the packages. The list of ambiguous results is split by exact package name. So it is a non-empty list of non-empty lists.
data SearchResult a Source
None | |
Unambiguous a | |
Ambiguous [a] |
searchByNameSubstring :: PackageInstalled a => PackageIndex a -> String -> [a] Source
Does a case-insensitive substring search by package name.
That is, all packages that contain the given string in their name.
Bulk queries
allPackages :: PackageIndex a -> [a] Source
Get all the packages from the index.
allPackagesByName :: PackageIndex a -> [(PackageName, [a])] Source
Get all the packages from the index.
They are grouped by package name (case-sensitively).
allPackagesBySourcePackageId :: PackageInstalled a => PackageIndex a -> [(PackageId, [a])] Source
Get all the packages from the index.
They are grouped by source package id (package name and version).
Special queries
brokenPackages :: PackageInstalled a => PackageIndex a -> [(a, [InstalledPackageId])] Source
All packages that have immediate dependencies that are not in the index.
Returns such packages along with the dependencies that they're missing.
dependencyClosure :: PackageInstalled a => PackageIndex a -> [InstalledPackageId] -> Either (PackageIndex a) [(a, [InstalledPackageId])] Source
Tries to take the transitive closure of the package dependencies.
If the transitive closure is complete then it returns that subset of the
index. Otherwise it returns the broken packages as in brokenPackages
.
- Note that if the result is
Right []
it is because at least one of the original givenPackageId
s do not occur in the index.
reverseDependencyClosure :: PackageInstalled a => PackageIndex a -> [InstalledPackageId] -> [a] Source
Takes the transitive closure of the packages reverse dependencies.
- The given
PackageId
s must be in the index.
topologicalOrder :: PackageInstalled a => PackageIndex a -> [a] Source
reverseTopologicalOrder :: PackageInstalled a => PackageIndex a -> [a] Source
dependencyInconsistencies :: PackageInstalled a => PackageIndex a -> [(PackageName, [(PackageId, Version)])] Source
Given a package index where we assume we want to use all the packages
(use dependencyClosure
if you need to get such a index subset) find out
if the dependencies within it use consistent versions of each package.
Return all cases where multiple packages depend on different versions of
some other package.
Each element in the result is a package name along with the packages that depend on it and the versions they require. These are guaranteed to be distinct.
dependencyCycles :: PackageInstalled a => PackageIndex a -> [[a]] Source
Find if there are any cycles in the dependency graph. If there are no
cycles the result is []
.
This actually computes the strongly connected components. So it gives us a list of groups of packages where within each group they all depend on each other, directly or indirectly.
dependencyGraph :: PackageInstalled a => PackageIndex a -> (Graph, Vertex -> a, InstalledPackageId -> Maybe Vertex) Source
Builds a graph of the package dependencies.
Dependencies on other packages that are not in the index are discarded.
You can check if there are any such dependencies with brokenPackages
.
moduleNameIndex :: InstalledPackageIndex -> Map ModuleName [InstalledPackageInfo] Source
A rough approximation of GHC's module finder, takes a InstalledPackageIndex
and
turns it into a map from module names to their source packages. It's used to
initialize the build-deps
field in cabal init
.
Variants of special queries supporting fake map
fakeLookupInstalledPackageId :: PackageInstalled a => FakeMap -> PackageIndex a -> InstalledPackageId -> Maybe a Source
Variant of lookupInstalledPackageId
which accepts a FakeMap
. See Note [FakeMap].
brokenPackages' :: PackageInstalled a => FakeMap -> PackageIndex a -> [(a, [InstalledPackageId])] Source
Variant of brokenPackages
which accepts a FakeMap
. See Note [FakeMap].
dependencyClosure' :: PackageInstalled a => FakeMap -> PackageIndex a -> [InstalledPackageId] -> Either (PackageIndex a) [(a, [InstalledPackageId])] Source
Variant of dependencyClosure
which accepts a FakeMap
. See Note [FakeMap].
reverseDependencyClosure' :: PackageInstalled a => FakeMap -> PackageIndex a -> [InstalledPackageId] -> [a] Source
Variant of reverseDependencyClosure
which accepts a FakeMap
. See Note [FakeMap].
dependencyInconsistencies' :: PackageInstalled a => FakeMap -> PackageIndex a -> [(PackageName, [(PackageId, Version)])] Source
Variant of dependencyInconsistencies
which accepts a FakeMap
. See Note [FakeMap].
dependencyCycles' :: PackageInstalled a => FakeMap -> PackageIndex a -> [[a]] Source
Variant of dependencyCycles
which accepts a FakeMap
. See Note [FakeMap].
dependencyGraph' :: PackageInstalled a => FakeMap -> PackageIndex a -> (Graph, Vertex -> a, InstalledPackageId -> Maybe Vertex) Source
Variant of dependencyGraph
which accepts a FakeMap
. See Note [FakeMap].