dune icon indicating copy to clipboard operation
dune copied to clipboard

fix(utop): accept absolute paths to workspace directories

Open chizy7 opened this issue 5 months ago • 0 comments

Fixes #15108.

dune utop $PWD/lib crashed with an internal Code_error while dune utop lib worked. Common.prefix_target is a no-op on absolute strings, so the absolute path reached Path.Build.relative, which raises on absolute input.

This change localizes an absolute DIR argument with Path.Expert.try_localize_external before use. this is the same approach that dune exec (#12094) and dune runtest (#11936) already uses. A relative path still goes through Common.prefix_target so the run-from-a-subdirectory case is unchanged, and a part outside the workspace stays external and still produces the clean Error: cannot find directory: ... message.

Based on @Alizter's repro in #15116, the test was flipped from asserting the crash to checking the working foolib output.

questions I have:

  • The issue suggests migrating DIR to Arg.Workspace_path. That converter doesn't exist yet, and a cmdliner conv can't localize at parse time since localization needs Build.build_dir, which is only set after Common.init. I went with the inline localization that exec and runtest already use. Happy to extract a shared Arg.Workspace_path for #15109/#15110 if thats preferred. Should that live in this PR or a follow-up?
  • An absolute path pointing into _build would localize to an in-build path. exec handles that through Path.relative_to_source_in_build_or_external. This isn't covered by the repro or the issue's required behaviors, so I left it out for now. Let me know if you would like that included here.
  • I also wasnt sure if there is a preferred place for sharing this localization logic across commands instead of keeping it inline.

chizy7 avatar Jun 21 '26 20:06 chizy7