Skip to content

Adding constraint to ocamlformat developer tool fails #12866

Open

Description

@Sudha247

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 of dune --version): "Nightly build 2025-12-04T02:46:51Z, git revision b25137a5321432edb6a36a19c1c5d5484bab5252"
  • Version of ocaml (output of ocamlc --version): 5.2.0+ox
  • Operating system (distribution and version): Ubuntu 20.02

Activity

  1. added
    package management
    on Dec 5, 2025
  2. added
    dev tools
    on Dec 10, 2025
  3. shonfeder commented on Dec 11, 2025

    @shonfeder
    Member

    Is this a duplicate (or at least a special case of) #12777 ?

  4. Sudha247 commented on Dec 15, 2025

    @Sudha247
    MemberAuthor

    It is definitely related to #12777. However, this one is a bug report of an existing failure, and #12777 is a feature enhancement request for specifying constraints.

  5. Sudha247 commented on Dec 22, 2025

    @Sudha247
    MemberAuthor

    The same behaviour happens when adding constraints to other dev tools such as ocamllsp. As the error message indicates, I suspect it has something to do with the path, _build/.dev-tools.locks/ocaml-lsp-server, being treated as an external path when it is actually inside the _build directory.

  6. Sudha247 commented on Dec 22, 2025

    @Sudha247
    MemberAuthor

    After digging into this a bit and trying to reproduce this with a cram test, I think this could be a special case of #12851. The failure happens specifically for .patch files within .dev-tools.locks/. I will try to dig further.

  7. added theissue type on May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    dev toolspackage management

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions