-
Notifications
You must be signed in to change notification settings - Fork 71
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
WIP: Fix opam-repo commit selection for lint-fmt #403
WIP: Fix opam-repo commit selection for lint-fmt #403
Conversation
Signed-off-by: Nathan Rebours <nathan.p.rebours@gmail.com>
Signed-off-by: Nathan Rebours <nathan.p.rebours@gmail.com>
This happened again: https://ci.ocamllabs.io/github/ocamllabs/opam-monorepo/commit/565c2a8742680a0d571d7a305e3c6f7d8b5fd8cc/variant/(lint-fmt) This needs to be refreshed and reviewed so we can move on with this. CC @maiste @tmcgilchrist. We had a discussion recently about having to declare the ocamlformat dependency in the metadata. If we decide to go down that road that fix might not be needed anymore so please let me know! |
Hi @NathanReb, Another thing, maybe it would be worth going more profound in the code structure to find some |
Fly-by, but opam 2.2 adds a tools predicate (dev has other meanings, and isn’t appropriate for use for this IIRC) but the we may be able to get more opinionated about that with 2.2 |
(The opam feature is ocaml/opam#5016) |
This is a helpful feature to have in |
Not necessarily - the predicate is compatible with older versions (predicates not recognised by older opams will just be assumed to be |
That sounds like the better option to me as well, this information does belong in the opam file as that's what you'll ultimately use to install those tools. Additionally that could provide useful information on dev tools usage in opam! At the moment you basically have to read @maiste do you have any specific plans to move forward on this? |
@dra27 I was recently surprised to get errors for undefined variables though. We had to use |
I personally always have mines at the root and I have never worked on a project that was hiding it somewhere else so I don't feel a particular need for that specific feature but you might no more than I do about this. Ultimately it's not my decision to make. I do care about a fix for the opam-repo selection bug though as it has prevented me from upgrading ocamlformat several times now! I'd be more than willing to add it to my opam and test the suggested feature once someone's started working on it if that can help! |
I plan to work on it next week as I still have some work to finish this week on my TODO list. |
As the linting situation has been merged in #472 (which was a rebase and an upgrade from this one), I close this draft PR. Feel free to reopen in any case. |
Fixes #398
This is still work in progress but a bit of feedback on this would be greatly appreciated!
CC@emillon who was my pair programming partner on this and who wrote the nice summary below:
Ways to improve this / future work
Making it correct
At the moment we just pick the first solution and hope that it will be compatible with the worker that is selected for the lint-fmt job (first in the list of solutions for the main build), but that is not guaranteed.
We can return the whole selection (where we return just a commit), and use that instead of the first compatible worker. That scheme is also used for other kinds of lint builds (opam and doc) so they would need to be adjusted. This seems to be the best solution but requires more work.
Some older versions of ocamlformat could have a different behavior depending on the version of ocaml they have been compiled with. This is not the case with recent versions of ocaml and ocamlformat, but if we want to support that we would need to select the worker with most recent compiler (from the list of compatible ones).
The candidate implementation calls the solver for all platforms and only returns the first one. This is slow (see below) but in the case we keep the "use first worker for lint builds" strategy, it is possible just call the solver once by first. No guarantee that it always works.
Making it faster
If the solution needs to call the solver on all platform and just pick one, it is possible to change the solver API so that rather than querying for solves on all platforms, waiting for all the results and using
List.hd
, we instead pass a flag asking for early return of the first solution (akin to usingLIMIT 1
in SQL rather thanList.hd
).Finally, if the function that maps ocamlformat+dune version to
opam-repository
commit is too expensive to compute (it's at least an extra solver call in the analysis phase, possibly more), we can cache it separately by altering the pipeline a bit:In this new pipeline, analyse returns (for the formatting part) only the parsed ocamlformat and dune constraints instead of the
opam-repository
commit to use. And a new node (analyse-fmt
) matches these constraints against the current state ofopam-repository
. This part is computed and cached separately.Code TODOs
ocaml < 4.08
in formatting jobs. We could probably drop this.