Skip to content

Commit b38f0c5

Browse files
committed
Driver: Process markdown files installed in opam doc dir
1 parent 01fa456 commit b38f0c5

File tree

6 files changed

+48
-7
lines changed

6 files changed

+48
-7
lines changed

src/driver/compile.ml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ let init_stats (units : Odoc_unit.t list) =
3838
| `Intf { hidden = false; _ } -> non_hidden + 1
3939
| _ -> non_hidden
4040
in
41-
let mlds = match unit.kind with `Mld -> mlds + 1 | _ -> mlds in
41+
let mlds = match unit.kind with `Mld | `Md -> mlds + 1 | _ -> mlds in
4242
(total, total_impl, non_hidden, mlds, assets, indexes))
4343
(0, 0, 0, 0, 0, Fpath.Set.empty)
4444
units
@@ -182,6 +182,11 @@ let compile ?partial ~partial_dir (all : Odoc_unit.t list) =
182182
~includes ~parent_id:unit.parent_id;
183183
Atomic.incr Stats.stats.compiled_mlds;
184184
Ok [ unit ]
185+
| `Md ->
186+
Odoc.compile_md ~output_dir:unit.output_dir ~input_file:unit.input_file
187+
~parent_id:unit.parent_id;
188+
Atomic.incr Stats.stats.compiled_mlds;
189+
Ok [ unit ]
185190
in
186191
let res = Fiber.List.map compile all in
187192
(* For voodoo mode, we need to keep which modules successfully compiled *)
@@ -231,7 +236,8 @@ let link : compiled list -> _ =
231236
| `Intf _ -> Atomic.incr Stats.stats.linked_units
232237
| `Mld -> Atomic.incr Stats.stats.linked_mlds
233238
| `Asset -> ()
234-
| `Impl _ -> Atomic.incr Stats.stats.linked_impls);
239+
| `Impl _ -> Atomic.incr Stats.stats.linked_impls
240+
| `Md -> Atomic.incr Stats.stats.linked_mlds);
235241
c
236242
in
237243
Fiber.List.map link compiled

src/driver/odoc.ml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ type compile_deps = { digest : Digest.t; deps : (string * Digest.t) list }
2222

2323
let odoc = ref (Cmd.v "odoc")
2424

25+
let odoc_md = ref (Cmd.v "odoc-md")
26+
2527
let compile_deps f =
2628
let cmd = Cmd.(!odoc % "compile-deps" % Fpath.to_string f) in
2729
let desc = Printf.sprintf "Compile deps for %s" (Fpath.to_string f) in
@@ -54,6 +56,22 @@ let compile ~output_dir ~input_file:file ~includes ~parent_id =
5456
(Some (`Compile, Fpath.to_string file))
5557
desc cmd output_file
5658

59+
let compile_md ~output_dir ~input_file:file ~parent_id =
60+
let open Cmd in
61+
let output_file =
62+
let _, f = Fpath.split_base file in
63+
Some Fpath.(output_dir // Id.to_fpath parent_id // set_ext "odoc" f)
64+
in
65+
let cmd =
66+
!odoc_md % Fpath.to_string file % "--output-dir" % p output_dir
67+
in
68+
let cmd = cmd % "--parent-id" % Id.to_string parent_id in
69+
let desc = Printf.sprintf "Compiling Markdown %s" (Fpath.to_string file) in
70+
let lines = Cmd_outputs.submit desc cmd output_file in
71+
Cmd_outputs.(
72+
add_prefixed_output cmd compile_output (Fpath.to_string file) lines)
73+
74+
5775
let compile_asset ~output_dir ~name ~parent_id =
5876
let open Cmd in
5977
let output_file =

src/driver/odoc.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ val compile :
2525
includes:Fpath.set ->
2626
parent_id:Id.t ->
2727
unit
28+
val compile_md : output_dir:Fpath.t -> input_file:Fpath.t -> parent_id:Id.t -> unit
2829

2930
val compile_asset : output_dir:Fpath.t -> name:string -> parent_id:Id.t -> unit
3031

src/driver/odoc_unit.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ type impl_extra = { src_id : Odoc.Id.t; src_path : Fpath.t }
7070
type impl = [ `Impl of impl_extra ]
7171

7272
type mld = [ `Mld ]
73-
73+
type md = [ `Md ]
7474
type asset = [ `Asset ]
7575

76-
type all_kinds = [ impl | intf | mld | asset ]
76+
type all_kinds = [ impl | intf | mld | asset | md ]
7777
type t = all_kinds unit
7878

7979
let rec pp_kind : all_kinds Fmt.t =
@@ -82,6 +82,7 @@ let rec pp_kind : all_kinds Fmt.t =
8282
| `Intf x -> Format.fprintf fmt "`Intf %a" pp_intf_extra x
8383
| `Impl x -> Format.fprintf fmt "`Impl %a" pp_impl_extra x
8484
| `Mld -> Format.fprintf fmt "`Mld"
85+
| `Md -> Format.fprintf fmt "`Md"
8586
| `Asset -> Format.fprintf fmt "`Asset"
8687

8788
and pp_intf_extra fmt x =

src/driver/odoc_unit.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ type impl_extra = { src_id : Odoc.Id.t; src_path : Fpath.t }
4444
type impl = [ `Impl of impl_extra ]
4545

4646
type mld = [ `Mld ]
47-
47+
type md = [`Md]
4848
type asset = [ `Asset ]
4949

50-
type t = [ impl | intf | mld | asset ] unit
50+
type t = [ impl | intf | mld | asset | md ] unit
5151

5252
val pp : t Fmt.t
5353

src/driver/odoc_units_of.ml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,20 @@ let packages ~dirs ~extra_libs_paths (pkgs : Packages.t list) : t list =
214214
in
215215
[ unit ]
216216
in
217+
let of_md pkg (md :Fpath.t) : md unit list =
218+
let ext = Fpath.get_ext md in
219+
match ext with
220+
| ".md" ->
221+
let rel_dir = doc_dir pkg in
222+
let kind = `Md in
223+
let name = md |> Fpath.rem_ext |> Fpath.basename |> ( ^ ) "page-" in
224+
let lib_deps = Util.StringSet.empty in
225+
let unit = make_unit ~name ~kind ~rel_dir ~input_file:md ~pkg ~include_dirs:Fpath.Set.empty ~lib_deps in
226+
[ unit ]
227+
| _ ->
228+
Logs.debug (fun m -> m "Skipping non-markdown doc file %a" Fpath.pp md);
229+
[]
230+
in
217231
let of_asset pkg (asset : Packages.asset) : asset unit list =
218232
let open Fpath in
219233
let { Packages.asset_path; asset_rel_path } = asset in
@@ -234,6 +248,7 @@ let packages ~dirs ~extra_libs_paths (pkgs : Packages.t list) : t list =
234248
let lib_units :> t list list = List.map (of_lib pkg) pkg.libraries in
235249
let mld_units :> t list list = List.map (of_mld pkg) pkg.mlds in
236250
let asset_units :> t list list = List.map (of_asset pkg) pkg.assets in
251+
let md_units :> t list list = Fpath.Set.fold (fun md acc -> of_md pkg md :: acc) pkg.other_docs [] in
237252
let pkg_index :> t list =
238253
let has_index_page =
239254
List.exists
@@ -248,7 +263,7 @@ let packages ~dirs ~extra_libs_paths (pkgs : Packages.t list) : t list =
248263
let index = index_of pkg in
249264
[ Landing_pages.package ~dirs ~pkg ~index ]
250265
in
251-
List.concat ((pkg_index :: lib_units) @ mld_units @ asset_units)
266+
List.concat ((pkg_index :: lib_units) @ mld_units @ asset_units @ md_units)
252267
in
253268

254269
let pkg_list :> t = Landing_pages.package_list ~dirs pkgs in

0 commit comments

Comments
 (0)