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

pkg: fix dev-tool bug where dune fmt would revert file #10990

Merged
merged 2 commits into from
Oct 15, 2024
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
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 *)
Loading