因为我需要破解一些东西来做类似的事情,所以如果我在这里发布它作为答案可能会有所帮助(至少在 OCamlbuild 具有该功能之前)。所以,这是我的相关部分myocamlbuild.ml
:
open Ocamlbuild_plugin;;
dispatch begin function
| After_rules ->
(* Using both .ml and .mli files to build documentation: *)
rule "ocaml: ml & mli -> odoc"
~insert:`top
~tags:["ocaml"; "doc"; "doc_use_interf_n_implem"]
~prod:"%.odoc"
(* "%.cmo" so that cmis of ml dependencies are already built: *)
~deps:["%.ml"; "%.mli"; "%.cmo"]
begin fun env build ->
let mli = env "%.mli" and ml = env "%.ml" and odoc = env "%.odoc" in
let tags =
(Tags.union (tags_of_pathname mli) (tags_of_pathname ml))
++"doc_use_interf_n_implem"++"ocaml"++"doc" in
let include_dirs = Pathname.include_dirs_of (Pathname.dirname ml) in
let include_flags =
List.fold_right (fun p acc -> A"-I" :: A p :: acc) include_dirs [] in
Cmd (S [!Options.ocamldoc; A"-dump"; Px odoc;
T (tags++"doc"++"pp"); S (include_flags);
A"-intf"; P mli; A"-impl"; P ml])
end;
(* Specifying merge options with tags: *)
pflag ["ocaml"; "doc"; "doc_use_interf_n_implem"] "merge"
(fun s -> S[A"-m"; A s]);
end
然后将标签添加doc_use_interf_n_implem
到.ml
和/或.mli
应该从实现和接口生成文档的文件应该可以解决问题。
使用上面的代码,添加合并选项也可以通过添加标签来完成,例如merge(A)
(合并所有)。
请注意,这是一个 hack,可能会破坏复杂项目中的内容。值得注意的是,我没有使用camlp[45]
-processed 文件测试它,也没有使用 4.00.1 以外的 OCamlbuild 版本进行测试。