diff --git a/Cabal/Distribution/Simple/Configure.hs b/Cabal/Distribution/Simple/Configure.hs index 6c859c7bf..343a487f2 100644 --- a/Cabal/Distribution/Simple/Configure.hs +++ b/Cabal/Distribution/Simple/Configure.hs @@ -46,6 +46,7 @@ module Distribution.Simple.Configure (configure, getPackageDBContents, configCompiler, configCompilerAux, configCompilerEx, configCompilerAuxEx, + computeEffectiveProfiling, ccLdOptionsBuildInfo, checkForeignDeps, interpretPackageDbFlags, @@ -1074,11 +1075,18 @@ 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 +-- | Compute the effective value of the profiling flags +-- @--enable-library-profiling@ and @--enable-executable-profiling@ +-- from the specified 'ConfigFlags'. This may be useful for +-- external Cabal tools which need to interact with Setup in +-- a backwards-compatible way: the most predictable mechanism +-- for enabling profiling across many legacy versions is to +-- NOT use @--enable-profiling@ and use those two flags instead. +-- +-- Note that @--enable-executable-profiling@ also affects profiling +-- of benchmarks and (non-detailed) test suites. +computeEffectiveProfiling :: ConfigFlags -> (Bool {- lib -}, Bool {- exe -}) +computeEffectiveProfiling cfg = -- 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. @@ -1089,6 +1097,14 @@ configureProfiling verbosity cfg comp = do (mappend (configProf cfg) (configProfExe cfg)) tryLibProfiling = fromFlagOrDefault tryExeProfiling (mappend (configProf cfg) (configProfLib cfg)) + in (tryLibProfiling, tryExeProfiling) + +-- | 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 + let (tryLibProfiling, tryExeProfiling) = computeEffectiveProfiling cfg tryExeProfileLevel = fromFlagOrDefault ProfDetailDefault (configProfDetail cfg) diff --git a/cabal-install/Distribution/Client/Setup.hs b/cabal-install/Distribution/Client/Setup.hs index 15fd59835..87dfadb4d 100644 --- a/cabal-install/Distribution/Client/Setup.hs +++ b/cabal-install/Distribution/Client/Setup.hs @@ -76,7 +76,7 @@ import Distribution.Simple.Program (ProgramDb, defaultProgramDb) import Distribution.Simple.Command hiding (boolOpt, boolOpt') import qualified Distribution.Simple.Command as Command import Distribution.Simple.Configure - ( configCompilerAuxEx, interpretPackageDbFlags ) + ( configCompilerAuxEx, interpretPackageDbFlags, computeEffectiveProfiling ) import qualified Distribution.Simple.Setup as Cabal import Distribution.Simple.Setup ( ConfigFlags(..), BuildFlags(..), ReplFlags @@ -393,21 +393,25 @@ filterConfigureFlags flags cabalLibVersion } -- Cabal < 1.23 doesn't know about '--profiling-detail'. + -- Cabal < 1.23 has a hacked up version of 'enable-profiling' + -- which we shouldn't use. + (tryLibProfiling, tryExeProfiling) = computeEffectiveProfiling flags flags_1_23_0 = flags_latest { configProfDetail = NoFlag , configProfLibDetail = NoFlag - , configIPID = NoFlag } + , configIPID = NoFlag + , configProf = mempty + , configProfExe = Flag tryExeProfiling + , configProfLib = Flag tryLibProfiling + } -- Cabal < 1.22 doesn't know about '--disable-debug-info'. flags_1_22_0 = flags_1_23_0 { configDebugInfo = NoFlag } -- Cabal < 1.21.1 doesn't know about 'disable-relocatable' -- Cabal < 1.21.1 doesn't know about 'enable-profiling' + -- (but we already dealt with it in flags_1_23_0) flags_1_21_1 = flags_1_22_0 { configRelocatable = NoFlag - , configProf = NoFlag - , configProfExe = configProf flags - , configProfLib = - mappend (configProf flags) (configProfLib flags) , configCoverage = NoFlag , configLibCoverage = configCoverage flags }