Module B00.Memo
Build memoizer.
A memoizer ties together and environment, an operation cache, a guard and an executor.
Memoizer
type feedback=[|`Fiber_exn of exn * Stdlib.Printexc.raw_backtrace|`Fiber_fail of string|`Miss_tool of Tool.t * string|`Op_cache_error of Op.t * string|`Op_complete of Op.t * [ `Did_not_write of B0_std.Fpath.t list ]]The type for memoizer feedback.
val pp_feedback : feedback B0_std.Fmt.tpp_feedback ppfformats feedback.
type tThe type for memoizers. This ties together an environment, a aguard, an operation cache and an executor.
val create : ?clock:B0_std.Time.counter -> ?cpu_clock:B0_std.Time.cpu_counter -> feedback:(feedback -> unit) -> cwd:B0_std.Fpath.t -> Env.t -> Guard.t -> Op_cache.t -> Exec.t -> tval memo : ?hash_fun:(module B0_std.Hash.T) -> ?env:B0_std.Os.Env.t -> ?cwd:B0_std.Fpath.t -> ?cachedir:B0_std.Fpath.t -> ?max_spawn:int -> ?feedback:([ feedback | File_cache.feedback | Exec.feedback ] -> unit) -> unit -> (t, string) Stdlib.resultmemois a simplercreatehash_fundefaults toOp_cache.create's default.max_spawndefaults toExec.create's default.envdefaults toOs.Env.currentcwddefaults toOs.Dir.cwdcachedirdefaults toFpath.(cwd / "_b0" / "cache")feedbackdefaults formats feedback on stdout.
val clock : t -> B0_std.Time.counterclock mism's clock.
val cpu_clock : t -> B0_std.Time.cpu_countercpu_clock mism's cpu clock.
val op_cache : t -> Op_cache.top_cache mism's operation cache.
val hash_fun : t -> (module B0_std.Hash.T)hash_fun mism's hash function.
val stir : block:bool -> t -> unitstir ~block mruns the memoizer a bit. Ifblockistrueblocks until the memoizer is stuck with no operation to perform.
val finish : t -> (unit, B0_std.Fpath.Set.t) Stdlib.resultfinish mfinishes the memoizer. This blocks until there are no operation to execute likestirdoes. If no operations are left waiting this returnsOk (). If there are remaining wiating operations it aborts them and returnsError fswithfsthe files that never became ready and where not supposed to be written by the waiting operations.
Fibers
val fail : ('b, Stdlib.Format.formatter, unit, 'a) Stdlib.format4 -> 'bfail fmt ...fails the fiber with the given error message.
val fail_error : ('a, string) Stdlib.result -> 'afail_errorfails the fiber with the given error.
Files and directories
val file_ready : t -> B0_std.Fpath.t -> unitready m pdeclares pathpto be ready, that is exists and is up-to-date inb. This is typically used with source files and files external to the build (e.g. installed libraries).
val wait_files : t -> B0_std.Fpath.t list -> unit fiberwait_files m files kcontinues withk ()whenfilesbecome ready. FIXME Unclear whether we really want this though this is kind of areadsconstraint for a pure OCaml operation, but then we gotread.
val read : t -> B0_std.Fpath.t -> string fiberread m file kreads the contents of filefileasswhen it becomes ready and continues withk s.
val write : t -> ?salt:string -> ?reads:B0_std.Fpath.t list -> ?mode:int -> B0_std.Fpath.t -> (unit -> (string, string) Stdlib.result) -> unitwrite m ~reads file wwritesfilewith dataw ()and modemode(defaults to0o644) whenreadsare ready.w's result must only depend onreadsandsalt(defaults to"").
val mkdir : t -> B0_std.Fpath.t -> unit fibermkdir m dir kcreates directorydirand continues withk ()at which point filediris ready.
Memoizing tool spawns
val tool : t -> Tool.t -> B0_std.Cmd.t -> cmdtool m tis tooltmemoized. Use the resulting function to spawn the tool with the given arguments.
val spawn : t -> ?reads:B0_std.Fpath.t list -> ?writes:B0_std.Fpath.t list -> ?env:B0_std.Os.Env.t -> ?cwd:B0_std.Fpath.t -> ?stdin:B0_std.Fpath.t -> ?stdout:Op.Spawn.stdo -> ?stderr:Op.Spawn.stdo -> ?success_exits:Op.Spawn.success_exits -> ?k:(int -> unit) -> cmd -> unitspawn m ~reads ~writes ~env ~cwd ~stdin ~stdout ~stderr ~success_exits cmdspawnscmdoncereadsfiles are ready and makes fileswritesready if the spawn succeeds and the file exists. The rest of the arguments are:stdinreads input from the given file. If unspecified reads from the standard input of the program running the build. Warning. The file is not automatically added toreads, this allows for example to useOs.File.null.stdoutandstderr, the redirections for the standard outputs of the command, seestdo. Warning. File redirections are not automatically added towrites; this allows for example to useOs.File.null.success_exitsthe exit codes that determine if the build operation is successful (defaults to0, use[]to always succeed)env, environment variables added to the build environment. This overrides environment variables read by the tool in the build environment except for forced one. It also allows to specify environment that may not be mentioned by the running tool's environment specification.cwdthe current working directory. Default iscwd. In general it's better to avoid using relative file paths and tweaking thecwd. Construct your paths using the absolute directory functions and make your invocations independent from thecwd.k, if specified a fiber invoked once the spawn has succesfully executed with the exit code.
TODO. More expressive power could by added by:
- Support to refine the read and write set after the operation returns.
Note. If the tool spawn acts on a sort of "main" file (e.g. a source file) it should be specified as the first element of
reads, this is interpreted specially by certain build tracer.
Future values
module Fut : sig ... endFuture values.