MyNixOS website logo
Description

Experimental extensions to shake-plus.

Experimental extensions to shake-plus - within-style file rules, HashMap and IxSet batch loaders.

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.

Metadata

Version

0.4.1.0

License

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows