B0_unit
Build units.
A unit is a named build procedure and an optional action to perform once the unit has built. Units are the smallest unit of build in b0 files.
Either of the build procedure or the action can be a nop. Actions can also require a bit more than the unit itself from the build in order to run.
type build_proc = B0_build.t -> unit B0_std.Fut.t
The type for unit build procedures. Note that when the future determines the build may not be finished.
val build_nop : build_proc
build_nop
does nothing.
val make : ?doc:string -> ?meta:B0_meta.t -> string -> build_proc -> t
make n proc ~doc ~meta ~action
is a build unit named n
with build procedure proc
, synopsis doc
and metada meta
.
val build_proc : t -> build_proc
proc u
are the unit's build procedure.
val tool_name : string B0_meta.key
tool_name
is an executable name without the platform specific executable extension.
val exe_file : B0_std.Fpath.t B0_std.Fut.t B0_meta.key
exe_file
is an absolute file path to an executable build by the unit.
val outcomes : B0_std.Fpath.t list B0_std.Bval.t B0_meta.key
outcomes
is the set of public file outcomes.
val is_public : t -> bool
is_public u
is true
iff u
's meta has B0_meta.public
set to true
.
get_or_suggest_tool tool_name
are tools names whose tool_name
match tool_name
and are filtered by keep
val tool_is_user_accessible : t -> bool
tool_is_user_accessible u
assumes u
has a tool name. This then returns true
iff u
is_public
or in_root_scope
.
module Action : sig ... end
Actions.
val is_actionable : t -> bool
actionable u
is true
if u
has an action that can be run. This checks that either u
has an exe_file
or a `Fun
action.
These helper functions create units with a build_nop
build procedure.
val of_action' :
?store:B0_store.binding list ->
?packs:B0_pack.t list ->
?units:t list ->
?dyn_units:(args:B0_std.Cmd.t -> t list) ->
?doc:string ->
?meta:B0_meta.t ->
string ->
Action.func ->
t
of_action' name func
is an action named name
implemented with action function func
. units
and packs
are units and packs that must be built to run the action. store
are store bindings that must be enforced in the build.
val of_action :
?store:B0_store.binding list ->
?packs:B0_pack.t list ->
?units:t list ->
?dyn_units:(args:B0_std.Cmd.t -> t list) ->
?doc:string ->
?meta:B0_meta.t ->
string ->
(B0_env.t -> t -> args:B0_std.Cmd.t -> (unit, string) Stdlib.result) ->
t
of_action
is like of_action'
but with a function func
that evaluates to unit which are turned into Ok Os.Exit.ok
.
Use B0_std_cli
to parse actions arguments and Os.Exit
for exit codes. Given a suitable Cmdliner
term this function can be used to implement the action's command.
TODO Add a quick getopt interface.
val of_cmdliner_cmd :
?store:B0_store.binding list ->
?packs:B0_pack.t list ->
?units:t list ->
?dyn_units:(args:B0_std.Cmd.t -> t list) ->
?doc:string ->
?meta:B0_meta.t ->
string ->
(B0_env.t -> t -> B0_std.Os.Exit.t Cmdliner.Cmd.t) ->
t
of_cmdliner_cmd name cmd
is like make_action
is an action from the Cmdliner command cmd
. See also Action.of_cmdliner_term
.
Note. The command is under a thunk to avoid toplevel inits. This entails a bit of repetition for name and doc but you can access those of the action in the thunk to define the cmdliner command.
include B0_def.S with type t := t with type Set.t = B0_defs.Unit.Set.t
val define : ?doc:string -> ?meta:B0_meta.t -> string -> B0_def.def
val def : t -> B0_def.def
val name : t -> string
val basename : t -> string
val doc : t -> string
val mem_meta : 'a B0_meta.key -> t -> bool
val has_tag : bool B0_meta.key -> t -> bool
val find_meta : 'a B0_meta.key -> t -> 'a option
val find_or_default_meta : 'a B0_meta.key -> t -> 'a
val get_meta : 'a B0_meta.key -> t -> ('a, string) Stdlib.result
val add : t -> unit
val fold : (t -> 'a -> 'a) -> 'a -> 'a
val list : unit -> t list
val find : string -> t option
val get : string -> t
val get_or_hint : string -> (t, string) Stdlib.result
val get_list_or_hint :
all_if_empty:bool ->
string list ->
(t list, string) Stdlib.result
val scope_path : t -> string list
val in_root_scope : t -> bool
val in_current_scope : t -> bool
val scope_dir : t -> B0_std.Fpath.t option
val scope_dir' : t -> (B0_std.Fpath.t, string) Stdlib.result
val in_scope_dir : t -> B0_std.Fpath.t -> B0_std.Fpath.t option
val in_scope_dir' :
t ->
B0_std.Fpath.t ->
(B0_std.Fpath.t, string) Stdlib.result
val pp_name_str : string B0_std.Fmt.t
val pp_name : t B0_std.Fmt.t
val pp_doc : t B0_std.Fmt.t
val pp_synopsis : t B0_std.Fmt.t
val pp : t B0_std.Fmt.t
module Set : sig ... end
module Map : sig ... end
val tool_name_map : Set.t -> t B0_std.String.Map.t
tool_name_map units
are the user accessible tools defined by the set of units units
.