Add root and rootexec sections to .install files - #6938
Conversation
prefix and prefixexec sections to .install files
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 |
|
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
left a comment
There was a problem hiding this comment.
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).
| Pp.singleton -| Pp.V.string -| pp_check_relative | ||
| -| pp_check_not_absolute | ||
| -| pp_check ~name:"rel-filename" | ||
| ~f:(fun s -> List.exists |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
|
Thanks for the review @rjbou. I believe I addressed all your comments other than the desire for more testing |
|
@rjbou at this point, would you consider this feature safe to assume for the next opam release (i.e., it would be reasonable for Do let me know if there is anything else you’d like me to do on the PR! |
prefix and prefixexec sections to .install filesroot and rootexec sections to .install files
54a7476 to
8ad3d2f
Compare
|
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. |
8ad3d2f to
93ee4a1
Compare
|
Added the new checks |
| Pp.warn ~pos | ||
| "Path '%s' begins with %s directory in 'root' field. \ | ||
| Use '%s' field instead." | ||
| str root root |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Do you have an example of a legitimate case ?
There was a problem hiding this comment.
Could we split it to a separate PR and think about it later?
opened #7039
| 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 |
There was a problem hiding this comment.
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, …)
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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.
| Pp.warn ~pos | ||
| "Path '%s' begins with %s directory in 'root' field. \ | ||
| Use '%s' field instead." | ||
| str root root |
There was a problem hiding this comment.
Do you have an example of a legitimate case ?
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 |
81eaad9 to
b0af601
Compare
kit-ty-kate
left a comment
There was a problem hiding this comment.
lgtm modulo the minor issue i raised above
b0af601 to
53ab983
Compare
53ab983 to
b6d7fee
Compare
…y paths target without using '..' Co-authored-by: Raja Boujbel <raja.boujbel@ocamlpro.com>
b6d7fee to
77536e3
Compare
|
Updated accordingly, and extracted #7039 specific tests in that PR |
77536e3 to
d3852d5
Compare
|
Thanks! |
Would close #6919