Skip to content

WIP: Narrow which in pkg context#15381

Draft
punchagan wants to merge 7 commits into
ocaml:mainfrom
punchagan:narrow-pkg-which
Draft

WIP: Narrow which in pkg context#15381
punchagan wants to merge 7 commits into
ocaml:mainfrom
punchagan:narrow-pkg-which

Conversation

@punchagan

@punchagan punchagan commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Stacked on #15412 and #15413

In the Lock-kind contexts, %{bin:X} and %{bin-available:X} fall through to Pkg_rules.which via Context.which which runs Artifacts_and_deps.of_closure on all the lock-dir packages. The function adds a dependency on the cookie, which is a build artifact, of all the lock-dir packages. This means we add a dependency on building all the packages in the lock-dir to resolve these pforms, leading to one of the reasons for the in-and-out cycles as described here. #14736 added a test, which was extended in #15222, to document the behavior when expanding these pforms.

This PR narrows the closure of packages passed to Artifacts_and_deps.of_closure to the dependency closure of the package that owns the stanza's directory, when expanding these pforms. When there is no owning package, the previous behavior of using the whole lockdir closure is still retained.

Previously, all lock-dir packages' bin layouts were also added to PATH. This PR applies the same narrowing as the pforms. Only the bin layouts of the owning package's dependency closure are added to PATH. So, a stanza can run only binaries from the packages it depends on. If there's no owning package for a stanza, the old behavior is retained.

@punchagan punchagan force-pushed the narrow-pkg-which branch 5 times, most recently from 344e923 to e258dde Compare July 1, 2026 10:12
@punchagan punchagan requested a review from Alizter July 1, 2026 17:03
@punchagan punchagan force-pushed the narrow-pkg-which branch 2 times, most recently from 8aaa6fd to e186b0f Compare July 2, 2026 09:12
Extend the test as a precursor to fixing PATH to include only the
bin layouts of packages that the owning package of a stanza explicitly
depend on.

Signed-off-by: Puneeth Chaganti <punchagan@muse-amuse.in>
punchagan added 4 commits July 3, 2026 17:06
This commit extends the resolve-program-from-undeclared-pkg.t cram test
in preparation for narrowing of the lockdir packages on PATH based on
the dependency closure of a stanza's owning package.

This PR is similar to ocaml#15222

Signed-off-by: Puneeth Chaganti <punchagan@muse-amuse.in>
Signed-off-by: Puneeth Chaganti <punchagan@muse-amuse.in>
Signed-off-by: Puneeth Chaganti <punchagan@muse-amuse.in>
We only add the bin layouts of the packages in the dependencies closure
of a stanza to the env's PATH.

Signed-off-by: Puneeth Chaganti <punchagan@muse-amuse.in>
punchagan added 2 commits July 3, 2026 17:11
Signed-off-by: Puneeth Chaganti <punchagan@muse-amuse.in>
Signed-off-by: Puneeth Chaganti <punchagan@muse-amuse.in>
val which : Context_name.t -> (Filename.t -> Path.t option Memo.t) Staged.t

val which_for_packages
: ?packages:Package.Name.Set.t option

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is still a WIP, but this argument being optional just obscures the scope of the changes.

Alizter added a commit that referenced this pull request Jul 6, 2026
<!-- Thank you for contributing to dune!

 For general guidelines on contributing to dune, see
https://github.com/ocaml/dune/blob/main/CONTRIBUTING.md#developing-dune
-->

## Description
Extend the test as a precursor to fixing PATH to include only the bin
layouts of packages that the owning package of a stanza explicitly
depend on.

## Related Issue and Motivation
<!-- Why is this change required? What problem does it solve? -->
<!-- If it closes an open issue, link to the issue here. -->
<!-- Non-trivial contributions are expected to be preceded by an issue,
as
     per CONTRIBUTING.md. -->

This change is a preparatory improvement to the test for the changes in
#15381
Alizter added a commit that referenced this pull request Jul 6, 2026
## Description

This commit extends the resolve-program-from-undeclared-pkg.t cram test
in preparation for narrowing of the lockdir packages on PATH based on
the dependency closure of a stanza's owning package.

This PR is similar to #15222

## Related Issue and Motivation
<!-- Why is this change required? What problem does it solve? -->
<!-- If it closes an open issue, link to the issue here. -->
<!-- Non-trivial contributions are expected to be preceded by an issue,
as
     per CONTRIBUTING.md. -->

This is a preparatory change in the resolve-program test case for
narrowing of the lockdir package binaries available on PATH implemented
in #15381.
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