2
2
3
3
type ty = Module of Packages .modulety | Mld of Packages .mld
4
4
5
- type impl = { impl_odoc : Fpath .t ; impl_odocl : Fpath .t ; src : Fpath .t }
5
+ type impl = { impl_odoc : Fpath .t ; impl_odocl : Fpath .t ; src : Fpath .t }
6
6
7
7
type pkg_args = {
8
8
docs : (string * Fpath .t ) list ;
@@ -69,7 +69,7 @@ let init_stats (pkgs : Packages.t Util.StringMap.t) =
69
69
70
70
open Eio.Std
71
71
72
- type partial =
72
+ type partial =
73
73
(string * compiled ) list * (string * Packages .modulety ) Util.StringMap .t
74
74
75
75
let unmarshal filename =
@@ -87,26 +87,34 @@ let marshal (v : partial) filename =
87
87
88
88
let find_partials odoc_dir =
89
89
let tbl = Hashtbl. create 1000 in
90
- let hashes_result = Bos.OS.Dir. fold_contents ~dotfiles: false
91
- (fun p hashes ->
92
- if Fpath. filename p = " index.m"
93
- then
94
- let (tbl', hashes') = unmarshal p in
95
- List. iter (fun (k ,v ) -> Hashtbl. replace tbl k (Promise. create_resolved (Ok v))) tbl';
96
- Util.StringMap. union (fun _x o1 _o2 -> Some o1) hashes hashes'
97
- else hashes) Util.StringMap. empty odoc_dir in
90
+ let hashes_result =
91
+ Bos.OS.Dir. fold_contents ~dotfiles: false
92
+ (fun p hashes ->
93
+ if Fpath. filename p = " index.m" then (
94
+ let tbl', hashes' = unmarshal p in
95
+ List. iter
96
+ (fun (k , v ) ->
97
+ Hashtbl. replace tbl k (Promise. create_resolved (Ok v)))
98
+ tbl';
99
+ Util.StringMap. union (fun _x o1 _o2 -> Some o1) hashes hashes')
100
+ else hashes)
101
+ Util.StringMap. empty odoc_dir
102
+ in
98
103
match hashes_result with
99
- | Ok h -> h, tbl
100
- | Error _ -> (* odoc_dir doesn't exist...? *) Util.StringMap. empty, tbl
104
+ | Ok h -> ( h, tbl)
105
+ | Error _ -> (* odoc_dir doesn't exist...? *) ( Util.StringMap. empty, tbl)
101
106
102
107
let compile partial ~output_dir ?linked_dir all =
103
108
let linked_dir = Option. value linked_dir ~default: output_dir in
104
109
let hashes = mk_byhash all in
105
110
let other_hashes, tbl =
106
111
match partial with
107
112
| Some _ -> find_partials output_dir
108
- | None -> Util.StringMap. empty, Hashtbl. create 10 in
109
- let all_hashes = Util.StringMap. union (fun _x o1 _o2 -> Some o1) hashes other_hashes in
113
+ | None -> (Util.StringMap. empty, Hashtbl. create 10 )
114
+ in
115
+ let all_hashes =
116
+ Util.StringMap. union (fun _x o1 _o2 -> Some o1) hashes other_hashes
117
+ in
110
118
let pkg_args =
111
119
let docs, libs =
112
120
Util.StringMap. fold
@@ -115,7 +123,8 @@ let compile partial ~output_dir ?linked_dir all =
115
123
let lib =
116
124
List. map
117
125
(fun lib ->
118
- ( lib.Packages. lib_name, Fpath. (output_dir // lib.Packages. odoc_dir )))
126
+ ( lib.Packages. lib_name,
127
+ Fpath. (output_dir // lib.Packages. odoc_dir) ))
119
128
pkg.Packages. libraries
120
129
in
121
130
let docs = doc :: docs and libs = List. rev_append lib libs in
@@ -165,7 +174,12 @@ let compile partial ~output_dir ?linked_dir all =
165
174
Odoc. compile_impl ~output_dir ~input_file: impl.mip_path
166
175
~includes ~parent_id: impl.mip_parent_id ~source_id: si.src_id;
167
176
Atomic. incr Stats. stats.compiled_impls;
168
- Some { impl_odoc = odoc_file; impl_odocl= odocl_file; src = si.src_path }
177
+ Some
178
+ {
179
+ impl_odoc = odoc_file;
180
+ impl_odocl = odocl_file;
181
+ src = si.src_path;
182
+ }
169
183
| None -> None )
170
184
| None -> None
171
185
in
@@ -203,81 +217,77 @@ let compile partial ~output_dir ?linked_dir all =
203
217
in
204
218
let to_build = Util.StringMap. bindings hashes |> List. map fst in
205
219
let mod_results = Fiber.List. map compile to_build in
206
- let zipped_res = List. map2 (fun a b -> (a,b)) to_build mod_results in
207
- let zipped = List. filter_map (function (a , Ok b ) -> Some (a,b) | _ -> None ) zipped_res in
220
+ let zipped_res = List. map2 (fun a b -> (a, b)) to_build mod_results in
221
+ let zipped =
222
+ List. filter_map (function a , Ok b -> Some (a, b) | _ -> None ) zipped_res
223
+ in
208
224
let mods =
209
225
List. filter_map (function Ok x -> Some x | Error _ -> None ) mod_results
210
226
in
211
- let result = Util.StringMap. fold
212
- (fun package_name (pkg : Packages.t ) acc ->
213
- Logs. debug (fun m ->
214
- m " Package %s mlds: [%a]" pkg.name
215
- Fmt. (list ~sep: sp Packages. pp_mld)
216
- pkg.mlds);
217
- List. fold_left
218
- (fun acc (mld : Packages.mld ) ->
219
- let odoc_file = Fpath. (output_dir // mld.Packages. mld_odoc_file) in
220
- let odocl_file = Fpath. (linked_dir // mld.Packages. mld_odocl_file) in
221
- let odoc_output_dir = Fpath. split_base odoc_file |> fst in
222
- Odoc. compile ~output_dir ~input_file: mld.mld_path
223
- ~includes: Fpath.Set. empty ~parent_id: mld.mld_parent_id;
224
- Atomic. incr Stats. stats.compiled_mlds;
225
- let include_dirs =
226
- List. map (fun f -> Fpath. (output_dir // f)) mld.mld_deps
227
- |> Fpath.Set. of_list
228
- in
229
- let include_dirs = Fpath.Set. add odoc_output_dir include_dirs in
230
- let odoc_output_dir = Fpath. split_base odoc_file |> fst in
231
- {
232
- m = Mld mld;
233
- odoc_output_dir;
234
- odoc_file;
235
- odocl_file;
236
- include_dirs;
237
- impl = None ;
238
- pkg_args;
239
- pkg_dir = mld.mld_pkg_dir;
240
- pkg_name = package_name;
241
- }
242
- :: acc)
243
- acc pkg.mlds)
244
- all mods in
227
+ let result =
228
+ Util.StringMap. fold
229
+ (fun package_name (pkg : Packages.t ) acc ->
230
+ Logs. debug (fun m ->
231
+ m " Package %s mlds: [%a]" pkg.name
232
+ Fmt. (list ~sep: sp Packages. pp_mld)
233
+ pkg.mlds);
234
+ List. fold_left
235
+ (fun acc (mld : Packages.mld ) ->
236
+ let odoc_file = Fpath. (output_dir // mld.Packages. mld_odoc_file) in
237
+ let odocl_file =
238
+ Fpath. (linked_dir // mld.Packages. mld_odocl_file)
239
+ in
240
+ let odoc_output_dir = Fpath. split_base odoc_file |> fst in
241
+ Odoc. compile ~output_dir ~input_file: mld.mld_path
242
+ ~includes: Fpath.Set. empty ~parent_id: mld.mld_parent_id;
243
+ Atomic. incr Stats. stats.compiled_mlds;
244
+ let include_dirs =
245
+ List. map (fun f -> Fpath. (output_dir // f)) mld.mld_deps
246
+ |> Fpath.Set. of_list
247
+ in
248
+ let include_dirs = Fpath.Set. add odoc_output_dir include_dirs in
249
+ let odoc_output_dir = Fpath. split_base odoc_file |> fst in
250
+ {
251
+ m = Mld mld;
252
+ odoc_output_dir;
253
+ odoc_file;
254
+ odocl_file;
255
+ include_dirs;
256
+ impl = None ;
257
+ pkg_args;
258
+ pkg_dir = mld.mld_pkg_dir;
259
+ pkg_name = package_name;
260
+ }
261
+ :: acc)
262
+ acc pkg.mlds)
263
+ all mods
264
+ in
245
265
246
266
(match partial with
247
267
| Some l -> marshal (zipped, hashes) Fpath. (l / " index.m" )
248
268
| None -> () );
249
269
result
250
270
251
- type linked = {
252
- output_file : Fpath .t ;
253
- src : Fpath .t option ;
254
- pkg_dir : Fpath .t ;
255
- }
271
+ type linked = { output_file : Fpath .t ; src : Fpath .t option ; pkg_dir : Fpath .t }
256
272
257
273
let link : compiled list -> _ =
258
274
fun compiled ->
259
275
let link : compiled -> linked list =
260
276
fun c ->
261
277
let includes = Fpath.Set. add c.odoc_output_dir c.include_dirs in
262
278
let link input_file output_file =
263
- let { pkg_args = { libs; docs }; pkg_name; _ } =
264
- c
265
- in
266
- Odoc. link ~input_file ~output_file ~includes ~libs ~docs ~current_package: pkg_name ()
279
+ let { pkg_args = { libs; docs }; pkg_name; _ } = c in
280
+ Odoc. link ~input_file ~output_file ~includes ~libs ~docs
281
+ ~current_package: pkg_name ()
267
282
in
268
283
let impl =
269
284
match c.impl with
270
285
| Some { impl_odoc; impl_odocl; src } ->
271
- Logs. debug (fun m -> m " Linking impl: %a -> %a" Fpath. pp impl_odoc Fpath. pp impl_odocl);
286
+ Logs. debug (fun m ->
287
+ m " Linking impl: %a -> %a" Fpath. pp impl_odoc Fpath. pp impl_odocl);
272
288
link impl_odoc impl_odocl;
273
289
Atomic. incr Stats. stats.linked_impls;
274
- [
275
- {
276
- pkg_dir = c.pkg_dir;
277
- output_file = impl_odocl;
278
- src = Some src;
279
- };
280
- ]
290
+ [ { pkg_dir = c.pkg_dir; output_file = impl_odocl; src = Some src } ]
281
291
| None -> []
282
292
in
283
293
match c.m with
@@ -290,12 +300,7 @@ let link : compiled list -> _ =
290
300
(match c.m with
291
301
| Module _ -> Atomic. incr Stats. stats.linked_units
292
302
| Mld _ -> Atomic. incr Stats. stats.linked_mlds);
293
- {
294
- output_file = c.odocl_file;
295
- src = None ;
296
- pkg_dir = c.pkg_dir;
297
- }
298
- :: impl
303
+ { output_file = c.odocl_file; src = None ; pkg_dir = c.pkg_dir } :: impl
299
304
in
300
305
Fiber.List. map link compiled |> List. concat
301
306
@@ -304,8 +309,7 @@ let index_one ~odocl_dir pkgname pkg =
304
309
let output_file = Fpath. (odocl_dir // dir / Odoc. index_filename) in
305
310
let libs =
306
311
List. map
307
- (fun lib ->
308
- (lib.Packages. lib_name, Fpath. (odocl_dir // lib.odoc_dir)))
312
+ (fun lib -> (lib.Packages. lib_name, Fpath. (odocl_dir // lib.odoc_dir)))
309
313
pkg.Packages. libraries
310
314
in
311
315
Odoc. compile_index ~json: false ~output_file ~libs
@@ -315,7 +319,9 @@ let index_one ~odocl_dir pkgname pkg =
315
319
let index ~odocl_dir pkgs = Util.StringMap. iter (index_one ~odocl_dir ) pkgs
316
320
317
321
let sherlodoc_index_one ~html_dir ~odocl_dir _ pkg_content =
318
- let inputs = [ Fpath. (odocl_dir // pkg_content.Packages. pkg_dir / Odoc. index_filename) ] in
322
+ let inputs =
323
+ [ Fpath. (odocl_dir // pkg_content.Packages. pkg_dir / Odoc. index_filename) ]
324
+ in
319
325
let dst = Fpath. (html_dir // Sherlodoc. db_js_file pkg_content.pkg_dir) in
320
326
let dst_dir, _ = Fpath. split_base dst in
321
327
Util. mkdir_p dst_dir;
@@ -331,20 +337,16 @@ let sherlodoc ~html_dir ~odocl_dir pkgs =
331
337
Util. mkdir_p dst_dir;
332
338
let inputs =
333
339
pkgs |> Util.StringMap. bindings
334
- |> List. map (fun (_pkgname , pkg ) -> Fpath. (odocl_dir // pkg.Packages. pkg_dir / Odoc. index_filename))
340
+ |> List. map (fun (_pkgname , pkg ) ->
341
+ Fpath. (odocl_dir // pkg.Packages. pkg_dir / Odoc. index_filename))
335
342
in
336
343
Sherlodoc. index ~format ~inputs ~dst ()
337
344
338
345
let html_generate output_dir ~odocl_dir linked =
339
346
let html_generate : linked -> unit =
340
347
fun l ->
341
- let search_uris =
342
- [
343
- Sherlodoc. db_js_file l.pkg_dir;
344
- Sherlodoc. js_file;
345
- ]
346
- in
347
- let index = Some (Fpath. (odocl_dir // l.pkg_dir / Odoc. index_filename)) in
348
+ let search_uris = [ Sherlodoc. db_js_file l.pkg_dir; Sherlodoc. js_file ] in
349
+ let index = Some Fpath. (odocl_dir // l.pkg_dir / Odoc. index_filename) in
348
350
Odoc. html_generate ~search_uris ?index
349
351
~output_dir: (Fpath. to_string output_dir)
350
352
~input_file: l.output_file ?source:l.src () ;
0 commit comments