-
Notifications
You must be signed in to change notification settings - Fork 454
Add (format-dune-file) action
#11166
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
Conversation
src/dune_rules/stanzas/rule_conf.ml
Outdated
| ; "aliases", Field | ||
| ; "alias", Field | ||
| ; "enabled_if", Field | ||
| ; "format-dune-file", Field |
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.
Shouldn't it be this?
| ; "format-dune-file", Field | |
| ; "format-dune-file", Since ((3,18), Field) |
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.
Thanks, fixed.
rgrinberg
left a comment
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.
There's already a format action defined in Format_rules. You can just use that instead of extending the engine.
Thanks, I had missed this. This is now done: a7abf53. For simplicity, the action now has the form |
| Error: unclosed parenthesis at end of input | ||
| 1 | ||
|
|
||
| Using the built-in action. |
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.
Maybe add a test demonstraating how the action fails when given an invalid dune file?
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.
Done, thanks.
|
Would be appreciated if the update to dune lang 3.18 was done in a separate PR |
Good idea, done in #11175 |
a7abf53 to
6978294
Compare
|
Thanks for the review @rgrinberg. I think all issues have been addressed. |
Signed-off-by: Nicolás Ojeda Bär <[email protected]>
Signed-off-by: Nicolás Ojeda Bär <[email protected]>
Signed-off-by: Nicolás Ojeda Bär <[email protected]>
Signed-off-by: Nicolás Ojeda Bär <[email protected]>
Signed-off-by: Nicolás Ojeda Bär <[email protected]>
Signed-off-by: Nicolás Ojeda Bär <[email protected]>
Signed-off-by: Nicolás Ojeda Bär <[email protected]>
73fb0b2 to
9317471
Compare
|
Planning to merge soon if the CI passes. Yell if you object! |
Signed-off-by: Nicolás Ojeda Bär <[email protected]> Signed-off-by: Chris Armstrong <[email protected]>
CHANGES: ### Fixed - Support HaikuOS: don't call `execve` since it's not allowed if other pthreads have been created. The fact that Haiku can't call `execve` from other threads than the principal thread of a process (a team in haiku jargon), is a discrepancy to POSIX and hence there is a [bug about it](https://dev.haiku-os.org/ticket/18665). (@Sylvain78, ocaml/dune#10953) - Fix flag ordering in generated Merlin configurations (ocaml/dune#11503, @voodoos, fixes ocaml/merlin#1900, reported by @vouillon) ### Added - Add `(format-dune-file <src> <dst>)` action. It provides a replacement to `dune format-dune-file` command. (ocaml/dune#11166, @nojb) - Allow the `--prefix` flag when configuring dune with `ocaml configure.ml`. This allows to set the prefix just like `$ dune install --prefix`. (ocaml/dune#11172, @rgrinberg) - Allow arguments starting with `+` in preprocessing definitions (starting with `(lang dune 3.18)`). (@amonteiro, ocaml/dune#11234) - Support for opam `(maintenance_intent ...)` in dune-project (ocaml/dune#11274, @art-w) - Validate opam `maintenance_intent` (ocaml/dune#11308, @art-w) - Support `not` in package dependencies constraints (ocaml/dune#11404, @art-w, reported by @hannesm) ### Changed - Warn when failing to discover root due to reads failing. The previous behavior was to abort. (@KoviRobi, ocaml/dune#11173) - Use shorter path for inline-tests artifacts. (@hhugo, ocaml/dune#11307) - Allow dash in `dune init` project name (ocaml/dune#11402, @art-w, reported by @saroupille) - On Windows, under heavy load, file delete operations can sometimes fail due to AV programs, etc. Guard against it by retrying the operation up to 30x with a 1s waiting gap (ocaml/dune#11437, fixes ocaml/dune#11425, @MSoegtropIMC) - Cache: we now only store the executable permission bit for files (ocaml/dune#11541, fixes ocaml/dune#11533, @ElectreAAS) - Display negative error codes on Windows in hex which is the more customary way to display `NTSTATUS` codes (ocaml/dune#11504, @MisterDA)
CHANGES: ### Fixed - Support HaikuOS: don't call `execve` since it's not allowed if other pthreads have been created. The fact that Haiku can't call `execve` from other threads than the principal thread of a process (a team in haiku jargon), is a discrepancy to POSIX and hence there is a [bug about it](https://dev.haiku-os.org/ticket/18665). (@Sylvain78, ocaml/dune#10953) - Fix flag ordering in generated Merlin configurations (ocaml/dune#11503, @voodoos, fixes ocaml/merlin#1900, reported by @vouillon) ### Added - Add `(format-dune-file <src> <dst>)` action. It provides a replacement to `dune format-dune-file` command. (ocaml/dune#11166, @nojb) - Allow the `--prefix` flag when configuring dune with `ocaml configure.ml`. This allows to set the prefix just like `$ dune install --prefix`. (ocaml/dune#11172, @rgrinberg) - Allow arguments starting with `+` in preprocessing definitions (starting with `(lang dune 3.18)`). (@amonteiro, ocaml/dune#11234) - Support for opam `(maintenance_intent ...)` in dune-project (ocaml/dune#11274, @art-w) - Validate opam `maintenance_intent` (ocaml/dune#11308, @art-w) - Support `not` in package dependencies constraints (ocaml/dune#11404, @art-w, reported by @hannesm) ### Changed - Warn when failing to discover root due to reads failing. The previous behavior was to abort. (@KoviRobi, ocaml/dune#11173) - Use shorter path for inline-tests artifacts. (@hhugo, ocaml/dune#11307) - Allow dash in `dune init` project name (ocaml/dune#11402, @art-w, reported by @saroupille) - On Windows, under heavy load, file delete operations can sometimes fail due to AV programs, etc. Guard against it by retrying the operation up to 30x with a 1s waiting gap (ocaml/dune#11437, fixes ocaml/dune#11425, @MSoegtropIMC) - Cache: we now only store the executable permission bit for files (ocaml/dune#11541, fixes ocaml/dune#11533, @ElectreAAS) - Display negative error codes on Windows in hex which is the more customary way to display `NTSTATUS` codes (ocaml/dune#11504, @MisterDA)
|
Hi, I just discovered this new feature in the dune changelog for 3.18, sounds nice! I'm using This works well, so I am not sure which issue does it cause to call dune recursively from an action. At any rate, I am not able to directly translate this to the new construct, as I am using the format command in the mode where it reads from stdin and emit the fmt to stdout (in a pipi-stdout construct). Do you think the action could be extended to support this, or should I just leave this alone and not pay attention? Thanks! |
Even if it works today, there's no guarantee that this will continue to work in the future. In general, Dune is not really designed to be reentrant. For example, it is planned to modify
It would add a bit of complexity, so we will probably not do it unless there is a clear need for it. You should be able to use the new construct by introducing intermediate files in your Dune rules. If you can share the code somewhere, I can try to suggest some pointers. |
Do you mean for me to link you to code where I am using this? If so, there are some instances of this pattern I'm using in this repo: https://github.com/mbarbin/bopkit/blob/cfc30b189b4bb852ddd92bcc40178f03b2e24927/stdlib/pulse/dune#L14 (this is taken from this file) (rule
(target dune.inc)
(deps
(glob_files *.bop))
(alias runtest)
(mode promote)
(action
(with-stdout-to
%{target}
(pipe-stdout
(run %{bin:bopkit} fmt gen-dune "\%{bin:bopkit}" fmt file)
(run dune format-dune-file)))))I'm ok to try and fix the rules according to your guidance if you think that's best. Thanks for your help! |
Something along the following lines should do the trick:
Yes, the motivation to introduce the new action was to help people migrate away from calling |
|
Thanks I'll try the change with the intermediate raw file.
I should note here that I find it very useful for dune to export a command that can be used to auto-format dune files. I am using this in the dunolint project (see here). It would be nice if you could commit to having a command that could remain usable in the future for this. For my use case I'd be OK if that command is made a bit less user-friendly, and adds more parameter (such as the lang version). Alternatively, that'd work quite well for that project if the functionality is exposed from within an OCaml lib directly. I'm happy to make this into a discussion or separate issue if you'd like. |
Good to know. Our plan is not to get rid of this command, but to improve it, by having it read the Dune metadata and format according to the version of the Dune lang used by the project containing the Dune file being formatted (right now, |
I gave it a shot in this pr based on your suggestion of splitting the rule in 2. There was no issue, I just wanted to say thank you! There was a pre-existing "issue" with this repo, which is made visible again by this change (but unrelated) : the construct that I am changing is repeated many times, and thus I had to repeat the fix many times. I opened this discussion with a potential idea to improve, if you have other ideas, please let me know! Thanks! |
|
@mbarbin Thanks for the confirmation. Cheers! |
Context is #10892 (comment).
This exposes a user action
(format-dune-file file)which outputs the formatted contents offile(assumed to contain S-expressions) to standard output. It uses the version for the formatting specified by the current project.This action should be used instead of calling
dune format-dune-filefrom inside a user rule, which does not work well (calling Dune recursively is not really well supported).cc @maiste @Leonidas-from-XIV