Skip to content

Commit 2323259

Browse files
authored
Read Library Names from Packages Correctly (#136)
* (refactor) rename some modules, group dune and ocamlobjinfo in library_names module * (fix) use findlib to read META, then extract module names for libs with ocamlobjinfo * remove dune-package parsing * filter out library names that contain __private__ * read library base name from META archive(byte) because filename was wrong Fixes #125 * remove Without_dune wrapper module * minor refactors * add a test case for reading library names from a dune package * refactor * pin odoc and odoc-parser to the same commit as the pipeline * don't fail when archive(byte) = "" * only consider META files without extension
1 parent 8ca85d9 commit 2323259

34 files changed

+367
-367
lines changed

dune-project

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@
5353
voodoo-lib
5454
; odoc.2.2.0 pinned by the pipeline
5555
(odoc
56-
(>= 2.2.0))
56+
(= 2.2.2))
57+
(odoc-parser
58+
(= 2.0.0))
5759
bos
5860
astring
5961
cmdliner
@@ -71,7 +73,9 @@
7173
voodoo-lib
7274
; odoc.2.2.0 pinned by the pipeline
7375
(odoc
74-
(>= 2.2.0))
76+
(= 2.2.2))
77+
(odoc-parser
78+
(= 2.0.0))
7579
conf-pandoc
7680
astring
7781
cmdliner

src/voodoo-do/do.ml

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -167,37 +167,28 @@ let run pkg_name ~blessed ~failed =
167167
match index_res with Ok index -> index | Error _ -> Index.empty
168168
in
169169

170-
let dune =
171-
match Dune.(find package >>= process_file) with
172-
| Ok x ->
173-
Format.eprintf "Got dune\n%!";
174-
Some x
175-
| Error (`Msg m) ->
176-
Format.eprintf "No dune: %s\n%!" m;
177-
None
178-
in
179170
let opam_file = match Opam.find package with Ok f -> Some f | _ -> None in
180171

181-
let libraries =
182-
match Ocamlobjinfo.find package with
183-
| Ok packages -> Ocamlobjinfo.process packages
184-
| Error _err -> []
185-
in
172+
let libraries = Library_names.get_libraries package in
186173

187174
let package_mlds, otherdocs = Package_mlds.find package in
188175

189176
let error_log = Error_log.find package in
190177

191-
let parent =
192-
Version.gen_parent package ~blessed ~modules ~dune ~libraries ~package_mlds
193-
~error_log ~failed
178+
let auto_generated_index_mld =
179+
Auto_generated_index_mld.gen package ~blessed ~modules ~libraries
180+
~package_mlds ~error_log ~failed
194181
in
195182

196-
let () = Package_info.gen ~output:output_path ~dune ~libraries in
183+
let () =
184+
Package_info.gen ~output:output_path ~libraries:libraries.libraries
185+
in
197186

198-
let sis = Compat.List.concat_map (get_source_info parent) prep in
187+
let sis =
188+
Compat.List.concat_map (get_source_info auto_generated_index_mld) prep
189+
in
199190
let this_index = InputSelect.select sis in
200-
Index.write this_index parent;
191+
Index.write this_index auto_generated_index_mld;
201192
let index = Index.combine this_index index in
202193
let rec compile h si compiled =
203194
if List.mem si.Sourceinfo.path compiled then compiled
@@ -212,16 +203,20 @@ let run pkg_name ~blessed ~failed =
212203
in
213204
let includes = IncludePaths.get index si in
214205
let output = Sourceinfo.output_file si in
215-
Odoc.compile ~parent:parent.Mld.name ~output si.path ~includes
216-
~children:[];
206+
Odoc.compile ~parent:auto_generated_index_mld.Mld.name ~output si.path
207+
~includes ~children:[];
217208
si.path :: compiled
218209
in
219210
let _ = ignore (Index.M.fold compile this_index.intern []) in
220-
let mldvs = Package_mlds.compile ~parent package_mlds in
211+
let mldvs =
212+
Package_mlds.compile ~parent:auto_generated_index_mld package_mlds
213+
in
221214
let unit_includes = IncludePaths.link index in
222215
let docs_includes = Package_mlds.include_paths mldvs in
223216
let all_includes = Fpath.Set.union unit_includes docs_includes in
224-
let all_includes = Fpath.Set.add (Mld.compile_dir parent) all_includes in
217+
let all_includes =
218+
Fpath.Set.add (Mld.compile_dir auto_generated_index_mld) all_includes
219+
in
225220
let output = Fpath.(v "html") in
226221
Util.mkdir_p output;
227222
Index.M.iter
@@ -240,16 +235,22 @@ let run pkg_name ~blessed ~failed =
240235
else Sourceinfo.output_odocl si :: acc)
241236
this_index.intern []
242237
in
243-
Odoc.link (Mld.output_file parent) ~includes:all_includes
244-
~output:(Mld.output_odocl parent);
238+
Odoc.link
239+
(Mld.output_file auto_generated_index_mld)
240+
~includes:all_includes
241+
~output:(Mld.output_odocl auto_generated_index_mld);
245242
List.iter
246243
(fun mldv ->
247244
Odoc.link (Mld.output_file mldv) ~includes:all_includes
248245
~output:(Mld.output_odocl mldv))
249246
mldvs;
250-
let odocls = odocls @ List.map Mld.output_odocl (parent :: mldvs) in
247+
let odocls =
248+
odocls @ List.map Mld.output_odocl (auto_generated_index_mld :: mldvs)
249+
in
251250
Format.eprintf "%d other files to copy\n%!" (List.length otherdocs);
252-
let otherdocs, _opam_file = Otherdocs.copy parent otherdocs opam_file in
251+
let otherdocs, _opam_file =
252+
Otherdocs.copy auto_generated_index_mld otherdocs opam_file
253+
in
253254
List.iter (fun p -> Format.eprintf "dest: %a\n%!" Fpath.pp p) otherdocs;
254255
List.iter (Odoc.html ~output) odocls;
255256
let () =
File renamed without changes.
File renamed without changes.

src/voodoo-gen/main.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ let generate_pkgver output_dir name_filter version_filter =
102102
Fpath.normalize @@ Odoc_odoc.Fs.File.append output_dir output_path
103103
in
104104
let paths =
105-
List.rev_map (Rendering.render ~output) files
105+
List.rev_map (Generate_html_docs.render ~output) files
106106
|> List.rev_map Result.get_ok |> List.flatten
107107
in
108108
let foutput =
@@ -116,7 +116,8 @@ let generate_pkgver output_dir name_filter version_filter =
116116
in
117117

118118
Package_info.gen ~input:parent ~output:output_prefix paths;
119-
Rendering.render_other ~parent ~otherdocs ~output |> Result.get_ok;
119+
Generate_html_docs.render_other ~parent ~otherdocs ~output
120+
|> Result.get_ok;
120121

121122
let otherdocs =
122123
let init = Voodoo_serialize.Status.Otherdocs.empty in

src/voodoo/version.ml renamed to src/voodoo/auto_generated_index_mld.ml

Lines changed: 13 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,20 @@
1-
let gen_with_dune (dune : Dune.t) =
2-
let libraries =
3-
if List.length dune.Dune.libraries = 0 then []
4-
else
5-
let x =
6-
List.map
7-
(fun l ->
8-
let a =
9-
match l.Dune.Library.ty with
10-
| Dune.Library.Wrapped w ->
11-
if Util.is_hidden w.alias_module then
12-
[
13-
Printf.sprintf "Documentation: {!module-%s}"
14-
w.main_module_name;
15-
]
16-
else
17-
[
18-
Printf.sprintf "Documentation: {!modules:%s}"
19-
(String.concat " "
20-
(List.map
21-
(fun s -> w.main_module_name ^ "." ^ s)
22-
w.modules));
23-
]
24-
| Dune.Library.Unwrapped u ->
25-
[
26-
Printf.sprintf "Documentation: {!modules:%s}"
27-
(String.concat " " u.modules);
28-
]
29-
| Dune.Library.Singleton s ->
30-
[ Printf.sprintf "Documentation: {!module-%s}" s ]
31-
in
32-
let deps =
33-
if List.length l.dependencies > 0 then
34-
[ "Dependencies:"; String.concat ", " l.dependencies ]
35-
else []
36-
in
37-
[ "{2 " ^ l.name ^ "}" ] @ a @ ("" :: deps))
38-
dune.libraries
39-
|> List.flatten
40-
in
41-
[
42-
"{1 Libraries}";
43-
"This package provides the following libraries (via dune):";
44-
]
45-
@ x
46-
in
47-
libraries
48-
49-
let gen_with_libraries (libraries : Ocamlobjinfo.t list) =
1+
let gen_with_libraries (libraries : Library_names.library list) =
502
let libraries =
513
if List.length libraries = 0 then []
524
else
535
let x =
546
List.map
55-
(fun { Ocamlobjinfo.library_name; units } ->
7+
(fun { Library_names.name; modules; _ } ->
568
let non_hidden =
57-
List.filter (fun x -> not (Util.is_hidden x)) units
9+
List.filter (fun x -> not (Util.is_hidden x)) modules
5810
in
5911
let a =
6012
[
6113
Printf.sprintf "Documentation: {!modules:%s}"
6214
(String.concat " " non_hidden);
6315
]
6416
in
65-
[ "{2 " ^ library_name ^ "}" ] @ a @ [ "" ])
17+
[ "{2 " ^ name ^ "}" ] @ a @ [ "" ])
6618
libraries
6719
|> List.flatten
6820
in
@@ -94,35 +46,28 @@ let gen_with_error l =
9446
]
9547

9648
let gen :
97-
dune:Dune.t option ->
98-
libraries:Ocamlobjinfo.t list ->
99-
error_log:Error_log.t ->
100-
failed:bool ->
101-
string =
102-
fun ~dune ~libraries ~error_log ~failed ->
49+
libraries:Library_names.t -> error_log:Error_log.t -> failed:bool -> string
50+
=
51+
fun ~libraries ~error_log ~failed ->
10352
Format.eprintf "libraries: [%s]\n%!"
10453
(String.concat ","
105-
(List.map (fun x -> x.Ocamlobjinfo.library_name) libraries));
54+
(List.map (fun x -> x.Library_names.name) libraries.libraries));
10655
let result =
10756
if failed then gen_with_error error_log
108-
else
109-
match dune with
110-
| Some d -> gen_with_dune d
111-
| _ -> gen_with_libraries libraries
57+
else gen_with_libraries libraries.libraries
11258
in
11359
String.concat "\n" result
11460

115-
let gen_parent :
61+
let gen :
11662
Package.t ->
11763
blessed:bool ->
11864
modules:string list ->
119-
dune:Dune.t option ->
120-
libraries:Ocamlobjinfo.t list ->
65+
libraries:Library_names.t ->
12166
package_mlds:Fpath.t list ->
12267
error_log:Error_log.t ->
12368
failed:bool ->
12469
Mld.t =
125-
fun package ~blessed ~modules ~dune ~libraries ~package_mlds ~error_log ~failed ->
70+
fun package ~blessed ~modules ~libraries ~package_mlds ~error_log ~failed ->
12671
let cwd = Fpath.v "." in
12772
let mld_index, mld_children =
12873
List.partition (fun mld -> Fpath.basename mld = "index.mld") package_mlds
@@ -174,7 +119,7 @@ let gen_parent :
174119

175120
let content =
176121
match mld_index with
177-
| [] -> gen ~dune ~libraries ~error_log ~failed
122+
| [] -> gen ~libraries ~error_log ~failed
178123
| x :: _ ->
179124
let ic = open_in (Fpath.to_string x) in
180125
let result = really_input_string ic (in_channel_length ic) in
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
val gen_parent :
1+
val gen :
22
Package.t ->
33
blessed:bool ->
44
modules:string list ->
5-
dune:Dune.t option ->
6-
libraries:Ocamlobjinfo.t list ->
5+
libraries:Library_names.t ->
76
package_mlds:Fpath.t list ->
87
error_log:Error_log.t ->
98
failed:bool ->
109
Mld.t
11-
(** [gen_parent] generates the content of the version page. *)
10+
(** [gen] generates an index.mld file for packages that don't have one. *)

src/voodoo/dune

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
(library
22
(name voodoo_lib)
33
(public_name voodoo-lib)
4-
(libraries astring fpath bos bos.setup sexplib yojson voodoo-lib.serialize))
4+
(libraries
5+
findlib
6+
astring
7+
fpath
8+
bos
9+
bos.setup
10+
sexplib
11+
yojson
12+
voodoo-lib.serialize))

0 commit comments

Comments
 (0)