Commit c1615bb9 authored by Edward Z. Yang's avatar Edward Z. Yang

Introduce new ComponentEnabledSpec, removing testEnabled/benchmarkEnabled.

As per an existing TODO in the code, the use of
testEnabled/benchmarkEnabled to indicate if a component
was enabled/disabled by the user command line was an
egregious violation of abstraction.  This commit removes
these two fields, instead passing along the necessary
enabling information with ComponentEnabledSpec instead.

As there were not many uses of testEnabled/benchmarkEnabled,
this was not too difficult to do.
Signed-off-by: default avatarEdward Z. Yang <ezyang@cs.stanford.edu>
parent be5f9e9b
......@@ -64,7 +64,6 @@ module Distribution.PackageDescription (
hasTests,
withTest,
testModules,
enabledTests,
-- * Benchmarks
Benchmark(..),
......@@ -76,7 +75,6 @@ module Distribution.PackageDescription (
hasBenchmarks,
withBenchmark,
benchmarkModules,
enabledBenchmarks,
-- * Build information
BuildInfo(..),
......@@ -447,8 +445,12 @@ hasPublicLib p = any f (libraries p)
hasLibs :: PackageDescription -> Bool
hasLibs p = any (buildable . libBuildInfo) (libraries p)
-- |If the package description has a library section, call the given
-- function with the library build info as argument.
-- | If the package description has a buildable library section,
-- call the given function with the library build info as argument.
-- You probably want 'withLibLBI' if you have a 'LocalBuildInfo',
-- see the note in
-- "Distribution.Simple.LocalBuildInfo#buildable_vs_enabled_components"
-- for more information.
withLib :: PackageDescription -> (Library -> IO ()) -> IO ()
withLib pkg_descr f =
sequence_ [f lib | lib <- libraries pkg_descr, buildable (libBuildInfo lib)]
......@@ -532,7 +534,10 @@ hasExes :: PackageDescription -> Bool
hasExes p = any (buildable . buildInfo) (executables p)
-- | Perform the action on each buildable 'Executable' in the package
-- description.
-- description. You probably want 'withExeLBI' if you have a
-- 'LocalBuildInfo', see the note in
-- "Distribution.Simple.LocalBuildInfo#buildable_vs_enabled_components"
-- for more information.
withExe :: PackageDescription -> (Executable -> IO ()) -> IO ()
withExe pkg_descr f =
sequence_ [f exe | exe <- executables pkg_descr, buildable (buildInfo exe)]
......@@ -549,13 +554,7 @@ exeModules exe = otherModules (buildInfo exe)
data TestSuite = TestSuite {
testName :: String,
testInterface :: TestSuiteInterface,
testBuildInfo :: BuildInfo,
testEnabled :: Bool
-- TODO: By having a 'testEnabled' field in the PackageDescription, we
-- are mixing build status information (i.e., arguments to 'configure')
-- with static package description information. This is undesirable, but
-- a better solution is waiting on the next overhaul to the
-- GenericPackageDescription -> PackageDescription resolution process.
testBuildInfo :: BuildInfo
}
deriving (Generic, Show, Read, Eq, Typeable, Data)
......@@ -593,8 +592,7 @@ instance Monoid TestSuite where
mempty = TestSuite {
testName = mempty,
testInterface = mempty,
testBuildInfo = mempty,
testEnabled = False
testBuildInfo = mempty
}
mappend = (Semi.<>)
......@@ -602,8 +600,7 @@ instance Semigroup TestSuite where
a <> b = TestSuite {
testName = combine' testName,
testInterface = combine testInterface,
testBuildInfo = combine testBuildInfo,
testEnabled = testEnabled a || testEnabled b
testBuildInfo = combine testBuildInfo
}
where combine field = field a `mappend` field b
combine' f = case (f a, f b) of
......@@ -627,14 +624,14 @@ emptyTestSuite = mempty
hasTests :: PackageDescription -> Bool
hasTests = any (buildable . testBuildInfo) . testSuites
-- | Get all the enabled test suites from a package.
enabledTests :: PackageDescription -> [TestSuite]
enabledTests = filter testEnabled . testSuites
-- | Perform an action on each buildable 'TestSuite' in a package.
-- You probably want 'withTestLBI' if you have a 'LocalBuildInfo', see the note in
-- "Distribution.Simple.LocalBuildInfo#buildable_vs_enabled_components"
-- for more information.
withTest :: PackageDescription -> (TestSuite -> IO ()) -> IO ()
withTest pkg_descr f =
mapM_ f $ filter (buildable . testBuildInfo) $ enabledTests pkg_descr
sequence_ [ f test | test <- testSuites pkg_descr, buildable (testBuildInfo test) ]
-- | Get all the module names from a test suite.
testModules :: TestSuite -> [ModuleName]
......@@ -695,9 +692,7 @@ testType test = case testInterface test of
data Benchmark = Benchmark {
benchmarkName :: String,
benchmarkInterface :: BenchmarkInterface,
benchmarkBuildInfo :: BuildInfo,
benchmarkEnabled :: Bool
-- TODO: See TODO for 'testEnabled'.
benchmarkBuildInfo :: BuildInfo
}
deriving (Generic, Show, Read, Eq, Typeable, Data)
......@@ -731,8 +726,7 @@ instance Monoid Benchmark where
mempty = Benchmark {
benchmarkName = mempty,
benchmarkInterface = mempty,
benchmarkBuildInfo = mempty,
benchmarkEnabled = False
benchmarkBuildInfo = mempty
}
mappend = (Semi.<>)
......@@ -740,8 +734,7 @@ instance Semigroup Benchmark where
a <> b = Benchmark {
benchmarkName = combine' benchmarkName,
benchmarkInterface = combine benchmarkInterface,
benchmarkBuildInfo = combine benchmarkBuildInfo,
benchmarkEnabled = benchmarkEnabled a || benchmarkEnabled b
benchmarkBuildInfo = combine benchmarkBuildInfo
}
where combine field = field a `mappend` field b
combine' f = case (f a, f b) of
......@@ -765,14 +758,14 @@ emptyBenchmark = mempty
hasBenchmarks :: PackageDescription -> Bool
hasBenchmarks = any (buildable . benchmarkBuildInfo) . benchmarks
-- | Get all the enabled benchmarks from a package.
enabledBenchmarks :: PackageDescription -> [Benchmark]
enabledBenchmarks = filter benchmarkEnabled . benchmarks
-- | Perform an action on each buildable 'Benchmark' in a package.
-- You probably want 'withBenchLBI' if you have a 'LocalBuildInfo', see the note in
-- "Distribution.Simple.LocalBuildInfo#buildable_vs_enabled_components"
-- for more information.
withBenchmark :: PackageDescription -> (Benchmark -> IO ()) -> IO ()
withBenchmark pkg_descr f =
mapM_ f $ filter (buildable . benchmarkBuildInfo) $ enabledBenchmarks pkg_descr
sequence_ [f bench | bench <- benchmarks pkg_descr, buildable (benchmarkBuildInfo bench)]
-- | Get all the module names from a benchmark.
benchmarkModules :: Benchmark -> [ModuleName]
......@@ -935,12 +928,10 @@ allBuildInfo pkg_descr = [ bi | lib <- libraries pkg_descr
, buildable bi ]
++ [ bi | tst <- testSuites pkg_descr
, let bi = testBuildInfo tst
, buildable bi
, testEnabled tst ]
, buildable bi ]
++ [ bi | tst <- benchmarks pkg_descr
, let bi = benchmarkBuildInfo tst
, buildable bi
, benchmarkEnabled tst ]
, buildable bi ]
--FIXME: many of the places where this is used, we actually want to look at
-- unbuildable bits too, probably need separate functions
......
......@@ -43,6 +43,7 @@ import Distribution.Simple.Utils hiding (findPackageDesc, notice)
import Distribution.Version
import Distribution.Package
import Distribution.Text
import Distribution.Simple.LocalBuildInfo hiding (compiler)
import Language.Haskell.Extension
import Data.Maybe
......@@ -1283,7 +1284,7 @@ checkPackageVersions pkg =
-- open upper bound. To get a typical configuration we finalise
-- using no package index and the current platform.
finalised = finalizePackageDescription
[] (const True) buildPlatform
[] defaultComponentEnabled (const True) buildPlatform
(unknownCompilerInfo
(CompilerId buildCompilerFlavor (Version [] [])) NoAbiTag)
[] pkg
......
......@@ -48,6 +48,7 @@ import Distribution.Text
import Distribution.Compat.ReadP as ReadP hiding ( char )
import qualified Distribution.Compat.ReadP as ReadP ( char )
import Distribution.Compat.Semigroup as Semi
import Distribution.Simple.LocalBuildInfo
import Control.Arrow (first)
import Data.Char ( isAlphaNum )
......@@ -211,6 +212,7 @@ instance Semigroup d => Semigroup (DepTestRslt d) where
resolveWithFlags ::
[(FlagName,[Bool])]
-- ^ Domain for each flag name, will be tested in order.
-> ComponentEnabledSpec
-> OS -- ^ OS as returned by Distribution.System.buildOS
-> Arch -- ^ Arch as returned by Distribution.System.buildArch
-> CompilerInfo -- ^ Compiler information
......@@ -220,7 +222,7 @@ resolveWithFlags ::
-> Either [Dependency] (TargetSet PDTagged, FlagAssignment)
-- ^ Either the missing dependencies (error case), or a pair of
-- (set of build targets with dependencies, chosen flag assignments)
resolveWithFlags dom os arch impl constrs trees checkDeps =
resolveWithFlags dom enabled os arch impl constrs trees checkDeps =
either (Left . fromDepMapUnion) Right $ explore (build [] dom)
where
extraConstrs = toDepMap constrs
......@@ -245,7 +247,7 @@ resolveWithFlags dom os arch impl constrs trees checkDeps =
-- apply additional constraints to all dependencies
first (`constrainBy` extraConstrs) .
simplifyCondTree (env flags)
deps = overallDependencies targetSet
deps = overallDependencies enabled targetSet
in case checkDeps (fromDepMap deps) of
DepOk | null ts -> Right (targetSet, flags)
| otherwise -> tryAll $ map explore ts
......@@ -416,15 +418,15 @@ newtype TargetSet a = TargetSet [(DependencyMap, a)]
-- | Combine the target-specific dependencies in a TargetSet to give the
-- dependencies for the package as a whole.
overallDependencies :: TargetSet PDTagged -> DependencyMap
overallDependencies (TargetSet targets) = mconcat depss
overallDependencies :: ComponentEnabledSpec -> TargetSet PDTagged -> DependencyMap
overallDependencies enabled (TargetSet targets) = mconcat depss
where
(depss, _) = unzip $ filter (removeDisabledSections . snd) targets
removeDisabledSections :: PDTagged -> Bool
removeDisabledSections (Lib _ l) = buildable (libBuildInfo l)
removeDisabledSections (Exe _ e) = buildable (buildInfo e)
removeDisabledSections (Test _ t) = testEnabled t && buildable (testBuildInfo t)
removeDisabledSections (Bench _ b) = benchmarkEnabled b && buildable (benchmarkBuildInfo b)
removeDisabledSections (Lib _ l) = componentEnabled enabled (CLib l)
removeDisabledSections (Exe _ e) = componentEnabled enabled (CExe e)
removeDisabledSections (Test _ t) = componentEnabled enabled (CTest t)
removeDisabledSections (Bench _ b) = componentEnabled enabled (CBench b)
removeDisabledSections PDNull = True
-- Apply extra constraints to a dependency map.
......@@ -505,6 +507,10 @@ flattenTaggedTargets (TargetSet targets) = foldr untag ([], [], [], []) targets
-- Convert GenericPackageDescription to PackageDescription
--
-- ezyang: Arguably, this should be:
-- data PDTagged = PDComp String Component
-- | PDNull
-- Also, what the heck is the String? The componentName?
data PDTagged = Lib String Library
| Exe String Executable
| Test String TestSuite
......@@ -549,6 +555,7 @@ instance Semigroup PDTagged where
--
finalizePackageDescription ::
FlagAssignment -- ^ Explicitly specified flag assignments
-> ComponentEnabledSpec
-> (Dependency -> Bool) -- ^ Is a given dependency satisfiable from the set of
-- available packages? If this is unknown then use
-- True.
......@@ -560,7 +567,7 @@ finalizePackageDescription ::
(PackageDescription, FlagAssignment)
-- ^ Either missing dependencies or the resolved package
-- description along with the flag assignments chosen.
finalizePackageDescription userflags satisfyDep
finalizePackageDescription userflags enabled satisfyDep
(Platform arch os) impl constraints
(GenericPackageDescription pkg flags libs0 exes0 tests0 bms0) =
case resolveFlags of
......@@ -569,7 +576,7 @@ finalizePackageDescription userflags satisfyDep
, executables = exes'
, testSuites = tests'
, benchmarks = bms'
, buildDepends = fromDepMap (overallDependencies targetSet)
, buildDepends = fromDepMap (overallDependencies enabled targetSet)
}
, flagVals )
......@@ -582,7 +589,7 @@ finalizePackageDescription userflags satisfyDep
++ map (\(name,tree) -> mapTreeData (Bench name) tree) bms0
resolveFlags =
case resolveWithFlags flagChoices os arch impl constraints condTrees check of
case resolveWithFlags flagChoices enabled os arch impl constraints condTrees check of
Right (targetSet, fs) ->
let (libs, exes, tests, bms) = flattenTaggedTargets targetSet in
Right ( (map (\(n,l) -> (libFillInDefaults l) { libName = n }) libs,
......
......@@ -152,10 +152,10 @@ ppTestSuites suites =
maybeTestType | testInterface testsuite == mempty = Nothing
| otherwise = Just (testType testsuite)
ppTestSuite (TestSuite _ _ buildInfo' _)
(Just (TestSuite _ _ buildInfo2 _)) =
ppDiffFields binfoFieldDescrs buildInfo' buildInfo2
$+$ ppCustomFields (customFieldsBI buildInfo')
ppTestSuite test' (Just test2) =
ppDiffFields binfoFieldDescrs
(testBuildInfo test') (testBuildInfo test2)
$+$ ppCustomFields (customFieldsBI (testBuildInfo test'))
testSuiteMainIs test = case testInterface test of
TestSuiteExeV10 _ f -> Just f
......@@ -182,10 +182,10 @@ ppBenchmarks suites =
maybeBenchmarkType | benchmarkInterface benchmark == mempty = Nothing
| otherwise = Just (benchmarkType benchmark)
ppBenchmark (Benchmark _ _ buildInfo' _)
(Just (Benchmark _ _ buildInfo2 _)) =
ppDiffFields binfoFieldDescrs buildInfo' buildInfo2
$+$ ppCustomFields (customFieldsBI buildInfo')
ppBenchmark bench' (Just bench2) =
ppDiffFields binfoFieldDescrs
(benchmarkBuildInfo bench') (benchmarkBuildInfo bench2)
$+$ ppCustomFields (customFieldsBI (benchmarkBuildInfo bench'))
benchmarkMainIs benchmark = case benchmarkInterface benchmark of
BenchmarkExeV10 _ f -> Just f
......
......@@ -40,9 +40,7 @@ bench args pkg_descr lbi flags = do
let verbosity = fromFlag $ benchmarkVerbosity flags
benchmarkNames = args
pkgBenchmarks = PD.benchmarks pkg_descr
enabledBenchmarks = [ t | t <- pkgBenchmarks
, PD.benchmarkEnabled t
, PD.buildable (PD.benchmarkBuildInfo t) ]
enabledBenchmarks = map fst (LBI.enabledBenchLBIs pkg_descr lbi)
-- Run the benchmark
doBench :: PD.Benchmark -> IO ExitCode
......
......@@ -81,7 +81,7 @@ build pkg_descr lbi flags suffixes
-- a --assume-deps-up-to-date with multiple arguments. Arguably, we should
-- error early in this case.
targets <- readBuildTargets pkg_descr (buildArgs flags)
(cname, _) <- checkBuildTargets verbosity pkg_descr targets >>= \r -> case r of
(cname, _) <- checkBuildTargets verbosity pkg_descr lbi targets >>= \r -> case r of
[] -> die "In --assume-deps-up-to-date mode you must specify a target"
[target'] -> return target'
_ -> die "In --assume-deps-up-to-date mode you can only build a single target"
......@@ -106,7 +106,7 @@ build pkg_descr lbi flags suffixes
lbi' suffixes comp clbi distPref
| otherwise = do
targets <- readBuildTargets pkg_descr (buildArgs flags)
targets' <- checkBuildTargets verbosity pkg_descr targets
targets' <- checkBuildTargets verbosity pkg_descr lbi targets
let componentsToBuild = componentsInBuildOrder lbi (map fst targets')
info verbosity $ "Component build order: "
++ intercalate ", " (map (showComponentName . componentLocalName) componentsToBuild)
......@@ -145,9 +145,10 @@ repl pkg_descr lbi flags suffixes args = do
targets <- readBuildTargets pkg_descr args
targets' <- case targets of
-- This seems DEEPLY questionable.
[] -> return $ take 1 [ componentName c
| c <- pkgEnabledComponents pkg_descr ]
[target] -> fmap (map fst) (checkBuildTargets verbosity pkg_descr [target])
| c <- pkgBuildableComponents pkg_descr ]
[target] -> fmap (map fst) (checkBuildTargets verbosity pkg_descr lbi [target])
_ -> die $ "The 'repl' command does not support multiple targets at once."
let componentsToBuild = componentsInBuildOrder lbi targets'
componentForRepl = last componentsToBuild
......
......@@ -947,16 +947,17 @@ caseFold = lowercase
--
-- Also swizzle into a more convenient form.
--
checkBuildTargets :: Verbosity -> PackageDescription -> [BuildTarget]
checkBuildTargets :: Verbosity -> PackageDescription -> LocalBuildInfo -> [BuildTarget]
-> IO [(ComponentName, Maybe (Either ModuleName FilePath))]
checkBuildTargets _ pkg [] =
return [ (componentName c, Nothing) | c <- pkgEnabledComponents pkg ]
checkBuildTargets _ pkg lbi [] =
return [ (componentName c, Nothing) | c <- enabledComponents pkg lbi ]
checkBuildTargets verbosity pkg targets = do
checkBuildTargets verbosity pkg lbi targets = do
let (enabled, disabled) =
partitionEithers
[ case componentDisabledReason (getComponent pkg cname) of
[ case componentDisabledReason (componentEnabledSpec lbi)
(getComponent pkg cname) of
Nothing -> Left target'
Just reason -> Right (cname, reason)
| target <- targets
......
......@@ -373,6 +373,12 @@ configure (pkg_descr0', pbi) cfg = do
let internalPackageSet :: InstalledPackageIndex
internalPackageSet = getInternalPackages pkg_descr0
-- Make a data structure describing what components are enabled.
let enabled :: ComponentEnabledSpec
enabled = ComponentEnabledSpec
{ testsEnabled = fromFlag (configTests cfg)
, benchmarksEnabled = fromFlag (configBenchmarks cfg) }
-- allConstraints: The set of all 'Dependency's we have. Used ONLY
-- to 'configureFinalizedPackage'.
-- requiredDepsMap: A map from 'PackageName' to the specifically
......@@ -410,7 +416,7 @@ configure (pkg_descr0', pbi) cfg = do
-- cleaner to then configure the dependencies afterwards.
(pkg_descr :: PackageDescription,
flags :: FlagAssignment)
<- configureFinalizedPackage verbosity cfg
<- configureFinalizedPackage verbosity cfg enabled
allConstraints
(dependencySatisfiable
(fromFlagOrDefault False (configExactConfiguration cfg))
......@@ -571,7 +577,7 @@ configure (pkg_descr0', pbi) cfg = do
-- From there, we build a ComponentLocalBuildInfo for each of the
-- components, which lets us actually build each component.
buildComponents <-
case mkComponentsGraph pkg_descr internalPkgDeps of
case mkComponentsGraph enabled pkg_descr internalPkgDeps of
Left componentCycle -> reportComponentCycle componentCycle
Right comps ->
mkComponentsLocalBuildInfo cfg comp packageDependsIndex pkg_descr
......@@ -668,6 +674,7 @@ configure (pkg_descr0', pbi) cfg = do
let lbi = LocalBuildInfo {
configFlags = cfg',
flagAssignment = flags,
componentEnabledSpec = enabled,
extraConfigArgs = [], -- Currently configure does not
-- take extra args, but if it
-- did they would go here.
......@@ -892,6 +899,7 @@ relaxPackageDeps (RelaxDepsSome allowNewerDeps') gpd =
configureFinalizedPackage
:: Verbosity
-> ConfigFlags
-> ComponentEnabledSpec
-> [Dependency]
-> (Dependency -> Bool) -- ^ tests if a dependency is satisfiable.
-- Might say it's satisfiable even when not.
......@@ -899,27 +907,18 @@ configureFinalizedPackage
-> Platform
-> GenericPackageDescription
-> IO (PackageDescription, FlagAssignment)
configureFinalizedPackage verbosity cfg
configureFinalizedPackage verbosity cfg enabled
allConstraints satisfies comp compPlatform pkg_descr0 = do
let enableTest t = t { testEnabled = fromFlag (configTests cfg) }
flaggedTests = map (\(n, t) -> (n, mapTreeData enableTest t))
(condTestSuites pkg_descr0)
enableBenchmark bm = bm { benchmarkEnabled =
fromFlag (configBenchmarks cfg) }
flaggedBenchmarks = map (\(n, bm) ->
(n, mapTreeData enableBenchmark bm))
(condBenchmarks pkg_descr0)
pkg_descr0'' = pkg_descr0 { condTestSuites = flaggedTests
, condBenchmarks = flaggedBenchmarks }
(pkg_descr0', flags) <-
case finalizePackageDescription
(configConfigurationsFlags cfg)
enabled
satisfies
compPlatform
(compilerInfo comp)
allConstraints
pkg_descr0''
pkg_descr0
of Right r -> return r
Left missing ->
die $ "Encountered missing dependencies:\n"
......@@ -1435,13 +1434,15 @@ configCompilerAux = fmap (\(a,_,b) -> (a,b)) . configCompilerAuxEx
-- (although it is in the absence of Backpack.)
--
-- TODO: tighten up the type of 'internalPkgDeps'
mkComponentsGraph :: PackageDescription
mkComponentsGraph :: ComponentEnabledSpec
-> PackageDescription
-> [PackageId]
-> Either [ComponentName]
[(Component, [ComponentName])]
mkComponentsGraph pkg_descr internalPkgDeps =
mkComponentsGraph enabled pkg_descr internalPkgDeps =
let graph = [ (c, componentName c, componentDeps c)
| c <- pkgEnabledComponents pkg_descr ]
| c <- pkgBuildableComponents pkg_descr
, componentEnabled enabled c ]
in case checkComponentsCyclic graph of
Just ccycle -> Left [ cname | (_,cname,_) <- ccycle ]
Nothing -> Right [ (c, cdeps) | (c, _, cdeps) <- topSortFromEdges graph ]
......
......@@ -61,7 +61,7 @@ install pkg_descr lbi flags
| fromFlag (copyAssumeDepsUpToDate flags) = do
checkHasLibsOrExes
targets <- readBuildTargets pkg_descr (copyArgs flags)
targets' <- checkBuildTargets verbosity pkg_descr targets
targets' <- checkBuildTargets verbosity pkg_descr lbi targets
case targets' of
_ | null (copyArgs flags)
-> copyPackage verbosity pkg_descr lbi distPref copydest
......@@ -74,7 +74,7 @@ install pkg_descr lbi flags
| otherwise = do
checkHasLibsOrExes
targets <- readBuildTargets pkg_descr (copyArgs flags)
targets' <- checkBuildTargets verbosity pkg_descr targets
targets' <- checkBuildTargets verbosity pkg_descr lbi targets
copyPackage verbosity pkg_descr lbi distPref copydest
......
......@@ -38,11 +38,9 @@ module Distribution.Simple.LocalBuildInfo (
foldComponent,
componentName,
componentBuildInfo,
componentEnabled,
componentDisabledReason,
ComponentDisabledReason(..),
componentBuildable,
pkgComponents,
pkgEnabledComponents,
pkgBuildableComponents,
lookupComponent,
getComponent,
maybeGetDefaultLibraryLocalBuildInfo,
......@@ -58,7 +56,19 @@ module Distribution.Simple.LocalBuildInfo (
withComponentsLBI,
withLibLBI,
withExeLBI,
withBenchLBI,
withTestLBI,
enabledTestLBIs,
enabledBenchLBIs,
enabledComponents,
-- $buildable_vs_enabled_components
ComponentEnabledSpec(..),
defaultComponentEnabled,
componentEnabled,
componentDisabledReason,
ComponentDisabledReason(..),
-- * Installation directories
module Distribution.Simple.InstallDirs,
......@@ -102,6 +112,8 @@ data LocalBuildInfo = LocalBuildInfo {
-- Needed to re-run configuration when .cabal is out of date
flagAssignment :: FlagAssignment,
-- ^ The final set of flags which were picked for this package
componentEnabledSpec :: ComponentEnabledSpec,
-- ^ What components were enabled during configuration, and why.
extraConfigArgs :: [String],
-- ^ Extra args on the command line for the configuration step.
-- Needed to re-run configuration when .cabal is out of date
......@@ -152,6 +164,76 @@ data LocalBuildInfo = LocalBuildInfo {
instance Binary LocalBuildInfo
-- $buildable_vs_enabled_components
-- #buildable_vs_enabled_components#
--
-- = Note: Buildable versus enabled components
-- What's the difference between a buildable component (ala
-- 'componentBuildable') versus enabled component (ala
-- 'componentEnabled')?
--
-- A component is __buildable__ if, after resolving flags and
-- conditionals, there is no @buildable: False@ property in it.
-- This is a /static/ property that arises from the
-- Cabal file and the package description flattening; once we have
-- a 'PackageDescription' buildability is known.
--
-- A component is __enabled__ if it is buildable, and the user
-- configured (@./Setup configure@) the package to build it,
-- e.g., using @--enable-tests@ or @--enable-benchmarks@.
-- Once we have a 'LocalBuildInfo', whether or not a component
-- is enabled is known.
--
-- Generally speaking, most Cabal API code cares if a component
-- is enabled, as opposed to buildable. (For example, if you
-- want to run a preprocessor on each component prior to building
-- them, you want to run this on each /enabled/ component.)
-- | Describes what components are enabled by user-interaction.
-- See also this note in
-- "Distribution.Simple.LocalBuildInfo#buildable_vs_enabled_components".
--
-- @since 1.26.0.0
data ComponentEnabledSpec
= ComponentEnabledSpec {
testsEnabled :: Bool,
benchmarksEnabled :: Bool
}
deriving (Generic, Read, Show)
instance Binary ComponentEnabledSpec
-- | The default set of enabled components. Historically tests and
-- benchmarks are NOT enabled by default.
--
-- @since 1.26.0.0
defaultComponentEnabled :: ComponentEnabledSpec
defaultComponentEnabled = ComponentEnabledSpec False False
-- | Is this component enabled? See also this note in
-- "Distribution.Simple.LocalBuildInfo#buildable_vs_enabled_components".
--
-- @since 1.26.0.0
componentEnabled :: ComponentEnabledSpec -> Component -> Bool
componentEnabled enabled = isNothing . componentDisabledReason enabled
-- | Is this component disabled, and if so, why?
--
-- @since 1.26.0.0
componentDisabledReason :: ComponentEnabledSpec -> Component
-> Maybe ComponentDisabledReason
componentDisabledReason enabled (CTest _)
| not (testsEnabled enabled) = Just DisabledAllTests
componentDisabledReason enabled (CBench _)
| not (benchmarksEnabled enabled) = Just DisabledAllBenchmarks
componentDisabledReason _ _ = Nothing
-- | A reason explaining why a component is disabled.
--
-- @since 1.26.0.0
data ComponentDisabledReason = DisabledComponent