Adding constraint to `ocamlformat` developer tool fails
Nobody has claimed this yet.
- Dominant language
- OCaml
- Stars
- 1.9k
- Forks
- 500
- Avg merge
- 15h 21m
- Merged PRs (30d)
- 277
Description
Expected Behavior
Adding constraints to developer tools in general, and ocamlformat in particular lets you install the version of ocamlformat per the constraints (as long as it exists)
Actual Behavior
Adding constraints to the path of ocamlformat leads it the path being treated as an external path outside _build, but in reality it is inside _build.
Internal error, please report upstream including the contents of _build/log.
Description:
("as_outside_build_dir_exn",
{ path =
In_build_dir ".dev-tools.locks/ocamlformat/ocaml-compiler-libs.files"
})
Raised at Stdune__Code_error.raise in file "stdune__Code_error.ml", line 11,
characters 30-62
Called from Dune_rules__Lock_rules.scan_lock_directory.scan in file
"dune_rules__Lock_rules.ml", line 431, characters 25-60
Called from Fiber__Core.apply2 in file "fiber__Core.ml", line 93, characters
6-11
-> required by ("gen-rules", In_build_dir "_private/default/.lock")
-> required by ("load-dir", In_build_dir "_private/default/.lock")
-> required by
("build-file", In_build_dir "_private/default/.lock/dune.lock")
-> required by ("<unnamed>", ())
-> required by
("gen-rules", In_build_dir "_private/default/.dev-tool/ocamlformat")
-> required by
("gen-rules", In_build_dir "_private/default/.dev-tool/ocamlformat/target")
-> required by
("gen-rules",
In_build_dir "_private/default/.dev-tool/ocamlformat/target/bin")
-> required by
("load-dir",
In_build_dir "_private/default/.dev-tool/ocamlformat/target/bin")
-> required by
("build-file",
In_build_dir
"_private/default/.dev-tool/ocamlformat/target/bin/ocamlformat")
-> required by ("toplevel", ())
I must not crash. Uncertainty is the mind-killer. Exceptions are the
little-death that brings total obliteration. I will fully express my cases.
Execution will pass over me and through me. And when it has gone past, I
will unwind the stack along its path. Where the cases are handled there will
be nothing. Only I will remain.
Reproduction
- PR with a reproducing test:
$ cat > dune <<'EOF'
(executable
(public_name main))
EOF
$ cat > dune-workspace <<'EOF'
(lang dune 3.21)
(pkg enabled)
(repository
(name oxcaml)
(url git+file:///home/sudha/ocaml/work/oxcaml/oxcaml-opam-repository))
(pin
(name ocamlbuild)
(url "git+https://github.com/Sudha247/ocamlbuild#oxcaml+dune")
(package
(name ocamlbuild)
(version 0.15.0+ox)))
(lock_dir
(path "dune.lock")
(repositories overlay oxcaml upstream))
(lock_dir
(path "_build/.dev-tools.locks/ocamlformat")
(pins ocamlbuild)
(constraints
(ocaml-lsp-server (= 1.19.0+ox))
(ocaml-variants (= 5.2.0+ox)))
(repositories :standard oxcaml))
EOF
$ cat > dune-project <<'EOF'
(lang dune 3.21)
(package
(name hello-oxcaml)
(depends
ocaml
(ocaml-variants
(= 5.2.0+ox))))
EOF
$ cat > main.ml <<'EOF'
let () =
(* The `local_` keyword requires OxCaml *)
let local_ i = 42 in
let j = i + 1 in
Printf.printf "%d\n" j
EOF
$ dune tools install ocamlformat
Specifications
- Version of
dune(output ofdune --version):"Nightly build 2025-12-04T02:46:51Z, git revision b25137a5321432edb6a36a19c1c5d5484bab5252" - Version of
ocaml(output ofocamlc --version):5.2.0+ox - Operating system (distribution and version): Ubuntu 20.02
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reproduction in the issue and inspect dune_rules__Lock_rules.ml around line 431, where scan_lock_directory raises the as_outside_build_dir_exn error. Run dune tools install ocamlformat using the supplied dune-workspace and constraints. Done means constrained developer-tool installation completes without treating the in-build lock path as external.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ocaml
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100