Skip to content

Commit d851077

Browse files
committed
Sidebar generate: Update driver
1 parent e4b03f3 commit d851077

File tree

7 files changed

+65
-18
lines changed

7 files changed

+65
-18
lines changed

src/driver/compile.ml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -269,15 +269,22 @@ let html_generate ~occurrence_file output_dir linked =
269269
let compile_index : Odoc_unit.index -> _ =
270270
fun index ->
271271
let compile_index_one
272-
({ pkg_args; output_file; json; search_dir = _ } as index :
272+
({ pkg_args; output_file; json; search_dir = _; sidebar } as index :
273273
Odoc_unit.index) =
274274
let libs_linked = Odoc_unit.Pkg_args.linked_libs pkg_args in
275275
let pages_linked = Odoc_unit.Pkg_args.linked_pages pkg_args in
276276
let () =
277277
Odoc.compile_index ~json ~occurrence_file ~output_file ~libs:libs_linked
278278
~docs:pages_linked ()
279279
in
280-
sherlodoc_index_one ~output_dir index
280+
let sidebar =
281+
match sidebar with
282+
| None -> None
283+
| Some { output_file; json } ->
284+
Odoc.sidebar_generate ~output_file ~json index.output_file ();
285+
Some output_file
286+
in
287+
(sherlodoc_index_one ~output_dir index, sidebar)
281288
in
282289
match Hashtbl.find_opt tbl index.output_file with
283290
| None ->
@@ -305,17 +312,16 @@ let html_generate ~occurrence_file output_dir linked =
305312
Odoc.html_generate_asset ~output_dir ~input_file:l.odoc_file
306313
~asset_path:l.input_file ()
307314
| _ ->
308-
let search_uris, index =
315+
let search_uris, sidebar =
309316
match l.index with
310317
| None -> (None, None)
311318
| Some index ->
312-
let db_path = compile_index index in
319+
let db_path, sidebar = compile_index index in
313320
let search_uris = [ db_path; Sherlodoc.js_file ] in
314-
let index = index.output_file in
315-
(Some search_uris, Some index)
321+
(Some search_uris, sidebar)
316322
in
317-
Odoc.html_generate ?search_uris ?index ~output_dir ~input_file ();
318-
Odoc.html_generate ?search_uris ?index ~output_dir ~input_file
323+
Odoc.html_generate ?search_uris ?sidebar ~output_dir ~input_file ();
324+
Odoc.html_generate ?search_uris ?sidebar ~output_dir ~input_file
319325
~as_json:true ();
320326
Atomic.incr Stats.stats.generated_units
321327
in

src/driver/odoc.ml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ end
1818

1919
let index_filename = "index.odoc-index"
2020

21+
let sidebar_filename = "sidebar.odoc-sidebar"
22+
2123
type compile_deps = { digest : Digest.t; deps : (string * Digest.t) list }
2224

2325
let odoc = ref (Cmd.v "odoc")
@@ -179,11 +181,26 @@ let compile_index ?(ignore_output = false) ~output_file ?occurrence_file ~json
179181
in
180182
ignore @@ Cmd_outputs.submit log desc cmd (Some output_file)
181183

182-
let html_generate ~output_dir ?index ?(ignore_output = false)
184+
let sidebar_generate ?(ignore_output = false) ~output_file ~json input_file () =
185+
let json = if json then Cmd.v "--json" else Cmd.empty in
186+
let cmd =
187+
Cmd.(
188+
!odoc % "sidebar-generate" %% json %% v "-o" % p output_file
189+
% p input_file)
190+
in
191+
let desc =
192+
Printf.sprintf "Generating sidebar for %s" (Fpath.to_string output_file)
193+
in
194+
let log =
195+
if ignore_output then None else Some (`Generate, Fpath.to_string output_file)
196+
in
197+
ignore @@ Cmd_outputs.submit log desc cmd (Some output_file)
198+
199+
let html_generate ~output_dir ?sidebar ?(ignore_output = false)
183200
?(search_uris = []) ?(as_json = false) ~input_file:file () =
184201
let open Cmd in
185202
let index =
186-
match index with None -> empty | Some idx -> v "--index" % p idx
203+
match sidebar with None -> empty | Some idx -> v "--sidebar" % p idx
187204
in
188205
let search_uris =
189206
List.fold_left

src/driver/odoc.mli

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module Id : sig
66
end
77

88
val index_filename : string
9+
val sidebar_filename : string
910

1011
val odoc : Bos.Cmd.t ref
1112

@@ -50,9 +51,17 @@ val compile_index :
5051
unit ->
5152
unit
5253

54+
val sidebar_generate :
55+
?ignore_output:bool ->
56+
output_file:Fpath.t ->
57+
json:bool ->
58+
Fpath.t ->
59+
unit ->
60+
unit
61+
5362
val html_generate :
5463
output_dir:string ->
55-
?index:Fpath.t ->
64+
?sidebar:Fpath.t ->
5665
?ignore_output:bool ->
5766
?search_uris:Fpath.t list ->
5867
?as_json:bool ->

src/driver/odoc_unit.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,14 @@ module Pkg_args = struct
3636
x.odoc_dir Fpath.pp x.odocl_dir sfp_pp x.pages sfp_pp x.libs
3737
end
3838

39+
type sidebar = { output_file : Fpath.t; json : bool }
40+
3941
type index = {
4042
pkg_args : Pkg_args.t;
4143
output_file : Fpath.t;
4244
json : bool;
4345
search_dir : Fpath.t;
46+
sidebar : sidebar option;
4447
}
4548

4649
let pp_index fmt x =

src/driver/odoc_unit.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ module Pkg_args : sig
1616
val pp : t Fmt.t
1717
end
1818

19+
type sidebar = { output_file : Fpath.t; json : bool }
1920
type index = {
2021
pkg_args : Pkg_args.t;
2122
output_file : Fpath.t;
2223
json : bool;
2324
search_dir : Fpath.t;
25+
sidebar : sidebar option;
2426
}
2527

2628
type 'a unit = {

src/driver/odoc_units_of.ml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,17 @@ let packages ~dirs ~extra_paths (pkgs : Packages.t list) : t list =
8484
in
8585
let pkg_args = base_args pkg pkg_libs in
8686
let output_file = Fpath.(index_dir / pkg.name / Odoc.index_filename) in
87-
{ pkg_args; output_file; json = false; search_dir = pkg.pkg_dir }
87+
let sidebar =
88+
let output_file = Fpath.(index_dir / pkg.name / Odoc.sidebar_filename) in
89+
{ output_file; json = false }
90+
in
91+
{
92+
pkg_args;
93+
output_file;
94+
json = false;
95+
search_dir = pkg.pkg_dir;
96+
sidebar = Some sidebar;
97+
}
8898
in
8999

90100
let make_unit ~name ~kind ~rel_dir ~input_file ~pkg ~lib_deps ~enable_warnings

src/odoc/bin/main.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -553,14 +553,14 @@ module Sidebar = struct
553553
| Some file, `JSON when not (Fpath.has_ext "json" (Fpath.v file)) ->
554554
Error
555555
(`Msg
556-
"When generating a json index, the output must have a .json file \
557-
extension")
558-
| Some file, `Marshall when not (Fpath.has_ext "odoc-index" (Fpath.v file))
559-
->
556+
"When generating a sidebar with --json, the output must have a \
557+
.json file extension")
558+
| Some file, `Marshall
559+
when not (Fpath.has_ext "odoc-sidebar" (Fpath.v file)) ->
560560
Error
561561
(`Msg
562-
"When generating a binary index, the output must have a \
563-
.odoc-sidebar file extension")
562+
"When generating sidebar, the output must have a .odoc-sidebar \
563+
file extension")
564564
| Some file, _ -> Ok (Fs.File.of_string file)
565565
| None, `JSON -> Ok (Fs.File.of_string "sidebar.json")
566566
| None, `Marshall -> Ok (Fs.File.of_string "sidebar.odoc-sidebar")

0 commit comments

Comments
 (0)