Skip to content
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

Merged
merged 25 commits into from
Oct 17, 2023

Conversation

EmileTrotignon
Copy link
Contributor

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.

@Alizter
Copy link
Collaborator

Alizter commented Mar 11, 2023

Can you setup a cram test showing the feature? It should be possible to mock a browser for xdg-open in the cram test.

@EmileTrotignon
Copy link
Contributor Author

@Alizter I have not managed to mock a browser for xdg-open, so I justed mock xdg-open itself.

Copy link
Collaborator

@Alizter Alizter left a 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
Copy link
Collaborator

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)
Copy link
Collaborator

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.

Copy link
Contributor Author

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 ?

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
Copy link
Member

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

Copy link
Contributor Author

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
Copy link
Member

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?

Copy link
Contributor Author

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) =
Copy link
Member

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?

Copy link
Contributor Author

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.

@EmileTrotignon
Copy link
Contributor Author

I have finally tested this on a mac, and it works ! I still have to test it on windows.
I think mac and linux support is enough to get this out of draft though.

@EmileTrotignon EmileTrotignon marked this pull request as ready for review April 27, 2023 14:10
@Alizter Alizter requested review from rgrinberg and Alizter May 8, 2023 15:03
bin/build_cmd.ml Outdated
| None ->
Dune_console.print
[ Pp.text
"No browser could be found, you will have to open the \
Copy link
Collaborator

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
Copy link
Collaborator

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.

@EmileTrotignon
Copy link
Contributor Author

@Alizter The last commit takes your comment into account.

Copy link
Collaborator

@Alizter Alizter left a 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/'
Copy link
Collaborator

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 $@
Copy link
Collaborator

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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
documentation yourself.\n"
documentation yourself."

bin/ocaml/doc.ml Outdated
(Path.to_absolute_filename cmd)
args ~env:Env.initial
| None ->
Console.print
Copy link
Collaborator

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
Comment on lines 45 to 49
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

@EmileTrotignon
Copy link
Contributor Author

Hey @Alizter
I have pushed a commit that takes your comment into account

@Alizter
Copy link
Collaborator

Alizter commented Jul 18, 2023

@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")
Copy link
Collaborator

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)

Copy link
Contributor Author

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.

Copy link
Collaborator

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.

Copy link
Contributor Author

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".

Copy link
Collaborator

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 $@
Copy link
Collaborator

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

@emillon
Copy link
Collaborator

emillon commented Jul 20, 2023

@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)

@EmileTrotignon EmileTrotignon force-pushed the ocaml_doc_cmd branch 2 times, most recently from 860d879 to c637bbd Compare September 27, 2023 13:37
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
Copy link
Collaborator

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.

_
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]>
@rgrinberg rgrinberg linked an issue Oct 17, 2023 that may be closed by this pull request
@rgrinberg rgrinberg added this to the 3.11 milestone Oct 17, 2023
@rgrinberg rgrinberg changed the title Ocaml doc cmd feature: introduce [$ dune ocaml doc] Oct 17, 2023
@rgrinberg rgrinberg merged commit dcce29f into ocaml:main Oct 17, 2023
rgrinberg added a commit that referenced this pull request Oct 17, 2023
Signed-off-by: Rudi Grinberg <[email protected]>

<!-- ps-id: fc38372b-c49f-499a-be6f-86e6d2ec5761 -->
rgrinberg added a commit that referenced this pull request Oct 17, 2023
Signed-off-by: Rudi Grinberg <[email protected]>
emillon added a commit to emillon/opam-repository that referenced this pull request Nov 28, 2023
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dune doc
4 participants