Skip to content

Commit

Permalink
Merge pull request #10990 from gridbugs/dune-fmt-stale-file-fix
Browse files Browse the repository at this point in the history
pkg: fix dev-tool bug where `dune fmt` would revert file
  • Loading branch information
gridbugs authored Oct 15, 2024
2 parents 1becc6e + 40720f4 commit ed871ba
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/dune_rules/format_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,19 @@ module Ocamlformat = struct
(let open Action_builder.O in
(* This ensures that at is installed as a dev tool before
running it. *)
let+ () = Action_builder.path path in
let+ () = Action_builder.path path
(* Declare the dependency on the input file so changes to the input
file trigger ocamlformat to run again on the updated file. *)
and+ () = Action_builder.path (Path.build input) in
let args = [ flag_of_kind kind; Path.Build.basename input ] in
Action.chdir (Path.build dir) @@ Action.run (Ok path) args |> Action.Full.make)
in
let open Action_builder.With_targets.O in
(* Depend on [extra_deps] so if the ocamlformat config file
changes then ocamlformat will run again. *)
extra_deps dir >>> action
extra_deps dir
>>> action
|> With_targets.map ~f:(Action.Full.add_sandbox Sandbox_config.needs_sandboxing)
;;

let action_when_ocamlformat_isn't_locked ~input kind =
Expand Down
4 changes: 2 additions & 2 deletions test/blackbox-tests/test-cases/pkg/ocamlformat/gh10991.t
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Update the file:
Promoting _build/default/.formatted/foo.ml to foo.ml.
[1]

After formatting a second time, the recent change to the file was ignored:
The update to the file persists after formatting it a second time:
$ cat foo.ml
let () = print_endline "Hello, world"
let () = print_endline "Hello, ocaml!"
(* formatted with fake ocamlformat *)

0 comments on commit ed871ba

Please sign in to comment.