Skip to content

fix: expand path pforms to start with ./ when in same directory - #15156

Merged
Alizter merged 1 commit into
ocaml:mainfrom
Alizter:push-wuxumyrurvsu
Jun 17, 2026
Merged

Alizter merged 1 commit into
ocaml:mainfrom
Alizter:push-wuxumyrurvsu

Conversation

@Alizter

@Alizter Alizter commented Jun 12, 2026 •

Copy link
Copy Markdown
Collaborator

Value.string_of_path now uses Path.reach_for_running instead of
Path.reach. The user-visible effect is that pforms producing path
values (%{bin:...}, %{dep:...}, %{path:...}, and friends) render
bare-basename paths with a leading ./. This stops shells like bash
in (bash ...) and (system ...) actions from treating a
same-directory binary as a PATH lookup.

Path.reach_for_running itself is tightened so that the current
directory stays as . rather than becoming ./.. Bare basenames
(the actual hazard) still get the ./ prefix.

Also rewrites the bin:<program> paragraph in
doc/concepts/variables.rst into three short paragraphs covering
resolution, the (deps ...) PATH-symlink mechanism, and the fact that
(run %{bin:foo} ...) and (run foo ...) behave the same.

@Alizter
Alizter force-pushed the push-wuxumyrurvsu branch 2 times, most recently from d46674f to 24789d0 Compare June 12, 2026 11:46
@Alizter
Alizter requested a review from Copilot June 12, 2026 11:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts how %{bin:...} is represented and stringified so that program paths are unambiguous to downstream consumers (notably shells like bash). It introduces a new Value.Prog variant that stringifies via Path.reach_for_running (adding ./ when the reached path would otherwise look like a bare command), and changes %{bin:...} expansion to produce Prog rather than Path.

Changes:

  • Introduce Value.Prog and make its string conversion use Path.reach_for_running to ensure leading ./ for bare basenames.
  • Switch %{bin:...} macro expansion to yield Prog, propagating support through related expanders and consumers.
  • Update blackbox tests, docs, and changelog to reflect the new %{bin:...} behavior.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
test/blackbox-tests/test-cases/bin-pform/runnable-argument.t Updates the blackbox test to expect (bash %{bin:foo}) to succeed now that %{bin:...} becomes ./foo.exe when appropriate.
test/blackbox-tests/test-cases/bin-pform/public-name.t Updates expected output to include ./ for %{bin:...} expansions that are bare basenames.
src/source/workspace.ml Adds handling for Value.Prog when evaluating conditional lockdir selections.
src/dune_rules/slang_expand.ml Treats Prog like other path values when producing type errors for boolean contexts.
src/dune_rules/simple_rules.ml Allows Prog in target/path validation where Path was previously accepted.
src/dune_rules/pkg_rules.ml Extends pkg action expansion logic to treat Prog consistently alongside Path/Dir.
src/dune_rules/expander.ml Changes %{bin:...} expansion to depend on the resolved program path but return Value.Prog.
src/dune_rules/action_unexpanded.ml Ensures Prog is accepted anywhere an executable value can be Path.
src/dune_lang/value.mli Exposes the new Value.Prog variant in the public interface.
src/dune_lang/value.ml Implements Prog semantics, including to_string via Path.reach_for_running.
doc/concepts/variables.rst Updates documentation for bin:<program> to describe runnable-path behavior and the new ./ disambiguation.
doc/changes/changed/15156.md Adds a changelog entry describing the %{bin:...} leading-./ behavior.

@Alizter
Alizter marked this pull request as ready for review June 12, 2026 12:49
@Alizter
Alizter requested a review from rgrinberg June 12, 2026 12:49
Comment thread src/dune_lang/value.ml Resolved
@Alizter
Alizter force-pushed the push-wuxumyrurvsu branch from 24789d0 to 8f8bb41 Compare June 12, 2026 16:31
@Alizter
Alizter marked this pull request as draft June 12, 2026 16:32
@Alizter
Alizter force-pushed the push-wuxumyrurvsu branch from 8f8bb41 to 7ed8346 Compare June 12, 2026 16:32
@shonfeder shonfeder mentioned this pull request Jun 14, 2026
30 tasks done
@Alizter
Alizter force-pushed the push-wuxumyrurvsu branch 3 times, most recently from 30b319a to 8f1262a Compare June 15, 2026 08:50
@Alizter Alizter changed the title fix: expand %{bin:...} starting with ./ fix: expand path pforms to start with ./ when in same directory Jun 15, 2026
@Alizter
Alizter force-pushed the push-wuxumyrurvsu branch 2 times, most recently from ebe7949 to febb53f Compare June 15, 2026 09:05
@Alizter
Alizter marked this pull request as ready for review June 15, 2026 09:05
@Alizter
Alizter marked this pull request as draft June 15, 2026 11:16
@Alizter

Alizter commented Jun 15, 2026 •

Copy link
Copy Markdown
Collaborator Author

This is currently the fix that I want to do, but it is a bit more breaking than I intended. I'll need to find the least disruptive way to do this, perhaps guarding behind dune lang or something. But... that defeats the point of the "fix". I'll need to think further on this.

@rgrinberg

Copy link
Copy Markdown
Member

What does it break?

@shonfeder

Copy link
Copy Markdown
Member

If you could guard the whole changeset (including the {%bin:..} change that introduced the regression) behind a lang version easily, that would be elegant. But if it's not easy, I think we can take this breaking change as is. AFAIK, this is strictly an improvement, and any "breakage" would only result form incorrect and brittle test or path handling logic, so arguably from broken logic in the first place.

@Alizter
Alizter force-pushed the push-wuxumyrurvsu branch from febb53f to 53b4e8c Compare June 16, 2026 14:46
@Alizter

Alizter commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator Author

What does it break?

This is currently breaking wasm_of_ocaml:

They have some program that does ocaml %{deps} in an action. Then for each argument they use Filename.chop_suffix to infer a module name which leads to ./foo:./foo.wat rather than foo:foo.wat. The better thing to do here would be to use Filename.basename |> Filename.chop_suffix.

I'll try patching this so the OxCaml job, which is the only job using the built version of dune to build all the packages, can build.

@rgrinberg

Copy link
Copy Markdown
Member

Okay, that can be fixed with an upper bound. The list of dependencies isn't guaranteed to be made of base names today already

Value.string_of_path now uses Path.reach_for_running so that pforms
render bare-basename paths with a leading "./". This avoids bash and
other shells (in (bash ...) and (system ...) actions) treating
same-directory binaries as PATH lookups.

Also rewrites the %{bin:NAME} entry in doc/concepts/variables.rst.

Signed-off-by: Ali Caglayan <[email protected]>
@Alizter
Alizter force-pushed the push-wuxumyrurvsu branch from 53b4e8c to f206421 Compare June 17, 2026 09:08
@Alizter
Alizter marked this pull request as ready for review June 17, 2026 10:07
vouillon pushed a commit to ocsigen/js_of_ocaml that referenced this pull request Jul 2, 2026
Dune `deps` variables are expanded to paths. The representation of this
has changed with ocaml/dune#15156, causing the
wasm_of_ocaml runtime build to fail on the pending dune 3.24: when
`args.ml` is run with the `.wat` deps in the rule's own directory those
arguments are now "./foo.wat" rather than "foo.wat", and
`Filename.chop_suffix ".wat"` on them produces "./foo", which is not a valid
wasm-link module name. By taking the basename of the path before chopping the
suffix, we get a fix that works regardless of the path representation.
vouillon pushed a commit to ocsigen/js_of_ocaml that referenced this pull request Jul 2, 2026
dune 3.24 expands %{dep:file} to a leading-./ path form (ocaml/dune#15156).
The md5/md5_nat and dump_sourcemap tests pass such a dep as an argument to a
program that prints the path verbatim, so their output gained a ./ prefix and
the expected-output diffs failed on CI.

Pass the filenames as literal arguments (emitted verbatim by every dune
version) and declare them via explicit (deps ...) instead, keeping the tests
working across the supported dune range (>= 3.20).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
mseri pushed a commit to ocaml/opam-repository that referenced this pull request Jul 3, 2026
CHANGES:

## Bug fixes
* Runtime/wasm: derive the wat-module name from the basename of the input
  path in `runtime/wasm/args.ml`, so dune 3.24's leading-`./` path-form
  representation (ocaml/dune#15156) keeps producing well-formed
  `module:path` lines for `wasmoo_link_wasm` (ocsigen/js_of_ocaml#2371)
* Tests: pass file paths as literal arguments (with explicit `(deps ...)`)
  instead of `%{dep:...}` in the `md5`/`md5_nat`, `dump_sourcemap` and
  `check-prim` tests, which echo the path verbatim, so dune 3.24's leading-`./`
  path form (ocaml/dune#15156) no longer breaks their expected output (ocsigen/js_of_ocaml#2384)
mseri pushed a commit to paurkedal/opam-repository that referenced this pull request Jul 3, 2026
CHANGES:

## Bug fixes
* Runtime/wasm: derive the wat-module name from the basename of the input
  path in `runtime/wasm/args.ml`, so dune 3.24's leading-`./` path-form
  representation (ocaml/dune#15156) keeps producing well-formed
  `module:path` lines for `wasmoo_link_wasm` (ocsigen/js_of_ocaml#2371)
* Tests: pass file paths as literal arguments (with explicit `(deps ...)`)
  instead of `%{dep:...}` in the `md5`/`md5_nat`, `dump_sourcemap` and
  `check-prim` tests, which echo the path verbatim, so dune 3.24's leading-`./`
  path form (ocaml/dune#15156) no longer breaks their expected output (ocsigen/js_of_ocaml#2384)
Kakadu pushed a commit to Kakadu/opam-repository that referenced this pull request Jul 4, 2026
CHANGES:

## Bug fixes
* Runtime/wasm: derive the wat-module name from the basename of the input
  path in `runtime/wasm/args.ml`, so dune 3.24's leading-`./` path-form
  representation (ocaml/dune#15156) keeps producing well-formed
  `module:path` lines for `wasmoo_link_wasm` (ocsigen/js_of_ocaml#2371)
* Tests: pass file paths as literal arguments (with explicit `(deps ...)`)
  instead of `%{dep:...}` in the `md5`/`md5_nat`, `dump_sourcemap` and
  `check-prim` tests, which echo the path verbatim, so dune 3.24's leading-`./`
  path form (ocaml/dune#15156) no longer breaks their expected output (ocsigen/js_of_ocaml#2384)
@Alizter Alizter added this to the 3.25.0 milestone Jul 8, 2026
Alizter added a commit that referenced this pull request Jul 21, 2026
Generate the 3.24.1 section from the release branch changelog fragments.
This also includes #15156, whose fragment remained after the 3.24.0 release
and was absent from that published changelog.

Signed-off-by: Ali Caglayan <[email protected]>
Alizter added a commit that referenced this pull request Jul 21, 2026
Generate the 3.24.1 section of `CHANGES.md` from the changelog fragments
on the release branch and remove the consumed fragments.

This includes the seven entries from the current 3.24.1 backports, plus
#15156. The latter shipped in 3.24.0 but its fragment remained on the
release branch and the entry is absent from the published 3.24.0
changelog.

Validation:
- `./dune.exe runtest doc/changes/scripts`
- reviewed the generated section and confirmed no release fragments
remain in `added`, `changed`, or `fixed`
- no broader Dune test suite was run
Alizter added a commit that referenced this pull request Jul 21, 2026
The change shipped in 3.24.0, so record the previously omitted entry in that
release rather than presenting it as a 3.24.1 change.

Signed-off-by: Ali Caglayan <[email protected]>
Alizter added a commit that referenced this pull request Jul 21, 2026
Follow up on #15579 by moving the #15156 entry from the 3.24.1 section
to `3.24.0 → Changed`.

#15156 shipped in 3.24.0. Its fragment was omitted when that release
changelog was generated, but placing it under 3.24.1 would incorrectly
present the behavior as a patch-release change.

Validation:
- `./dune.exe runtest doc/changes/scripts`
- diff is only the relocation within `CHANGES.md`
- no broader Dune test suite was run
@Alizter Alizter modified the milestones: 3.25.0, 3.24.0 Jul 21, 2026
craff pushed a commit to craff/opam-repository that referenced this pull request Jul 25, 2026
These packages make use of non-normalized paths from dune variables in
their tests. But in dune 3.24 the representation of variables expanding
to paths within the current directory changes to always include the `./`
prefix. As a result, test in these package versions have trivial errors
with dune >= 3.24. This change to dune was introduced in ocaml/dune#15156
craff pushed a commit to craff/opam-repository that referenced this pull request Jul 25, 2026
CHANGES:

## Bug fixes
* Runtime/wasm: derive the wat-module name from the basename of the input
  path in `runtime/wasm/args.ml`, so dune 3.24's leading-`./` path-form
  representation (ocaml/dune#15156) keeps producing well-formed
  `module:path` lines for `wasmoo_link_wasm` (ocsigen/js_of_ocaml#2371)
* Tests: pass file paths as literal arguments (with explicit `(deps ...)`)
  instead of `%{dep:...}` in the `md5`/`md5_nat`, `dump_sourcemap` and
  `check-prim` tests, which echo the path verbatim, so dune 3.24's leading-`./`
  path form (ocaml/dune#15156) no longer breaks their expected output (ocsigen/js_of_ocaml#2384)
georgyo added a commit to georgyo/avalon-bonsai that referenced this pull request Sep 3, 2026
…efs (#11)

* Pin dune to 3.22.2+ox; dune 3.24's ./-prefixed %{deps} breaks bonsai_web

The "Bump opam lock" re-materialization (2d88231) resolved dune to upstream
3.24.2 instead of the OxCaml-patched 3.22.2+ox, because oxcaml/opam-repository
5a5a760 relaxed the `oxcaml-dune` guard to accept dune >= 3.24.2. That broke
`nix build .#default` in CI (run 33622341785): bonsai_web's kado, legacy_view
and partial_render_table_styling libraries fail with

    File "web/view/kado/src/app.ml", line 1, characters 8-10:
    1 | include ./app__generated
    Error: Syntax error

Those `app.ml` files are generated at build time by ppx_css's `css_inliner`,
run from a `(bash "%{bin:css_inliner} %{deps} ...")` rule. dune 3.24.0 changed
every path-valued pform, `%{deps}` included, to expand same-directory paths
with a leading `./` (ocaml/dune#15156), and css_inliner builds the alias
module's name from that path with `String.capitalize`, so the generated
`include` now names `./app__generated`. The latest published ppx_css
(v0.18~preview.130.106+341) still does this.

Pin `dune = "3.22.2+ox"` in the flake query (the newest OxCaml-patched dune;
opam-nix turns it into the exact request `dune.3.22.2+ox`) and re-materialize
package-defs.json. The resolution goes back to dune, dune-configurator
3.22.2+ox with the `oxcaml-dune*-patches` meta-packages, and drops the
`oxcaml-dune*` guards, dune-build-info and cppo that 3.24.2 had pulled in.
flake.lock is untouched, so package-defs.lock only changes if the lock helper
rewrites it.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LgG4z5LoFzQ2afZzxtbq4N

* Re-materialize package-defs.json with dune pinned to 3.22.2+ox

Regenerated against the unchanged flake.lock repo revs (package-defs.lock is
byte-identical), so the only intended change is the resolution: dune and
dune-configurator return to 3.22.2+ox with oxcaml-dune-patches and
oxcaml-dune-configurator-patches enabled, and the oxcaml-dune* guards,
dune-build-info and cppo that upstream 3.24.2 dragged in are gone. The solver
also reshuffled a few optional leaves that nothing here links against
(backoff, ctypes, extlib, notty-community, omd, portable_lockfree_htbl). The
compiler and every Jane Street preview stay at 5.2.0+ox / 130.106+341.

`__opam_nix_files` picks the oxcaml-dune patch back up; `__opam_nix_repos`
differs only because the inputs were fetched over git this time (nothing reads
it — see the note above `scope` in flake.nix). opam-nix-pin-git-refs reports
nothing to pin.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LgG4z5LoFzQ2afZzxtbq4N

* Shorten the dune pin comment

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LgG4z5LoFzQ2afZzxtbq4N

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>
samoht added a commit to samoht/opam-repository that referenced this pull request Nov 9, 2026
Otherwise the tests fail with dune 3.22:

```
  File "plugins/wrapper/test/generated/pascal_errors.expected", line 1, characters 0-0:
  diff --git a/_build/default/plugins/wrapper/test/generated/pascal_errors b/_build/default/plugins/wrapper/test/generated/pascal_errors
  new file mode 100644
```

and with dune 3.24:

```
  -            pos_fname = "lib_behaviour.mli";
  +            pos_fname = "./lib_behaviour.mli";
```

dune 3.22 no longer reads a missing expected file as empty
(ocaml/dune#13696), and dune 3.24 expands %{dep:lib.mli} to ./lib.mli
(ocaml/dune#15156). Both are fixed upstream after 0.7.2
(ocaml-gospel/ortac#382, and the expected file added in 0.8.0).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(bash %{bin:foo}) no longer works

4 participants