Merge pull request #294 from janestreet/revert-290-new-odoc
Revert "RFC update odoc rules"
This commit is contained in:
commit
27cbf1de38
|
@ -410,13 +410,7 @@ module Gen(P : Params) = struct
|
||||||
);
|
);
|
||||||
|
|
||||||
(* Odoc *)
|
(* Odoc *)
|
||||||
let mld_files =
|
Odoc.setup_library_rules sctx lib ~dir ~requires ~modules ~dep_graph;
|
||||||
String_set.fold files ~init:[] ~f:(fun fn acc ->
|
|
||||||
if Filename.check_suffix fn ".mld" then fn :: acc else acc)
|
|
||||||
in
|
|
||||||
Odoc.setup_library_rules sctx lib ~dir ~requires ~modules ~dep_graph
|
|
||||||
~mld_files
|
|
||||||
;
|
|
||||||
|
|
||||||
let flags =
|
let flags =
|
||||||
match alias_module with
|
match alias_module with
|
||||||
|
|
209
src/odoc.ml
209
src/odoc.ml
|
@ -9,147 +9,113 @@ let ( ++ ) = Path.relative
|
||||||
let get_odoc sctx = SC.resolve_program sctx "odoc" ~hint:"opam install odoc"
|
let get_odoc sctx = SC.resolve_program sctx "odoc" ~hint:"opam install odoc"
|
||||||
let odoc_ext = ".odoc"
|
let odoc_ext = ".odoc"
|
||||||
|
|
||||||
module Mld = struct
|
let module_deps (m : Module.t) ~dir ~dep_graph ~modules =
|
||||||
type t = {
|
|
||||||
name : string; (** source file name without the extension. *)
|
|
||||||
odoc_input_name : string;
|
|
||||||
odoc_file_name : string;
|
|
||||||
}
|
|
||||||
|
|
||||||
let odoc_file ~dir {odoc_file_name; _} =
|
|
||||||
Path.relative dir odoc_file_name
|
|
||||||
|
|
||||||
let odoc_input ~dir {odoc_input_name; _} =
|
|
||||||
Path.relative dir odoc_input_name
|
|
||||||
end
|
|
||||||
|
|
||||||
module Module_or_mld = struct
|
|
||||||
type t =
|
|
||||||
| Mld of Mld.t
|
|
||||||
| Module of Module.t
|
|
||||||
|
|
||||||
let odoc_file ~dir = function
|
|
||||||
| Mld m -> Mld.odoc_file ~dir m
|
|
||||||
| Module m -> Module.odoc_file ~dir m
|
|
||||||
|
|
||||||
let odoc_input ~dir = function
|
|
||||||
| Mld m -> Mld.odoc_input ~dir m
|
|
||||||
| Module m -> Module.cmti_file m ~dir
|
|
||||||
end
|
|
||||||
|
|
||||||
let module_or_mld_deps (m : Module_or_mld.t) ~dir ~dep_graph ~modules =
|
|
||||||
Build.dyn_paths
|
Build.dyn_paths
|
||||||
(dep_graph
|
(dep_graph
|
||||||
>>^ fun graph ->
|
>>^ fun graph ->
|
||||||
match m with
|
List.map (Utils.find_deps ~dir graph m.name)
|
||||||
| Mld _ -> []
|
~f:(fun name ->
|
||||||
| Module m ->
|
let m = Utils.find_module ~dir modules name in
|
||||||
List.map (Utils.find_deps ~dir graph m.name)
|
Module.odoc_file m ~dir))
|
||||||
~f:(fun name ->
|
|
||||||
let m = Utils.find_module ~dir modules name in
|
|
||||||
Module.odoc_file m ~dir))
|
|
||||||
|
|
||||||
let compile sctx (m : Module_or_mld.t) ~odoc ~dir ~includes ~dep_graph
|
let compile_module sctx (m : Module.t) ~odoc ~dir ~includes ~dep_graph ~modules
|
||||||
~modules ~lib_public_name =
|
~lib_public_name =
|
||||||
let context = SC.context sctx in
|
let context = SC.context sctx in
|
||||||
let odoc_file = Module_or_mld.odoc_file m ~dir in
|
let odoc_file = Module.odoc_file m ~dir in
|
||||||
SC.add_rule sctx
|
SC.add_rule sctx
|
||||||
(module_or_mld_deps m ~dir ~dep_graph ~modules
|
(module_deps m ~dir ~dep_graph ~modules
|
||||||
>>>
|
>>>
|
||||||
includes
|
includes
|
||||||
>>>
|
>>>
|
||||||
Build.run ~context ~dir odoc ~extra_targets:[odoc_file]
|
Build.run ~context ~dir odoc ~extra_targets:[odoc_file]
|
||||||
[ A "compile"
|
[ A "compile"
|
||||||
; A "-I"; Path dir
|
|
||||||
; Dyn (fun x -> x)
|
; Dyn (fun x -> x)
|
||||||
|
; A "-I"; Path dir
|
||||||
; As ["--pkg"; lib_public_name]
|
; As ["--pkg"; lib_public_name]
|
||||||
; A "-o"; Path odoc_file
|
; Dep (Module.cmti_file m ~dir)
|
||||||
; Dep (Module_or_mld.odoc_input m ~dir)
|
|
||||||
]);
|
]);
|
||||||
(m, odoc_file)
|
(m, odoc_file)
|
||||||
|
|
||||||
let to_html sctx (m : Module_or_mld.t) odoc_file ~doc_dir ~odoc ~dir ~includes
|
let to_html sctx (m : Module.t) odoc_file ~doc_dir ~odoc ~dir ~includes
|
||||||
~lib_public_name ~(lib : Library.t) =
|
~lib_public_name ~(lib : Library.t) =
|
||||||
let context = SC.context sctx in
|
let context = SC.context sctx in
|
||||||
let to_remove, html_dir, html_file, jbuilder_keep =
|
let html_dir = doc_dir ++ lib_public_name ++ String.capitalize_ascii m.obj_name in
|
||||||
match m with
|
let html_file = html_dir ++ "index.html" in
|
||||||
| Mld m ->
|
SC.add_rule sctx
|
||||||
let html_dir = doc_dir ++ lib_public_name in
|
(SC.Libs.static_file_deps (dir, lib) ~ext:odoc_ext
|
||||||
let html_file = html_dir ++ (m.Mld.name ^ ".html") in
|
>>>
|
||||||
html_file, html_dir, html_file, []
|
includes
|
||||||
| Module m ->
|
>>>
|
||||||
let html_dir = doc_dir ++ lib_public_name ++ String.capitalize_ascii m.obj_name in
|
Build.progn
|
||||||
let html_file = html_dir ++ "index.html" in
|
[ Build.remove_tree html_dir
|
||||||
let jbuilder_keep =
|
; Build.mkdir html_dir
|
||||||
Build.create_file (html_dir ++ Config.jbuilder_keep_fname)
|
; Build.run ~context ~dir odoc ~extra_targets:[html_file]
|
||||||
in
|
[ A "html"
|
||||||
html_dir, html_dir, html_file, [jbuilder_keep]
|
; Dyn (fun x -> x)
|
||||||
|
; A "-I"; Path dir
|
||||||
|
; A "-o"; Path doc_dir
|
||||||
|
; Dep odoc_file
|
||||||
|
]
|
||||||
|
; Build.create_file (html_dir ++ Config.jbuilder_keep_fname)
|
||||||
|
]
|
||||||
|
);
|
||||||
|
html_file
|
||||||
|
|
||||||
|
let lib_index sctx ~odoc ~dir ~(lib : Library.t) ~lib_public_name ~doc_dir ~modules
|
||||||
|
~includes =
|
||||||
|
let context = SC.context sctx in
|
||||||
|
let generated_index_mld = dir ++ sprintf "%s-generated.mld" lib.name in
|
||||||
|
let source_index_mld = dir ++ sprintf "%s.mld" lib.name in
|
||||||
|
let header = {|{%html:<nav><a href="../index.html">Up</a></nav>%}|} in
|
||||||
|
SC.add_rule sctx
|
||||||
|
(Build.if_file_exists source_index_mld
|
||||||
|
~then_:(Build.contents source_index_mld
|
||||||
|
>>^ fun s -> sprintf "%s\n%s" header s)
|
||||||
|
~else_:(Build.arr (fun () ->
|
||||||
|
(if lib.wrapped then
|
||||||
|
sprintf
|
||||||
|
"%s\n\
|
||||||
|
{1 Library %s}\n\
|
||||||
|
The entry point for this library is module {!module:%s}."
|
||||||
|
header
|
||||||
|
lib_public_name
|
||||||
|
(String.capitalize_ascii lib.name)
|
||||||
|
else
|
||||||
|
sprintf
|
||||||
|
"%s\n\
|
||||||
|
{1 Library %s}\n\
|
||||||
|
This library exposes the following toplevel modules: {!modules:%s}."
|
||||||
|
header
|
||||||
|
lib_public_name
|
||||||
|
(String_map.keys modules |> String.concat ~sep:" "))))
|
||||||
|
>>>
|
||||||
|
Build.write_file_dyn generated_index_mld);
|
||||||
|
let html_file =
|
||||||
|
doc_dir ++ lib_public_name ++ "index.html"
|
||||||
in
|
in
|
||||||
SC.add_rule sctx
|
SC.add_rule sctx
|
||||||
(SC.Libs.static_file_deps (dir, lib) ~ext:odoc_ext
|
(SC.Libs.static_file_deps (dir, lib) ~ext:odoc_ext
|
||||||
>>>
|
>>>
|
||||||
includes
|
includes
|
||||||
>>>
|
>>>
|
||||||
Build.progn (
|
Build.run ~context ~dir odoc ~extra_targets:[html_file]
|
||||||
Build.remove_tree to_remove
|
[ A "html"
|
||||||
:: Build.mkdir html_dir
|
; Dyn (fun x -> x)
|
||||||
:: Build.run ~context ~dir odoc ~extra_targets:[html_file]
|
; A "-I"; Path dir
|
||||||
[ A "html"
|
; A "-o"; Path doc_dir
|
||||||
; A "-I"; Path dir
|
; A "--index-for"; A lib_public_name
|
||||||
; Dyn (fun x -> x)
|
; Dep generated_index_mld
|
||||||
; A "-o"; Path doc_dir
|
]);
|
||||||
; Dep odoc_file
|
|
||||||
]
|
|
||||||
:: jbuilder_keep
|
|
||||||
)
|
|
||||||
);
|
|
||||||
html_file
|
html_file
|
||||||
|
|
||||||
let all_mld_files sctx ~(lib : Library.t) ~lib_public_name ~modules ~dir files =
|
|
||||||
let header = {|{%html:<nav><a href="../index.html">Up</a></nav>%}|} in
|
|
||||||
let all_files =
|
|
||||||
if List.mem "index.mld" ~set:files then files else "index.mld" :: files
|
|
||||||
in
|
|
||||||
List.map all_files ~f:(fun file ->
|
|
||||||
let name = Filename.chop_extension file in
|
|
||||||
let odoc_input_name = sprintf "%s-generated.mld" name in
|
|
||||||
let odoc_file_name = sprintf "page-%s%s" name odoc_ext in
|
|
||||||
let generated_mld = dir ++ odoc_input_name in
|
|
||||||
let source_mld = dir ++ file in
|
|
||||||
SC.add_rule sctx
|
|
||||||
(Build.if_file_exists source_mld
|
|
||||||
~then_:(Build.contents source_mld
|
|
||||||
>>^ fun s -> sprintf "%s\n%s" header s)
|
|
||||||
~else_:(Build.arr (fun () ->
|
|
||||||
(if lib.wrapped then
|
|
||||||
sprintf
|
|
||||||
"%s\n\
|
|
||||||
{1 Library %s}\n\
|
|
||||||
The entry point for this library is module {!module:%s}."
|
|
||||||
header
|
|
||||||
lib_public_name
|
|
||||||
(String.capitalize_ascii lib.name)
|
|
||||||
else
|
|
||||||
sprintf
|
|
||||||
"%s\n\
|
|
||||||
{1 Library %s}\n\
|
|
||||||
This library exposes the following toplevel modules: {!modules:%s}."
|
|
||||||
header
|
|
||||||
lib_public_name
|
|
||||||
(String_map.keys modules |> String.concat ~sep:" "))))
|
|
||||||
>>>
|
|
||||||
Build.write_file_dyn generated_mld);
|
|
||||||
{ Mld. name; odoc_file_name; odoc_input_name }
|
|
||||||
)
|
|
||||||
|
|
||||||
let doc_dir ~context = Path.relative context.Context.build_dir "_doc"
|
let doc_dir ~context = Path.relative context.Context.build_dir "_doc"
|
||||||
|
|
||||||
let css_file ~doc_dir = doc_dir ++ "odoc.css"
|
let css_file ~doc_dir = doc_dir ++ "odoc.css"
|
||||||
|
|
||||||
let toplevel_index ~doc_dir = doc_dir ++ "index.html"
|
let toplevel_index ~doc_dir = doc_dir ++ "index.html"
|
||||||
|
|
||||||
let setup_library_rules sctx (lib : Library.t) ~dir ~modules ~mld_files
|
let setup_library_rules sctx (lib : Library.t) ~dir ~modules ~requires
|
||||||
~requires ~(dep_graph:Ocamldep.dep_graph) =
|
~(dep_graph:Ocamldep.dep_graph) =
|
||||||
Option.iter lib.public ~f:(fun public ->
|
Option.iter lib.public ~f:(fun public ->
|
||||||
let context = SC.context sctx in
|
let context = SC.context sctx in
|
||||||
let dep_graph =
|
let dep_graph =
|
||||||
|
@ -172,23 +138,13 @@ let setup_library_rules sctx (lib : Library.t) ~dir ~modules ~mld_files
|
||||||
SC.Libs.file_deps sctx ~ext:odoc_ext
|
SC.Libs.file_deps sctx ~ext:odoc_ext
|
||||||
>>^ Lib.include_flags)
|
>>^ Lib.include_flags)
|
||||||
in
|
in
|
||||||
let mld_files =
|
|
||||||
all_mld_files sctx ~dir ~lib ~lib_public_name:public.name
|
|
||||||
~modules mld_files
|
|
||||||
in
|
|
||||||
let mld_and_odoc_files =
|
|
||||||
List.map mld_files ~f:(fun m ->
|
|
||||||
compile sctx ~odoc ~dir ~includes ~dep_graph ~modules
|
|
||||||
~lib_public_name:public.name (Mld m))
|
|
||||||
in
|
|
||||||
let modules_and_odoc_files =
|
let modules_and_odoc_files =
|
||||||
List.map (String_map.values modules) ~f:(fun m ->
|
List.map (String_map.values modules)
|
||||||
compile sctx ~odoc ~dir ~includes ~dep_graph ~modules
|
~f:(compile_module sctx ~odoc ~dir ~includes ~dep_graph ~modules
|
||||||
~lib_public_name:public.name (Module m))
|
~lib_public_name:public.name)
|
||||||
in
|
in
|
||||||
let inputs_and_odoc_files = modules_and_odoc_files @ mld_and_odoc_files in
|
|
||||||
SC.Libs.setup_file_deps_alias sctx ~ext:odoc_ext (dir, lib)
|
SC.Libs.setup_file_deps_alias sctx ~ext:odoc_ext (dir, lib)
|
||||||
(List.map inputs_and_odoc_files ~f:snd);
|
(List.map modules_and_odoc_files ~f:snd);
|
||||||
let doc_dir = doc_dir ~context in
|
let doc_dir = doc_dir ~context in
|
||||||
(*
|
(*
|
||||||
let modules_and_odoc_files =
|
let modules_and_odoc_files =
|
||||||
|
@ -200,13 +156,18 @@ let setup_library_rules sctx (lib : Library.t) ~dir ~modules ~mld_files
|
||||||
modules_and_odoc_files
|
modules_and_odoc_files
|
||||||
in*)
|
in*)
|
||||||
let html_files =
|
let html_files =
|
||||||
List.map inputs_and_odoc_files ~f:(fun (m, odoc_file) ->
|
List.map modules_and_odoc_files ~f:(fun (m, odoc_file) ->
|
||||||
to_html sctx m odoc_file ~doc_dir ~odoc ~dir ~includes ~lib
|
to_html sctx m odoc_file ~doc_dir ~odoc ~dir ~includes ~lib
|
||||||
~lib_public_name:public.name)
|
~lib_public_name:public.name)
|
||||||
in
|
in
|
||||||
|
let lib_index_html =
|
||||||
|
lib_index sctx ~dir ~lib ~lib_public_name:public.name ~doc_dir
|
||||||
|
~modules ~includes ~odoc
|
||||||
|
in
|
||||||
Alias.add_deps (SC.aliases sctx) (Alias.doc ~dir)
|
Alias.add_deps (SC.aliases sctx) (Alias.doc ~dir)
|
||||||
(css_file ~doc_dir
|
(css_file ~doc_dir
|
||||||
:: toplevel_index ~doc_dir
|
:: toplevel_index ~doc_dir
|
||||||
|
:: lib_index_html
|
||||||
:: html_files))
|
:: html_files))
|
||||||
|
|
||||||
let setup_css_rule sctx =
|
let setup_css_rule sctx =
|
||||||
|
|
|
@ -8,7 +8,6 @@ val setup_library_rules
|
||||||
-> Library.t
|
-> Library.t
|
||||||
-> dir:Path.t
|
-> dir:Path.t
|
||||||
-> modules:Module.t String_map.t
|
-> modules:Module.t String_map.t
|
||||||
-> mld_files:string list
|
|
||||||
-> requires:(unit, Lib.t list) Build.t
|
-> requires:(unit, Lib.t list) Build.t
|
||||||
-> dep_graph:Ocamldep.dep_graph
|
-> dep_graph:Ocamldep.dep_graph
|
||||||
-> unit
|
-> unit
|
||||||
|
|
Loading…
Reference in New Issue