Skip to content

Commit 24b3817

Browse files
authored
Compiler: more debug for jsoo link (#1437)
1 parent fae1e6b commit 24b3817

File tree

1 file changed

+32
-19
lines changed

1 file changed

+32
-19
lines changed

compiler/lib/link_js.ml

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -281,16 +281,13 @@ let link ~output ~linkall ~mklib ~toplevel ~files ~resolve_sourcemap_url ~source
281281
, all )
282282
else requires, to_link, all))
283283
in
284-
let skip = StringSet.diff all to_link in
284+
let _skip = StringSet.diff all to_link in
285285
if (not (StringSet.is_empty missing)) && not mklib
286286
then
287287
failwith
288288
(Printf.sprintf
289289
"Could not find compilation unit for %s"
290290
(String.concat ~sep:", " (StringSet.elements missing)));
291-
if debug ()
292-
then
293-
Format.eprintf "Not linking %s@." (String.concat ~sep:", " (StringSet.elements skip));
294291
if times () then Format.eprintf " scan: %a@." Timer.print t;
295292
let sm = ref [] in
296293
let build_info = ref None in
@@ -309,6 +306,14 @@ let link ~output ~linkall ~mklib ~toplevel ~files ~resolve_sourcemap_url ~source
309306

310307
let build_info_emitted = ref false in
311308
List.iter files ~f:(fun (file, (build_info_for_file, units)) ->
309+
let is_runtime =
310+
match build_info_for_file with
311+
| Some bi -> (
312+
match Build_info.kind bi with
313+
| `Runtime -> Some bi
314+
| `Cma | `Exe | `Cmo | `Unknown -> None)
315+
| None -> None
316+
in
312317
let sm_for_file = ref None in
313318
let ic = Line_reader.open_ file in
314319
let skip ic = Line_reader.drop ic in
@@ -334,7 +339,7 @@ let link ~output ~linkall ~mklib ~toplevel ~files ~resolve_sourcemap_url ~source
334339
skip ic;
335340
if not !build_info_emitted
336341
then (
337-
let bi = if mklib then Build_info.with_kind bi `Cma else bi in
342+
let bi = Build_info.with_kind bi (if mklib then `Cma else `Unknown) in
338343
Line_writer.write_lines oc (Build_info.to_string bi);
339344
build_info_emitted := true)
340345
| Drop -> skip ic
@@ -348,15 +353,31 @@ let link ~output ~linkall ~mklib ~toplevel ~files ~resolve_sourcemap_url ~source
348353
warn
349354
"Warning: your program contains effect handlers; you should \
350355
probably run js_of_ocaml with option '--enable=effects'@.");
356+
(if mklib
357+
then
358+
let u = if linkall then { u with force_link = true } else u in
359+
Line_writer.write_lines oc (Unit_info.to_string u));
360+
let size = ref 0 in
361+
while
362+
match Line_reader.peek ic with
363+
| None -> false
364+
| Some line -> (
365+
match prefix_kind line with
366+
| `Other ->
367+
size := !size + String.length line + 1;
368+
true
369+
| `Json_base64 _ | `Url _ | `Build_info _ | `Unit -> false)
370+
do
371+
copy ic oc
372+
done;
351373
if debug ()
352374
then
353375
Format.eprintf
354-
"Copy %s@."
355-
(String.concat ~sep:"," (StringSet.elements u.provides));
356-
if mklib
357-
then
358-
let u = if linkall then { u with force_link = true } else u in
359-
Line_writer.write_lines oc (Unit_info.to_string u))
376+
"Copy %d bytes for %s@."
377+
!size
378+
(match is_runtime with
379+
| None -> String.concat ~sep:", " (StringSet.elements u.provides)
380+
| Some _ -> "the js runtime"))
360381
else (
361382
if debug ()
362383
then
@@ -381,14 +402,6 @@ let link ~output ~linkall ~mklib ~toplevel ~files ~resolve_sourcemap_url ~source
381402
read ();
382403
Line_writer.write oc "";
383404
Line_reader.close ic;
384-
let is_runtime =
385-
match build_info_for_file with
386-
| Some bi -> (
387-
match Build_info.kind bi with
388-
| `Runtime -> Some bi
389-
| `Cma | `Exe | `Cmo | `Unknown -> None)
390-
| None -> None
391-
in
392405
(match is_runtime with
393406
| None -> ()
394407
| Some bi ->

0 commit comments

Comments
 (0)