Skip to content

Commit 88bbc4f

Browse files
Respect potentially existing lock dir when running format rules (#12847)
* Respect an existing lock file if it was created Signed-off-by: Marek Kubica <marek@tarides.com> * Confirm that the fix solves the repro case Signed-off-by: Marek Kubica <marek@tarides.com> --------- Signed-off-by: Marek Kubica <marek@tarides.com>
1 parent 15eead0 commit 88bbc4f

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

src/dune_rules/format_rules.ml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,12 @@ module Ocamlformat = struct
3737
via locking and can expect it to exist. If it doesn't, it's a bug
3838
*)
3939
match Config.get Compile_time.lock_dev_tools with
40-
| `Enabled -> true
41-
| `Disabled -> false
40+
| `Enabled -> Memo.return true
41+
| `Disabled ->
42+
(* even if lock_dev_tools might be disabled, there might be a lock dir
43+
created by `dune tools install` *)
44+
let path = Lock_dir.dev_tool_external_lock_dir Ocamlformat in
45+
Fs_memo.dir_exists (Path.Outside_build_dir.External path)
4246
;;
4347

4448
(* Config files for ocamlformat. When these are changed, running
@@ -133,7 +137,7 @@ let gen_rules_output
133137
let loc = Format_config.loc config in
134138
let dir = Path.Build.parent_exn output_dir in
135139
let alias_formatted = Alias.fmt ~dir:output_dir in
136-
let ocamlformat_is_locked = Ocamlformat.dev_tool_lock_dir_exists () in
140+
let* ocamlformat_is_locked = Ocamlformat.dev_tool_lock_dir_exists () in
137141
let setup_formatting file =
138142
(let input_basename = Path.Source.basename file in
139143
let input = Path.Build.relative dir input_basename in

test/blackbox-tests/test-cases/pkg/ocamlformat/ocamlformat-dune-tools-install.t

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,9 @@ Formatting should use the locked ocamlformat with the feature flag enabled:
6060
It should also use the locked dev tool when the feature flag is not passed:
6161

6262
$ dune fmt --preview
63-
ocamlformat from PATH, not pkg
64-
-> required by _build/default/.formatted/foo.ml
65-
-> required by alias .formatted/fmt
66-
-> required by alias fmt
63+
File "foo.ml", line 1, characters 0-0:
64+
Error: Files _build/default/foo.ml and _build/default/.formatted/foo.ml
65+
differ.
6766
[1]
6867

6968
It should use the ocamlformat from PATH when the lock dir is deleted:

0 commit comments

Comments
 (0)