module System.Build.Runner(
Runner,
RunnerExit,
(>--),
(>==),
pathTransform,
pathTransform',
(!!!),
(>->),
(->-),
(+>>),
(++>>),
(>===>),
(>=>=>)
) where
import Control.Monad
import Data.Maybe
import System.Cmd
import System.Directory
import System.Exit
import System.Build.FilePather
import System.Build.Extensions
import System.Build.Command
import System.Build.CompilePaths
import System.Build.OutputDirectory
import System.Build.OutputReferenceGet
import System.Build.OutputReferenceSet
type Runner e r = r -> [FilePath] -> IO e
type RunnerExit r = Runner ExitCode r
(>--) :: (Monad m) =>
m ExitCode ->
m ExitCode ->
m ExitCode
f >-- g = do e <- f
if e == ExitSuccess
then g
else return e
infixl 3 >--
(>==) :: (Monad m) =>
m ExitCode ->
m () ->
m ()
p >== q = do e <- p
when (e == ExitSuccess) q
infixl 3 >==
pathTransform :: ([FilePath] -> IO [FilePath]) ->
Runner x t ->
Runner x t
pathTransform k f c p = k p >>= f c
pathTransform' :: (Extensions e) =>
e ->
Runner x r ->
Runner x r
pathTransform' = pathTransform . recurse
where
recurse c p = fmap concat $ find always (constant $ extension ==|| exts' c) `mapM` p
(!!!) :: (Command c, CompilePaths c) =>
RunnerExit c
c !!! z = do s <- command c
system (s ++ ' ' : c =>> z)
infixl 7 !!!
(>->) :: (OutputDirectory c, Command c, CompilePaths c) =>
RunnerExit c
c >-> z = do mkdirectory (outdir c)
c !!! z
where
mkdirectory = mapM_ (createDirectoryIfMissing True) . maybeToList
infixl 7 >->
(->-) :: (OutputDirectory c, Extensions c, CompilePaths c, Command c) =>
RunnerExit c
c ->- p = pathTransform' c (>->) c p
(+>>) :: (OutputReferenceGet r, OutputReferenceSet r) =>
FilePath
-> r
-> r
v +>> k = setReference (v : getReference k) k
infixl 7 +>>
(++>>) :: (OutputReferenceGet r, OutputReferenceSet r) =>
[FilePath]
-> r
-> r
v ++>> k = setReference (v ++ getReference k) k
infixl 7 ++>>
(>===>) :: (OutputDirectory o, OutputReferenceGet r, OutputReferenceSet r) =>
o
-> r
-> r
v >===> w = case outdir v of Nothing -> w
Just y -> y +>> w
infixl 3 >===>
(>=>=>) :: (OutputDirectory o, OutputReferenceGet o, OutputReferenceGet r, OutputReferenceSet r) =>
o
-> r
-> r
v >=>=> w = v >===> (getReference v ++>> w)
infixl 3 >=>=>