{-# LANGUAGE RecordWildCards, FlexibleInstances, MultiParamTypeClasses #-}
module GHC.Unit.Info
( GenericUnitInfo (..)
, GenUnitInfo
, UnitInfo
, UnitKey (..)
, UnitKeyInfo
, mkUnitKeyInfo
, mapUnitInfo
, mkUnitPprInfo
, mkUnit
, PackageId(..)
, PackageName(..)
, Version(..)
, unitPackageNameString
, unitPackageIdString
, pprUnitInfo
, collectIncludeDirs
, collectExtraCcOpts
, collectLibraryDirs
, collectFrameworks
, collectFrameworksDirs
, unitHsLibs
)
where
import GHC.Prelude
import GHC.Platform.Ways
import GHC.Utils.Misc
import GHC.Utils.Outputable
import GHC.Utils.Panic
import GHC.Types.Unique
import GHC.Data.FastString
import qualified GHC.Data.ShortText as ST
import GHC.Unit.Module as Module
import GHC.Unit.Ppr
import GHC.Unit.Database
import GHC.Settings
import Data.Version
import Data.Bifunctor
import Data.List (isPrefixOf, stripPrefix)
type GenUnitInfo unit = GenericUnitInfo PackageId PackageName unit ModuleName (GenModule (GenUnit unit))
type UnitKeyInfo = GenUnitInfo UnitKey
type UnitInfo = GenUnitInfo UnitId
mkUnitKeyInfo :: DbUnitInfo -> UnitKeyInfo
mkUnitKeyInfo :: DbUnitInfo -> UnitKeyInfo
mkUnitKeyInfo = (ByteString -> UnitKey)
-> (ByteString -> PackageId)
-> (ByteString -> PackageName)
-> (ByteString -> ModuleName)
-> (DbModule -> GenModule (GenUnit UnitKey))
-> DbUnitInfo
-> UnitKeyInfo
forall uid1 uid2 srcpkg1 srcpkg2 srcpkgname1 srcpkgname2 modname1
modname2 mod1 mod2.
(uid1 -> uid2)
-> (srcpkg1 -> srcpkg2)
-> (srcpkgname1 -> srcpkgname2)
-> (modname1 -> modname2)
-> (mod1 -> mod2)
-> GenericUnitInfo srcpkg1 srcpkgname1 uid1 modname1 mod1
-> GenericUnitInfo srcpkg2 srcpkgname2 uid2 modname2 mod2
mapGenericUnitInfo
ByteString -> UnitKey
mkUnitKey'
ByteString -> PackageId
mkPackageIdentifier'
ByteString -> PackageName
mkPackageName'
ByteString -> ModuleName
mkModuleName'
DbModule -> GenModule (GenUnit UnitKey)
mkModule'
where
mkPackageIdentifier' :: ByteString -> PackageId
mkPackageIdentifier' = FastString -> PackageId
PackageId (FastString -> PackageId)
-> (ByteString -> FastString) -> ByteString -> PackageId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> FastString
mkFastStringByteString
mkPackageName' :: ByteString -> PackageName
mkPackageName' = FastString -> PackageName
PackageName (FastString -> PackageName)
-> (ByteString -> FastString) -> ByteString -> PackageName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> FastString
mkFastStringByteString
mkUnitKey' :: ByteString -> UnitKey
mkUnitKey' = FastString -> UnitKey
UnitKey (FastString -> UnitKey)
-> (ByteString -> FastString) -> ByteString -> UnitKey
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> FastString
mkFastStringByteString
mkModuleName' :: ByteString -> ModuleName
mkModuleName' = FastString -> ModuleName
mkModuleNameFS (FastString -> ModuleName)
-> (ByteString -> FastString) -> ByteString -> ModuleName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> FastString
mkFastStringByteString
mkVirtUnitKey' :: DbInstUnitId -> GenUnit UnitKey
mkVirtUnitKey' DbInstUnitId
i = case DbInstUnitId
i of
DbInstUnitId ByteString
cid [(ByteString, DbModule)]
insts -> UnitKey
-> [(ModuleName, GenModule (GenUnit UnitKey))] -> GenUnit UnitKey
forall u.
IsUnitId u =>
u -> [(ModuleName, GenModule (GenUnit u))] -> GenUnit u
mkVirtUnit (ByteString -> UnitKey
mkUnitKey' ByteString
cid) (((ByteString, DbModule)
-> (ModuleName, GenModule (GenUnit UnitKey)))
-> [(ByteString, DbModule)]
-> [(ModuleName, GenModule (GenUnit UnitKey))]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((ByteString -> ModuleName)
-> (DbModule -> GenModule (GenUnit UnitKey))
-> (ByteString, DbModule)
-> (ModuleName, GenModule (GenUnit UnitKey))
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap ByteString -> ModuleName
mkModuleName' DbModule -> GenModule (GenUnit UnitKey)
mkModule') [(ByteString, DbModule)]
insts)
DbUnitId ByteString
uid -> Definite UnitKey -> GenUnit UnitKey
forall uid. Definite uid -> GenUnit uid
RealUnit (UnitKey -> Definite UnitKey
forall unit. unit -> Definite unit
Definite (ByteString -> UnitKey
mkUnitKey' ByteString
uid))
mkModule' :: DbModule -> GenModule (GenUnit UnitKey)
mkModule' DbModule
m = case DbModule
m of
DbModule DbInstUnitId
uid ByteString
n -> GenUnit UnitKey -> ModuleName -> GenModule (GenUnit UnitKey)
forall u. u -> ModuleName -> GenModule u
mkModule (DbInstUnitId -> GenUnit UnitKey
mkVirtUnitKey' DbInstUnitId
uid) (ByteString -> ModuleName
mkModuleName' ByteString
n)
DbModuleVar ByteString
n -> ModuleName -> GenModule (GenUnit UnitKey)
forall u. ModuleName -> GenModule (GenUnit u)
mkHoleModule (ByteString -> ModuleName
mkModuleName' ByteString
n)
mapUnitInfo :: IsUnitId v => (u -> v) -> GenUnitInfo u -> GenUnitInfo v
mapUnitInfo :: (u -> v) -> GenUnitInfo u -> GenUnitInfo v
mapUnitInfo u -> v
f = (u -> v)
-> (PackageId -> PackageId)
-> (PackageName -> PackageName)
-> (ModuleName -> ModuleName)
-> (GenModule (GenUnit u) -> GenModule (GenUnit v))
-> GenUnitInfo u
-> GenUnitInfo v
forall uid1 uid2 srcpkg1 srcpkg2 srcpkgname1 srcpkgname2 modname1
modname2 mod1 mod2.
(uid1 -> uid2)
-> (srcpkg1 -> srcpkg2)
-> (srcpkgname1 -> srcpkgname2)
-> (modname1 -> modname2)
-> (mod1 -> mod2)
-> GenericUnitInfo srcpkg1 srcpkgname1 uid1 modname1 mod1
-> GenericUnitInfo srcpkg2 srcpkgname2 uid2 modname2 mod2
mapGenericUnitInfo
u -> v
f
PackageId -> PackageId
forall a. a -> a
id
PackageName -> PackageName
forall a. a -> a
id
ModuleName -> ModuleName
forall a. a -> a
id
((GenUnit u -> GenUnit v)
-> GenModule (GenUnit u) -> GenModule (GenUnit v)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((u -> v) -> GenUnit u -> GenUnit v
forall v u. IsUnitId v => (u -> v) -> GenUnit u -> GenUnit v
mapGenUnit u -> v
f))
newtype PackageId = PackageId FastString deriving (PackageId -> PackageId -> Bool
(PackageId -> PackageId -> Bool)
-> (PackageId -> PackageId -> Bool) -> Eq PackageId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PackageId -> PackageId -> Bool
$c/= :: PackageId -> PackageId -> Bool
== :: PackageId -> PackageId -> Bool
$c== :: PackageId -> PackageId -> Bool
Eq)
newtype PackageName = PackageName
{ PackageName -> FastString
unPackageName :: FastString
}
deriving (PackageName -> PackageName -> Bool
(PackageName -> PackageName -> Bool)
-> (PackageName -> PackageName -> Bool) -> Eq PackageName
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PackageName -> PackageName -> Bool
$c/= :: PackageName -> PackageName -> Bool
== :: PackageName -> PackageName -> Bool
$c== :: PackageName -> PackageName -> Bool
Eq)
instance Uniquable PackageId where
getUnique :: PackageId -> Unique
getUnique (PackageId FastString
n) = FastString -> Unique
forall a. Uniquable a => a -> Unique
getUnique FastString
n
instance Uniquable PackageName where
getUnique :: PackageName -> Unique
getUnique (PackageName FastString
n) = FastString -> Unique
forall a. Uniquable a => a -> Unique
getUnique FastString
n
instance Outputable PackageId where
ppr :: PackageId -> SDoc
ppr (PackageId FastString
str) = FastString -> SDoc
ftext FastString
str
instance Outputable PackageName where
ppr :: PackageName -> SDoc
ppr (PackageName FastString
str) = FastString -> SDoc
ftext FastString
str
unitPackageIdString :: GenUnitInfo u -> String
unitPackageIdString :: GenUnitInfo u -> String
unitPackageIdString GenUnitInfo u
pkg = FastString -> String
unpackFS FastString
str
where
PackageId FastString
str = GenUnitInfo u -> PackageId
forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod -> srcpkgid
unitPackageId GenUnitInfo u
pkg
unitPackageNameString :: GenUnitInfo u -> String
unitPackageNameString :: GenUnitInfo u -> String
unitPackageNameString GenUnitInfo u
pkg = FastString -> String
unpackFS FastString
str
where
PackageName FastString
str = GenUnitInfo u -> PackageName
forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod
-> srcpkgname
unitPackageName GenUnitInfo u
pkg
pprUnitInfo :: UnitInfo -> SDoc
pprUnitInfo :: UnitInfo -> SDoc
pprUnitInfo GenericUnitInfo {Bool
[(ModuleName, Maybe (GenModule (GenUnit UnitId)))]
[(ModuleName, GenModule (GenUnit UnitId))]
[(UnitId, ShortText)]
[ModuleName]
[ShortText]
[UnitId]
Maybe PackageName
Version
ShortText
UnitId
PackageName
PackageId
unitIsTrusted :: forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod -> Bool
unitIsExposed :: forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod -> Bool
unitIsIndefinite :: forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod -> Bool
unitHiddenModules :: forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod
-> [modulename]
unitExposedModules :: forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod
-> [(modulename, Maybe mod)]
unitHaddockHTMLs :: forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod
-> [ShortText]
unitHaddockInterfaces :: forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod
-> [ShortText]
unitIncludeDirs :: forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod
-> [ShortText]
unitIncludes :: forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod
-> [ShortText]
unitCcOptions :: forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod
-> [ShortText]
unitLinkerOptions :: forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod
-> [ShortText]
unitExtDepFrameworkDirs :: forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod
-> [ShortText]
unitExtDepFrameworks :: forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod
-> [ShortText]
unitLibraryDynDirs :: forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod
-> [ShortText]
unitLibraryDirs :: forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod
-> [ShortText]
unitExtDepLibsGhc :: forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod
-> [ShortText]
unitExtDepLibsSys :: forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod
-> [ShortText]
unitLibraries :: forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod
-> [ShortText]
unitImportDirs :: forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod
-> [ShortText]
unitAbiDepends :: forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod
-> [(uid, ShortText)]
unitDepends :: forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod -> [uid]
unitAbiHash :: forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod -> ShortText
unitComponentName :: forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod
-> Maybe srcpkgname
unitPackageVersion :: forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod -> Version
unitInstantiations :: forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod
-> [(modulename, mod)]
unitInstanceOf :: forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod -> uid
unitId :: forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod -> uid
unitIsTrusted :: Bool
unitIsExposed :: Bool
unitIsIndefinite :: Bool
unitHiddenModules :: [ModuleName]
unitExposedModules :: [(ModuleName, Maybe (GenModule (GenUnit UnitId)))]
unitHaddockHTMLs :: [ShortText]
unitHaddockInterfaces :: [ShortText]
unitIncludeDirs :: [ShortText]
unitIncludes :: [ShortText]
unitCcOptions :: [ShortText]
unitLinkerOptions :: [ShortText]
unitExtDepFrameworkDirs :: [ShortText]
unitExtDepFrameworks :: [ShortText]
unitLibraryDynDirs :: [ShortText]
unitLibraryDirs :: [ShortText]
unitExtDepLibsGhc :: [ShortText]
unitExtDepLibsSys :: [ShortText]
unitLibraries :: [ShortText]
unitImportDirs :: [ShortText]
unitAbiDepends :: [(UnitId, ShortText)]
unitDepends :: [UnitId]
unitAbiHash :: ShortText
unitComponentName :: Maybe PackageName
unitPackageVersion :: Version
unitPackageName :: PackageName
unitPackageId :: PackageId
unitInstantiations :: [(ModuleName, GenModule (GenUnit UnitId))]
unitInstanceOf :: UnitId
unitId :: UnitId
unitPackageName :: forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod
-> srcpkgname
unitPackageId :: forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod -> srcpkgid
..} =
[SDoc] -> SDoc
vcat [
String -> SDoc -> SDoc
field String
"name" (PackageName -> SDoc
forall a. Outputable a => a -> SDoc
ppr PackageName
unitPackageName),
String -> SDoc -> SDoc
field String
"version" (String -> SDoc
text (Version -> String
showVersion Version
unitPackageVersion)),
String -> SDoc -> SDoc
field String
"id" (UnitId -> SDoc
forall a. Outputable a => a -> SDoc
ppr UnitId
unitId),
String -> SDoc -> SDoc
field String
"exposed" (Bool -> SDoc
forall a. Outputable a => a -> SDoc
ppr Bool
unitIsExposed),
String -> SDoc -> SDoc
field String
"exposed-modules" ([(ModuleName, Maybe (GenModule (GenUnit UnitId)))] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [(ModuleName, Maybe (GenModule (GenUnit UnitId)))]
unitExposedModules),
String -> SDoc -> SDoc
field String
"hidden-modules" ([SDoc] -> SDoc
fsep ((ModuleName -> SDoc) -> [ModuleName] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr [ModuleName]
unitHiddenModules)),
String -> SDoc -> SDoc
field String
"trusted" (Bool -> SDoc
forall a. Outputable a => a -> SDoc
ppr Bool
unitIsTrusted),
String -> SDoc -> SDoc
field String
"import-dirs" ([SDoc] -> SDoc
fsep ((ShortText -> SDoc) -> [ShortText] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (String -> SDoc
text (String -> SDoc) -> (ShortText -> String) -> ShortText -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortText -> String
ST.unpack) [ShortText]
unitImportDirs)),
String -> SDoc -> SDoc
field String
"library-dirs" ([SDoc] -> SDoc
fsep ((ShortText -> SDoc) -> [ShortText] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (String -> SDoc
text (String -> SDoc) -> (ShortText -> String) -> ShortText -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortText -> String
ST.unpack) [ShortText]
unitLibraryDirs)),
String -> SDoc -> SDoc
field String
"dynamic-library-dirs" ([SDoc] -> SDoc
fsep ((ShortText -> SDoc) -> [ShortText] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (String -> SDoc
text (String -> SDoc) -> (ShortText -> String) -> ShortText -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortText -> String
ST.unpack) [ShortText]
unitLibraryDynDirs)),
String -> SDoc -> SDoc
field String
"hs-libraries" ([SDoc] -> SDoc
fsep ((ShortText -> SDoc) -> [ShortText] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (String -> SDoc
text (String -> SDoc) -> (ShortText -> String) -> ShortText -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortText -> String
ST.unpack) [ShortText]
unitLibraries)),
String -> SDoc -> SDoc
field String
"extra-libraries" ([SDoc] -> SDoc
fsep ((ShortText -> SDoc) -> [ShortText] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (String -> SDoc
text (String -> SDoc) -> (ShortText -> String) -> ShortText -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortText -> String
ST.unpack) [ShortText]
unitExtDepLibsSys)),
String -> SDoc -> SDoc
field String
"extra-ghci-libraries" ([SDoc] -> SDoc
fsep ((ShortText -> SDoc) -> [ShortText] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (String -> SDoc
text (String -> SDoc) -> (ShortText -> String) -> ShortText -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortText -> String
ST.unpack) [ShortText]
unitExtDepLibsGhc)),
String -> SDoc -> SDoc
field String
"include-dirs" ([SDoc] -> SDoc
fsep ((ShortText -> SDoc) -> [ShortText] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (String -> SDoc
text (String -> SDoc) -> (ShortText -> String) -> ShortText -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortText -> String
ST.unpack) [ShortText]
unitIncludeDirs)),
String -> SDoc -> SDoc
field String
"includes" ([SDoc] -> SDoc
fsep ((ShortText -> SDoc) -> [ShortText] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (String -> SDoc
text (String -> SDoc) -> (ShortText -> String) -> ShortText -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortText -> String
ST.unpack) [ShortText]
unitIncludes)),
String -> SDoc -> SDoc
field String
"depends" ([SDoc] -> SDoc
fsep ((UnitId -> SDoc) -> [UnitId] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map UnitId -> SDoc
forall a. Outputable a => a -> SDoc
ppr [UnitId]
unitDepends)),
String -> SDoc -> SDoc
field String
"cc-options" ([SDoc] -> SDoc
fsep ((ShortText -> SDoc) -> [ShortText] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (String -> SDoc
text (String -> SDoc) -> (ShortText -> String) -> ShortText -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortText -> String
ST.unpack) [ShortText]
unitCcOptions)),
String -> SDoc -> SDoc
field String
"ld-options" ([SDoc] -> SDoc
fsep ((ShortText -> SDoc) -> [ShortText] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (String -> SDoc
text (String -> SDoc) -> (ShortText -> String) -> ShortText -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortText -> String
ST.unpack) [ShortText]
unitLinkerOptions)),
String -> SDoc -> SDoc
field String
"framework-dirs" ([SDoc] -> SDoc
fsep ((ShortText -> SDoc) -> [ShortText] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (String -> SDoc
text (String -> SDoc) -> (ShortText -> String) -> ShortText -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortText -> String
ST.unpack) [ShortText]
unitExtDepFrameworkDirs)),
String -> SDoc -> SDoc
field String
"frameworks" ([SDoc] -> SDoc
fsep ((ShortText -> SDoc) -> [ShortText] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (String -> SDoc
text (String -> SDoc) -> (ShortText -> String) -> ShortText -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortText -> String
ST.unpack) [ShortText]
unitExtDepFrameworks)),
String -> SDoc -> SDoc
field String
"haddock-interfaces" ([SDoc] -> SDoc
fsep ((ShortText -> SDoc) -> [ShortText] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (String -> SDoc
text (String -> SDoc) -> (ShortText -> String) -> ShortText -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortText -> String
ST.unpack) [ShortText]
unitHaddockInterfaces)),
String -> SDoc -> SDoc
field String
"haddock-html" ([SDoc] -> SDoc
fsep ((ShortText -> SDoc) -> [ShortText] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (String -> SDoc
text (String -> SDoc) -> (ShortText -> String) -> ShortText -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortText -> String
ST.unpack) [ShortText]
unitHaddockHTMLs))
]
where
field :: String -> SDoc -> SDoc
field String
name SDoc
body = String -> SDoc
text String
name SDoc -> SDoc -> SDoc
<> SDoc
colon SDoc -> SDoc -> SDoc
<+> Int -> SDoc -> SDoc
nest Int
4 SDoc
body
mkUnit :: UnitInfo -> Unit
mkUnit :: UnitInfo -> GenUnit UnitId
mkUnit UnitInfo
p
| UnitInfo -> Bool
forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod -> Bool
unitIsIndefinite UnitInfo
p = UnitId
-> [(ModuleName, GenModule (GenUnit UnitId))] -> GenUnit UnitId
forall u.
IsUnitId u =>
u -> [(ModuleName, GenModule (GenUnit u))] -> GenUnit u
mkVirtUnit (UnitInfo -> UnitId
forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod -> uid
unitInstanceOf UnitInfo
p) (UnitInfo -> [(ModuleName, GenModule (GenUnit UnitId))]
forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod
-> [(modulename, mod)]
unitInstantiations UnitInfo
p)
| Bool
otherwise = Definite UnitId -> GenUnit UnitId
forall uid. Definite uid -> GenUnit uid
RealUnit (UnitId -> Definite UnitId
forall unit. unit -> Definite unit
Definite (UnitInfo -> UnitId
forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod -> uid
unitId UnitInfo
p))
mkUnitPprInfo :: (u -> FastString) -> GenUnitInfo u -> UnitPprInfo
mkUnitPprInfo :: (u -> FastString) -> GenUnitInfo u -> UnitPprInfo
mkUnitPprInfo u -> FastString
ufs GenUnitInfo u
i = FastString -> String -> Version -> Maybe String -> UnitPprInfo
UnitPprInfo
(u -> FastString
ufs (GenUnitInfo u -> u
forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod -> uid
unitId GenUnitInfo u
i))
(GenUnitInfo u -> String
forall u. GenUnitInfo u -> String
unitPackageNameString GenUnitInfo u
i)
(GenUnitInfo u -> Version
forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod -> Version
unitPackageVersion GenUnitInfo u
i)
((FastString -> String
unpackFS (FastString -> String)
-> (PackageName -> FastString) -> PackageName -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PackageName -> FastString
unPackageName) (PackageName -> String) -> Maybe PackageName -> Maybe String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GenUnitInfo u -> Maybe PackageName
forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod
-> Maybe srcpkgname
unitComponentName GenUnitInfo u
i)
collectIncludeDirs :: [UnitInfo] -> [FilePath]
collectIncludeDirs :: [UnitInfo] -> [String]
collectIncludeDirs [UnitInfo]
ps = (ShortText -> String) -> [ShortText] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map ShortText -> String
ST.unpack ([ShortText] -> [String]) -> [ShortText] -> [String]
forall a b. (a -> b) -> a -> b
$ [ShortText] -> [ShortText]
forall a. Ord a => [a] -> [a]
ordNub ((ShortText -> Bool) -> [ShortText] -> [ShortText]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (ShortText -> Bool) -> ShortText -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortText -> Bool
ST.null) ((UnitInfo -> [ShortText]) -> [UnitInfo] -> [ShortText]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap UnitInfo -> [ShortText]
forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod
-> [ShortText]
unitIncludeDirs [UnitInfo]
ps))
collectExtraCcOpts :: [UnitInfo] -> [String]
[UnitInfo]
ps = (ShortText -> String) -> [ShortText] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map ShortText -> String
ST.unpack ((UnitInfo -> [ShortText]) -> [UnitInfo] -> [ShortText]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap UnitInfo -> [ShortText]
forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod
-> [ShortText]
unitCcOptions [UnitInfo]
ps)
collectLibraryDirs :: Ways -> [UnitInfo] -> [FilePath]
collectLibraryDirs :: Ways -> [UnitInfo] -> [String]
collectLibraryDirs Ways
ws = [String] -> [String]
forall a. Ord a => [a] -> [a]
ordNub ([String] -> [String])
-> ([UnitInfo] -> [String]) -> [UnitInfo] -> [String]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> Bool) -> [String] -> [String]
forall a. (a -> Bool) -> [a] -> [a]
filter String -> Bool
forall (f :: * -> *) a. Foldable f => f a -> Bool
notNull ([String] -> [String])
-> ([UnitInfo] -> [String]) -> [UnitInfo] -> [String]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UnitInfo -> [String]) -> [UnitInfo] -> [String]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (Ways -> UnitInfo -> [String]
libraryDirsForWay Ways
ws)
collectFrameworks :: [UnitInfo] -> [String]
collectFrameworks :: [UnitInfo] -> [String]
collectFrameworks [UnitInfo]
ps = (ShortText -> String) -> [ShortText] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map ShortText -> String
ST.unpack ((UnitInfo -> [ShortText]) -> [UnitInfo] -> [ShortText]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap UnitInfo -> [ShortText]
forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod
-> [ShortText]
unitExtDepFrameworks [UnitInfo]
ps)
collectFrameworksDirs :: [UnitInfo] -> [String]
collectFrameworksDirs :: [UnitInfo] -> [String]
collectFrameworksDirs [UnitInfo]
ps = (ShortText -> String) -> [ShortText] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map ShortText -> String
ST.unpack ([ShortText] -> [ShortText]
forall a. Ord a => [a] -> [a]
ordNub ((ShortText -> Bool) -> [ShortText] -> [ShortText]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (ShortText -> Bool) -> ShortText -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortText -> Bool
ST.null) ((UnitInfo -> [ShortText]) -> [UnitInfo] -> [ShortText]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap UnitInfo -> [ShortText]
forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod
-> [ShortText]
unitExtDepFrameworkDirs [UnitInfo]
ps)))
libraryDirsForWay :: Ways -> UnitInfo -> [String]
libraryDirsForWay :: Ways -> UnitInfo -> [String]
libraryDirsForWay Ways
ws
| Ways -> Way -> Bool
hasWay Ways
ws Way
WayDyn = (ShortText -> String) -> [ShortText] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map ShortText -> String
ST.unpack ([ShortText] -> [String])
-> (UnitInfo -> [ShortText]) -> UnitInfo -> [String]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UnitInfo -> [ShortText]
forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod
-> [ShortText]
unitLibraryDynDirs
| Bool
otherwise = (ShortText -> String) -> [ShortText] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map ShortText -> String
ST.unpack ([ShortText] -> [String])
-> (UnitInfo -> [ShortText]) -> UnitInfo -> [String]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UnitInfo -> [ShortText]
forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod
-> [ShortText]
unitLibraryDirs
unitHsLibs :: GhcNameVersion -> Ways -> UnitInfo -> [String]
unitHsLibs :: GhcNameVersion -> Ways -> UnitInfo -> [String]
unitHsLibs GhcNameVersion
namever Ways
ways0 UnitInfo
p = (ShortText -> String) -> [ShortText] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (String -> String
mkDynName (String -> String) -> (ShortText -> String) -> ShortText -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String
addSuffix (String -> String) -> (ShortText -> String) -> ShortText -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortText -> String
ST.unpack) (UnitInfo -> [ShortText]
forall srcpkgid srcpkgname uid modulename mod.
GenericUnitInfo srcpkgid srcpkgname uid modulename mod
-> [ShortText]
unitLibraries UnitInfo
p)
where
ways1 :: Ways
ways1 = Way -> Ways -> Ways
removeWay Way
WayDyn Ways
ways0
ways2 :: Ways
ways2 | Ways
ways1 Ways -> Way -> Bool
`hasWay` Way
WayDebug Bool -> Bool -> Bool
|| Ways
ways1 Ways -> Way -> Bool
`hasWay` Way
WayProf
= Way -> Ways -> Ways
removeWay Way
WayTracing Ways
ways1
| Bool
otherwise
= Ways
ways1
tag :: String
tag = Ways -> String
waysTag (Ways -> Ways
fullWays Ways
ways2)
rts_tag :: String
rts_tag = Ways -> String
waysTag Ways
ways2
mkDynName :: String -> String
mkDynName String
x
| Bool -> Bool
not (Ways
ways0 Ways -> Way -> Bool
`hasWay` Way
WayDyn) = String
x
| String
"HS" String -> String -> Bool
forall a. Eq a => [a] -> [a] -> Bool
`isPrefixOf` String
x = String
x String -> String -> String
forall a. [a] -> [a] -> [a]
++ GhcNameVersion -> String
dynLibSuffix GhcNameVersion
namever
| Just String
x' <- String -> String -> Maybe String
forall a. Eq a => [a] -> [a] -> Maybe [a]
stripPrefix String
"C" String
x = String
x'
| Bool
otherwise
= String -> String
forall a. String -> a
panic (String
"Don't understand library name " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
x)
addSuffix :: String -> String
addSuffix rts :: String
rts@String
"HSrts" = String
rts String -> String -> String
forall a. [a] -> [a] -> [a]
++ (String -> String
expandTag String
rts_tag)
addSuffix rts :: String
rts@String
"HSrts-1.0.2" = String
rts String -> String -> String
forall a. [a] -> [a] -> [a]
++ (String -> String
expandTag String
rts_tag)
addSuffix String
other_lib = String
other_lib String -> String -> String
forall a. [a] -> [a] -> [a]
++ (String -> String
expandTag String
tag)
expandTag :: String -> String
expandTag String
t | String -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
t = String
""
| Bool
otherwise = Char
'_'Char -> String -> String
forall a. a -> [a] -> [a]
:String
t