Commit 1d840ee0 authored by ttuegel's avatar ttuegel
Browse files

Configure: disable profiling if unsupported by compiler

parent 47bdafb1
......@@ -58,6 +58,7 @@ module Distribution.Simple.Compiler (
packageKeySupported,
unitIdSupported,
coverageSupported,
profilingSupported,
-- * Support for profiling detail levels
ProfDetailLevel(..),
......@@ -325,6 +326,15 @@ coverageSupported comp =
GHCJS -> True
_ -> False
-- | Does this compiler support profiling?
profilingSupported :: Compiler -> Bool
profilingSupported comp =
case compilerFlavor comp of
GHC -> True
GHCJS -> True
LHC -> True
_ -> False
-- | Utility function for GHC only features
ghcSupported :: String -> Compiler -> Bool
ghcSupported key comp =
......
......@@ -642,27 +642,7 @@ configure (pkg_descr0', pbi) cfg = do
++ "is not being built. Linking will fail if any executables "
++ "depend on the library."
-- The --profiling flag sets the default for both libs and exes,
-- but can be overidden by --library-profiling, or the old deprecated
-- --executable-profiling flag.
let profEnabledLibOnly = configProfLib cfg
profEnabledBoth = fromFlagOrDefault False (configProf cfg)
profEnabledLib = fromFlagOrDefault profEnabledBoth profEnabledLibOnly
profEnabledExe = fromFlagOrDefault profEnabledBoth (configProfExe cfg)
-- The --profiling-detail and --library-profiling-detail flags behave
-- similarly
profDetailLibOnly <- checkProfDetail (configProfLibDetail cfg)
profDetailBoth <- liftM (fromFlagOrDefault ProfDetailDefault)
(checkProfDetail (configProfDetail cfg))
let profDetailLib = fromFlagOrDefault profDetailBoth profDetailLibOnly
profDetailExe = profDetailBoth
when (profEnabledExe && not profEnabledLib) $
warn verbosity $
"Executables will be built with profiling, but library "
++ "profiling is disabled. Linking will fail if any executables "
++ "depend on the library."
configProf <- configureProfiling verbosity cfg comp
configCoverage <- configureCoverage verbosity cfg comp
......@@ -675,7 +655,7 @@ configure (pkg_descr0', pbi) cfg = do
foldl' (\m clbi -> Map.insertWith (++) (componentLocalName clbi) [clbi] m)
Map.empty buildComponents
let lbi = configCoverage
let lbi = (configCoverage . configProf)
LocalBuildInfo {
configFlags = cfg,
flagAssignment = flags,
......@@ -694,12 +674,12 @@ configure (pkg_descr0', pbi) cfg = do
localPkgDescr = pkg_descr',
withPrograms = programsConfig'',
withVanillaLib = fromFlag $ configVanillaLib cfg,
withProfLib = profEnabledLib,
withSharedLib = withSharedLib_,
withDynExe = withDynExe_,
withProfExe = profEnabledExe,
withProfLibDetail = profDetailLib,
withProfExeDetail = profDetailExe,
withProfLib = False,
withProfLibDetail = ProfDetailNone,
withProfExe = False,
withProfExeDetail = ProfDetailNone,
withOptimization = fromFlag $ configOptimization cfg,
withDebugInfo = fromFlag $ configDebugInfo cfg,
withGHCiLib = fromFlagOrDefault ghciLibByDefault $
......@@ -756,15 +736,6 @@ configure (pkg_descr0', pbi) cfg = do
where
verbosity = fromFlag (configVerbosity cfg)
checkProfDetail (Flag (ProfDetailOther other)) = do
warn verbosity $
"Unknown profiling detail level '" ++ other
++ "', using default.\n"
++ "The profiling detail levels are: " ++ intercalate ", "
[ name | (name, _, _) <- knownProfDetailLevels ]
return (Flag ProfDetailDefault)
checkProfDetail other = return other
mkProgramsConfig :: ConfigFlags -> ProgramConfiguration -> ProgramConfiguration
mkProgramsConfig cfg initialProgramsConfig = programsConfig
where
......@@ -1039,6 +1010,67 @@ configureCoverage verbosity cfg comp = do
++ "program coverage. Program coverage has been disabled.")
return apply
-- | Select and apply profiling settings for the build based on the
-- 'ConfigFlags' and 'Compiler'.
configureProfiling :: Verbosity -> ConfigFlags -> Compiler
-> IO (LocalBuildInfo -> LocalBuildInfo)
configureProfiling verbosity cfg comp = do
-- The --profiling flag sets the default for both libs and exes,
-- but can be overidden by --library-profiling, or the old deprecated
-- --executable-profiling flag.
--
-- The --profiling-detail and --library-profiling-detail flags behave
-- similarly
let tryExeProfiling = fromFlagOrDefault False
(mappend (configProf cfg) (configProfExe cfg))
tryLibProfiling = fromFlagOrDefault tryExeProfiling
(mappend (configProf cfg) (configProfLib cfg))
tryExeProfileLevel = fromFlagOrDefault ProfDetailDefault
(configProfDetail cfg)
tryLibProfileLevel = fromFlagOrDefault ProfDetailDefault
(mappend
(configProfDetail cfg)
(configProfLibDetail cfg))
checkProfileLevel (ProfDetailOther other) = do
warn verbosity
("Unknown profiling detail level '" ++ other
++ "', using default.\nThe profiling detail levels are: "
++ intercalate ", "
[ name | (name, _, _) <- knownProfDetailLevels ])
return ProfDetailDefault
checkProfileLevel other = return other
(exeProfWithoutLibProf, applyProfiling) <-
if profilingSupported comp
then do
exeLevel <- checkProfileLevel tryExeProfileLevel
libLevel <- checkProfileLevel tryLibProfileLevel
let apply lbi = lbi { withProfLib = tryLibProfiling
, withProfLibDetail = libLevel
, withProfExe = tryExeProfiling
, withProfExeDetail = exeLevel
}
return (tryExeProfiling && not tryLibProfiling, apply)
else do
let apply lbi = lbi { withProfLib = False
, withProfLibDetail = ProfDetailNone
, withProfExe = False
, withProfExeDetail = ProfDetailNone
}
when (tryExeProfiling || tryLibProfiling) $ warn verbosity
("The compiler " ++ showCompilerId comp ++ " does not support "
++ "profiling. Profiling has been disabled.")
return (False, apply)
when exeProfWithoutLibProf $ warn verbosity
("Executables will be built with profiling, but library "
++ "profiling is disabled. Linking will fail if any executables "
++ "depend on the library.")
return applyProfiling
-- -----------------------------------------------------------------------------
-- Configuring package dependencies
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment