Skip to content
Open
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
2 changes: 2 additions & 0 deletions bin/print_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ let rec encode_action : Action.For_shell.t -> Dune_lang.t =
]
| Ignore (outputs, r) ->
List [ atom (sprintf "ignore-%s" (Outputs.to_string outputs)); encode_action r ]
| If_file_exists (path, action) ->
List [ atom "if-file-exists"; Encoder.string path; encode_action action ]
| Progn l -> List (atom "progn" :: List.map l ~f:encode_action)
| Concurrent l -> List (atom "concurrent" :: List.map l ~f:encode_action)
| Echo xs -> List (atom "echo" :: List.map xs ~f:string)
Expand Down
3 changes: 3 additions & 0 deletions doc/changes/added/16209.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Format generated corrections before optional text diffs compare or promote
them, according to the source's formatting configuration, starting in Dune
3.25. (#16209, @rgrinberg)
9 changes: 8 additions & 1 deletion src/dune_engine/action.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ struct
let ignore_stdout t = Ignore (Stdout, t)
let ignore_stderr t = Ignore (Stderr, t)
let ignore_outputs t = Ignore (Outputs, t)
let if_file_exists path t = If_file_exists (path, t)
let progn ts = Progn ts
let concurrent ts = Concurrent ts
let echo s = Echo s
Expand Down Expand Up @@ -309,6 +310,10 @@ let digest =
| System command ->
int d 22;
string d command
| If_file_exists (path, t) ->
int d 23;
digest_path d ~dir path;
loop d t ~dir
in
fun d t -> loop d t ~dir:Path.root
;;
Expand All @@ -320,6 +325,7 @@ let fold_one_step t ~init:acc ~f =
| Redirect_out (_, _, _, t)
| Redirect_in (_, _, t)
| Ignore (_, t)
| If_file_exists (_, t)
| With_accepted_exit_codes (_, t) -> f acc t
| Progn l | Pipe (_, l) | Concurrent l -> List.fold_left l ~init:acc ~f
| Run _
Expand Down Expand Up @@ -367,6 +373,7 @@ let exists t ~leaf ~extension =
| Redirect_out (_, _, _, t)
| Redirect_in (_, _, t)
| Ignore (_, t)
| If_file_exists (_, t)
| With_accepted_exit_codes (_, t) -> loop t
| Progn l | Pipe (_, l) | Concurrent l -> List.exists l ~f:loop
| Extension extension_ -> extension extension_
Expand Down Expand Up @@ -423,7 +430,7 @@ let is_useful_to memoize =
| Setenv (_, _, t) -> loop t
| Redirect_out (_, _, _, t) -> memoize || loop t
| Redirect_in (_, _, t) -> loop t
| Ignore (_, t) | With_accepted_exit_codes (_, t) -> loop t
| Ignore (_, t) | If_file_exists (_, t) | With_accepted_exit_codes (_, t) -> loop t
| Progn l | Pipe (_, l) | Concurrent l -> List.exists l ~f:loop
| Echo _ -> false
| Cat _ -> memoize
Expand Down
2 changes: 2 additions & 0 deletions src/dune_engine/action_exec.ml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ let rec exec t ~ectx ~eenv : Done_or_more_deps.t Fiber.t =
redirect_out t ~ectx ~eenv outputs ~perm fn
| Redirect_in (inputs, fn, t) -> redirect_in t ~ectx ~eenv inputs fn
| Ignore (outputs, t) -> redirect_out t ~ectx ~eenv ~perm:Normal outputs Dev_null.path
| If_file_exists (path, t) ->
if Fpath.exists (Path.to_string path) then exec t ~ectx ~eenv else Fiber.return Done
| Progn ts -> exec_list ts ~ectx ~eenv
| Concurrent ts ->
Fiber.parallel_map ts ~f:(fun t ->
Expand Down
2 changes: 2 additions & 0 deletions src/dune_engine/action_intf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ module type Ast = sig
| Redirect_out of Outputs.t * target * File_perm.t * t
| Redirect_in of Inputs.t * path * t
| Ignore of Outputs.t * t
| If_file_exists of path * t
| Progn of t list
| Concurrent of t list
| Echo of string list
Expand Down Expand Up @@ -82,6 +83,7 @@ module type Helpers = sig
val ignore_stdout : t -> t
val ignore_stderr : t -> t
val ignore_outputs : t -> t
val if_file_exists : path -> t -> t
val progn : t list -> t
val concurrent : t list -> t
val echo : string list -> t
Expand Down
1 change: 1 addition & 0 deletions src/dune_engine/action_mapper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module Make (Src : Action_intf.Ast) (Dst : Action_intf.Ast) = struct
Redirect_out (outputs, f_target ~dir fn, perm, f t ~dir)
| Redirect_in (inputs, fn, t) -> Redirect_in (inputs, f_path ~dir fn, f t ~dir)
| Ignore (outputs, t) -> Ignore (outputs, f t ~dir)
| If_file_exists (path, t) -> If_file_exists (f_path ~dir path, f t ~dir)
| Progn l -> Progn (List.map l ~f:(fun t -> f t ~dir))
| Concurrent l -> Concurrent (List.map l ~f:(fun t -> f t ~dir))
| Echo xs -> Echo (List.map xs ~f:(f_string ~dir))
Expand Down
14 changes: 13 additions & 1 deletion src/dune_lang/format.ml
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,17 @@ let format_to_channel ~version ~src oc =
;;

let format_action ~version ~src ~dst =
Path.build dst |> Io.with_file_out ~f:(format_to_channel ~version ~src)
let dst = Path.build dst in
if Path.equal src dst
then
Temp.with_temp_file
~dir:(Path.parent_exn dst)
~prefix:"dune-format"
~suffix:"output"
~f:(function
| Error exn -> raise exn
| Ok temporary ->
Io.with_file_out temporary ~f:(format_to_channel ~version ~src);
Fpath.rename_exn (Path.to_string temporary) (Path.to_string dst))
else Io.with_file_out dst ~f:(format_to_channel ~version ~src)
;;
Loading
Loading