Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove action extension intermediate environment/context #10827

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/dune_engine/action.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@ module type T = sig
type t
end

type context = Action_intf.context =
{ targets : Targets.Validated.t option
; context : Build_context.t option
; metadata : Process.metadata
; rule_loc : Loc.t
; build_deps : Dep.Set.t -> Dep.Facts.t Fiber.t
}

type env = Action_intf.env =
{ working_dir : Path.t
; env : Env.t
; stdout_to : Process.Io.output Process.Io.t
; stderr_to : Process.Io.output Process.Io.t
; stdin_from : Process.Io.input Process.Io.t
; prepared_dependencies : Dune_action_plugin.Private.Protocol.Dependency.Set.t
; exit_codes : int Predicate.t
}

module Make
(Program : T)
(Path : T)
Expand Down
18 changes: 18 additions & 0 deletions src/dune_engine/action.mli
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,24 @@ end

module Ext : module type of Action_intf.Ext

type context = Action_intf.context =
{ targets : Targets.Validated.t option
; context : Build_context.t option
; metadata : Process.metadata
; rule_loc : Loc.t
; build_deps : Dep.Set.t -> Dep.Facts.t Fiber.t
}

type env = Action_intf.env =
{ working_dir : Path.t
; env : Env.t
; stdout_to : Process.Io.output Process.Io.t
; stderr_to : Process.Io.output Process.Io.t
; stdin_from : Process.Io.input Process.Io.t
; prepared_dependencies : Dune_action_plugin.Private.Protocol.Dependency.Set.t
; exit_codes : int Predicate.t
}

(** result of the lookup of a program, the path to it or information about the
failure and possibly a hint how to fix it *)
module Prog : sig
Expand Down
60 changes: 14 additions & 46 deletions src/dune_engine/action_exec.ml
Original file line number Diff line number Diff line change
Expand Up @@ -138,27 +138,11 @@ module Exec_result = struct
;;
end

type exec_context =
{ targets : Targets.Validated.t option
; context : Build_context.t option
; metadata : Process.metadata
; rule_loc : Loc.t
; build_deps : Dep.Set.t -> Dep.Facts.t Fiber.t
}

type exec_environment =
{ working_dir : Path.t
; env : Env.t
; stdout_to : Process.Io.output Process.Io.t
; stderr_to : Process.Io.output Process.Io.t
; stdin_from : Process.Io.input Process.Io.t
; prepared_dependencies : DAP.Dependency.Set.t
; exit_codes : int Predicate.t
}

open Produce.O

let exec_run ~display ~ectx ~eenv prog args : _ Produce.t =
let exec_run ~display ~(ectx : Action_intf.context) ~(eenv : Action_intf.env) prog args
: _ Produce.t
=
let* (res : (Proc.Times.t, int) result) =
Produce.of_fiber
@@ Process.run_with_times
Expand All @@ -178,7 +162,14 @@ let exec_run ~display ~ectx ~eenv prog args : _ Produce.t =
| Ok times -> Produce.incr_duration times.elapsed_time
;;

let exec_run_dynamic_client ~display ~ectx ~eenv prog args =
let exec_run_dynamic_client
~display
~(ectx : Action_intf.context)
~(eenv : Action_intf.env)
prog
args
=
let* () = Produce.of_fiber @@ Rpc.ensure_ready () in
let run_arguments_fn = Temp.create File ~prefix:"dune" ~suffix:"run" in
let response_fn = Temp.create File ~prefix:"dune" ~suffix:"response" in
let run_arguments =
Expand Down Expand Up @@ -289,26 +280,6 @@ let bash_exn =
[ Pp.textf "I need bash to %s but I couldn't find it :(" needed_to ]
;;

(* When passing these to an extension, they shouldn't need to know about any
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 } =
{ Action.Ext.targets; context; purpose = metadata.purpose; rule_loc; build_deps }
;;

let restrict_env
{ working_dir
; env
; stdout_to
; stderr_to
; stdin_from
; exit_codes
; prepared_dependencies = _
}
=
{ Action.Ext.working_dir; env; stdout_to; stderr_to; stdin_from; exit_codes }
;;

let zero = Predicate_lang.element 0
let maybe_async f = Produce.of_fiber (maybe_async f)

Expand Down Expand Up @@ -402,10 +373,7 @@ let rec exec t ~display ~ectx ~eenv : done_or_more_deps Produce.t =
Done
| Pipe (outputs, l) -> exec_pipe ~display ~ectx ~eenv outputs l
| Extension (module A) ->
let+ () =
Produce.of_fiber
@@ A.Spec.action A.v ~ectx:(restrict_ctx ectx) ~eenv:(restrict_env eenv)
in
let+ () = Produce.of_fiber @@ A.Spec.action A.v ~ectx ~eenv in
Done

and redirect_out t ~display ~ectx ~eenv ~perm outputs fn =
Expand Down Expand Up @@ -539,7 +507,7 @@ let exec
=
let ectx =
let metadata = Process.create_metadata ~purpose:(Build_job targets) () in
{ targets; metadata; context; rule_loc; build_deps }
{ Action_intf.targets; metadata; context; rule_loc; build_deps }
and eenv =
let env =
match
Expand All @@ -553,7 +521,7 @@ let exec
(* TODO generify *)
[ Some { source = Path.to_absolute_filename root; target } ]
in
{ working_dir = Path.root
{ Action_intf.working_dir = Path.root
; env
; stdout_to =
Process.Io.make_stdout
Expand Down
33 changes: 17 additions & 16 deletions src/dune_engine/action_intf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,25 @@ module type Helpers = sig
val mkdir : target -> t
end

module Ext = struct
type context =
{ targets : Targets.Validated.t option
; context : Build_context.t option
; purpose : Process.purpose
; rule_loc : Loc.t
; build_deps : Dep.Set.t -> Dep.Facts.t Fiber.t
}
type context =
{ targets : Targets.Validated.t option
; context : Build_context.t option
; metadata : Process.metadata
; rule_loc : Loc.t
; build_deps : Dep.Set.t -> Dep.Facts.t Fiber.t
}

type env =
{ working_dir : Path.t
; env : Env.t
; stdout_to : Process.Io.output Process.Io.t
; stderr_to : Process.Io.output Process.Io.t
; stdin_from : Process.Io.input Process.Io.t
; exit_codes : int Predicate.t
}
type env =
{ working_dir : Path.t
; env : Env.t
; stdout_to : Process.Io.output Process.Io.t
; stderr_to : Process.Io.output Process.Io.t
; stdin_from : Process.Io.input Process.Io.t
; prepared_dependencies : Dune_action_plugin.Private.Protocol.Dependency.Set.t
; exit_codes : int Predicate.t
}

module Ext = struct
module type Spec = sig
type ('path, 'target) t

Expand Down
2 changes: 1 addition & 1 deletion src/dune_patch/dune_patch.ml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ module Spec = struct
let is_useful_to ~memoize = memoize
let encode patch input _ : Sexp.t = List [ Atom name; input patch ]

let action patch ~ectx:_ ~(eenv : Action.Ext.env) =
let action patch ~ectx:_ ~(eenv : Action.env) =
exec !Dune_engine.Clflags.display ~patch ~dir:eenv.working_dir ~stderr:eenv.stderr_to
;;
end
Expand Down
2 changes: 1 addition & 1 deletion src/dune_rules/cram/cram_exec.ml
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ module Spec = struct
let bimap path f _ = f path
let is_useful_to ~memoize:_ = true
let encode script path _ : Sexp.t = List [ Atom name; path script ]
let action script ~ectx:_ ~(eenv : Action.Ext.env) = run ~env:eenv.env ~script
let action script ~ectx:_ ~(eenv : Action.env) = run ~env:eenv.env ~script
end

let action script =
Expand Down
6 changes: 3 additions & 3 deletions src/dune_rules/pkg_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -649,8 +649,8 @@ module Run_with_path = struct

let action
{ prog; args; ocamlfind_destdir; pkg }
~(ectx : Action.Ext.context)
~(eenv : Action.Ext.env)
~(ectx : Action.context)
~(eenv : Action.env)
=
let open Fiber.O in
let display = !Clflags.display in
Expand All @@ -664,7 +664,7 @@ module Run_with_path = struct
| Path p -> Path.to_absolute_filename p)
|> String.concat ~sep:"")
in
let metadata = Process.create_metadata ~purpose:ectx.purpose () in
let metadata = Process.create_metadata ~purpose:ectx.metadata.purpose () in
let env =
Env.add
eenv.env
Expand Down
2 changes: 1 addition & 1 deletion src/promote/diff_action.ml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ module Spec = struct
List [ Atom name; Atom (Bool.to_string optional); mode; input file1; output file2 ]
;;

let action diff ~(ectx : Dune_engine.Action.Ext.context) ~eenv:_ =
let action diff ~(ectx : Dune_engine.Action.context) ~eenv:_ =
exec ~rule_loc:ectx.rule_loc diff
;;
end
Expand Down
Loading