[@@@module Sys.getenv "HOME" ^ "/u/webs/run__html" ^ ".ml"]
[@@@module "%/.." ^ "/fileutils" ^ ".ml"]
[@@@module "%/.." ^ "/path" ^ ".ml"]
[@@@module "%/.." ^ "/unfold/path" ^ ".ml"]
[@@@module "%/.." ^ "/list" ^ ".ml"]
open Layer9
(* TODO(kinten) use Odoc *)
module Doc' =
functor (Env :
sig val pr : [\`Unix | \`Generic] Process.mgr_ty Resource.t val fs : Fs.dir_ty Path.t end) ->
struct
let compile ~output srcpath =
(* traceln "layer9.ocamldoc: doc: output is '%s'" Path.(native_exn output); *)
Path.mkdirs ~exists_ok:true ~perm:0o700 Path.(Env.fs / (Filename.dirname @@ native_exn output));
Process.run Env.pr ["odoc"; "compile"; Path.native_exn srcpath; "-o"; Path.native_exn output]
let html ~output_dir irpath =
Path.mkdirs ~exists_ok:true ~perm:0o700 output_dir;
Process.run Env.pr ["odoc"; "html"; Path.native_exn irpath; "--output-dir"; Path.native_exn output_dir]
end
module Tmp =
struct
let dir fs = Path.(fs / Sys.getenv "HOME" / "s" / "layer9.ocamldoc" / "_tmp")
end
let gencache, genuse = Hashtbl.create 10, Mutex.create ()
let genfile ~process_mgr ~fs ~writer:to_client path =
let path = Sys.getenv "HOME" ^ "/" ^ (String.concat "/" path) in
let new_ns s = "." ^ s in
let mld_src = Path.unfold ~fs ~ext:".mld" Path.(fs / path) in
( Mutex.use_rw ~protect:true genuse @@ fun () ->
match Hashtbl.find gencache Path.(native_exn mld_src)
with last_mod, () when Fileutils.get_mod mld_src = last_mod -> ()
| _, () | exception Not_found ->
let module Doc = Doc'(struct let pr, fs = process_mgr, fs end) in
let irpath = Path.(Tmp.dir fs / new_ns (
mld_src |> prepend ~fs "page-" |> change_ext ~fs ".odoc" |> native_exn )) in
Doc.compile ~output:irpath mld_src;
Doc.html irpath ~output_dir:Path.(dir ~fs irpath);
Hashtbl.add gencache Path.(native_exn mld_src) ( (Fileutils.get_mod mld_src), () )
);
Flow.copy_string begin Run__html.ok @@
Path.load Path.(Tmp.dir fs / new_ns (
mld_src |> change_ext ~fs ".html" |> native_exn ))
end to_client
let gensig ~writer:to_client path =
()
let [@warning "-8"] () =
let requires = ["odoc.html"] in
let icon = "" in
Driver.register_route (Route.info "ocamldoc" (* ~icon *)
~doc:{%typ| mldoc and ml signature support for `layer9` |}) @@
.< function path, query, o
when (".mld" = Filename.extension (String.concat "/" path))
|| List.exists (function ("ocamldoc" | "mldoc" | "mld"), _ -> true | _ -> false) query ->
genfile path ~fs:o#fs ~writer:o#writer ~process_mgr:o#process_mgr
| p, q, o when (".mli" = Filename.extension (String.concat "/" p))
-> gensig p ~writer:o#writer >.
[@metaocaml.functionliteral]