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

Add using_terminal stanza #3660

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 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
7 changes: 5 additions & 2 deletions src/dune/action.ml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ let fold_one_step t ~init:acc ~f =
| Redirect_in (_, _, t)
| Ignore (_, t)
| With_accepted_exit_codes (_, t)
| No_infer t ->
| No_infer t
| Using_terminal t ->
f acc t
| Progn l
| Pipe (_, l) ->
Expand Down Expand Up @@ -205,7 +206,8 @@ let rec is_dynamic = function
| Redirect_in (_, _, t)
| Ignore (_, t)
| With_accepted_exit_codes (_, t)
| No_infer t ->
| No_infer t
| Using_terminal t ->
is_dynamic t
| Progn l
| Pipe (_, l) ->
Expand Down Expand Up @@ -290,6 +292,7 @@ let is_useful_to distribute memoize =
| With_accepted_exit_codes (_, t)
| No_infer t ->
loop t
| Using_terminal t -> loop t
| Progn l
| Pipe (_, l) ->
List.exists l ~f:loop
Expand Down
1 change: 1 addition & 0 deletions src/dune/action_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ struct
; target into
]
| No_infer r -> List [ atom "no-infer"; encode r ]
| Using_terminal t -> List [ atom "using-terminal"; encode t ]
| Pipe (outputs, l) ->
List
( atom (sprintf "pipe-%s" (Outputs.to_string outputs))
Expand Down
3 changes: 2 additions & 1 deletion src/dune/action_dune_lang.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ let ensure_at_most_one_dynamic_run ~loc action =
| Redirect_in (_, _, t)
| Ignore (_, t)
| With_accepted_exit_codes (_, t)
| No_infer t ->
| No_infer t
| Using_terminal t ->
loop t
| Run _
| Echo _
Expand Down
11 changes: 11 additions & 0 deletions src/dune/action_exec.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ open Import
open Fiber.O
module DAP = Dune_action_plugin.Private.Protocol

(* This feels like the wrong place for this, but I'm not sure of a better one. *)
let terminal_lock = Fiber.Mutex.create ()

(** A version of [Dune_action_plugin.Private.Protocol.Dependency] where all
relative paths are replaced by [Path.t]. (except the protocol doesn't
support Globs yet) *)
Expand Down Expand Up @@ -351,6 +354,14 @@ let rec exec t ~ectx ~eenv =
Io.write_lines target (String.Set.to_list lines);
Fiber.return Done
| No_infer t -> exec t ~ectx ~eenv
| Using_terminal t ->
Fiber.Mutex.with_lock terminal_lock (fun () ->
exec t ~ectx
~eenv:
{ eenv with
stdout_to = Process.Io.stdout
; stderr_to = Process.Io.stderr
})
| Pipe (outputs, l) -> exec_pipe ~ectx ~eenv outputs l
| Format_dune_file (src, dst) ->
Format_dune_lang.format_file ~input:(Some src)
Expand Down
1 change: 1 addition & 0 deletions src/dune/action_intf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ module type Ast = sig
| Diff of (path, target) Diff.t
| Merge_files_into of path list * string list * target
| No_infer of t
| Using_terminal of t
| Pipe of Outputs.t * t list
| Format_dune_file of path * target
end
Expand Down
1 change: 1 addition & 0 deletions src/dune/action_mapper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ module Make (Src : Action_intf.Ast) (Dst : Action_intf.Ast) = struct
, List.map extras ~f:(f_string ~dir)
, f_target ~dir target )
| No_infer t -> No_infer (f t ~dir)
| Using_terminal t -> Using_terminal (f t ~dir)
| Pipe (outputs, l) -> Pipe (outputs, List.map l ~f:(fun t -> f t ~dir))
| Format_dune_file (src, dst) ->
Format_dune_file (f_path ~dir src, f_target ~dir dst)
Expand Down
1 change: 1 addition & 0 deletions src/dune/action_to_sh.ml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ let simplify act =
(String.quote_for_shell target))
:: acc
| No_infer act -> loop act acc
| Using_terminal act -> loop act acc
| Pipe (outputs, l) -> Pipe (List.map ~f:block l, outputs) :: acc
| Format_dune_file (src, dst) ->
Redirect_out
Expand Down
5 changes: 4 additions & 1 deletion src/dune/action_unexpanded.ml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ module Partial = struct
, List.map ~f:(E.string ~expander) extras
, E.target ~expander target )
| No_infer t -> No_infer (expand t ~expander)
| Using_terminal t -> Using_terminal (expand t ~expander)
| Pipe (outputs, l) -> Pipe (outputs, List.map l ~f:(expand ~expander))
| Format_dune_file (src, dst) ->
Format_dune_file (E.path ~expander src, E.target ~expander dst)
Expand Down Expand Up @@ -316,6 +317,7 @@ let rec partial_expand t ~expander : Partial.t =
, List.map extras ~f:(E.string ~expander)
, E.target ~expander target )
| No_infer t -> No_infer (partial_expand t ~expander)
| Using_terminal t -> Using_terminal (partial_expand t ~expander)
| Pipe (outputs, l) -> Pipe (outputs, List.map l ~f:(partial_expand ~expander))
| Format_dune_file (src, dst) ->
Format_dune_file (E.path ~expander src, E.target ~expander dst)
Expand Down Expand Up @@ -422,7 +424,8 @@ end = struct
acc +< src +@+ dst
| Chdir (_, t)
| Setenv (_, _, t)
| Ignore (_, t) ->
| Ignore (_, t)
| Using_terminal t ->
infer acc t
| Progn l
| Pipe (_, l) ->
Expand Down