-
Notifications
You must be signed in to change notification settings - Fork 415
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
feature: introduce [$ dune ocaml doc] #7262
Conversation
Can you setup a cram test showing the feature? It should be possible to mock a browser for xdg-open in the cram test. |
@Alizter I have not managed to mock a browser for xdg-open, so I justed mock xdg-open itself. |
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.
I know this is still a draft, but some initial comments and suggestions.
boot/libs.ml
Outdated
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.
You probably want to revert this change. This happens automatically I think on macos.
@@ -0,0 +1,4 @@ | |||
(lang dune 3.6) |
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.
We can use lang 3.8 for this.
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.
3.8 gives me an error, I bumped to 3.7. Maybe a rebase will fix this ?
c3d7ee2
to
12d8932
Compare
bin/build_cmd.ml
Outdated
let open Option.O in | ||
let path = Env_path.path Env.initial in | ||
let* cmd_name, args = | ||
match Ocaml_config.system doc_ctx.ocaml_config with |
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.
We now have a Platform
module that you can use
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.
Oh that's very nice, thanks !
bin/build_cmd.ml
Outdated
absolute_toplevel_index_path | ||
]; | ||
|
||
let url = Printf.sprintf {|file://%s|} absolute_toplevel_index_path in |
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.
Any reason why you don't use normal strings?
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.
I guess I was worried of having to escape the //
, but that's not needed, I'll change that.
bin/build_cmd.ml
Outdated
let term = | ||
let+ common = Common.term in | ||
let config = Common.init common in | ||
let request (setup : Import.Main.build_system) = |
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.
Could you minimize request
to only what's required to build the docs and run everything else (printing, opening the docs) separately?
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.
No I do not think I reasonably could, because I need the setup
variable to compute the path were the index of the doc is located. I could escape it with a ref, but I don't think that would be better.
9ffb13c
to
00ade25
Compare
I have finally tested this on a mac, and it works ! I still have to test it on windows. |
bin/build_cmd.ml
Outdated
| None -> | ||
Dune_console.print | ||
[ Pp.text | ||
"No browser could be found, you will have to open the \ |
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.
Please use Console.print
instead.
bin/build_cmd.ml
Outdated
absolute_toplevel_index_path | ||
]; | ||
|
||
let url = Printf.sprintf "file://%s" absolute_toplevel_index_path in |
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.
String concatenation is perhaps simpler.
@Alizter The last commit takes your comment into account. |
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.
Just a few more comments.
This tests shows how to use the `dune ocaml doc` command to open the | ||
documentation index to a browser. | ||
$ export PATH=.:$PATH | ||
$ dune ocaml doc | sed -e 's/.*file:\/\/\([^ ]*\).*/\1/' |
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.
You can use a different deliminator rather than /
for sed so you don't have to escape so many characters. Something like # should work.
@@ -0,0 +1,2 @@ | |||
#!/bin/sh | |||
echo $@ |
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.
Adding something like
echo "Web browser received arg:"
might make the test easier to read. Same for the other one.
Better yet have a single copy and create symlinks so we don't have to duplicate.
bin/ocaml/doc.ml
Outdated
Console.print | ||
[ Pp.text | ||
"No browser could be found, you will have to open the \ | ||
documentation yourself.\n" |
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.
documentation yourself.\n" | |
documentation yourself." |
bin/ocaml/doc.ml
Outdated
(Path.to_absolute_filename cmd) | ||
args ~env:Env.initial | ||
| None -> | ||
Console.print |
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.
If this is meant to be a warning, then you can use User_warning.emit instead.
bin/ocaml/doc.ml
Outdated
match Platform.OS.value with | ||
| Platform.OS.Darwin -> Some ("open", [ "-u" ]) | ||
| Platform.OS.Linux -> Some ("xdg-open", []) | ||
| Platform.OS.Windows -> Some ("start", []) | ||
| Platform.OS.Other -> None |
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.
match Platform.OS.value with | |
| Platform.OS.Darwin -> Some ("open", [ "-u" ]) | |
| Platform.OS.Linux -> Some ("xdg-open", []) | |
| Platform.OS.Windows -> Some ("start", []) | |
| Platform.OS.Other -> None | |
match (Platform.OS.value : Platform.OS.t) with | |
| Darwin -> Some ("open", [ "-u" ]) | |
| Linux -> Some ("xdg-open", []) | |
| Windows -> Some ("start", []) | |
| Other -> None |
Hey @Alizter |
@emillon Could you take a look at this one? |
bin/ocaml/doc.ml
Outdated
let open Action_builder.O in | ||
let+ () = | ||
Alias.in_dir | ||
~name:(Dune_engine.Alias.Name.of_string "doc") |
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.
Can you add that as Dune_engine.Alias.doc
? (and change the of_string "doc" in that file to use it)
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 is already an Alias.doc variable, but it has the wrong type.
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 has been moved since then, you can find it in the Alias0
module.
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 done. It feels a bit weird though, because it is the only such string in the alias module, except for "default".
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.
You don't need to change the Alias
module. This identifier already exists, it is in Alias0
module https://github.com/ocaml/dune/blob/main/src/dune_rules/alias0.ml
@@ -0,0 +1,2 @@ | |||
#!/bin/sh | |||
echo $@ |
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 are a couple newlines to be fixed
@EmileTrotignon friendly ping. we're starting the 3.10 release process next week so it's a good opportunity to get this in, otherwise it won't be in before 3.11 (end of September probably) |
860d879
to
c637bbd
Compare
bin/ocaml/doc.ml
Outdated
@@ -44,7 +44,7 @@ let term = | |||
| Darwin -> Some ("open", [ "-u" ]) | |||
| Linux -> Some ("xdg-open", []) | |||
| Windows -> None | |||
| Other -> None | |||
| Other | FreeBSD | NetBSD | OpenBSD -> None |
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.
FTR BSD platforms can have open or xdg-open but it's probably not worth adding support for it in this PR.
5195917
to
4ba0aaf
Compare
Co-authored-by: Jon Ludlam <[email protected]>
Also windows, but should be tested.
Signed-off-by: Rudi Grinberg <[email protected]>
4ba0aaf
to
d53fbe6
Compare
Signed-off-by: Rudi Grinberg <[email protected]>
Signed-off-by: Rudi Grinberg <[email protected]>
Signed-off-by: Rudi Grinberg <[email protected]>
Signed-off-by: Rudi Grinberg <[email protected]>
Signed-off-by: Rudi Grinberg <[email protected]> <!-- ps-id: fc38372b-c49f-499a-be6f-86e6d2ec5761 -->
Signed-off-by: Rudi Grinberg <[email protected]>
CHANGES: - Introduce `$ dune ocaml doc` to open and browse documentation. (ocaml/dune#7262, fixes ocaml/dune#6831, @EmileTrotignon) - `dune cache trim` now accepts binary byte units: `KiB`, `MiB`, etc. (ocaml/dune#8618, @Alizter) - No longer force colors for OCaml 4.03 and 4.04 (ocaml/dune#8778, @rgrinberg) - Introduce new experimental odoc rules (ocaml/dune#8803, @jonjudlam) - Introduce the `runtest_alias` field to the `cram` stanza. This allows removing default `runtest` alias from tests. (@rgrinberg, ocaml/dune#8887) - Do not ignore libraries named `bigarray` when they are defined in conjunction with OCaml 5.0 (ocaml/dune#8902, fixes ocaml/dune#8901, @rgrinberg) - Dependencies in the copying sandbox are now writeable (ocaml/dune#8920, @rgrinberg) - Absent packages shouldn't prevent all rules from being loaded (ocaml/dune#8948, fixes ocaml/dune#8630, @rgrinberg) - Correctly determine the stanza of menhir modules when `(include_subdirs qualified)` is enabled (@rgrinberg, ocaml/dune#8949, fixes ocaml/dune#7610) - Display cache location in Dune log (ocaml/dune#8974, @nojb) - Re-run actions whenever `(expand_aliases_in_sandbox)` changes (ocaml/dune#8990, @rgrinberg) - Rules that only use internal dune actions (`write-file`, `echo`, etc.) can now be sandboxed. (ocaml/dune#9041, fixes ocaml/dune#8854, @rgrinberg) - Do not re-run rules when their location changes (ocaml/dune#9052, @rgrinberg) - Correctly ignore `bigarray` on recent version of OCaml (ocaml/dune#9076, @rgrinberg) - Add `test_` prefix to default test name in `dune init project` (ocaml/dune#9257, fixes ocaml/dune#9131, @9sako6) - Add `coqdoc_flags` field to `coq` field of `env` stanza allowing the setting of workspace-wide defaults for `coqdoc_flags`. (ocaml/dune#9280, fixes ocaml/dune#9139, @Alizter) - [coq rules] Be more tolerant when coqc --print-version / --config don't work properly, and fallback to a reasonable default. This fixes problems when building Coq projects with `(stdlib no)` and likely other cases. (ocaml/dune#8966, fix ocaml/dune#8958, @Alizter, reported by Lasse Blaauwbroek) - Dune will now run at a lower framerate of 15 fps rather than 60 when `INSIDE_EMACS`. (ocaml/dune#8812, @Alizter) - dune-build-info: when `version=""` is found in a `META` file, we now return `None` as a version string (ocaml/dune#9177, @emillon) - Dune can now be built and installed on Haiku (ocaml/dune#8795, fix ocaml/dune#8551, @Alizter) - Mark installed directories in `dune-package` files. This fixes `(package)` dependencies against packages that contain such directories. (ocaml/dune#8953, fixes ocaml/dune#8915, @emillon)
This is a feature from issue #6831
It adds a new command "dune ocaml doc" that builds the doc, and then open its index in a browser. If no browser can be found, it print the location of the index.
There are no tests for this feature, as I do not know of a way to automatically test it.
I also only tested this on my machine, and this does very different stuff on different systems, so I would like if someone with a windows or an osx machine would be able to test it.