Copyright | (c) The University of Glasgow 2009 Duncan Coutts 2014 |
---|---|
Maintainer | ghc-devs@haskell.org |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
This module provides the view of GHC's database of registered packages that is shared between GHC the compiler/library, and the ghc-pkg program. It defines the database format that is shared between GHC and ghc-pkg.
The database format, and this library are constructed so that GHC does not have to depend on the Cabal library. The ghc-pkg program acts as the gateway between the external package format (which is defined by Cabal) and the internal package format which is specialised just for GHC.
GHC the compiler only needs some of the information which is kept about registered packages, such as module names, various paths etc. On the other hand ghc-pkg has to keep all the information from Cabal packages and be able to regurgitate it for users and other tools.
The first trick is that we duplicate some of the information in the package
database. We essentially keep two versions of the database in one file, one
version used only by ghc-pkg which keeps the full information (using the
serialised form of the InstalledPackageInfo
type defined by the Cabal
library); and a second version written by ghc-pkg and read by GHC which has
just the subset of information that GHC needs.
The second trick is that this module only defines in detail the format of the second version -- the bit GHC uses -- and the part managed by ghc-pkg is kept in the file but here we treat it as an opaque blob of data. That way this library avoids depending on Cabal.
Synopsis
- data GenericUnitInfo compid srcpkgid srcpkgname uid modulename mod = GenericUnitInfo {
- unitId :: uid
- unitInstanceOf :: compid
- unitInstantiations :: [(modulename, mod)]
- unitPackageId :: srcpkgid
- unitPackageName :: srcpkgname
- unitPackageVersion :: Version
- unitComponentName :: Maybe srcpkgname
- unitAbiHash :: ShortText
- unitDepends :: [uid]
- unitAbiDepends :: [(uid, ShortText)]
- unitImportDirs :: [FilePathST]
- unitLibraries :: [ShortText]
- unitExtDepLibsSys :: [ShortText]
- unitExtDepLibsGhc :: [ShortText]
- unitLibraryDirs :: [FilePathST]
- unitLibraryDynDirs :: [FilePathST]
- unitExtDepFrameworks :: [ShortText]
- unitExtDepFrameworkDirs :: [FilePathST]
- unitLinkerOptions :: [ShortText]
- unitCcOptions :: [ShortText]
- unitIncludes :: [ShortText]
- unitIncludeDirs :: [FilePathST]
- unitHaddockInterfaces :: [FilePathST]
- unitHaddockHTMLs :: [FilePathST]
- unitExposedModules :: [(modulename, Maybe mod)]
- unitHiddenModules :: [modulename]
- unitIsIndefinite :: Bool
- unitIsExposed :: Bool
- unitIsTrusted :: Bool
- type DbUnitInfo = GenericUnitInfo ByteString ByteString ByteString ByteString ByteString DbModule
- data DbModule
- = DbModule { }
- | DbModuleVar { }
- data DbInstUnitId
- mapGenericUnitInfo :: (uid1 -> uid2) -> (cid1 -> cid2) -> (srcpkg1 -> srcpkg2) -> (srcpkgname1 -> srcpkgname2) -> (modname1 -> modname2) -> (mod1 -> mod2) -> GenericUnitInfo cid1 srcpkg1 srcpkgname1 uid1 modname1 mod1 -> GenericUnitInfo cid2 srcpkg2 srcpkgname2 uid2 modname2 mod2
- data DbMode
- data DbOpenMode (mode :: DbMode) t where
- DbOpenReadOnly :: DbOpenMode 'DbReadOnly t
- DbOpenReadWrite :: t -> DbOpenMode 'DbReadWrite t
- isDbOpenReadMode :: DbOpenMode mode t -> Bool
- readPackageDbForGhc :: FilePath -> IO [DbUnitInfo]
- readPackageDbForGhcPkg :: Binary pkgs => FilePath -> DbOpenMode mode t -> IO (pkgs, DbOpenMode mode PackageDbLock)
- writePackageDb :: Binary pkgs => FilePath -> [DbUnitInfo] -> pkgs -> IO ()
- data PackageDbLock
- lockPackageDb :: FilePath -> IO PackageDbLock
- unlockPackageDb :: PackageDbLock -> IO ()
- mkMungePathUrl :: FilePathST -> FilePathST -> (FilePathST -> FilePathST, FilePathST -> FilePathST)
- mungeUnitInfoPaths :: FilePathST -> FilePathST -> GenericUnitInfo a b c d e f -> GenericUnitInfo a b c d e f
Documentation
data GenericUnitInfo compid srcpkgid srcpkgname uid modulename mod Source #
Information about an unit (a unit is an installed module library).
This is a subset of Cabal's InstalledPackageInfo
, with just the bits
that GHC is interested in.
Some types are left as parameters to be instantiated differently in ghc-pkg and in ghc itself.
GenericUnitInfo | |
|
Instances
Binary DbUnitInfo Source # | |
Defined in GHC.Unit.Database put :: DbUnitInfo -> Put Source # get :: Get DbUnitInfo Source # putList :: [DbUnitInfo] -> Put Source # | |
(Show uid, Show compid, Show modulename, Show mod, Show srcpkgid, Show srcpkgname) => Show (GenericUnitInfo compid srcpkgid srcpkgname uid modulename mod) Source # | |
Defined in GHC.Unit.Database | |
(Eq uid, Eq compid, Eq modulename, Eq mod, Eq srcpkgid, Eq srcpkgname) => Eq (GenericUnitInfo compid srcpkgid srcpkgname uid modulename mod) Source # | |
Defined in GHC.Unit.Database (==) :: GenericUnitInfo compid srcpkgid srcpkgname uid modulename mod -> GenericUnitInfo compid srcpkgid srcpkgname uid modulename mod -> Bool # (/=) :: GenericUnitInfo compid srcpkgid srcpkgname uid modulename mod -> GenericUnitInfo compid srcpkgid srcpkgname uid modulename mod -> Bool # |
type DbUnitInfo = GenericUnitInfo ByteString ByteString ByteString ByteString ByteString DbModule Source #
ghc-boot
's UnitInfo, serialized to the database.
ghc-boot
's Module
, serialized to the database.
data DbInstUnitId Source #
ghc-boot
's instantiated unit id, serialized to the database.
DbInstUnitId ByteString [(ByteString, DbModule)] | Instantiated unit |
DbUnitId ByteString | Uninstantiated unit |
Instances
Show DbInstUnitId Source # | |
Defined in GHC.Unit.Database | |
Binary DbInstUnitId Source # | |
Defined in GHC.Unit.Database put :: DbInstUnitId -> Put Source # get :: Get DbInstUnitId Source # putList :: [DbInstUnitId] -> Put Source # | |
Eq DbInstUnitId Source # | |
Defined in GHC.Unit.Database (==) :: DbInstUnitId -> DbInstUnitId -> Bool # (/=) :: DbInstUnitId -> DbInstUnitId -> Bool # |
mapGenericUnitInfo :: (uid1 -> uid2) -> (cid1 -> cid2) -> (srcpkg1 -> srcpkg2) -> (srcpkgname1 -> srcpkgname2) -> (modname1 -> modname2) -> (mod1 -> mod2) -> GenericUnitInfo cid1 srcpkg1 srcpkgname1 uid1 modname1 mod1 -> GenericUnitInfo cid2 srcpkg2 srcpkgname2 uid2 modname2 mod2 Source #
Convert between GenericUnitInfo instances
Read and write
data DbOpenMode (mode :: DbMode) t where Source #
DbOpenMode
holds a value of type t
but only in DbReadWrite
mode. So
it is like Maybe
but with a type argument for the mode to enforce that the
mode is used consistently.
DbOpenReadOnly :: DbOpenMode 'DbReadOnly t | |
DbOpenReadWrite :: t -> DbOpenMode 'DbReadWrite t |
Instances
Foldable (DbOpenMode mode) Source # | |
Defined in GHC.Unit.Database fold :: Monoid m => DbOpenMode mode m -> m Source # foldMap :: Monoid m => (a -> m) -> DbOpenMode mode a -> m Source # foldMap' :: Monoid m => (a -> m) -> DbOpenMode mode a -> m Source # foldr :: (a -> b -> b) -> b -> DbOpenMode mode a -> b Source # foldr' :: (a -> b -> b) -> b -> DbOpenMode mode a -> b Source # foldl :: (b -> a -> b) -> b -> DbOpenMode mode a -> b Source # foldl' :: (b -> a -> b) -> b -> DbOpenMode mode a -> b Source # foldr1 :: (a -> a -> a) -> DbOpenMode mode a -> a Source # foldl1 :: (a -> a -> a) -> DbOpenMode mode a -> a Source # toList :: DbOpenMode mode a -> [a] Source # null :: DbOpenMode mode a -> Bool Source # length :: DbOpenMode mode a -> Int Source # elem :: Eq a => a -> DbOpenMode mode a -> Bool Source # maximum :: Ord a => DbOpenMode mode a -> a Source # minimum :: Ord a => DbOpenMode mode a -> a Source # sum :: Num a => DbOpenMode mode a -> a Source # product :: Num a => DbOpenMode mode a -> a Source # | |
Traversable (DbOpenMode mode) Source # | |
Defined in GHC.Unit.Database traverse :: Applicative f => (a -> f b) -> DbOpenMode mode a -> f (DbOpenMode mode b) Source # sequenceA :: Applicative f => DbOpenMode mode (f a) -> f (DbOpenMode mode a) Source # mapM :: Monad m => (a -> m b) -> DbOpenMode mode a -> m (DbOpenMode mode b) Source # sequence :: Monad m => DbOpenMode mode (m a) -> m (DbOpenMode mode a) Source # | |
Functor (DbOpenMode mode) Source # | |
Defined in GHC.Unit.Database fmap :: (a -> b) -> DbOpenMode mode a -> DbOpenMode mode b Source # (<$) :: a -> DbOpenMode mode b -> DbOpenMode mode a Source # |
isDbOpenReadMode :: DbOpenMode mode t -> Bool Source #
readPackageDbForGhc :: FilePath -> IO [DbUnitInfo] Source #
Read the part of the package DB that GHC is interested in.
readPackageDbForGhcPkg :: Binary pkgs => FilePath -> DbOpenMode mode t -> IO (pkgs, DbOpenMode mode PackageDbLock) Source #
Read the part of the package DB that ghc-pkg is interested in
Note that the Binary instance for ghc-pkg's representation of packages is not defined in this package. This is because ghc-pkg uses Cabal types (and Binary instances for these) which this package does not depend on.
If we open the package db in read only mode, we get its contents. Otherwise we additionally receive a PackageDbLock that represents a lock on the database, so that we can safely update it later.
writePackageDb :: Binary pkgs => FilePath -> [DbUnitInfo] -> pkgs -> IO () Source #
Write the whole of the package DB, both parts.
Locking
data PackageDbLock Source #
Represents a lock of a package db.
lockPackageDb :: FilePath -> IO PackageDbLock Source #
Acquire an exclusive lock related to package DB under given location.
unlockPackageDb :: PackageDbLock -> IO () Source #
Release the lock related to package DB.
Misc
mkMungePathUrl :: FilePathST -> FilePathST -> (FilePathST -> FilePathST, FilePathST -> FilePathST) Source #
mungeUnitInfoPaths :: FilePathST -> FilePathST -> GenericUnitInfo a b c d e f -> GenericUnitInfo a b c d e f Source #
Perform path/URL variable substitution as per the Cabal ${pkgroot} spec (http:/www.haskell.orgpipermaillibraries2009-May/011772.html) Paths/URLs can be relative to ${pkgroot} or ${pkgrooturl}. The "pkgroot" is the directory containing the package database.
Also perform a similar substitution for the older GHC-specific "$topdir" variable. The "topdir" is the location of the ghc installation (obtained from the -B option).