-
Notifications
You must be signed in to change notification settings - Fork 413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
track opam file metadata in dune-project and rewrite opam files #2017
Conversation
Re feedback on the approach, I wonder if any thought has been given to the related problem of how to keep this metadata in sync with changes made to the opam files in the opam-repository? For example, it has happened that missing dependency version constraints were noticed and added directly to opam-repo, and then when I made a new release the added constraint was lost. Other than manually checking each package's opam file in the repo before each release, I don't know of a work flow to preserve such changes. |
@jjb that's a really good question, and one I've also observed but not thought of a solution to yet. It's not quite clear to me whose responsibility (opam tooling vs dune tooling) it should be. One solution is to put it in the forthcoming duniverse/dune-get tool (https://github.com/avsm/duniverse) which acts as a bridge between both tools. Your usecase is now on my list as something that needs a solution. |
Woops, I did indeed, sorry! Although if it subliminally encourages you to return to OCaml, then this PR has done its job well :-) |
Could there be a way to indicate the libraries that a package provides as well? If dune project could set opam ‘constraints’ for a package, maybe there could be a soft way to have The common confusion for beginners is the package->library hierarchy and especially the naming quirks. ‘Admitting’ and protocoling the hierarchy could remove most of the friction. |
dune.opam
Outdated
@@ -11,7 +11,6 @@ depends: [ | |||
"base-threads" | |||
] | |||
build: [ | |||
# opam 2 sets OPAM_SWITCH_PREFIX, so we don't need a hardcoded path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this comment removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm was this removed due to the rewriting of the opam file removing comments. We should test that specifically to make sure comments are preserved
@jonludlam I've cleaned up the PR and made the opam file diffing work when an extension is enabled in the dune-project file: One last thing that I'd like to see before the PR is merged is the removal of all pp/sexp functions introduced in favor of |
d9f721e
to
73d314d
Compare
I've changed the status of this PR to be ready for review. One thing that I'd like a second opinion on is the name of this option in the dune-project file. Currently, it's |
73d314d
to
1578721
Compare
@jonludlam I got rid of blang_decode. I'm not sure why it was split this way, but it doesn't seem necessary anymore. |
@rgrinberg wrote:
Why do we need this at all? Just the presence of the |
Yeah, I think that's acceptable as well. This would be a breaking change technically however. At least for people who have used this opam field before it did anything. |
@rgrinberg Thanks very much! A few comments - I'm still leaning in the direction of executing this on I've got some improvements to the docs generation that depends on this, but I'll make that in a separate PR when this is merged. |
Then I suppose there's no need to choose. We could make it a dependency of both aliases.
Perhaps we should not do any correction if any comments are encountered? I don't think we can merge the code in its current state if it's going to drop user comments. |
There is a 'format preserving printer' in v2.0.0 of opam-file-format which attempts to preserve comments - dune currently has 2.0.0~beta which predates it. Let me try upgrading that and seeing if we can use that to fix the opam comment issue. |
56d5d3b
to
9ca9ed0
Compare
That seems to do the trick. Just need to enable the rewriting on existence of (opam) now and hook it up to the runtest target as well as install. |
9ca9ed0
to
44877ab
Compare
@rauanmayemir I'm still thinking about your comment about merging libraries. It's fairly intertwined with opam's "special" status in dune as the unit of |
@jonludlam phew! That would have been quite the blocker for automated rewriting of opam files otherwise. |
(>= uri 1.9.0) | ||
(< uri 2.0.0) | ||
(< fieldslib v0.12) | ||
(< fieldslib v0.12))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a duplicate - needs to be > something?
Just had a chat with @avsm - as it stands this PR does nothing with the constraints in dune-project, let's fix that so that the constraints are fixed in the opam files before we merge this. |
To make this feature more useful, we should consider adding the following checks:
This last suggestion is a bit unrelated, but i've been meaning to bring it up before: Currently, dune supports tests that don't belong to any package. That seems like a bit of a hidden pitfall to me because opam is executing the test suites per package. This results in the same tests being run multiple times. I'm wondering if we should warn users about such dangling tests, if this is desired, we can have them mark such tests explicitly: |
All three of those suggestions seem like excellent ideas. I wonder if it's better to merge this PR and then do them separately, since they cover some semantic changes to dune files. |
One second, where is the doc? :) We don't need to describe everything in detail, but the feature should at least be mentioned in the |
I would like to squash all the commits as well, as the history isn't making much sense. |
2ebeff3
to
c65a332
Compare
I will add some brief docs and merge as this feature isn't complete yet. @avsm we can merge this PR now, but I'd caution us against releasing features piecemeal. The issue is that it puts a versioning burden down the line. For example, if we add a |
c65a332
to
c48248a
Compare
I've jotted down some documentation in a new opam section. I think we need such a section because there's quite a few opam specific things we can document. The release workflow with dune-release is one glaring example of something that isn't so easy to lookup. An alternative layout would be for this information to live in the dune project section instead, and the opam section can simply link to the appropriate dune-project section. |
Having a dedicated opam section in the manual seems good. Though, we should link it from the BTW, in the past, people have asked for a way to declare packages without writing
Then someone who is not targetting opam would simply omit the |
I was about to comment on this. Thank you @diml for bringing this up. It would be great to have a way to declare a package with dune without mentioning opam specifically as with esy we might not have an opam package in the first place (I think it might be confusing for novice esy users). I'd also suggest not to include the cascading behaviour for |
The I also think the |
c48248a
to
5b54c8d
Compare
@avsm what do you think? Having statically evaluated variables would indeed solve this problem and other similar ones. The |
I'm fine with the simpler non-cascading behaviour to start with, even if it's more verbose. There simply isn't that much overlap at the moment since we only have the opam backend. |
Thanks for the squash commit @rgrinberg -- I think it also needs a |
@avsm I don't think we want to generate esy metadata out of dune files, instead we can support dune-project files in esy directly. I'm mainly interested in not having Ideally though with esy I'd like not to duplicate package name in multiple places (being it |
Sounds good. Do you have an example of a dune-managed package that doesn't have a corresponding opam package, anywhere? So far it seems that all dune packages do map to opam packages. (I'm primarily aware that we don't have any non-opam tests at the moment, so some concrete example of using the non-opam package would be useful so we can ensure we do the right thing) |
Yes! Having |
Got it -- so it's for the very important getting-started usecase, but nothing else more complex that we're missing. It will be nice to have a dune project description with just the |
We could make it such that if you don't specify the package name it inherits the top-level name (and also ensure that no two packages have the same name)
Implicitly names that package 'dune'. We could also change the check for a .opam file to additionally check for a (package) stanza in dune-project with the correct name - does that sound right? |
Thanks, will do so.
Seems good to me. I will merge this PR as is, that should make it easier for all of us to contribute. The agenda:
@jonludlam Currently, the correction rules do no work if the opam file doesn't exist. I think dune should promote the opam file it assembled from the dune-project file. |
5b54c8d
to
da5c978
Compare
We add metadata that can be used to used to partially specify opam files. Common fields such as depends, conflicts, authors, are all handled. Dune will now automatically suggest corrections to the existing opam files based on this metadata in the dune files Co-authored-by: Jon Ludlam <jon@recoil.org> Signed-off-by: Anil Madhavapeddy <anil@recoil.org> Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
da5c978
to
ca0f643
Compare
CHANGES: - Restricted the set of variables available for expansion in the destination filename of `install` stanza to simplify implementation and avoid dependency cycles. (ocaml/dune#2073, @aalekseyev, @diml) - [menhir] call menhir from context root build_dir (ocaml/dune#2067, @ejgallego, review by @diml, @rgrinberg) - [coq] Add `coq.pp` stanza to help with pre-processing of grammar files (ocaml/dune#2054, @ejgallego, review by @rgrinberg) - Add a new more generic form for the *promote* mode: `(promote (until-clean) (into <dir>))` (ocaml/dune#2068, @diml) - Allow to promote only a subset of the targets via `(promote (only <pred>))`. For instance: `(promote (only *.mli))` (ocaml/dune#2068, @diml) - Improve the behavior when a strict subset of the targets of a rule is already in the source tree for projects using the dune language < 1.10 (ocaml/dune#2068, fixes ocaml/dune#2061, @diml) - With lang dune >= 1.10, rules in standard mode are no longer allowed to produce targets that are present in the source tree. This has been a warning for long enough (ocaml/dune#2068, @diml) - Allow %{...} variables in pps flags (ocaml/dune#2076, @mlasson review by @diml and @aalekseyev). - Add a 'cookies' option to ppx_rewriter/deriver flags in library stanzas. This allow to specify cookie requests from variables expanded at each invocation of the preprocessor. (ocaml/dune#2106, @mlasson @diml) - Add more opam metadata and use it to generate `.opam` files. In particular, a `package` field has been added to specify package specific information. (ocaml/dune#2017, ocaml/dune#2091, @avsm, @jonludlam, @rgrinberg) - Clean up the special support for `findlib.dynload`. Before, Dune would simply match on the library name. Now, we only match on the findlib package name when the library doesn't come from Dune. Someone writing a library called `findlib.dynload` with Dune would have to add `(special_builtin_support findlib_dynload)` to trigger the special behavior. (ocaml/dune#2115, @diml) - Install the `future_syntax` preprocessor as `ocaml-syntax-shims.exe` (ocaml/dune#2125, @rgrinberg) - Hide full command on errors and warnings in development and show them in CI. (detected using the `CI` environment variable). Commands for which the invocation might be omitted must output an error prefixed with `File `. Add an `--always-show-command-line` option to disable this behavior and always show the full command. (ocaml/dune#2120, fixes ocaml/dune#1733, @rgrinberg) - In `dune-workspace` files, add the ability to choose the host context and to create duplicates of the default context with different settings. (ocaml/dune#2098, @TheLortex, review by @diml, @rgrinberg and @aalekseyev) - Add support for hg in `dune subst` (ocaml/dune#2135, @diml) - Don't build documentation for implementations of virtual libraries (ocaml/dune#2141, fixes ocaml/dune#2138, @jonludlam) - Fix generation of the `-pp` flag in .merlin (ocaml/dune#2142, @rgrinberg) - Make `dune subst` add a `(version ...)` field to the `dune-project` file (ocaml/dune#2148, @diml) - Add the `%{os_type}` variable, which is a short-hand for `%{ocaml-config:os_type}` (ocaml/dune#1764, @diml) - Allow `enabled_if` fields in `library` stanzas, restricted to the `%{os_type}`, `%{model}`, `%{architecture}`, `%{system}` variables (ocaml/dune#1764, ocaml/dune#2164 @diml, @rgrinberg) - Fix `chdir` on external and source paths. Dune will also fail gracefully if the external or source path does not exist (ocaml/dune#2165, fixes ocaml/dune#2158, @rgrinberg) - Support the `.cc` extension fro C++ sources (ocaml/dune#2195, fixes ocaml/dune#83, @rgrinberg) - Run `ocamlformat` relative to the context root. This improves the locations of errors. (ocaml/dune#2196, fixes ocaml/dune#1370, @rgrinberg) - Fix detection of `README`, `LICENSE`, `CHANGE`, and `HISTORY` files. These would be undetected whenever the project was nested in another workspace. (ocaml/dune#2194, @rgrinberg) - Fix generation of `.merlin` whenever there's more than one stanza with the same ppx preprocessing specification (ocaml/dune#2209 ,fixes ocaml/dune#2206, @rgrinberg) - Fix generation of `.meriln` in the presence of the `copy_files` stanza and preprocessing specifications of other stanazs. (ocaml/dune#2211, fixes ocaml/dune#2206, @rgrinberg)
CHANGES: - Restricted the set of variables available for expansion in the destination filename of `install` stanza to simplify implementation and avoid dependency cycles. (ocaml/dune#2073, @aalekseyev, @diml) - [menhir] call menhir from context root build_dir (ocaml/dune#2067, @ejgallego, review by @diml, @rgrinberg) - [coq] Add `coq.pp` stanza to help with pre-processing of grammar files (ocaml/dune#2054, @ejgallego, review by @rgrinberg) - Add a new more generic form for the *promote* mode: `(promote (until-clean) (into <dir>))` (ocaml/dune#2068, @diml) - Allow to promote only a subset of the targets via `(promote (only <pred>))`. For instance: `(promote (only *.mli))` (ocaml/dune#2068, @diml) - Improve the behavior when a strict subset of the targets of a rule is already in the source tree for projects using the dune language < 1.10 (ocaml/dune#2068, fixes ocaml/dune#2061, @diml) - With lang dune >= 1.10, rules in standard mode are no longer allowed to produce targets that are present in the source tree. This has been a warning for long enough (ocaml/dune#2068, @diml) - Allow %{...} variables in pps flags (ocaml/dune#2076, @mlasson review by @diml and @aalekseyev). - Add a 'cookies' option to ppx_rewriter/deriver flags in library stanzas. This allow to specify cookie requests from variables expanded at each invocation of the preprocessor. (ocaml/dune#2106, @mlasson @diml) - Add more opam metadata and use it to generate `.opam` files. In particular, a `package` field has been added to specify package specific information. (ocaml/dune#2017, ocaml/dune#2091, @avsm, @jonludlam, @rgrinberg) - Clean up the special support for `findlib.dynload`. Before, Dune would simply match on the library name. Now, we only match on the findlib package name when the library doesn't come from Dune. Someone writing a library called `findlib.dynload` with Dune would have to add `(special_builtin_support findlib_dynload)` to trigger the special behavior. (ocaml/dune#2115, @diml) - Install the `future_syntax` preprocessor as `ocaml-syntax-shims.exe` (ocaml/dune#2125, @rgrinberg) - Hide full command on errors and warnings in development and show them in CI. (detected using the `CI` environment variable). Commands for which the invocation might be omitted must output an error prefixed with `File `. Add an `--always-show-command-line` option to disable this behavior and always show the full command. (ocaml/dune#2120, fixes ocaml/dune#1733, @rgrinberg) - In `dune-workspace` files, add the ability to choose the host context and to create duplicates of the default context with different settings. (ocaml/dune#2098, @TheLortex, review by @diml, @rgrinberg and @aalekseyev) - Add support for hg in `dune subst` (ocaml/dune#2135, @diml) - Don't build documentation for implementations of virtual libraries (ocaml/dune#2141, fixes ocaml/dune#2138, @jonludlam) - Fix generation of the `-pp` flag in .merlin (ocaml/dune#2142, @rgrinberg) - Make `dune subst` add a `(version ...)` field to the `dune-project` file (ocaml/dune#2148, @diml) - Add the `%{os_type}` variable, which is a short-hand for `%{ocaml-config:os_type}` (ocaml/dune#1764, @diml) - Allow `enabled_if` fields in `library` stanzas, restricted to the `%{os_type}`, `%{model}`, `%{architecture}`, `%{system}` variables (ocaml/dune#1764, ocaml/dune#2164 @diml, @rgrinberg) - Fix `chdir` on external and source paths. Dune will also fail gracefully if the external or source path does not exist (ocaml/dune#2165, fixes ocaml/dune#2158, @rgrinberg) - Support the `.cc` extension fro C++ sources (ocaml/dune#2195, fixes ocaml/dune#83, @rgrinberg) - Run `ocamlformat` relative to the context root. This improves the locations of errors. (ocaml/dune#2196, fixes ocaml/dune#1370, @rgrinberg) - Fix detection of `README`, `LICENSE`, `CHANGE`, and `HISTORY` files. These would be undetected whenever the project was nested in another workspace. (ocaml/dune#2194, @rgrinberg) - Fix generation of `.merlin` whenever there's more than one stanza with the same ppx preprocessing specification (ocaml/dune#2209 ,fixes ocaml/dune#2206, @rgrinberg) - Fix generation of `.merlin` in the presence of the `copy_files` stanza and preprocessing specifications of other stanazs. (ocaml/dune#2211, fixes ocaml/dune#2206, @rgrinberg) - Run `refmt` from the context's root directory. This improves error messages in case of syntax errors. (ocaml/dune#2223, @rgrinberg) - In .merlin files, don't pass `-dump-ast` to the `future_syntax` preprocessor. Merlin doesn't seem to like it when binary AST is generated by a `-pp` preprocessor. (ocaml/dune#2236, @aalekseyev) - `dune install` will verify that all files mentioned in all .install files exist before trying to install anything. This prevents partial installation of packages (ocaml/dune#2230, @rgrinberg)
This adds support for recording some common metadata in the
dune-project
file that can be used for the purpose of generating packages descriptions. Initially, common metadata is stored in the toplevel dune-project that can be shared between package managers, and opam-specific metadata is stored within anopam
field. This permits extension for direct support of other package managers in the future.As a reward for putting this metadata in dune-project, dune can now rewrite
opam
files to keep the metadata recorded in dune-project in sync with all the project files. Updating the metadata in dune-project will result inopam.corrected
files being written and normal dune promotion working. The current logic aims to leave opam files untouched for fields which are not specified in the dune-project file, and only rewrite ones which are specifically overridden there.An example dune-project file with the metadata is here:
It may be useful to lift the a constraints field up to the toplevel for some packages such as
ocaml
, so that a future PR can use that metadata to generate CI test files automatically. We can extract that from the opam-specific metadata at present though, and defer that to a future PR.(this branch is current a WIP, opening this to get more feedback on the approach while hacking with @jonludlam on it)
related to #1498