Commit 1b013b08 authored by quchen's avatar quchen

Add Haddocks to Target.hs

parent bee9ceed
......@@ -12,7 +12,7 @@ module Expression (
-- ** Common expressions
Args, Ways, Packages,
-- ** Targets
Target, PartialTarget (..), fromPartial, fullTarget, fullTargetWithWay,
Target, PartialTarget (..), unsafeFromPartial, fullTarget, fullTargetWithWay,
-- * Convenient accessors
getStage, getPackage, getBuilder, getOutputs, getInputs, getWay,
......@@ -150,7 +150,7 @@ interpret :: Target -> Expr a -> Action a
interpret = flip runReaderT
interpretPartial :: PartialTarget -> Expr a -> Action a
interpretPartial = interpret . fromPartial
interpretPartial = interpret . unsafeFromPartial
interpretWithStage :: Stage -> Expr a -> Action a
interpretWithStage s = interpretPartial $
......
{-# LANGUAGE DeriveGeneric, FlexibleInstances #-}
module Target (
Target (..), PartialTarget (..), fromPartial, fullTarget, fullTargetWithWay
) where
Target (..)
, PartialTarget (..)
, unsafeFromPartial
, fullTarget
, fullTargetWithWay
) where
import Control.Monad.Trans.Reader
......@@ -12,50 +16,53 @@ import Package
import Stage
import Way
-- Target captures all parameters relevant to the current build target:
-- * Stage and Package being built,
-- * Builder to be invoked,
-- * Way to be built (set to vanilla for most targets),
-- * source file(s) to be passed to Builder,
-- * file(s) to be produced.
-- | Parameters relevant to the current build target.
data Target = Target
{
stage :: Stage,
package :: Package,
builder :: Builder,
way :: Way,
inputs :: [FilePath],
outputs :: [FilePath]
stage :: Stage, -- ^ Stage being built
package :: Package, -- ^ Package being built
builder :: Builder, -- ^ Builder to be invoked
way :: Way, -- ^ Way to build (set to vanilla for most targets)
inputs :: [FilePath], -- ^ Source files passed to the builder
outputs :: [FilePath] -- ^ Files to be produced
}
deriving (Show, Eq, Generic)
-- If values of type 'a' form a Monoid then we can also derive a Monoid instance
-- for values of type 'ReaderT Target Action a':
-- * the empty computation returns the identity element of the underlying type
-- | If values of type @a@ form a 'Monoid' then we can also derive a 'Monoid'
-- instance for values of type @'ReaderT' 'Target' 'Action' a@:
--
-- * the empty computation is the identity element of the underlying type
-- * two computations can be combined by combining their results
instance Monoid a => Monoid (ReaderT Target Action a) where
mempty = return mempty
mappend = liftM2 mappend
-- PartialTarget is a partially constructed Target with fields Stage and
-- Package only. PartialTarget's are used for generating build rules.
-- A partially constructed Target with fields 'Stage' and 'Package' only.
-- 'PartialTarget's are used for generating build rules.
data PartialTarget = PartialTarget Stage Package deriving (Eq, Show)
-- Convert PartialTarget to Target assuming that unknown fields won't be used.
fromPartial :: PartialTarget -> Target
fromPartial (PartialTarget s p) = Target
-- | Convert 'PartialTarget' to a 'Target' assuming that unknown fields won't
-- be used.
unsafeFromPartial :: PartialTarget -> Target
unsafeFromPartial (PartialTarget s p) = Target
{
stage = s,
package = p,
builder = error "fromPartial: builder not set",
way = error "fromPartial: way not set",
inputs = error "fromPartial: inputs not set",
outputs = error "fromPartial: outputs not set"
builder = error "unsafeFromPartial: builder not set",
way = error "unsafeFromPartial: way not set",
inputs = error "unsafeFromPartial: inputs not set",
outputs = error "unsafeFromPartial: outputs not set"
}
-- Construct a full target by augmenting a PartialTarget with missing fields.
-- Most targets are built only one way, vanilla, hence we set it by default.
fullTarget :: PartialTarget -> Builder -> [FilePath] -> [FilePath] -> Target
-- | Construct a full 'Target' by augmenting a 'PartialTarget' with missing
-- fields. Most targets are built only one way, 'vanilla', hence it is set by
-- default. Use 'fullTargetWithWay' otherwise.
fullTarget ::
PartialTarget
-> Builder
-> [FilePath] -- ^ Source files
-> [FilePath] -- ^ Produced files
-> Target
fullTarget (PartialTarget s p) b srcs fs = Target
{
stage = s,
......@@ -66,8 +73,14 @@ fullTarget (PartialTarget s p) b srcs fs = Target
outputs = map unifyPath fs
}
-- Use this function to be explicit about the build way.
fullTargetWithWay :: PartialTarget -> Builder -> Way -> [FilePath] -> [FilePath] -> Target
-- | Like 'fullTarget', but allows an explicit 'Way' parameter.
fullTargetWithWay ::
PartialTarget
-> Builder
-> Way
-> [FilePath] -- ^ Source files
-> [FilePath] -- ^ Produced files
-> Target
fullTargetWithWay pt b w srcs fs = (fullTarget pt b srcs fs) { way = w }
-- Instances for storing in the Shake database
......
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