ocaml / ocamlbuild

The legacy OCamlbuild build manager
Other
122 stars 81 forks source link

MPR#5852: Ocamlbuild does not pass .ml files to ocamldoc when there is an .mli file present #206

Open damiendoligez opened 7 years ago

damiendoligez commented 7 years ago

PR transferred from https://caml.inria.fr/mantis/view.php?id=5852 [original reporter: @23Skidoo]

I want to include source code in my generated docs. This works when I invoke ocamldoc on the command-line like this:

ocamldoc -I _build -html -keep-code -colorize-code *.{ml,mli} -d .docdir

. However, I'm having troubles integrating this with ocamlbuild.

I'm using the following code in myocamlbuild.ml:

open Ocamlbuild_plugin;;

dispatch begin function
  | After_options ->
      Options.ocamldoc := S[A"ocamldoc"; A"-keep-code"; A"-colorize-code"]

| _ -> ()
end

But this only includes the source for files with no corresponding interface file - it looks like ocamlbuild refuses to pass .ml files to ocamldoc when there is an .mli file present. It'd be nice if it was possible to integrate ocamldoc -keep-code with ocamlbuild.

Armael commented 7 years ago

This happens because of the way ocamlbuild uses ocamldoc to build documentation, using intermediate odoc files produced using the -dump option of ocamldoc.

Currently, the process is as follows:

The issue is that exactly one .odoc file is build for each module. The fact that ocamldoc doesn't see the contents of a .ml if a .mli is present is because the rule producing a .odoc from a .mli has higher priority than the one producing a .odoc from a .ml.

For -keep-code to work as expected, we would need to run ocamldoc -dump ... on both the .ml and .mli, producing two different output files (.odoc and .odoci?). Then these two would be eventually fed to ocamldoc using -load — at this point ocamldoc would have the possibility of ignoring the contents of the .ml (default behavior), or using it along with the .mli (-keep-code).

Armael commented 7 years ago

I'd like to implement a fix along the lines of the last paragraph, but I'm not sure how at the moment. The difficulty is that, now, we would need to express that for each module of foo.odocl, we would like to build a .odoc and a .odoci. We would like to build both if possible, but if building one is not possible then it's still fine, as long as building the other one works.

I'm not sure how to encode this in ocamlbuild rules or how to implement this in Ocaml_tools.document_ocaml_project.

whitequark commented 7 years ago

Maybe you could gate the behavior on odoc_keep_code tag?