8

我想在我生成的文档中包含源代码。当我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

但这仅包括没有相应接口文件的文件的源 - 与这里所说的相反,它看起来像ocamlbuild拒绝将.ml文件传递给ocamldoc当有.mli文件存在时。有没有办法哄 ocamlbuild 做我想做的事?

4

2 回答 2

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

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

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

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

于 2013-11-07T13:13:41.147 回答
3

OCamlbuild 目前似乎不支持该功能。你能在 bugtracker 上提交一个功能请求吗?

于 2012-12-12T15:21:40.743 回答