Repository navigation
fix: expand path pforms to start with ./ when in same directory - #15156
Conversation
d46674f to
24789d0
Compare
There was a problem hiding this comment.
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.Progand make its string conversion usePath.reach_for_runningto ensure leading./for bare basenames. - Switch
%{bin:...}macro expansion to yieldProg, 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. |
24789d0 to
8f8bb41
Compare
8f8bb41 to
7ed8346
Compare
30b319a to
8f1262a
Compare
ebe7949 to
febb53f
Compare
|
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. |
|
What does it break? |
|
If you could guard the whole changeset (including the |
febb53f to
53b4e8c
Compare
This is currently breaking wasm_of_ocaml: They have some program that does 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. |
|
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]>
53b4e8c to
f206421
Compare
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.
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]>
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)
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)
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)
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]>
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
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]>
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
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
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)
…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]>
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).
Value.string_of_pathnow usesPath.reach_for_runninginstead ofPath.reach. The user-visible effect is that pforms producing pathvalues (
%{bin:...},%{dep:...},%{path:...}, and friends) renderbare-basename paths with a leading
./. This stops shells likebashin
(bash ...)and(system ...)actions from treating asame-directory binary as a
PATHlookup.Path.reach_for_runningitself is tightened so that the currentdirectory stays as
.rather than becoming./.. Bare basenames(the actual hazard) still get the
./prefix.Also rewrites the
bin:<program>paragraph indoc/concepts/variables.rstinto three short paragraphs coveringresolution, the
(deps ...)PATH-symlink mechanism, and the fact that(run %{bin:foo} ...)and(run foo ...)behave the same.(bash %{bin:foo})no longer works #15147