From fd2b6c9ea226e6a170f459b2e3f0153f78ce180d Mon Sep 17 00:00:00 2001 From: Chris Done Date: Tue, 17 Feb 2015 15:34:22 +0100 Subject: [PATCH] Add Shake.FilePath --- Development/Shake/FilePath.hs | 56 +++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 Development/Shake/FilePath.hs diff --git a/Development/Shake/FilePath.hs b/Development/Shake/FilePath.hs new file mode 100644 index 00000000..5750e0e4 --- /dev/null +++ b/Development/Shake/FilePath.hs @@ -0,0 +1,56 @@ +-- | Useful 'System.FilePath' wrapper around Shake. + +module Development.Shake.FilePath + (startShake + ,target + ,need + ,want + ,Target(Target) + ,unTarget + ,Rules + ,Action + ,CmdOption(..) + ,Shake.cmd) + where + +import Control.Monad.IO.Class +import Development.Shake (Rules,Action,CmdOption(..)) +import qualified Development.Shake as Shake +import Filesystem.Path.CurrentOS (FilePath) +import qualified Filesystem.Path.CurrentOS as FP +import Prelude hiding (FilePath) +import System.Environment + +-- | A simple opaque wrapper for the "target" abstraction. +newtype Target = Target + { unTarget :: FilePath + } + +-- | Start Shake with the given data directory. +startShake :: MonadIO m => Int -> FilePath -> Rules () -> m () +startShake threads dir rules = + liftIO (withArgs [] $ + Shake.shakeArgs + Shake.shakeOptions + { Shake.shakeFiles = FP.encodeString dir + , Shake.shakeThreads = threads + } $ + rules) + +-- | Declare a target, returning the target name. +target :: Target -> Action () -> Rules Target +target name act = do + (FP.encodeString + (unTarget name)) Shake.*> + const act + return name + +-- | Need the given dependencies. +need :: [Target] -> Action () +need xs = Shake.need $ + map (FP.encodeString . unTarget) xs + +-- | Need the given dependencies. +want :: [Target] -> Rules () +want xs = Shake.want + (map (FP.encodeString . unTarget) xs)