Skip to content

Commit ed871ba

Browse files
authored
Merge pull request ocaml#10990 from gridbugs/dune-fmt-stale-file-fix
pkg: fix dev-tool bug where `dune fmt` would revert file
2 parents 1becc6e + 40720f4 commit ed871ba

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/dune_rules/format_rules.ml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,19 @@ module Ocamlformat = struct
9090
(let open Action_builder.O in
9191
(* This ensures that at is installed as a dev tool before
9292
running it. *)
93-
let+ () = Action_builder.path path in
93+
let+ () = Action_builder.path path
94+
(* Declare the dependency on the input file so changes to the input
95+
file trigger ocamlformat to run again on the updated file. *)
96+
and+ () = Action_builder.path (Path.build input) in
9497
let args = [ flag_of_kind kind; Path.Build.basename input ] in
9598
Action.chdir (Path.build dir) @@ Action.run (Ok path) args |> Action.Full.make)
9699
in
97100
let open Action_builder.With_targets.O in
98101
(* Depend on [extra_deps] so if the ocamlformat config file
99102
changes then ocamlformat will run again. *)
100-
extra_deps dir >>> action
103+
extra_deps dir
104+
>>> action
105+
|> With_targets.map ~f:(Action.Full.add_sandbox Sandbox_config.needs_sandboxing)
101106
;;
102107

103108
let action_when_ocamlformat_isn't_locked ~input kind =

test/blackbox-tests/test-cases/pkg/ocamlformat/gh10991.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Update the file:
4444
Promoting _build/default/.formatted/foo.ml to foo.ml.
4545
[1]
4646

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

0 commit comments

Comments
 (0)