@@ -120,8 +120,7 @@ module Ocamlformat = struct
120120 ;;
121121end
122122
123- let format_action format ~input ~output ~expander kind =
124- let * ocamlformat_is_locked = Ocamlformat. dev_tool_lock_dir_exists () in
123+ let format_action format ~ocamlformat_is_locked ~input ~output ~expander kind =
125124 match (format : Dialect.Format.t ) with
126125 | Ocamlformat when ocamlformat_is_locked ->
127126 Memo. return (Ocamlformat. action_when_ocamlformat_is_locked ~input ~output kind)
@@ -157,6 +156,7 @@ let gen_rules_output
157156 let loc = Format_config. loc config in
158157 let dir = Path.Build. parent_exn output_dir in
159158 let alias_formatted = Alias. fmt ~dir: output_dir in
159+ let * ocamlformat_is_locked = Ocamlformat. dev_tool_lock_dir_exists () in
160160 let setup_formatting file =
161161 (let input_basename = Path.Source. basename file in
162162 let input = Path.Build. relative dir input_basename in
@@ -176,8 +176,16 @@ let gen_rules_output
176176 | None -> Dialect. format Dialect. ocaml kind
177177 | Some _ -> None )
178178 in
179- format_action format ~input ~output ~expander kind
180- |> Memo. bind ~f: (Super_context. add_rule sctx ~mode: Standard ~loc ~dir )
179+ format_action format ~ocamlformat_is_locked ~input ~output ~expander kind
180+ |> Memo. bind ~f: (fun rule ->
181+ if ocamlformat_is_locked
182+ then (
183+ let { Action_builder.With_targets. build; targets } = rule in
184+ Rule. make ~mode: Standard ~targets build |> Rules.Produce. rule)
185+ else
186+ let open Memo.O in
187+ let * sctx = sctx in
188+ Super_context. add_rule sctx ~mode: Standard ~loc ~dir rule)
181189 >>> add_diff loc alias_formatted ~input: (Path. build input) ~output )
182190 |> Memo.Option. iter ~f: Fun. id
183191 in
@@ -239,8 +247,7 @@ let with_config ~dir f =
239247let gen_rules sctx ~output_dir =
240248 let dir = Path.Build. parent_exn output_dir in
241249 with_config ~dir (fun config ->
242- let * sctx = sctx in
243- let expander = Super_context. expander sctx ~dir in
250+ let expander = sctx >> = Super_context. expander ~dir in
244251 let * project = Dune_load. find_project ~dir in
245252 let dialects = Dune_project. dialects project in
246253 let version = Dune_project. dune_version project in
0 commit comments