forked from haskell/cabal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce computations in the context of building a component
Introduces 'BuildM', a monad for actions defined in the context of building a component. Actions in the 'BuildM' monad have access to 'PreBuildComponentInputs', which is the information necessary and available to a build right before building a component (hence the name). Introduces as well 'BuildingWhat', a type that distinguishes the kind of build we are doing (Normal vs Repl vs Haddock vs Hscolour) and the different flags available for each kind of build.
- Loading branch information
Showing
3 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{-# LANGUAGE DerivingVia #-} | ||
{-# LANGUAGE NamedFieldPuns #-} | ||
|
||
module Distribution.Simple.Build.Monad | ||
( BuildM (..) | ||
, runBuildM | ||
, PreBuildComponentInputs (..) | ||
|
||
-- * Re-exports | ||
, BuildingWhat (..) | ||
, LocalBuildInfo (..) | ||
, TargetInfo (..) | ||
, buildingWhatVerbosity | ||
, buildingWhatDistPref | ||
) | ||
where | ||
|
||
import Control.Monad.Reader | ||
|
||
import Distribution.Simple.Setup (BuildingWhat (..), buildingWhatDistPref, buildingWhatVerbosity) | ||
import Distribution.Types.LocalBuildInfo | ||
import Distribution.Types.TargetInfo | ||
|
||
-- | The information required for a build computation (@'BuildM'@) | ||
-- which is available right before building each component, i.e. the pre-build | ||
-- component inputs. | ||
data PreBuildComponentInputs = PreBuildComponentInputs | ||
{ buildingWhat :: BuildingWhat | ||
-- ^ What kind of build are we doing? | ||
, localBuildInfo :: LocalBuildInfo | ||
-- ^ Information about the package | ||
, targetInfo :: TargetInfo | ||
-- ^ Information about an individual component | ||
} | ||
|
||
-- | Computations carried out in the context of building a component (e.g. @'buildAllExtraSources'@) | ||
newtype BuildM a = BuildM (PreBuildComponentInputs -> IO a) | ||
deriving (Functor, Applicative, Monad) via ReaderT PreBuildComponentInputs IO | ||
|
||
-- | Run a 'BuildM' action, i.e. a computation in the context of building a component. | ||
runBuildM :: BuildingWhat -> LocalBuildInfo -> TargetInfo -> BuildM a -> IO a | ||
runBuildM buildingWhat localBuildInfo targetInfo (BuildM f) = | ||
f PreBuildComponentInputs{buildingWhat, localBuildInfo, targetInfo} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters