Skip to content

test: bin pform expansion - #14431

Merged
Alizter merged 1 commit into
ocaml:mainfrom
Alizter:push-vxpoqsvypvsz
May 10, 2026
Merged

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

Conversation

@Alizter

@Alizter Alizter commented May 5, 2026 •

Copy link
Copy Markdown
Collaborator

In this PR we organise all the tests about %{bin:...} and increase our test coverage. This is in preparation of:

Add test/blackbox-tests/test-cases/bin-pform/ with focused tests for
the %{bin:NAME} pform.

New tests:

  • cram-path.t %{bin:...} in cram (deps ...)
  • env-binaries.t %{bin:...} for (env (binaries ...)) entries
  • include-deps.t %{bin:...} inside (include ...) deps
  • inline-tests.t %{bin:...} in (inline_tests (deps ...))
  • multiple-bins.t multiple %{bin:...} deps in a single rule
  • public-name.t %{bin:...} expansion for (public_name)
  • run-action.t %{bin:...} in (run ...) and PATH visibility
  • run-literal-vs-pform.t (run NAME) vs (run %{bin:NAME}) record different deps (build artifact vs install staging)
  • system.t %{bin:...} for a system binary on PATH
  • test-stanza.t %{bin:...} in a test stanza
  • missing-bin.t %{bin:...} and (run LITERAL) where the name doesn't resolve

Plus a cross-compilation analog of lib-pform-context-expansion-gh9199.t
at custom-cross-compilation/bin-pform-context-expansion.t.

Renamed:

  • bin-eager-deps.t -> bin-pform/lazy-failure.t
  • adversarial-binary-name.t -> bin-pform/colon-in-name.t
  • build-percent-form-bin.t -> bin-pform/cli-build.t

Split missing-lib-bin-pform-errors-gh1541.t: bin parts moved into
bin-pform/missing-bin.t, lib parts stay in missing-lib-pform-errors-gh1541.t.

setup-script.sh: add env_added helper.

@Alizter
Alizter force-pushed the push-vxpoqsvypvsz branch 3 times, most recently from 2390daf to 7f4417a Compare May 6, 2026 17:37
@Alizter Alizter self-assigned this May 6, 2026
@Alizter
Alizter force-pushed the push-vxpoqsvypvsz branch 6 times, most recently from 9901158 to c6c0a9d Compare May 10, 2026 18:41
Add test/blackbox-tests/test-cases/bin-pform/ with focused tests for
the %{bin:NAME} pform.

New tests:

- cram-path.t            %{bin:...} in cram (deps ...)
- env-binaries.t         %{bin:...} for (env (binaries ...)) entries
- include-deps.t         %{bin:...} inside (include ...) deps
- inline-tests.t         %{bin:...} in (inline_tests (deps ...))
- multiple-bins.t        multiple %{bin:...} deps in a single rule
- public-name.t          %{bin:...} expansion for (public_name)
- run-action.t           %{bin:...} in (run ...) and PATH visibility
- run-literal-vs-pform.t (run NAME) vs (run %{bin:NAME}) record
                         different deps (build artifact vs install
                         staging)
- system.t               %{bin:...} for a system binary on PATH
- test-stanza.t          %{bin:...} in a test stanza
- missing-bin.t          %{bin:...} and (run LITERAL) where the name
                         doesn't resolve

Plus a cross-compilation analog of lib-pform-context-expansion-gh9199.t
at custom-cross-compilation/bin-pform-context-expansion.t.

Renamed:

- bin-eager-deps.t          -> bin-pform/lazy-failure.t
- adversarial-binary-name.t -> bin-pform/colon-in-name.t
- build-percent-form-bin.t  -> bin-pform/cli-build.t

Split missing-lib-bin-pform-errors-gh1541.t: bin parts moved into
bin-pform/missing-bin.t, lib parts stay in
missing-lib-pform-errors-gh1541.t.

setup-script.sh: add env_added helper.

Signed-off-by: Ali Caglayan <[email protected]>
@Alizter
Alizter force-pushed the push-vxpoqsvypvsz branch from c6c0a9d to e3e3a21 Compare May 10, 2026 18:48
@Alizter
Alizter marked this pull request as ready for review May 10, 2026 18:49
@Alizter
Alizter requested a review from rgrinberg May 10, 2026 18:49
@Alizter
Alizter merged commit 3a63941 into ocaml:main May 10, 2026
29 checks passed
@Alizter
Alizter deleted the push-vxpoqsvypvsz branch May 10, 2026 20:48
Alizter added a commit that referenced this pull request May 21, 2026
Resolve `%{bin:...}` to the build artifact path (`Original_path`)
instead of the install staging area. When `%{bin:...}` appears in `(deps
...)`, a bin-layout directory is created under
`_build/install/<context>/.binaries/<digest>/` with correctly-named
symlinks, and added to `PATH`.

The legacy staging paths (`_build/install/default/bin`, `lib`, etc.)
remain on the root env for now. They cannot be removed until `(deps
(package ...))` provides its own scoped layout (the install-layout PR
#14373), since actions using `(package ...)` deps still rely on the
staging area for `PATH` and `OCAMLPATH` visibility.

Env binaries (from `(env (binaries ...))`) are excluded from the
bin-layout since they already use `.bin/` on `PATH`.

`Dep_conf_eval.unnamed` and `Dep_conf_eval.named` now return a single
`Env.t Action_builder.t` whose evaluation both registers deps and
produces the env (previously a tuple with a separate `unit
Action_builder.t` for deps registration). Build-tracking-only callers
(`lib_flags`, `simple_rules`) discard the env via
`Action_builder.ignore`.

`(include FILE)` inside `(deps ...)` propagates the recursive call's
`bin_env` via a new `Include_result` variant on `dep_evaluation_result`;
`named_paths_builder` folds the include `bin_env`s into the final
`bin_env` via `Env_path.extend_env_concat_path`. Without this, the
action's `PATH` would not get a bin-layout dir for include-d bin pforms.

The change is not gated by lang version: #3324 affects every lang
version, so gating would leave the bug unfixed for pre-3.24 projects.
The user-visible realignments are confined to in-`_build` paths and the
migration cost is small enough to not warrant a per-project opt-in.

- Fixes #3324
- Depends on #14430 (merged)
- Depends on #14431 (merged)
- [x] changelog
- [x] documentation

## Known limitations (deferred to follow-up)

- dune's sandbox does not relocate the `PATH` environment variable. The
bin-layout dir on `PATH` points at the un-sandboxed `_build/`. This
works locally because absolute paths are still readable from inside the
sandbox, but would break under remote action execution. Tracked by
`test/blackbox-tests/test-cases/bin-pform/sandbox.t`.
- `Bin_layout.Key.reverse_table` grows unboundedly in long-running
`--watch` sessions (one entry per unique sorted bin set). Pattern
inherited from `Ppx_driver.Key`. Bounded by the number of distinct bin
sets the workspace evaluates; unlikely to be a real problem.
@Alizter Alizter added this to the 3.24.0 milestone Jul 8, 2026
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.

2 participants