Skip to content

Commit 41ba6f7

Browse files
committed
Driver: Add missing library dependencies
Because we are separating libraries which might be co-located in your opam switch, it sometimes happens that a package is using types from a library without expressing it in their META files. For example, `Odoc_classify` is using the `Cmx_format` module interface, which we put in the `compiler-libs.optcomp` package. It only links against `compiler-libs.common` though, and there is no explicit dependency on `compiler-libs.optcomp` which works because the two libraries are in the same directory. This commit fixes this problem by post-processing the `Packages.t` datatype, finding hashes that aren't in any declared library dependency and adding them to the deps of that library.
1 parent 64e5a4f commit 41ba6f7

18 files changed

+284
-176
lines changed

src/driver/cmd_outputs.ml

+24-19
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
1-
let submit desc cmd output_file =
2-
match Worker_pool.submit desc cmd output_file with
3-
| Ok x -> x
4-
| Error exn -> raise exn
5-
6-
let compile_output = ref [ "" ]
7-
8-
let compile_src_output = ref [ "" ]
1+
type log_dest =
2+
[ `Compile
3+
| `Compile_src
4+
| `Link
5+
| `Count_occurrences
6+
| `Generate
7+
| `Index
8+
| `Source_tree
9+
| `Sherlodoc
10+
| `Classify ]
911

10-
let link_output = ref [ "" ]
12+
let outputs : (log_dest * [ `Out | `Err ] * string * string) list ref = ref []
1113

12-
let generate_output = ref [ "" ]
14+
let maybe_log log_dest r =
15+
match log_dest with
16+
| Some (dest, prefix) ->
17+
let add ty s = outputs := !outputs @ [ (dest, ty, prefix, s) ] in
18+
add `Out r.Run.output;
19+
add `Err r.Run.errors
20+
| None -> ()
1321

14-
let index_output = ref [ "" ]
15-
16-
let source_tree_output = ref [ "" ]
17-
18-
let add_prefixed_output cmd list prefix lines =
19-
if List.length lines > 0 then
20-
list :=
21-
!list
22-
@ (Bos.Cmd.to_string cmd :: List.map (fun l -> prefix ^ ": " ^ l) lines)
22+
let submit log_dest desc cmd output_file =
23+
match Worker_pool.submit desc cmd output_file with
24+
| Ok x ->
25+
maybe_log log_dest x;
26+
String.split_on_char '\n' x.output
27+
| Error exn -> raise exn

src/driver/compile.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -213,20 +213,20 @@ let link : compiled list -> _ =
213213
fun compiled ->
214214
let link : compiled -> linked =
215215
fun c ->
216-
let link input_file output_file =
216+
let link input_file output_file enable_warnings =
217217
let libs = Odoc_unit.Pkg_args.compiled_libs c.pkg_args in
218218
let pages = Odoc_unit.Pkg_args.compiled_pages c.pkg_args in
219219
let includes = c.include_dirs in
220220
Odoc.link ~input_file ~output_file ~includes ~libs ~docs:pages
221-
?current_package:c.pkgname ()
221+
~ignore_output:(not enable_warnings) ?current_package:c.pkgname ()
222222
in
223223
match c.kind with
224224
| `Intf { hidden = true; _ } ->
225225
Logs.debug (fun m -> m "not linking %a" Fpath.pp c.odoc_file);
226226
c
227227
| _ ->
228228
Logs.debug (fun m -> m "linking %a" Fpath.pp c.odoc_file);
229-
link c.odoc_file c.odocl_file;
229+
link c.odoc_file c.odocl_file c.enable_warnings;
230230
(match c.kind with
231231
| `Intf _ -> Atomic.incr Stats.stats.linked_units
232232
| `Mld -> Atomic.incr Stats.stats.linked_mlds

src/driver/dune_style.ml

+2-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ let of_dune_describe txt =
3535
let dune_describe dir =
3636
let cmd = Cmd.(!dune % "describe" % "--root" % p dir) in
3737
let out = Worker_pool.submit "dune describe" cmd None in
38-
match out with
39-
| Error _ -> []
40-
| Ok out -> of_dune_describe (String.concat "\n" out)
38+
match out with Error _ -> [] | Ok out -> of_dune_describe out.Run.output
4139

4240
let of_dune_build dir =
4341
let contents =
@@ -124,6 +122,7 @@ let of_dune_build dir =
124122
assets =
125123
[]
126124
(* When dune has a notion of doc assets, do something *);
125+
enable_warnings = false;
127126
pkg_dir;
128127
other_docs = Fpath.Set.empty;
129128
config = Global_config.empty;

src/driver/landing_pages.ml

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ let make_index ~dirs ~rel_dir ?index ~content () =
1818
odoc_file;
1919
odocl_file;
2020
include_dirs = Fpath.Set.empty;
21+
enable_warnings = false;
2122
kind = `Mld;
2223
index;
2324
}

src/driver/ocamlfind.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ let rec dep =
7777
let deps pkgs =
7878
let results = List.map dep pkgs in
7979
Ok
80-
(List.fold_left Util.StringSet.union Util.StringSet.empty
80+
(List.fold_left Util.StringSet.union
81+
(Util.StringSet.singleton "stdlib")
8182
(List.map (Result.value ~default:Util.StringSet.empty) results))
8283

8384
module Db = struct

src/driver/ocamlobjinfo.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ let get_source file srcdirs =
2626
in
2727
let lines =
2828
match lines_res with
29-
| Ok l -> l
29+
| Ok l -> String.split_on_char '\n' l.output
3030
| Error e ->
3131
Logs.err (fun m ->
3232
m "Error finding source for module %a: %s" Fpath.pp file

src/driver/odoc.ml

+41-39
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ let odoc = ref (Cmd.v "odoc")
2525
let compile_deps f =
2626
let cmd = Cmd.(!odoc % "compile-deps" % Fpath.to_string f) in
2727
let desc = Printf.sprintf "Compile deps for %s" (Fpath.to_string f) in
28-
let deps = Cmd_outputs.submit desc cmd None in
28+
let deps = Cmd_outputs.submit None desc cmd None in
2929
let l = List.filter_map (Astring.String.cut ~sep:" ") deps in
3030
let basename = Fpath.(basename (f |> rem_ext)) |> String.capitalize_ascii in
3131
match List.partition (fun (n, _) -> basename = n) l with
@@ -49,9 +49,10 @@ let compile ~output_dir ~input_file:file ~includes ~parent_id =
4949
in
5050
let cmd = cmd % "--parent-id" % Id.to_string parent_id in
5151
let desc = Printf.sprintf "Compiling %s" (Fpath.to_string file) in
52-
let lines = Cmd_outputs.submit desc cmd output_file in
53-
Cmd_outputs.(
54-
add_prefixed_output cmd compile_output (Fpath.to_string file) lines)
52+
ignore
53+
@@ Cmd_outputs.submit
54+
(Some (`Compile, Fpath.to_string file))
55+
desc cmd output_file
5556

5657
let compile_asset ~output_dir ~name ~parent_id =
5758
let open Cmd in
@@ -65,8 +66,7 @@ let compile_asset ~output_dir ~name ~parent_id =
6566

6667
let cmd = cmd % "--parent-id" % Id.to_string parent_id in
6768
let desc = Printf.sprintf "Compiling %s" name in
68-
let lines = Cmd_outputs.submit desc cmd output_file in
69-
Cmd_outputs.(add_prefixed_output cmd compile_output name lines)
69+
ignore @@ Cmd_outputs.submit (Some (`Compile, name)) desc cmd output_file
7070

7171
let compile_impl ~output_dir ~input_file:file ~includes ~parent_id ~source_id =
7272
let open Cmd in
@@ -91,9 +91,10 @@ let compile_impl ~output_dir ~input_file:file ~includes ~parent_id ~source_id =
9191
let desc =
9292
Printf.sprintf "Compiling implementation %s" (Fpath.to_string file)
9393
in
94-
let lines = Cmd_outputs.submit desc cmd output_file in
95-
Cmd_outputs.(
96-
add_prefixed_output cmd compile_output (Fpath.to_string file) lines)
94+
ignore
95+
@@ Cmd_outputs.submit
96+
(Some (`Compile, Fpath.to_string file))
97+
desc cmd output_file
9798

9899
let doc_args docs =
99100
let open Cmd in
@@ -137,11 +138,10 @@ let link ?(ignore_output = false) ~input_file:file ?output_file ~includes ~docs
137138
if Fpath.to_string file = "stdlib.odoc" then cmd % "--open=\"\"" else cmd
138139
in
139140
let desc = Printf.sprintf "Linking %s" (Fpath.to_string file) in
140-
141-
let lines = Cmd_outputs.submit desc cmd (Some output_file) in
142-
if not ignore_output then
143-
Cmd_outputs.(
144-
add_prefixed_output cmd link_output (Fpath.to_string file) lines)
141+
let log =
142+
if ignore_output then None else Some (`Link, Fpath.to_string file)
143+
in
144+
ignore @@ Cmd_outputs.submit log desc cmd (Some output_file)
145145

146146
let compile_index ?(ignore_output = false) ~output_file ?occurrence_file ~json
147147
~docs ~libs () =
@@ -161,10 +161,10 @@ let compile_index ?(ignore_output = false) ~output_file ?occurrence_file ~json
161161
let desc =
162162
Printf.sprintf "Generating index for %s" (Fpath.to_string output_file)
163163
in
164-
let lines = Cmd_outputs.submit desc cmd (Some output_file) in
165-
if not ignore_output then
166-
Cmd_outputs.(
167-
add_prefixed_output cmd index_output (Fpath.to_string output_file) lines)
164+
let log =
165+
if ignore_output then None else Some (`Index, Fpath.to_string output_file)
166+
in
167+
ignore @@ Cmd_outputs.submit log desc cmd (Some output_file)
168168

169169
let html_generate ~output_dir ?index ?(ignore_output = false)
170170
?(search_uris = []) ?(as_json = false) ~input_file:file () =
@@ -182,10 +182,10 @@ let html_generate ~output_dir ?index ?(ignore_output = false)
182182
in
183183
let cmd = if as_json then cmd % "--as-json" else cmd in
184184
let desc = Printf.sprintf "Generating HTML for %s" (Fpath.to_string file) in
185-
let lines = Cmd_outputs.submit desc cmd None in
186-
if not ignore_output then
187-
Cmd_outputs.(
188-
add_prefixed_output cmd generate_output (Fpath.to_string file) lines)
185+
let log =
186+
if ignore_output then None else Some (`Generate, Fpath.to_string file)
187+
in
188+
ignore @@ Cmd_outputs.submit log desc cmd None
189189

190190
let html_generate_asset ~output_dir ?(ignore_output = false) ~input_file:file
191191
~asset_path () =
@@ -195,10 +195,10 @@ let html_generate_asset ~output_dir ?(ignore_output = false) ~input_file:file
195195
% p asset_path
196196
in
197197
let desc = Printf.sprintf "Copying asset %s" (Fpath.to_string file) in
198-
let lines = Cmd_outputs.submit desc cmd None in
199-
if not ignore_output then
200-
Cmd_outputs.(
201-
add_prefixed_output cmd generate_output (Fpath.to_string file) lines)
198+
let log =
199+
if ignore_output then None else Some (`Generate, Fpath.to_string file)
200+
in
201+
ignore @@ Cmd_outputs.submit log desc cmd None
202202

203203
let html_generate_source ~output_dir ?(ignore_output = false) ~source
204204
?(search_uris = []) ?(as_json = false) ~input_file:file () =
@@ -216,26 +216,25 @@ let html_generate_source ~output_dir ?(ignore_output = false) ~source
216216
let cmd = if as_json then cmd % "--as-json" else cmd in
217217

218218
let desc = Printf.sprintf "Generating HTML for %s" (Fpath.to_string source) in
219-
let lines = Cmd_outputs.submit desc cmd None in
220-
if not ignore_output then
221-
Cmd_outputs.(
222-
add_prefixed_output cmd generate_output (Fpath.to_string source) lines)
219+
let log =
220+
if ignore_output then None else Some (`Generate, Fpath.to_string source)
221+
in
222+
ignore @@ Cmd_outputs.submit log desc cmd None
223223

224224
let support_files path =
225225
let open Cmd in
226226
let cmd = !odoc % "support-files" % "-o" % Fpath.to_string path in
227227
let desc = "Generating support files" in
228-
Cmd_outputs.submit desc cmd None
228+
Cmd_outputs.submit None desc cmd None
229229

230230
let count_occurrences ~input ~output =
231231
let open Cmd in
232232
let input = Cmd.of_values Fpath.to_string input in
233233
let output_c = v "-o" % p output in
234234
let cmd = !odoc % "count-occurrences" %% input %% output_c in
235235
let desc = "Counting occurrences" in
236-
let lines = Cmd_outputs.submit desc cmd None in
237-
Cmd_outputs.(
238-
add_prefixed_output cmd generate_output (Fpath.to_string output) lines)
236+
let log = Some (`Count_occurrences, Fpath.to_string output) in
237+
ignore @@ Cmd_outputs.submit log desc cmd None
239238

240239
let source_tree ?(ignore_output = false) ~parent ~output file =
241240
let open Cmd in
@@ -244,19 +243,22 @@ let source_tree ?(ignore_output = false) ~parent ~output file =
244243
!odoc % "source-tree" % "-I" % "." %% parent % "-o" % p output % p file
245244
in
246245
let desc = Printf.sprintf "Source tree for %s" (Fpath.to_string file) in
247-
let lines = Cmd_outputs.submit desc cmd None in
248-
if not ignore_output then
249-
Cmd_outputs.(
250-
add_prefixed_output cmd source_tree_output (Fpath.to_string file) lines)
246+
let log =
247+
if ignore_output then None else Some (`Source_tree, Fpath.to_string file)
248+
in
249+
ignore @@ Cmd_outputs.submit log desc cmd None
251250

252251
let classify dirs =
253252
let open Cmd in
254253
let cmd = List.fold_left (fun cmd d -> cmd % p d) (!odoc % "classify") dirs in
255254
let desc =
256255
Format.asprintf "Classifying [%a]" (Fmt.(list ~sep:sp) Fpath.pp) dirs
257256
in
257+
let log =
258+
Some (`Classify, String.concat "," (List.map Fpath.to_string dirs))
259+
in
258260
let lines =
259-
Cmd_outputs.submit desc cmd None |> List.filter (fun l -> l <> "")
261+
Cmd_outputs.submit log desc cmd None |> List.filter (fun l -> l <> "")
260262
in
261263
List.map
262264
(fun line ->

src/driver/odoc_driver.ml

+25-6
Original file line numberDiff line numberDiff line change
@@ -667,17 +667,36 @@ let run mode
667667
(fun () -> render_stats env nb_workers)
668668
in
669669

670-
let grep_log l s =
670+
let grep_log ty s =
671671
let open Astring in
672672
let do_ affix =
673-
let grep l = if String.is_infix ~affix l then Format.printf "%s\n" l in
674-
List.iter grep l
673+
let grep (dst, _err, prefix, content) =
674+
if dst = ty then
675+
let lines = String.cuts ~sep:"\n" content in
676+
List.iter
677+
(fun l ->
678+
if String.is_infix ~affix l then Format.printf "%s: %s\n" prefix l)
679+
lines
680+
in
681+
List.iter grep !Cmd_outputs.outputs
675682
in
676683
Option.iter do_ s
677684
in
678-
grep_log !Cmd_outputs.compile_output compile_grep;
679-
grep_log !Cmd_outputs.link_output link_grep;
680-
grep_log !Cmd_outputs.generate_output generate_grep;
685+
grep_log `Compile compile_grep;
686+
grep_log `Link link_grep;
687+
grep_log `Generate generate_grep;
688+
689+
List.iter
690+
(fun (dst, _err, prefix, content) ->
691+
match dst with
692+
| `Link ->
693+
if String.length content = 0 then ()
694+
else
695+
let lines = String.split_on_char '\n' content in
696+
List.iter (fun l -> Format.printf "%s: %s\n" prefix l) lines
697+
| _ -> ())
698+
!Cmd_outputs.outputs;
699+
681700
Format.eprintf "Final stats: %a@.%!" Stats.pp_stats Stats.stats;
682701
Format.eprintf "Total time: %f@.%!" (Stats.total_time ());
683702
if stats then Stats.bench_results html_dir

src/driver/odoc_unit.ml

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ type 'a unit = {
5858
pkgname : string option;
5959
include_dirs : Fpath.Set.t;
6060
index : index option;
61+
enable_warnings : bool;
6162
kind : 'a;
6263
}
6364

src/driver/odoc_unit.mli

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type 'a unit = {
3333
pkgname : string option;
3434
include_dirs : Fpath.Set.t;
3535
index : index option;
36+
enable_warnings : bool;
3637
kind : 'a;
3738
}
3839

0 commit comments

Comments
 (0)