shake-plus-extended

Experimental extensions to shake-plus

LTS Haskell 22.43:0.4.1.0
Stackage Nightly 2023-12-26:0.4.1.0
Latest on Hackage:0.4.1.0

See all snapshots shake-plus-extended appears in

MIT licensed by Daniel Firth
Maintained by [email protected]
This version can be pinned in stack with:shake-plus-extended-0.4.1.0@sha256:31488bea5f3215f93615bc6da6b7aa33fd78133c1acf69a138120cf9c1f6b8f1,2008

Shake+ Extended - Experimental Mechanisms For Shake

This library extends shake-plus, which enriches shake with ReaderT and the Path library. This extended ruleset introduces within, for better keeping track of source and output directories, as well as batch loading mechanisms using ixset-typed.

Using Within

One common complaint about Shake is having to keep track of source and output directories and translating FilePaths when using the input to an Action, leading to lots of repetition of the form (sourceFolder </>) . (-<.> ".ext") . dropDirectory1 which is prone to breakage. Using Path helps this to some degree, but in some cases is even more annoying because lots of Path functions use MonadThrow, leading to lots of monadic steps inside an RAction.

To alleviate this somewhat, we use Within b (Path Rel File) as a standard pattern for representing a file within a directory. Within is a type available in the within package that is simply a newtype wrapper over an Env comonad with the environment specialized to Path b Dir. We provide variants of the file operations and rules that typically accept or return Paths or contain callbacks that expect paths and change these to Within values. These functions are generally suffixed within. Here is the variant of getDirectoryFiles that produces Within values.

getDirectoryFilesWithin' :: MonadAction m => Within Rel [FilePattern] -> m [Within b (Path Rel File)]

You can convert to and from this within-style using within and fromWithin.

let x = $(mkRelFile "a.txt") `within` $(mkRelDir "foo") -- Within Rel (Path Rel File)
fromWithin x -- produces a `Path Rel File`

and you can assert that an existing path lies in a directory by using asWithin, which throws if the directory is not a proper prefix of the Path.

$(mkRelFile "foo/a.txt") `asWithin` $(mkRelDir "foo") -- fine
$(mkRelFile "a.txt") `asWithin` $(mkRelDir "foo") -- throws error

Filerules such as (%>) have within-style variants that accept an (Path b Dir) FilePattern on the left and carry that env to the callback.

(%^>) :: (Partial, MonadReader r m, MonadRules m) => Within Rel FilePattern -> (Within Rel (Path Rel File) -> RAction r ()) -> m ()

You change the underlying filepath with fmap or mapM, whilst you can move to a new parent directory by using localDir, or localDirM which is defined in the Within library for when the map between parent directories may throw. The Within library also contains more functions and instances for more precise changes between output and source directories.

Changes

Changelog for shake-plus-extended

V0.4.1.0

  • Add runLoggedShakeForward.

v0.4.0.0

  • Add `Development.Shake.Plus.Extended.Conduit” with conduit oracle.

v0.3.0.0

  • Add SimpleSPlusEnv with a LogFunc and a local Path Rel Dir.
  • Rework runSimpleShakePlus to runLoggedShakePlus and add new runSimpleShakePlus.

v0.2.0.0

  • Re-export Binary Path orphan.
  • Re-export Binary IxSet orphan.
  • Re-export Hashable IxSet orphan.
  • Merge Shakebook.Local with Shakebook.FileRules

v0.1.2.0

  • Add a proxy version of batchLoadIndex.

v0.1.1.0

  • Add HasLocalOut class for accessing a lens with a local output directory.
  • Add filerules (/%>) and (/|%>) for implicit rules inside a local directory.

v0.1.0.0

  • Initial commit with basic within style rules and loaders.