{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
module Distribution.Types.BuildInfo (
BuildInfo(..),
emptyBuildInfo,
allLanguages,
allExtensions,
usedExtensions,
usesTemplateHaskellOrQQ,
hcOptions,
hcProfOptions,
hcSharedOptions,
hcStaticOptions,
) where
import Prelude ()
import Distribution.Compat.Prelude
import Distribution.Types.Mixin
import Distribution.Types.Dependency
import Distribution.Types.ExeDependency
import Distribution.Types.LegacyExeDependency
import Distribution.Types.PkgconfigDependency
import Distribution.ModuleName
import Distribution.Compiler
import Language.Haskell.Extension
data BuildInfo = BuildInfo {
buildable :: Bool,
buildTools :: [LegacyExeDependency],
buildToolDepends :: [ExeDependency],
cppOptions :: [String],
asmOptions :: [String],
cmmOptions :: [String],
ccOptions :: [String],
cxxOptions :: [String],
ldOptions :: [String],
pkgconfigDepends :: [PkgconfigDependency],
frameworks :: [String],
extraFrameworkDirs:: [String],
asmSources :: [FilePath],
cmmSources :: [FilePath],
cSources :: [FilePath],
cxxSources :: [FilePath],
jsSources :: [FilePath],
hsSourceDirs :: [FilePath],
otherModules :: [ModuleName],
virtualModules :: [ModuleName],
autogenModules :: [ModuleName],
defaultLanguage :: Maybe Language,
otherLanguages :: [Language],
defaultExtensions :: [Extension],
otherExtensions :: [Extension],
oldExtensions :: [Extension],
extraLibs :: [String],
extraGHCiLibs :: [String],
extraBundledLibs :: [String],
extraLibFlavours :: [String],
extraDynLibFlavours :: [String],
extraLibDirs :: [String],
includeDirs :: [FilePath],
includes :: [FilePath],
autogenIncludes :: [FilePath],
installIncludes :: [FilePath],
options :: PerCompilerFlavor [String],
profOptions :: PerCompilerFlavor [String],
sharedOptions :: PerCompilerFlavor [String],
staticOptions :: PerCompilerFlavor [String],
customFieldsBI :: [(String,String)],
targetBuildDepends :: [Dependency],
mixins :: [Mixin]
}
deriving (Generic, Show, Read, Eq, Typeable, Data)
instance Binary BuildInfo
instance Structured BuildInfo
instance NFData BuildInfo where rnf = genericRnf
instance Monoid BuildInfo where
mempty = BuildInfo {
buildable = True,
buildTools = [],
buildToolDepends = [],
cppOptions = [],
asmOptions = [],
cmmOptions = [],
ccOptions = [],
cxxOptions = [],
ldOptions = [],
pkgconfigDepends = [],
frameworks = [],
extraFrameworkDirs = [],
asmSources = [],
cmmSources = [],
cSources = [],
cxxSources = [],
jsSources = [],
hsSourceDirs = [],
otherModules = [],
virtualModules = [],
autogenModules = [],
defaultLanguage = Nothing,
otherLanguages = [],
defaultExtensions = [],
otherExtensions = [],
oldExtensions = [],
extraLibs = [],
extraGHCiLibs = [],
extraBundledLibs = [],
extraLibFlavours = [],
extraDynLibFlavours = [],
extraLibDirs = [],
includeDirs = [],
includes = [],
autogenIncludes = [],
installIncludes = [],
options = mempty,
profOptions = mempty,
sharedOptions = mempty,
staticOptions = mempty,
customFieldsBI = [],
targetBuildDepends = [],
mixins = []
}
mappend = (<>)
instance Semigroup BuildInfo where
a <> b = BuildInfo {
buildable = buildable a && buildable b,
buildTools = combine buildTools,
buildToolDepends = combine buildToolDepends,
cppOptions = combine cppOptions,
asmOptions = combine asmOptions,
cmmOptions = combine cmmOptions,
ccOptions = combine ccOptions,
cxxOptions = combine cxxOptions,
ldOptions = combine ldOptions,
pkgconfigDepends = combine pkgconfigDepends,
frameworks = combineNub frameworks,
extraFrameworkDirs = combineNub extraFrameworkDirs,
asmSources = combineNub asmSources,
cmmSources = combineNub cmmSources,
cSources = combineNub cSources,
cxxSources = combineNub cxxSources,
jsSources = combineNub jsSources,
hsSourceDirs = combineNub hsSourceDirs,
otherModules = combineNub otherModules,
virtualModules = combineNub virtualModules,
autogenModules = combineNub autogenModules,
defaultLanguage = combineMby defaultLanguage,
otherLanguages = combineNub otherLanguages,
defaultExtensions = combineNub defaultExtensions,
otherExtensions = combineNub otherExtensions,
oldExtensions = combineNub oldExtensions,
extraLibs = combine extraLibs,
extraGHCiLibs = combine extraGHCiLibs,
extraBundledLibs = combine extraBundledLibs,
extraLibFlavours = combine extraLibFlavours,
extraDynLibFlavours = combine extraDynLibFlavours,
extraLibDirs = combineNub extraLibDirs,
includeDirs = combineNub includeDirs,
includes = combineNub includes,
autogenIncludes = combineNub autogenIncludes,
installIncludes = combineNub installIncludes,
options = combine options,
profOptions = combine profOptions,
sharedOptions = combine sharedOptions,
staticOptions = combine staticOptions,
customFieldsBI = combine customFieldsBI,
targetBuildDepends = combineNub targetBuildDepends,
mixins = combine mixins
}
where
combine field = field a `mappend` field b
combineNub field = nub (combine field)
combineMby field = field b `mplus` field a
emptyBuildInfo :: BuildInfo
emptyBuildInfo = mempty
allLanguages :: BuildInfo -> [Language]
allLanguages bi = maybeToList (defaultLanguage bi)
++ otherLanguages bi
allExtensions :: BuildInfo -> [Extension]
allExtensions bi = usedExtensions bi
++ otherExtensions bi
usedExtensions :: BuildInfo -> [Extension]
usedExtensions bi = oldExtensions bi
++ defaultExtensions bi
usesTemplateHaskellOrQQ :: BuildInfo -> Bool
usesTemplateHaskellOrQQ bi = any p (allExtensions bi)
where
p ex = ex `elem`
[EnableExtension TemplateHaskell, EnableExtension QuasiQuotes]
hcOptions :: CompilerFlavor -> BuildInfo -> [String]
hcOptions = lookupHcOptions options
hcProfOptions :: CompilerFlavor -> BuildInfo -> [String]
hcProfOptions = lookupHcOptions profOptions
hcSharedOptions :: CompilerFlavor -> BuildInfo -> [String]
hcSharedOptions = lookupHcOptions sharedOptions
hcStaticOptions :: CompilerFlavor -> BuildInfo -> [String]
hcStaticOptions = lookupHcOptions staticOptions
lookupHcOptions :: (BuildInfo -> PerCompilerFlavor [String])
-> CompilerFlavor -> BuildInfo -> [String]
lookupHcOptions f hc bi = case f bi of
PerCompilerFlavor ghc ghcjs
| hc == GHC -> ghc
| hc == GHCJS -> ghcjs
| otherwise -> mempty