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],
extraLibDirs :: [String],
includeDirs :: [FilePath],
includes :: [FilePath],
installIncludes :: [FilePath],
options :: [(CompilerFlavor,[String])],
profOptions :: [(CompilerFlavor,[String])],
sharedOptions :: [(CompilerFlavor,[String])],
staticOptions :: [(CompilerFlavor,[String])],
customFieldsBI :: [(String,String)],
targetBuildDepends :: [Dependency],
mixins :: [Mixin]
}
deriving (Generic, Show, Read, Eq, Typeable, Data)
instance Binary 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 = [],
extraLibDirs = [],
includeDirs = [],
includes = [],
installIncludes = [],
options = [],
profOptions = [],
sharedOptions = [],
staticOptions = [],
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,
extraLibDirs = combineNub extraLibDirs,
includeDirs = combineNub includeDirs,
includes = combineNub includes,
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 -> [(CompilerFlavor,[String])])
-> CompilerFlavor -> BuildInfo -> [String]
lookupHcOptions f hc bi = [ opt | (hc',opts) <- f bi
, hc' == hc
, opt <- opts ]