使ocamlbuild将.ml和.mli文件传递给ocamldoc

Mik*_*kov 8 ocaml ocamlbuild ocamldoc

我想在生成的文档中包含源代码.当我ocamldoc在命令行上调用时,这可以工作:ocamldoc -I _build -html -keep-code -colorize-code *.{ml,mli} -d .docdir.但是,我遇到了麻烦ocamlbuild.

我正在使用以下代码myocamlbuild.ml:

open Ocamlbuild_plugin;;

dispatch begin function
  | After_options ->
      Options.ocamldoc := S[A"ocamldoc"; A"-keep-code"; A"-colorize-code"]
  | _ -> ()
end
Run Code Online (Sandbox Code Playgroud)

但是这只包含没有相应接口文件的文件源 - 与此处所说的相反,它看起来像是在存在文件时ocamlbuild拒绝传递.ml文件.有没有办法哄ocamlbuild做我想要的?ocamldoc.mli

nbe*_*rth 4

由于我需要破解一些东西来完成类似的事情,如果我将其作为答案发布到此处也许会有所帮助(至少在 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
Run Code Online (Sandbox Code Playgroud)

然后将标签添加doc_use_interf_n_implem.ml和/或.mli应从实现和接口生成文档的文件中应该可以解决问题。

使用上面的代码,添加合并选项也可以通过添加标签来完成,例如merge(A)(合并所有)。

请注意,这是一个可能会破坏复杂项目中内容的黑客行为。值得注意的是,我没有使用camlp[45]-processed 文件来测试它,也没有使用 4.00.1 以外的 OCamlbuild 版本来测试它。