Skip to content

Add root and rootexec sections to .install files - #6938

Merged
kit-ty-kate merged 4 commits into
ocaml:masterfrom
WardBrian:feature/dot-install-prefix
Jul 15, 2026
Merged

Add root and rootexec sections to .install files#6938
kit-ty-kate merged 4 commits into
ocaml:masterfrom
WardBrian:feature/dot-install-prefix

Conversation

@WardBrian

@WardBrian WardBrian commented May 18, 2026

Copy link
Copy Markdown
Contributor

@WardBrian WardBrian changed the title Feature/dot install prefix Add prefix and prefixexec sections to .install files May 18, 2026
@dbuenzli

Copy link
Copy Markdown
Contributor

I'm currently unable to run the tests locally due to an issue that seems related to #5968

I recently got that aswell on a machine. It disappeared once I used the provided https://opam.ocaml.org/install.sh install script rather than download a binary and copy it to ~/.local/bin/opam. (I was in a hurry so did not try to understand but I suspect the install script does some bubblewrap magic).

@WardBrian

Copy link
Copy Markdown
Contributor Author

Using install.sh (and installing in /usr/local instead of /usr) is what eventually resolved my bwrap issue as a user, but not when running development versions it seems. Oddly enough, I seem to recall the tests running fine before when I was regularly running into #5968 as a user

@rjbou rjbou left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The PR itself looks good, I've put some comments on the code. It is missing a test where we see the new field (i realise that there is no test that checks all fields, it could be the moment to add, i can do it).

Comment thread src/core/opamFilename.mli Outdated
Comment thread src/format/opamFile.ml Outdated
Comment thread src/format/opamFile.ml Outdated
Comment thread src/format/opamFile.ml Outdated
Comment thread src/format/opamFile.ml Outdated
Comment thread src/format/opamFile.ml Outdated
Comment thread src/format/opamFile.ml Outdated
Comment thread src/format/opamFile.ml Outdated
Pp.singleton -| Pp.V.string -| pp_check_relative
-| pp_check_not_absolute
-| pp_check ~name:"rel-filename"
~f:(fun s -> List.exists

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The opam switch internal directory is only at the root of the switch prefix, there is nothing preventing users to have internal .opam-switch directories inside their packages file. It is possible to check the first element, but there is a need to handle the case where the filename begins with one or several ./././path (it is allowed)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is a conservative over-approximation. I believe the same is currently true for the might_escape check, since in theory a path like ./foo/bar/../bar should be fine, but I believe it will be prevented at the moment

The odds of someone having a legitimate use case for a .opam-switch path seem low enough that being conservative seems like it would be fine in this case

@WardBrian

Copy link
Copy Markdown
Contributor Author

Thanks for the review @rjbou. I believe I addressed all your comments other than the desire for more testing

@WardBrian

Copy link
Copy Markdown
Contributor Author

@rjbou at this point, would you consider this feature safe to assume for the next opam release (i.e., it would be reasonable for dune to assume its existence and change what it generates in .install files)?

Do let me know if there is anything else you’d like me to do on the PR!

@WardBrian WardBrian changed the title Add prefix and prefixexec sections to .install files Add root and rootexec sections to .install files Jun 18, 2026
@rjbou
rjbou force-pushed the feature/dot-install-prefix branch from 54a7476 to 8ad3d2f Compare July 10, 2026 19:07
@rjbou

rjbou commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Updated with the new tests. The main todo is to add prefix check for opam internals (other fields), and an update of the windows test, and it'll be ready.

@rjbou
rjbou force-pushed the feature/dot-install-prefix branch from 8ad3d2f to 93ee4a1 Compare July 13, 2026 10:23
@rjbou

rjbou commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Added the new checks

@kit-ty-kate kit-ty-kate left a comment

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.

the branch is a bit messy with all the fixup commits. I would suggest rebasing it with 3 commits (in order):

  • OpamFile.Install.fields refactoring
  • The addition of the root and rootexec fields
  • Additions to the reftests

Comment thread src/client/opamInitDefaults.ml Outdated
Comment thread src/format/opamFile.ml Outdated
Comment thread src/format/opamFile.ml Outdated
Comment on lines +3894 to +3897
Pp.warn ~pos
"Path '%s' begins with %s directory in 'root' field. \
Use '%s' field instead."
str root root

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.

I don't think it's worth adding a warning at this point and there are legitimate cases where using rootexec: ["file" {"share/blah"}] will trigger the warning. Could we split it to a separate PR and think about it later?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do you have an example of a legitimate case ?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could we split it to a separate PR and think about it later?

opened #7039

Comment thread tests/reftests/dot-install.test Outdated
Comment thread src/format/opamFile.ml Outdated
let paths = List.map OpamTypesBase.string_of_std_path paths in
(match OpamFilename.split ~sep:`Unspecified str with
| root::_::_ ->
if OpamStd.List.mem String.equal root paths then

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 check is not the right one. The name of the field and the name of the directory it points to can be different (e.g. the *exec fields, stublibs, toplevel, …)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We are not checking regarding the field name, but the root dir of the installation path (if given) versus all defined directories that will/would be created on the switch prefix given the .install file.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

cf #7039

Comment thread src/format/opamFile.ml Outdated
let paths = List.map OpamTypesBase.string_of_std_path paths in
(match OpamFilename.split ~sep:`Unspecified str with
| root::_::_ ->
if OpamStd.List.mem String.equal root paths then

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We are not checking regarding the field name, but the root dir of the installation path (if given) versus all defined directories that will/would be created on the switch prefix given the .install file.

Comment thread src/format/opamFile.ml Outdated
Comment on lines +3894 to +3897
Pp.warn ~pos
"Path '%s' begins with %s directory in 'root' field. \
Use '%s' field instead."
str root root

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do you have an example of a legitimate case ?

Comment thread src/client/opamInitDefaults.ml Outdated
@rjbou

rjbou commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

the branch is a bit messy with all the fixup commits.

It is intended, to highlight my changes to @WardBrian and reciprocally

@WardBrian

Copy link
Copy Markdown
Contributor Author

the branch is a bit messy with all the fixup commits.

It is intended, to highlight my changes to @WardBrian and reciprocally

This has definitely been helpful so far but at this point I’d be okay with you rebasing it and erasing this distinction

Comment thread src/format/opamFile.ml Outdated
Comment thread tests/reftests/dot-install-non-exe-fields.test Outdated
Comment thread tests/reftests/run.ml Outdated

@kit-ty-kate kit-ty-kate left a comment

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.

lgtm modulo the minor issue i raised above

@rjbou
rjbou force-pushed the feature/dot-install-prefix branch from b0af601 to 53ab983 Compare July 15, 2026 17:24
@kit-ty-kate
kit-ty-kate force-pushed the feature/dot-install-prefix branch from 53ab983 to b6d7fee Compare July 15, 2026 17:27
@rjbou
rjbou force-pushed the feature/dot-install-prefix branch from b6d7fee to 77536e3 Compare July 15, 2026 17:46
@rjbou

rjbou commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

Updated accordingly, and extracted #7039 specific tests in that PR

@kit-ty-kate
kit-ty-kate force-pushed the feature/dot-install-prefix branch from 77536e3 to d3852d5 Compare July 15, 2026 19:30
@kit-ty-kate

Copy link
Copy Markdown
Member

Thanks!

@kit-ty-kate
kit-ty-kate merged commit 8c142ef into ocaml:master Jul 15, 2026
40 of 41 checks passed
@WardBrian
WardBrian deleted the feature/dot-install-prefix branch July 23, 2026 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a prefix field to .install files

4 participants