From 154739e0de705d4271757407cbf13a95c3370483 Mon Sep 17 00:00:00 2001 From: Stephen Sherratt Date: Mon, 14 Oct 2024 16:41:09 +1100 Subject: [PATCH] pkg: sandbox format action when using devtool Signed-off-by: Stephen Sherratt --- src/dune_rules/format_rules.ml | 4 +++- test/blackbox-tests/test-cases/pkg/ocamlformat/gh10991.t | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/dune_rules/format_rules.ml b/src/dune_rules/format_rules.ml index 17f66f17a93..f4239f26919 100644 --- a/src/dune_rules/format_rules.ml +++ b/src/dune_rules/format_rules.ml @@ -97,7 +97,9 @@ module Ocamlformat = struct 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 = diff --git a/test/blackbox-tests/test-cases/pkg/ocamlformat/gh10991.t b/test/blackbox-tests/test-cases/pkg/ocamlformat/gh10991.t index 44a69d9b498..048d367c13a 100644 --- a/test/blackbox-tests/test-cases/pkg/ocamlformat/gh10991.t +++ b/test/blackbox-tests/test-cases/pkg/ocamlformat/gh10991.t @@ -18,18 +18,19 @@ Initial file: $ cat foo.ml let () = print_endline "Hello, world" +Formatting failed because the input file was not copied into the sandbox. $ DUNE_CONFIG__LOCK_DEV_TOOL=enabled dune fmt Solution for dev-tools.locks/ocamlformat: - ocamlformat.0.0.1 + cat: foo.ml: No such file or directory File "foo.ml", line 1, characters 0-0: Error: Files _build/default/foo.ml and _build/default/.formatted/foo.ml differ. Promoting _build/default/.formatted/foo.ml to foo.ml. [1] -After formatting the fake ocamlformat has added a suffix: +No formatting occured because input file wasn't copied to the sandbox. $ cat foo.ml - let () = print_endline "Hello, world" (* formatted with fake ocamlformat *) Update the file: @@ -44,7 +45,6 @@ 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: +No formatting occured because input file wasn't copied to the sandbox. $ cat foo.ml - let () = print_endline "Hello, world" (* formatted with fake ocamlformat *)