Module B0_unit.Exec

Unit executions.

These properties pertain to the interface that allows to execute units after they have been built as is done for example by the b0 command.

The execution procedure, will likely be refined when we get proper build environments and cross but basically:

type b0_unit := t

Environment

type env = [
  1. | `Build_env
    (*

    The build environment.

    *)
  2. | `Driver_env
    (*

    The b0 invocation process environment.

    *)
  3. | `Override of [ `Build_env | `Driver_env ] * B0_std.Os.Env.t
    (*

    Environment overriden by given values.

    *)
  4. | `Env of B0_std.Os.Env.t
    (*

    This exact environment.

    *)
  5. | `Fun of string * (b0_env -> b0_unit -> (B0_std.Os.Env.t, string) Stdlib.result)
    (*

    Doc string and function.

    *)
]

The type for execution environments.

val env : env B0_meta.key

env specifies the environement for executing a unit. If unspecified this is `Build_env.

val get_env : b0_env -> b0_unit -> (B0_std.Os.Env.t, string) Stdlib.result

get_env env u performs the logic to get the execution environment for unit u in environment env.

Cwd

type cwd = [
  1. | `Cwd
    (*

    The user's current working directory.

    *)
  2. | `Root_dir
    (*

    The root B0 file directory.

    *)
  3. | `Scope_dir
    (*

    The directory of the scope where the entity is defined.

    *)
  4. | `Unit_dir
    (*

    The unit's build directory.

    *)
  5. | `In of [ `Cwd | `Unit_dir | `Root_dir | `Scope_dir ] * B0_std.Fpath.t
  6. | `Fun of string * (b0_env -> b0_unit -> (B0_std.Fpath.t, string) B0_std.Result.t)
    (*

    Doc string and function.

    *)
]

The type for execution working directories.

val cwd : cwd B0_meta.key

cwd specifies the current working directory for executing a unit. If unspecified this is `Cwd.

val get_cwd : b0_env -> b0_unit -> (B0_std.Fpath.t, string) Stdlib.result

get_cwd env u performs the logic to get the cwd for unit u in environment env.

Execution

type t = [
  1. | `Unit_exe
    (*

    The unit's exe_file

    *)
  2. | `Cmd of string * (b0_env -> b0_unit -> args:B0_std.Cmd.t -> (B0_std.Cmd.t, string) Stdlib.result)
    (*

    Doc string and a function that returns a command to execute

    *)
  3. | `Fun of string * (b0_env -> ?env:B0_std.Os.Env.assignments -> ?cwd:B0_std.Fpath.t -> b0_unit -> args:B0_std.Cmd.t -> (B0_std.Os.Exit.t, string) Stdlib.result)
    (*

    Doc string and a function. The function is given the result of get_cwd and get_env.

    *)
]

The type for specifying unit executions.

val key : t B0_meta.key

key specifies the execution for a unit. If unspecified this is `Unit_exe.

val find : b0_unit -> (b0_env -> b0_unit -> args:B0_std.Cmd.t -> (B0_std.Os.Exit.t, string) Stdlib.result) option

find u is a function, if any, for executing unit u. The Given the environment, the unit and additional arguments potentially provided by the driver it performs the full execution logic.