Skip to content

Commit

Permalink
Add lazy mode to build_deps
Browse files Browse the repository at this point in the history
Signed-off-by: HasanA <mhmd_alameen1023@outlook.com>
  • Loading branch information
MA0010 committed Sep 10, 2024
1 parent 17d052a commit f7d4dcc
Show file tree
Hide file tree
Showing 11 changed files with 258 additions and 162 deletions.
4 changes: 3 additions & 1 deletion bin/describe/describe_pp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ let execute_pp_action ~sctx file pp_file dump_file =
in
let ok =
let open Fiber.O in
let build_deps deps = Build_system.build_deps deps |> Memo.run in
let build_deps build_mode deps =
Build_system.build_deps ~build_mode deps |> Memo.run
in
let* result = Dune_engine.Action_exec.exec input ~build_deps in
Dune_engine.Action_exec.Exec_result.ok_exn result >>| ignore
in
Expand Down
13 changes: 10 additions & 3 deletions src/dune_engine/action_exec.ml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ module Exec_result = struct
| Unix.Unix_error (err, call, args) -> Unix (err, call, args)
| Memo.Non_reproducible Scheduler.Run.Build_cancelled ->
Nonreproducible_build_cancelled
| Memo.Error.E e -> reraise (Memo.Error.get e)
| Memo.Cycle_error.E _ as e ->
(* [Memo.Cycle_error.t] is hard to serialize and can only be raised during action
execution with the dynamic dependencies plugin, which is not production-ready yet.
Expand Down Expand Up @@ -139,6 +140,11 @@ module Exec_result = struct
;;
end

(** mode for calling build_deps. in lazy mode, any attempt to do some build will fail.*)
type build_mode =
| Lazy
| Eager

module Action_res = struct
type t =
{ done_or_more_deps : Action_plugin.done_or_more_deps
Expand All @@ -165,7 +171,7 @@ type exec_context =
; context : Build_context.t option
; metadata : Process.metadata
; rule_loc : Loc.t
; build_deps : Dep.Set.t -> Dep.Facts.t Fiber.t
; build_deps : build_mode -> Dep.Set.t -> Dep.Facts.t Fiber.t
}

type exec_environment =
Expand Down Expand Up @@ -318,6 +324,7 @@ let bash_exn =
kind of dynamic build dependency functions or prepped dependencies, etc,
which should be handled here instead. *)
let restrict_ctx { targets; context; metadata; rule_loc; build_deps } =
let build_deps = build_deps Eager in
{ Action.Ext.targets; context; purpose = metadata.purpose; rule_loc; build_deps }
;;

Expand Down Expand Up @@ -635,12 +642,12 @@ let exec_until_all_deps_ready ~display ~ectx ~eenv t =
let* result = exec ~display ~ectx ~eenv t in
match result with
| { done_or_more_deps = Done; needed_deps = deps } ->
let* fact_map = Produce.of_fiber @@ ectx.build_deps deps in
let* fact_map = Produce.of_fiber @@ ectx.build_deps Lazy deps in
Produce.return (stages, (deps, fact_map))
| { done_or_more_deps = Need_more_deps (relative_deps, deps_to_build)
; needed_deps = _
} ->
let* fact_map = Produce.of_fiber @@ ectx.build_deps deps_to_build in
let* fact_map = Produce.of_fiber @@ ectx.build_deps Eager deps_to_build in
let stages = (deps_to_build, fact_map) :: stages in
let eenv =
{ eenv with
Expand Down
7 changes: 6 additions & 1 deletion src/dune_engine/action_exec.mli
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ module Exec_result : sig
val ok_exn : t -> ok Fiber.t
end

(** mode for calling build_deps. in lazy mode, any attempt to do some build will fail.*)
type build_mode =
| Lazy
| Eager

type input =
{ targets : Targets.Validated.t option (* Some Jane Street actions use [None] *)
; root : Path.t
Expand All @@ -41,5 +46,5 @@ type input =

val exec
: input
-> build_deps:(Dep.Set.t -> Dep.Fact.t Dep.Map.t Fiber.t)
-> build_deps:(build_mode -> Dep.Set.t -> Dep.Fact.t Dep.Map.t Fiber.t)
-> Exec_result.t Fiber.t
2 changes: 1 addition & 1 deletion src/dune_engine/action_runner.ml
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ let create server ~name =

module Worker = struct
let exec_action =
let build_deps _ = Code_error.raise "no dynamic actions yet" [] in
let build_deps _ _ = Code_error.raise "no dynamic actions yet" [] in
fun (action : Action_exec.input) ->
Log.info
[ Pp.text "action runner executing action:"
Expand Down
Loading

0 comments on commit f7d4dcc

Please sign in to comment.