|
@@ -21,7 +21,17 @@ let check_auxiliary_output com actx =
|
|
Genjson.generate com.types file
|
|
Genjson.generate com.types file
|
|
end
|
|
end
|
|
|
|
|
|
-let export_hxb com config cc platform zip m =
|
|
|
|
|
|
+let create_writer com config string_pool =
|
|
|
|
+ let anon_identification = new tanon_identification in
|
|
|
|
+ let warn w s p = com.Common.warning w com.warning_options s p in
|
|
|
|
+ let writer = HxbWriter.create config string_pool warn anon_identification in
|
|
|
|
+ writer,(fun () ->
|
|
|
|
+ let out = IO.output_string () in
|
|
|
|
+ HxbWriter.export writer out;
|
|
|
|
+ IO.close_out out
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+let export_hxb from_cache com config string_pool cc platform zip m =
|
|
let open HxbData in
|
|
let open HxbData in
|
|
match m.m_extra.m_kind with
|
|
match m.m_extra.m_kind with
|
|
| MCode | MMacro | MFake | MExtern -> begin
|
|
| MCode | MMacro | MFake | MExtern -> begin
|
|
@@ -29,8 +39,8 @@ let export_hxb com config cc platform zip m =
|
|
let l = platform :: (fst m.m_path @ [snd m.m_path]) in
|
|
let l = platform :: (fst m.m_path @ [snd m.m_path]) in
|
|
let path = (String.concat "/" l) ^ ".hxb" in
|
|
let path = (String.concat "/" l) ^ ".hxb" in
|
|
|
|
|
|
- try
|
|
|
|
- let hxb_cache = cc#get_hxb_module m.m_path in
|
|
|
|
|
|
+ if from_cache then begin
|
|
|
|
+ let hxb_cache = try cc#get_hxb_module m.m_path with Not_found -> raise Abort in
|
|
let out = IO.output_string () in
|
|
let out = IO.output_string () in
|
|
write_header out;
|
|
write_header out;
|
|
List.iter (fun (kind,data) ->
|
|
List.iter (fun (kind,data) ->
|
|
@@ -39,14 +49,12 @@ let export_hxb com config cc platform zip m =
|
|
) hxb_cache.mc_chunks;
|
|
) hxb_cache.mc_chunks;
|
|
let data = IO.close_out out in
|
|
let data = IO.close_out out in
|
|
zip#add_entry data path;
|
|
zip#add_entry data path;
|
|
- with Not_found ->
|
|
|
|
- let anon_identification = new tanon_identification in
|
|
|
|
- let warn w s p = com.Common.warning w com.warning_options s p in
|
|
|
|
- let writer = HxbWriter.create config warn anon_identification in
|
|
|
|
|
|
+ end else begin
|
|
|
|
+ let writer,close = create_writer com config string_pool in
|
|
HxbWriter.write_module writer m;
|
|
HxbWriter.write_module writer m;
|
|
- let out = IO.output_string () in
|
|
|
|
- HxbWriter.export writer out;
|
|
|
|
- zip#add_entry (IO.close_out out) path;
|
|
|
|
|
|
+ let bytes = close () in
|
|
|
|
+ zip#add_entry bytes path;
|
|
|
|
+ end
|
|
end
|
|
end
|
|
| _ ->
|
|
| _ ->
|
|
()
|
|
()
|
|
@@ -54,41 +62,61 @@ let export_hxb com config cc platform zip m =
|
|
let check_hxb_output ctx config =
|
|
let check_hxb_output ctx config =
|
|
let open HxbWriterConfig in
|
|
let open HxbWriterConfig in
|
|
let com = ctx.com in
|
|
let com = ctx.com in
|
|
|
|
+ let write_string_pool config zip name pool =
|
|
|
|
+ let writer,close = create_writer com config (Some pool) in
|
|
|
|
+ let a = StringPool.finalize writer.cp in
|
|
|
|
+ HxbWriter.HxbWriter.write_string_pool writer STR a;
|
|
|
|
+ let bytes = close () in
|
|
|
|
+ zip#add_entry bytes name;
|
|
|
|
+ in
|
|
let match_path_list l sl_path =
|
|
let match_path_list l sl_path =
|
|
List.exists (fun sl -> Ast.match_path true sl_path sl) l
|
|
List.exists (fun sl -> Ast.match_path true sl_path sl) l
|
|
in
|
|
in
|
|
- let try_write () =
|
|
|
|
|
|
+ let try_write from_cache =
|
|
let path = config.HxbWriterConfig.archive_path in
|
|
let path = config.HxbWriterConfig.archive_path in
|
|
let path = Str.global_replace (Str.regexp "\\$target") (platform_name ctx.com.platform) path in
|
|
let path = Str.global_replace (Str.regexp "\\$target") (platform_name ctx.com.platform) path in
|
|
let t = Timer.timer ["generate";"hxb"] in
|
|
let t = Timer.timer ["generate";"hxb"] in
|
|
Path.mkdir_from_path path;
|
|
Path.mkdir_from_path path;
|
|
let zip = new Zip_output.zip_output path 6 in
|
|
let zip = new Zip_output.zip_output path 6 in
|
|
- let export com config =
|
|
|
|
|
|
+ let export com config string_pool =
|
|
let cc = CommonCache.get_cache com in
|
|
let cc = CommonCache.get_cache com in
|
|
let target = Common.platform_name_macro com in
|
|
let target = Common.platform_name_macro com in
|
|
|
|
+
|
|
List.iter (fun m ->
|
|
List.iter (fun m ->
|
|
let t = Timer.timer ["generate";"hxb";s_type_path m.m_path] in
|
|
let t = Timer.timer ["generate";"hxb";s_type_path m.m_path] in
|
|
let sl_path = fst m.m_path @ [snd m.m_path] in
|
|
let sl_path = fst m.m_path @ [snd m.m_path] in
|
|
if not (match_path_list config.exclude sl_path) || match_path_list config.include' sl_path then
|
|
if not (match_path_list config.exclude sl_path) || match_path_list config.include' sl_path then
|
|
- Std.finally t (export_hxb com config cc target zip) m
|
|
|
|
|
|
+ Std.finally t (export_hxb from_cache com config string_pool cc target zip) m
|
|
) com.modules;
|
|
) com.modules;
|
|
in
|
|
in
|
|
Std.finally (fun () ->
|
|
Std.finally (fun () ->
|
|
zip#close;
|
|
zip#close;
|
|
t()
|
|
t()
|
|
) (fun () ->
|
|
) (fun () ->
|
|
- if config.target_config.generate then
|
|
|
|
- export com config.target_config;
|
|
|
|
- begin match com.get_macros() with
|
|
|
|
- | Some mcom when config.macro_config.generate ->
|
|
|
|
- export mcom config.macro_config
|
|
|
|
- | _ ->
|
|
|
|
- ()
|
|
|
|
|
|
+ let string_pool = if config.share_string_pool then Some (StringPool.create ()) else None in
|
|
|
|
+ if config.target_config.generate then begin
|
|
|
|
+ export com config.target_config string_pool;
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+ if config.macro_config.generate then begin
|
|
|
|
+ match com.get_macros() with
|
|
|
|
+ | Some mcom ->
|
|
|
|
+ let use_separate_pool = config.share_string_pool && from_cache in
|
|
|
|
+ let string_pool = if use_separate_pool then Some (StringPool.create ()) else string_pool in
|
|
|
|
+ export mcom config.macro_config string_pool;
|
|
|
|
+ if use_separate_pool then write_string_pool config.macro_config zip "StringPool.macro.hxb" (Option.get string_pool)
|
|
|
|
+ | _ ->
|
|
|
|
+ ()
|
|
end;
|
|
end;
|
|
|
|
+
|
|
|
|
+ if config.share_string_pool then
|
|
|
|
+ write_string_pool config.target_config zip "StringPool.hxb" (Option.get string_pool);
|
|
) ()
|
|
) ()
|
|
in
|
|
in
|
|
try
|
|
try
|
|
- try_write ()
|
|
|
|
|
|
+ (* This Abort case shouldn't happen, unless some modules are not stored in hxb cache (which should not be the case currently) *)
|
|
|
|
+ if ctx.comm.is_server then try try_write true with Abort -> try_write false
|
|
|
|
+ else try_write false
|
|
with Sys_error s ->
|
|
with Sys_error s ->
|
|
CompilationContext.error ctx (Printf.sprintf "Could not write to %s: %s" config.archive_path s) null_pos
|
|
CompilationContext.error ctx (Printf.sprintf "Could not write to %s: %s" config.archive_path s) null_pos
|
|
|
|
|