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

odoc: sherlodoc integration #9772

Merged
merged 2 commits into from
Feb 8, 2024
Merged

Conversation

EmileTrotignon
Copy link
Contributor

@EmileTrotignon EmileTrotignon commented Jan 18, 2024

This changes the rules that build the doc to enable search using sherlodoc : https://github.com/art-w/sherlodoc/tree/jsoo
The version of sherlodoc that allows to do so is not released, this is why this is a draft PR for now. I will keep this message up to date regarding to correct version of sherlodoc to use.

There are rules both for @doc and @doc-new.

I have tests but they are not exhaustive. I do not know how to test what happens when sherlodoc is not installed, even though I tested it by hand.

Edit: sherlodoc has been released on opam, I am taking this out of draft.

@EmileTrotignon
Copy link
Contributor Author

I notice there is an issue with the tests. Sherlodoc can be present or absent, but when it is absent, a warning is printed when the doc is built. This a good thing for the user, but for the tests its quite terrible as the warning shows up in a lot of places, even when it does not on my switch that has sherlodoc. Should I add sherlodoc as a test deps to fix this ?

@emillon emillon added the odoc label Jan 19, 2024
@emillon
Copy link
Collaborator

emillon commented Jan 19, 2024

Sherlodoc can be present or absent, but when it is absent, a warning is printed when the doc is built. This a good thing for the user

I'm not sure about that. I would prefer if the availability of sherlodoc would just result in progressive enhancement. (if it's not installed, do the same as before; if it's installed, users get a new feature).

Should I add sherlodoc as a test deps to fix this ?

The way we deal with this in dune's test suite is by creating a fake sherlodoc binary. It can print its argument, emit fake JS if you like, etc. This will also isolate the test suite from the specific version of sherlodoc that's being used.
You can see how refmt is handled, for example.

Do you want remarks on the implementation itself or is it too early?

@EmileTrotignon
Copy link
Contributor Author

EmileTrotignon commented Jan 19, 2024

I'm not sure about that. I would prefer if the availability of sherlodoc would just result in progressive enhancement. (if it's not installed, do the same as before; if it's installed, users get a new feature).

I am just concerned that users would never know about sherlodoc if they are never told to install it.

The way we deal with this in dune's test suite is by creating a fake sherlodoc binary. It can print its argument, emit fake JS if you like, etc. This will also isolate the test suite from the specific version of sherlodoc that's being used.
You can see how refmt is handled, for example.

That makes sense. It does not give a way to hide the binary though (which is only useful if we keep the warning).

Do you want remarks on the implementation itself or is it too early?

Yes please !

src/dune_rules/sherlodoc.ml Outdated Show resolved Hide resolved
src/dune_rules/sherlodoc.ml Outdated Show resolved Hide resolved
test/blackbox-tests/test-cases/odoc/doc-browser.t/foo.ml Outdated Show resolved Hide resolved
src/dune_rules/sherlodoc.ml Outdated Show resolved Hide resolved
src/dune_rules/odoc_new.ml Outdated Show resolved Hide resolved
src/dune_rules/odoc.ml Outdated Show resolved Hide resolved
@emillon
Copy link
Collaborator

emillon commented Jan 19, 2024

I am just concerned that users would never know about sherlodoc if they are never told to install it.

Dune is not a communication channel, it's a build system :)

It does not give a way to hide the binary though (which is only useful if we keep the warning).

You can either make a dedicated test, or make the existing one more modular by making several workspaces in it. You can also remove or chmod the binary as part of your test.

Regarding detecting the binary and setting up rules conditionally on that, we'll have to discuss that with the other maintainers, since there's another feature that'll require that, but in the meantime you can use resolve_program_memo.

@EmileTrotignon
Copy link
Contributor Author

Dune is not a communication channel, it's a build system :)

I see what you mean. It's not only a communication issue, my opinion is that sherlodoc should be packaged with odoc, I tried this to alleviate this issue. It's not dune's concern though, I'll remove it.

You can either make a dedicated test, or make the existing one more modular by making several workspaces in it. You can also remove or chmod the binary as part of your test.

Even with multiple test, is there a way to prevent dune from finding something that is installed ? I don't want the "sherlodoc is absent" tests to only work if sherlodoc is not installed on the current switch.

Regarding detecting the binary and setting up rules conditionally on that, we'll have to discuss that with the other maintainers, since there's another feature that'll require that, but in the meantime you can use resolve_program_memo

Fine !

@emillon
Copy link
Collaborator

emillon commented Jan 19, 2024

Even with multiple test, is there a way to prevent dune from finding something that is installed ? I don't want the "sherlodoc is absent" tests to only work if sherlodoc is not installed on the current switch.

Ah yes it can be a bit tricky to isolate from the dev switch. We have a couple tests that do that, for example https://github.com/ocaml/dune/blob/3.13.0/test/blackbox-tests/test-cases/melange/missing-melc.t#L13-L18 (and then we set PATH=_path without refering to the existing $PATH).

src/dune_rules/odoc.ml Outdated Show resolved Hide resolved
src/dune_rules/odoc.ml Outdated Show resolved Hide resolved
@emillon
Copy link
Collaborator

emillon commented Jan 22, 2024

I think that the ~search_db business can be considerably simplified since it always evaluates to the same path. so we can make bits refer to that path and it will get built only if necessary. I'll try something in that direction.

@emillon
Copy link
Collaborator

emillon commented Jan 22, 2024

OK, I had a look and indeed I think we can simplify this a lot by not making search_db depend on the sherlodoc parts:

  • (you can revert "Refactoring of installation checks" since the rest assumes the old API)
  • store the location of the search db in a new field in odoc_artefact
  • at build time, you can set this to Sherlodoc.Path.db_dot_js ~dir:(Paths.html ctx target)
  • Sherlodoc.odoc_args only needs this path, it can determine whether sherlodoc is active
  • the rest of the rules have to set up which odocl files are attached to each target. I don't think you have to check if sherlodoc is present, you can set the rule unconditionally.

That should simplify considerably the work you have to do. Do you need help with that or do you want to have a go at it?

@EmileTrotignon
Copy link
Contributor Author

I looked at it for a while, I think I would appreciate help

@EmileTrotignon
Copy link
Contributor Author

I have pushed a commit that make the search global in @doc-new. The reasons have been discussed with jon, and they are that the intent behind doc-new is to provide docs for the devs of the current project : it includes private libraries and dependencies by default.
The best search scope for this feature is to have everything be indexed in the same db, this allows to search through deps, and across the whole project.

@doc has more limited scope more suitable for sharing the docs (smaller js files, ability to upload separate parts of the same workspace separately)

@emillon
Copy link
Collaborator

emillon commented Feb 1, 2024

One thing you can do with the new fake sherlodoc I added is cat the db.js files that are generated. They contain the arguments passed to sherlodoc so you can see what docs contain which parts.

@emillon emillon mentioned this pull request Feb 7, 2024
20 tasks
@EmileTrotignon EmileTrotignon marked this pull request as ready for review February 7, 2024 14:39
@EmileTrotignon EmileTrotignon force-pushed the search-odoc-new branch 3 times, most recently from b7c850c to 81fbd1f Compare February 7, 2024 16:56
@emillon emillon changed the title Search bar in the docs odoc: sherlodoc integration Feb 8, 2024
@emillon emillon self-assigned this Feb 8, 2024
@emillon emillon force-pushed the search-odoc-new branch 2 times, most recently from 4ae5750 to 0020e1e Compare February 8, 2024 11:11
@emillon
Copy link
Collaborator

emillon commented Feb 8, 2024

this is now good to go in my opinion, except for the todo which I'm not sure is about.

This extends the rules for @doc and @doc-new so that if sherlodoc
(available from opam) is installed, a search bar is added on the HTML
output.

Signed-off-by: Emile Trotignon <emile@tarides.com>
Co-authored-by: Etienne Millon <me@emillon.org>
Co-authored-by: Christine Rose <christinerose@users.noreply.github.com>
@emillon
Copy link
Collaborator

emillon commented Feb 8, 2024

Thanks. In my view, this is ready to go.

@emillon emillon merged commit 04231a1 into ocaml:main Feb 8, 2024
5 of 6 checks passed
emillon added a commit to emillon/dune that referenced this pull request Feb 8, 2024
This extends the rules for @doc and @doc-new so that if sherlodoc
(available from opam) is installed, a search bar is added on the HTML
output.

Signed-off-by: Emile Trotignon <emile@tarides.com>
Co-authored-by: Emile Trotignon <emile@tarides.com>
Co-authored-by: Etienne Millon <me@emillon.org>
Co-authored-by: Christine Rose <christinerose@users.noreply.github.com>
emillon added a commit to emillon/opam-repository that referenced this pull request Feb 9, 2024
CHANGES:

### Added

- Introduce a `(dynamic_include ..)` stanza. This is like `(include foo)` but
  allows `foo` to be the target of a rule. Currently, there are some
  limitations on the stanzas that can be generated. For example, public
  executables, libraries are currently forbidden. (ocaml/dune#9913, @rgrinberg)

- Introduce `$ dune promotion list` to print the list of available promotions.
  (ocaml/dune#9705, @moyodiallo)

- If Sherlodoc is installed, add a search bar in generated HTML docs (ocaml/dune#9772,
  @EmileTrotignon)

- Add `only_sources` field to `copy_files` stanza (ocaml/dune#9827, fixes ocaml/dune#9709,
  @jchavarri)

- The `(foreign_library)` stanza now supports the `(enabled_if)` field. (ocaml/dune#9914,
  @nojb)

### Fixed

- Fix `$ dune install -p` incorrectly recognizing packages that are supposed to
  be filtered (ocaml/dune#9879, fixes ocaml/dune#4814, @rgrinberg)

- subst: correctly handle opam files in opam/ subdirectory (ocaml/dune#9895, fixes ocaml/dune#9862,
  @emillon)

- Odoc private rules are not set up if a library is not available due to
  `enabled_if` (ocaml/dune#9897, @rgrinberg and @jchavarri)

### Changed

- When dune language 3.14 is enabled, resolve the binary in `(run %{bin:..}
  ..)` from where the binary is built. (ocaml/dune#9708, @rgrinberg)

- boot: remove single-command bootstrap. This was an alternative bootstrap
  strategy that was used in certain conditions. Removal makes the bootstrap a
  bit slower on Linux when only a single core is available, but bootstrap is
  now reproducible in all cases. (ocaml/dune#9735, fixes ocaml/dune#9507, @emillon)
emillon added a commit to emillon/opam-repository that referenced this pull request Feb 12, 2024
CHANGES:

### Added

- Introduce a `(dynamic_include ..)` stanza. This is like `(include foo)` but
  allows `foo` to be the target of a rule. Currently, there are some
  limitations on the stanzas that can be generated. For example, public
  executables, libraries are currently forbidden. (ocaml/dune#9913, @rgrinberg)

- Introduce `$ dune promotion list` to print the list of available promotions.
  (ocaml/dune#9705, @moyodiallo)

- If Sherlodoc is installed, add a search bar in generated HTML docs (ocaml/dune#9772,
  @EmileTrotignon)

- Add `only_sources` field to `copy_files` stanza (ocaml/dune#9827, fixes ocaml/dune#9709,
  @jchavarri)

- The `(foreign_library)` stanza now supports the `(enabled_if)` field. (ocaml/dune#9914,
  @nojb)

### Fixed

- Fix `$ dune install -p` incorrectly recognizing packages that are supposed to
  be filtered (ocaml/dune#9879, fixes ocaml/dune#4814, @rgrinberg)

- subst: correctly handle opam files in opam/ subdirectory (ocaml/dune#9895, fixes ocaml/dune#9862,
  @emillon)

- Odoc private rules are not set up if a library is not available due to
  `enabled_if` (ocaml/dune#9897, @rgrinberg and @jchavarri)

### Changed

- When dune language 3.14 is enabled, resolve the binary in `(run %{bin:..}
  ..)` from where the binary is built. (ocaml/dune#9708, @rgrinberg)

- boot: remove single-command bootstrap. This was an alternative bootstrap
  strategy that was used in certain conditions. Removal makes the bootstrap a
  bit slower on Linux when only a single core is available, but bootstrap is
  now reproducible in all cases. (ocaml/dune#9735, fixes ocaml/dune#9507, @emillon)
nberth pushed a commit to nberth/opam-repository that referenced this pull request Jun 18, 2024
CHANGES:

### Added

- Introduce a `(dynamic_include ..)` stanza. This is like `(include foo)` but
  allows `foo` to be the target of a rule. Currently, there are some
  limitations on the stanzas that can be generated. For example, public
  executables, libraries are currently forbidden. (ocaml/dune#9913, @rgrinberg)

- Introduce `$ dune promotion list` to print the list of available promotions.
  (ocaml/dune#9705, @moyodiallo)

- If Sherlodoc is installed, add a search bar in generated HTML docs (ocaml/dune#9772,
  @EmileTrotignon)

- Add `only_sources` field to `copy_files` stanza (ocaml/dune#9827, fixes ocaml/dune#9709,
  @jchavarri)

- The `(foreign_library)` stanza now supports the `(enabled_if)` field. (ocaml/dune#9914,
  @nojb)

### Fixed

- Fix `$ dune install -p` incorrectly recognizing packages that are supposed to
  be filtered (ocaml/dune#9879, fixes ocaml/dune#4814, @rgrinberg)

- subst: correctly handle opam files in opam/ subdirectory (ocaml/dune#9895, fixes ocaml/dune#9862,
  @emillon)

- Odoc private rules are not set up if a library is not available due to
  `enabled_if` (ocaml/dune#9897, @rgrinberg and @jchavarri)

### Changed

- When dune language 3.14 is enabled, resolve the binary in `(run %{bin:..}
  ..)` from where the binary is built. (ocaml/dune#9708, @rgrinberg)

- boot: remove single-command bootstrap. This was an alternative bootstrap
  strategy that was used in certain conditions. Removal makes the bootstrap a
  bit slower on Linux when only a single core is available, but bootstrap is
  now reproducible in all cases. (ocaml/dune#9735, fixes ocaml/dune#9507, @emillon)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants