{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric      #-}
{-# LANGUAGE TypeFamilies       #-}
{-# LANGUAGE OverloadedStrings  #-}
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 Distribution.Utils.ShortText         (ShortText)

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 -> ShortText
copyright         :: !ShortText,
        InstalledPackageInfo -> ShortText
maintainer        :: !ShortText,
        InstalledPackageInfo -> ShortText
author            :: !ShortText,
        InstalledPackageInfo -> ShortText
stability         :: !ShortText,
        InstalledPackageInfo -> ShortText
homepage          :: !ShortText,
        InstalledPackageInfo -> ShortText
pkgUrl            :: !ShortText,
        InstalledPackageInfo -> ShortText
synopsis          :: !ShortText,
        InstalledPackageInfo -> ShortText
description       :: !ShortText,
        InstalledPackageInfo -> ShortText
category          :: !ShortText,
        -- 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]
libraryDirsStatic :: [FilePath],
        InstalledPackageInfo -> [String]
libraryDynDirs    :: [FilePath],  -- ^ overrides 'libraryDirs'
        InstalledPackageInfo -> String
dataDir           :: FilePath,
        InstalledPackageInfo -> [String]
hsLibraries       :: [String],
        InstalledPackageInfo -> [String]
extraLibraries    :: [String],
        InstalledPackageInfo -> [String]
extraLibrariesStatic :: [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
$c== :: InstalledPackageInfo -> InstalledPackageInfo -> Bool
== :: InstalledPackageInfo -> InstalledPackageInfo -> Bool
$c/= :: InstalledPackageInfo -> InstalledPackageInfo -> Bool
/= :: 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
$cfrom :: forall x. InstalledPackageInfo -> Rep InstalledPackageInfo x
$cto :: forall x. Rep InstalledPackageInfo x -> InstalledPackageInfo
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
$creadsPrec :: Int -> ReadS InstalledPackageInfo
readsPrec :: Int -> ReadS InstalledPackageInfo
$creadList :: ReadS [InstalledPackageInfo]
readList :: ReadS [InstalledPackageInfo]
$creadPrec :: ReadPrec InstalledPackageInfo
readPrec :: ReadPrec InstalledPackageInfo
$creadListPrec :: ReadPrec [InstalledPackageInfo]
readListPrec :: ReadPrec [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
$cshowsPrec :: Int -> InstalledPackageInfo -> ShowS
showsPrec :: Int -> InstalledPackageInfo -> ShowS
$cshow :: InstalledPackageInfo -> String
show :: InstalledPackageInfo -> String
$cshowList :: [InstalledPackageInfo] -> ShowS
showList :: [InstalledPackageInfo] -> ShowS
Show)

instance Binary InstalledPackageInfo
instance Structured 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 {
        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 :: ShortText
copyright         = ShortText
"",
        maintainer :: ShortText
maintainer        = ShortText
"",
        author :: ShortText
author            = ShortText
"",
        stability :: ShortText
stability         = ShortText
"",
        homepage :: ShortText
homepage          = ShortText
"",
        pkgUrl :: ShortText
pkgUrl            = ShortText
"",
        synopsis :: ShortText
synopsis          = ShortText
"",
        description :: ShortText
description       = ShortText
"",
        category :: ShortText
category          = ShortText
"",
        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       = [],
        libraryDirsStatic :: [String]
libraryDirsStatic = [],
        libraryDynDirs :: [String]
libraryDynDirs    = [],
        dataDir :: String
dataDir           = String
"",
        hsLibraries :: [String]
hsLibraries       = [],
        extraLibraries :: [String]
extraLibraries    = [],
        extraLibrariesStatic :: [String]
extraLibrariesStatic = [],
        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
    }