build-1.1: Build Systems à la Carte
Safe HaskellSafe-Inferred
LanguageHaskell2010

Build.Task.Opaque

Description

Opaque monadic tasks, whose inputs and outputs can be dynamic.

Synopsis

Documentation

type Variable = String Source #

Environment variables are identified by names.

data Key a where Source #

A collection of keys for accessing files, environment variables, and contents of directories. Directories are somewhat magic, because their values are derived from File keys, i.e. creating a new file in a directory requires updating the the corresponding Dir key.

Constructors

File 

Fields

Env 

Fields

Dir 

Fields

Instances

Instances details
Show (LogEntry Key) Source # 
Instance details

Defined in Build.Task.Opaque

type Get k f = forall a. k a -> f a Source #

Read a key's value in a computation context f.

type Put k f = forall a. k a -> a -> f () Source #

Write a key's value in a computation context f. Note: the type can be changed to forall a. k a -> f a -> f a to allow for static analysis of applicative and selective build tasks, since we cannot have a in a static context f, e.g. in Const. See more details in Section 5.3 of this paper: https://www.staff.ncl.ac.uk/andrey.mokhov/selective-functors.pdf.

type Task k a = forall f. Monad f => Get k f -> Put k f -> f a Source #

A build task is a stateful computation in a monadic context f that is given two callbacks: for reading and writing values to a key/value store.

type TaskName = String Source #

A unique task identifier, e.g. the path to the corresponding build script.

data NamedTask k Source #

A task along with its unique identifier.

Constructors

NamedTask 

Fields

type Tasks k = [NamedTask k] Source #

A collection of build tasks using the same read and write interface.

type BlackBox = Task Key () Source #

An example type of "black box" build tasks: we can only find out what they read and write by executing them in a monadic context.

type BlackBoxes = Tasks Key Source #

Multiple black boxes, e.g. a collection of build scripts lying around.

tasks :: BlackBoxes Source #

An example collection of black boxes.

build :: BlackBox Source #

A typical build script that compiles a couple of C files, possibly depending on some header files, and then links the resulting objects into an executable.

release :: BlackBox Source #

A script for packaging the contents of the directory out in an archive. Note that if called prematurely, it will miss some of the release files and will succeed, yielding an incomplete archive. The task will therefore need to be rerun whenever the key Dir "out" is updated.

compile :: FilePath -> FilePath -> BlackBox Source #

Compile a C source file, possibly including the lib.h header.

link :: FilePath -> FilePath -> BlackBox Source #

Link object files in a given directory, producing an executable. Note that this task can fail if run prematurely i.e. when some object files have not yet been placed in the obj directory, since some symbols will be undefined.

data LogEntry k where Source #

A task execution log entry, recording either a read from a key and the obtained value, or a write to a key, along with the written value.

Constructors

GetEntry :: k a -> a -> LogEntry k 
PutEntry :: k a -> a -> LogEntry k 

Instances

Instances details
Show (LogEntry Key) Source # 
Instance details

Defined in Build.Task.Opaque

type Log k = [LogEntry k] Source #

A log is a sequence of log entries, in the execution order.

hasWrongGet :: Log Key -> Key a -> a -> Bool Source #

Check if a log contains a GetEntry for a given Key. Useful to detect if a task has a certain input dependency.

execute :: forall m k. Monad m => Get k m -> Put k m -> Task k () -> m (Log k) Source #

Execute a monadic task using given callbacks Get and Put, logging all reads and writes.

newtype Store Source #

An association of keys to values.

Constructors

Store 

Fields

putValue :: Key a -> a -> Store -> Store Source #

exampleStore :: Store Source #

An example store with the following contents:

File "src/a.c" -> "a" File "src/b.c" -> "b...#include lib.h..." File "obj/main.o" -> "...main..." File "lib/lib.h" -> "lib..." File "out/README" -> "This is a README..." Env LIBDIR -> "lib" Dir "obj" -> ["main.o"] Dir "out" -> [README]

type Graph = TaskName -> Maybe (Log Key) Source #

Known information about build task dependencies.

blindBuild :: BlackBoxes -> Store -> Graph -> (Store, Graph) Source #

A build system that builds a collection of black box tasks by executing them blindly, and recording the resulting dependencies.

type ShowKey k = forall a. k a -> String Source #

A way to show the name of a key.

showKey :: ShowKey Key Source #

A simple pretty-printer for the data type Key.

showValue :: Key a -> a -> String Source #

Show a value corresponding to a key, extracting an appropriate Show instance from it.

getIO :: Get Key IO Source #

A Get in IO for GHCi experiments.

putIO :: Put Key IO Source #

A Put in IO for GHCi experiments.