{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
module Distribution.Types.Library (
Library(..),
emptyLibrary,
explicitLibModules,
libModulesAutogen,
) where
import Distribution.Compat.Prelude
import Prelude ()
import Distribution.ModuleName
import Distribution.Types.BuildInfo
import Distribution.Types.LibraryVisibility
import Distribution.Types.ModuleReexport
import Distribution.Types.LibraryName
import qualified Distribution.Types.BuildInfo.Lens as L
data Library = Library
{ libName :: LibraryName
, exposedModules :: [ModuleName]
, reexportedModules :: [ModuleReexport]
, signatures :: [ModuleName]
, libExposed :: Bool
, libVisibility :: LibraryVisibility
, libBuildInfo :: BuildInfo
}
deriving (Generic, Show, Eq, Read, Typeable, Data)
instance L.HasBuildInfo Library where
buildInfo f l = (\x -> l { libBuildInfo = x }) <$> f (libBuildInfo l)
instance Binary Library
instance NFData Library where rnf = genericRnf
emptyLibrary :: Library
emptyLibrary = Library
{ libName = LMainLibName
, exposedModules = mempty
, reexportedModules = mempty
, signatures = mempty
, libExposed = True
, libVisibility = mempty
, libBuildInfo = mempty
}
instance Monoid Library where
mempty = emptyLibrary
mappend = (<>)
instance Semigroup Library where
a <> b = Library
{ libName = combineLibraryName (libName a) (libName b)
, exposedModules = combine exposedModules
, reexportedModules = combine reexportedModules
, signatures = combine signatures
, libExposed = libExposed a && libExposed b
, libVisibility = combine libVisibility
, libBuildInfo = combine libBuildInfo
}
where combine field = field a `mappend` field b
explicitLibModules :: Library -> [ModuleName]
explicitLibModules lib = exposedModules lib
++ otherModules (libBuildInfo lib)
++ signatures lib
libModulesAutogen :: Library -> [ModuleName]
libModulesAutogen lib = autogenModules (libBuildInfo lib)
combineLibraryName :: LibraryName -> LibraryName -> LibraryName
combineLibraryName l@(LSubLibName _) _ = l
combineLibraryName _ l = l