{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric      #-}
{-# LANGUAGE TypeFamilies       #-}
module Distribution.Types.InstalledPackageInfo (
    InstalledPackageInfo (..),
    emptyInstalledPackageInfo,
    mungedPackageId,
    mungedPackageName,
    AbiDependency (..),
    ExposedModule (..),
    ) where

import Distribution.Compat.Prelude
import Prelude ()

import Distribution.Backpack
import Distribution.Compat.Graph            (IsNode (..))
import Distribution.License
import Distribution.ModuleName
import Distribution.Package                 hiding (installedUnitId)
import Distribution.Types.AbiDependency
import Distribution.Types.ExposedModule
import Distribution.Types.LibraryName
import Distribution.Types.LibraryVisibility
import Distribution.Types.MungedPackageId
import Distribution.Types.MungedPackageName
import Distribution.Version                 (nullVersion)

import qualified Distribution.Package as Package
import qualified Distribution.SPDX    as SPDX

-- -----------------------------------------------------------------------------
-- The InstalledPackageInfo type

-- For BC reasons, we continue to name this record an InstalledPackageInfo;
-- but it would more accurately be called an InstalledUnitInfo with Backpack
data InstalledPackageInfo
   = InstalledPackageInfo {
        -- these parts (sourcePackageId, installedUnitId) are
        -- exactly the same as PackageDescription
        InstalledPackageInfo -> PackageId
sourcePackageId   :: PackageId,
        InstalledPackageInfo -> LibraryName
sourceLibName     :: LibraryName,
        InstalledPackageInfo -> ComponentId
installedComponentId_ :: ComponentId,
        InstalledPackageInfo -> LibraryVisibility
libVisibility     :: LibraryVisibility,
        InstalledPackageInfo -> UnitId
installedUnitId   :: UnitId,
        -- INVARIANT: if this package is definite, OpenModule's
        -- OpenUnitId directly records UnitId.  If it is
        -- indefinite, OpenModule is always an OpenModuleVar
        -- with the same ModuleName as the key.
        InstalledPackageInfo -> [(ModuleName, OpenModule)]
instantiatedWith  :: [(ModuleName, OpenModule)],
        InstalledPackageInfo -> String
compatPackageKey  :: String,
        InstalledPackageInfo -> Either License License
license           :: Either SPDX.License License,
        InstalledPackageInfo -> String
copyright         :: String,
        InstalledPackageInfo -> String
maintainer        :: String,
        InstalledPackageInfo -> String
author            :: String,
        InstalledPackageInfo -> String
stability         :: String,
        InstalledPackageInfo -> String
homepage          :: String,
        InstalledPackageInfo -> String
pkgUrl            :: String,
        InstalledPackageInfo -> String
synopsis          :: String,
        InstalledPackageInfo -> String
description       :: String,
        InstalledPackageInfo -> String
category          :: String,
        -- these parts are required by an installed package only:
        InstalledPackageInfo -> AbiHash
abiHash           :: AbiHash,
        InstalledPackageInfo -> Bool
indefinite        :: Bool,
        InstalledPackageInfo -> Bool
exposed           :: Bool,
        -- INVARIANT: if the package is definite, OpenModule's
        -- OpenUnitId directly records UnitId.
        InstalledPackageInfo -> [ExposedModule]
exposedModules    :: [ExposedModule],
        InstalledPackageInfo -> [ModuleName]
hiddenModules     :: [ModuleName],
        InstalledPackageInfo -> Bool
trusted           :: Bool,
        InstalledPackageInfo -> [String]
importDirs        :: [FilePath],
        InstalledPackageInfo -> [String]
libraryDirs       :: [FilePath],
        InstalledPackageInfo -> [String]
libraryDynDirs    :: [FilePath],  -- ^ overrides 'libraryDirs'
        InstalledPackageInfo -> String
dataDir           :: FilePath,
        InstalledPackageInfo -> [String]
hsLibraries       :: [String],
        InstalledPackageInfo -> [String]
extraLibraries    :: [String],
        InstalledPackageInfo -> [String]
extraGHCiLibraries:: [String],    -- overrides extraLibraries for GHCi
        InstalledPackageInfo -> [String]
includeDirs       :: [FilePath],
        InstalledPackageInfo -> [String]
includes          :: [String],
        -- INVARIANT: if the package is definite, UnitId is NOT
        -- a ComponentId of an indefinite package
        InstalledPackageInfo -> [UnitId]
depends           :: [UnitId],
        InstalledPackageInfo -> [AbiDependency]
abiDepends        :: [AbiDependency],
        InstalledPackageInfo -> [String]
ccOptions         :: [String],
        InstalledPackageInfo -> [String]
cxxOptions        :: [String],
        InstalledPackageInfo -> [String]
ldOptions         :: [String],
        InstalledPackageInfo -> [String]
frameworkDirs     :: [FilePath],
        InstalledPackageInfo -> [String]
frameworks        :: [String],
        InstalledPackageInfo -> [String]
haddockInterfaces :: [FilePath],
        InstalledPackageInfo -> [String]
haddockHTMLs      :: [FilePath],
        InstalledPackageInfo -> Maybe String
pkgRoot           :: Maybe FilePath
    }
    deriving (InstalledPackageInfo -> InstalledPackageInfo -> Bool
(InstalledPackageInfo -> InstalledPackageInfo -> Bool)
-> (InstalledPackageInfo -> InstalledPackageInfo -> Bool)
-> Eq InstalledPackageInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: InstalledPackageInfo -> InstalledPackageInfo -> Bool
$c/= :: InstalledPackageInfo -> InstalledPackageInfo -> Bool
== :: InstalledPackageInfo -> InstalledPackageInfo -> Bool
$c== :: InstalledPackageInfo -> InstalledPackageInfo -> Bool
Eq, (forall x. InstalledPackageInfo -> Rep InstalledPackageInfo x)
-> (forall x. Rep InstalledPackageInfo x -> InstalledPackageInfo)
-> Generic InstalledPackageInfo
forall x. Rep InstalledPackageInfo x -> InstalledPackageInfo
forall x. InstalledPackageInfo -> Rep InstalledPackageInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep InstalledPackageInfo x -> InstalledPackageInfo
$cfrom :: forall x. InstalledPackageInfo -> Rep InstalledPackageInfo x
Generic, Typeable, ReadPrec [InstalledPackageInfo]
ReadPrec InstalledPackageInfo
Int -> ReadS InstalledPackageInfo
ReadS [InstalledPackageInfo]
(Int -> ReadS InstalledPackageInfo)
-> ReadS [InstalledPackageInfo]
-> ReadPrec InstalledPackageInfo
-> ReadPrec [InstalledPackageInfo]
-> Read InstalledPackageInfo
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [InstalledPackageInfo]
$creadListPrec :: ReadPrec [InstalledPackageInfo]
readPrec :: ReadPrec InstalledPackageInfo
$creadPrec :: ReadPrec InstalledPackageInfo
readList :: ReadS [InstalledPackageInfo]
$creadList :: ReadS [InstalledPackageInfo]
readsPrec :: Int -> ReadS InstalledPackageInfo
$creadsPrec :: Int -> ReadS InstalledPackageInfo
Read, Int -> InstalledPackageInfo -> ShowS
[InstalledPackageInfo] -> ShowS
InstalledPackageInfo -> String
(Int -> InstalledPackageInfo -> ShowS)
-> (InstalledPackageInfo -> String)
-> ([InstalledPackageInfo] -> ShowS)
-> Show InstalledPackageInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InstalledPackageInfo] -> ShowS
$cshowList :: [InstalledPackageInfo] -> ShowS
show :: InstalledPackageInfo -> String
$cshow :: InstalledPackageInfo -> String
showsPrec :: Int -> InstalledPackageInfo -> ShowS
$cshowsPrec :: Int -> InstalledPackageInfo -> ShowS
Show)

instance Binary InstalledPackageInfo

instance NFData InstalledPackageInfo where rnf :: InstalledPackageInfo -> ()
rnf = InstalledPackageInfo -> ()
forall a. (Generic a, GNFData (Rep a)) => a -> ()
genericRnf

instance Package.HasMungedPackageId InstalledPackageInfo where
   mungedId :: InstalledPackageInfo -> MungedPackageId
mungedId = InstalledPackageInfo -> MungedPackageId
mungedPackageId

instance Package.Package InstalledPackageInfo where
   packageId :: InstalledPackageInfo -> PackageId
packageId = InstalledPackageInfo -> PackageId
sourcePackageId

instance Package.HasUnitId InstalledPackageInfo where
   installedUnitId :: InstalledPackageInfo -> UnitId
installedUnitId = InstalledPackageInfo -> UnitId
installedUnitId

instance Package.PackageInstalled InstalledPackageInfo where
   installedDepends :: InstalledPackageInfo -> [UnitId]
installedDepends = InstalledPackageInfo -> [UnitId]
depends

instance IsNode InstalledPackageInfo where
    type Key InstalledPackageInfo = UnitId
    nodeKey :: InstalledPackageInfo -> Key InstalledPackageInfo
nodeKey       = InstalledPackageInfo -> Key InstalledPackageInfo
InstalledPackageInfo -> UnitId
installedUnitId
    nodeNeighbors :: InstalledPackageInfo -> [Key InstalledPackageInfo]
nodeNeighbors = InstalledPackageInfo -> [Key InstalledPackageInfo]
InstalledPackageInfo -> [UnitId]
depends

mungedPackageId :: InstalledPackageInfo -> MungedPackageId
mungedPackageId :: InstalledPackageInfo -> MungedPackageId
mungedPackageId InstalledPackageInfo
ipi =
    MungedPackageName -> Version -> MungedPackageId
MungedPackageId (InstalledPackageInfo -> MungedPackageName
mungedPackageName InstalledPackageInfo
ipi) (InstalledPackageInfo -> Version
forall pkg. Package pkg => pkg -> Version
packageVersion InstalledPackageInfo
ipi)

-- | Returns the munged package name, which we write into @name@ for
-- compatibility with old versions of GHC.
mungedPackageName :: InstalledPackageInfo -> MungedPackageName
mungedPackageName :: InstalledPackageInfo -> MungedPackageName
mungedPackageName InstalledPackageInfo
ipi = PackageName -> LibraryName -> MungedPackageName
MungedPackageName (InstalledPackageInfo -> PackageName
forall pkg. Package pkg => pkg -> PackageName
packageName InstalledPackageInfo
ipi) (InstalledPackageInfo -> LibraryName
sourceLibName InstalledPackageInfo
ipi)

emptyInstalledPackageInfo :: InstalledPackageInfo
emptyInstalledPackageInfo :: InstalledPackageInfo
emptyInstalledPackageInfo
   = InstalledPackageInfo :: PackageId
-> LibraryName
-> ComponentId
-> LibraryVisibility
-> UnitId
-> [(ModuleName, OpenModule)]
-> String
-> Either License License
-> String
-> String
-> String
-> String
-> String
-> String
-> String
-> String
-> String
-> AbiHash
-> Bool
-> Bool
-> [ExposedModule]
-> [ModuleName]
-> Bool
-> [String]
-> [String]
-> [String]
-> String
-> [String]
-> [String]
-> [String]
-> [String]
-> [String]
-> [UnitId]
-> [AbiDependency]
-> [String]
-> [String]
-> [String]
-> [String]
-> [String]
-> [String]
-> [String]
-> Maybe String
-> InstalledPackageInfo
InstalledPackageInfo {
        sourcePackageId :: PackageId
sourcePackageId   = PackageName -> Version -> PackageId
PackageIdentifier (String -> PackageName
mkPackageName String
"") Version
nullVersion,
        sourceLibName :: LibraryName
sourceLibName     = LibraryName
LMainLibName,
        installedComponentId_ :: ComponentId
installedComponentId_ = String -> ComponentId
mkComponentId String
"",
        installedUnitId :: UnitId
installedUnitId   = String -> UnitId
mkUnitId String
"",
        instantiatedWith :: [(ModuleName, OpenModule)]
instantiatedWith  = [],
        compatPackageKey :: String
compatPackageKey  = String
"",
        license :: Either License License
license           = License -> Either License License
forall a b. a -> Either a b
Left License
SPDX.NONE,
        copyright :: String
copyright         = String
"",
        maintainer :: String
maintainer        = String
"",
        author :: String
author            = String
"",
        stability :: String
stability         = String
"",
        homepage :: String
homepage          = String
"",
        pkgUrl :: String
pkgUrl            = String
"",
        synopsis :: String
synopsis          = String
"",
        description :: String
description       = String
"",
        category :: String
category          = String
"",
        abiHash :: AbiHash
abiHash           = String -> AbiHash
mkAbiHash String
"",
        indefinite :: Bool
indefinite        = Bool
False,
        exposed :: Bool
exposed           = Bool
False,
        exposedModules :: [ExposedModule]
exposedModules    = [],
        hiddenModules :: [ModuleName]
hiddenModules     = [],
        trusted :: Bool
trusted           = Bool
False,
        importDirs :: [String]
importDirs        = [],
        libraryDirs :: [String]
libraryDirs       = [],
        libraryDynDirs :: [String]
libraryDynDirs    = [],
        dataDir :: String
dataDir           = String
"",
        hsLibraries :: [String]
hsLibraries       = [],
        extraLibraries :: [String]
extraLibraries    = [],
        extraGHCiLibraries :: [String]
extraGHCiLibraries= [],
        includeDirs :: [String]
includeDirs       = [],
        includes :: [String]
includes          = [],
        depends :: [UnitId]
depends           = [],
        abiDepends :: [AbiDependency]
abiDepends        = [],
        ccOptions :: [String]
ccOptions         = [],
        cxxOptions :: [String]
cxxOptions        = [],
        ldOptions :: [String]
ldOptions         = [],
        frameworkDirs :: [String]
frameworkDirs     = [],
        frameworks :: [String]
frameworks        = [],
        haddockInterfaces :: [String]
haddockInterfaces = [],
        haddockHTMLs :: [String]
haddockHTMLs      = [],
        pkgRoot :: Maybe String
pkgRoot           = Maybe String
forall a. Maybe a
Nothing,
        libVisibility :: LibraryVisibility
libVisibility     = LibraryVisibility
LibraryVisibilityPrivate
    }