Skip to content

Commit

Permalink
Configure: disable profiling if unsupported by compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
ttuegel committed Jul 24, 2016
1 parent da0f17b commit de4e22b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 24 deletions.
10 changes: 10 additions & 0 deletions Cabal/Distribution/Simple/Compiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ module Distribution.Simple.Compiler (
packageKeySupported,
unitIdSupported,
coverageSupported,
profilingSupported,

-- * Support for profiling detail levels
ProfDetailLevel(..),
Expand Down Expand Up @@ -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 =
Expand Down
64 changes: 40 additions & 24 deletions Cabal/Distribution/Simple/Configure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -645,20 +645,45 @@ configure (pkg_descr0', pbi) cfg = 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.
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
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

(enableExeProf, profExeDetail, enableLibProf, profLibDetail) <-
if profilingSupported comp
then do
exeLevel <- checkProfileLevel tryExeProfileLevel
libLevel <- checkProfileLevel tryLibProfileLevel
return ( tryExeProfiling, exeLevel
, tryLibProfiling, libLevel
)
else do
when (tryExeProfiling || tryLibProfiling) $ warn verbosity
("The compiler " ++ showCompilerId comp ++ " does not support "
++ "profiling. Profiling has been disabled.")
return (False, ProfDetailNone, False, ProfDetailNone)

when (profEnabledExe && not profEnabledLib) $
when (enableExeProf && not enableLibProf) $
warn verbosity $
"Executables will be built with profiling, but library "
++ "profiling is disabled. Linking will fail if any executables "
Expand Down Expand Up @@ -703,12 +728,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 = enableLibProf,
withProfLibDetail = profLibDetail,
withProfExe = enableExeProf,
withProfExeDetail = profExeDetail,
withOptimization = fromFlag $ configOptimization cfg,
withDebugInfo = fromFlag $ configDebugInfo cfg,
withGHCiLib = fromFlagOrDefault ghciLibByDefault $
Expand Down Expand Up @@ -765,15 +790,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
Expand Down

0 comments on commit de4e22b

Please sign in to comment.