summaryrefslogtreecommitdiff
path: root/typing/cmt_format.ml
diff options
context:
space:
mode:
Diffstat (limited to 'typing/cmt_format.ml')
-rw-r--r--typing/cmt_format.ml51
1 files changed, 26 insertions, 25 deletions
diff --git a/typing/cmt_format.ml b/typing/cmt_format.ml
index 56cfba3903..fda1a4a56f 100644
--- a/typing/cmt_format.ml
+++ b/typing/cmt_format.ml
@@ -166,30 +166,31 @@ let record_value_dependency vd1 vd2 =
let save_cmt filename modname binary_annots sourcefile initial_env cmi =
if !Clflags.binary_annotations && not !Clflags.print_types then begin
- let oc = open_out_bin filename in
- let this_crc =
- match cmi with
- | None -> None
- | Some cmi -> Some (output_cmi filename oc cmi)
- in
- let source_digest = Misc.may_map Digest.file sourcefile in
- let cmt = {
- cmt_modname = modname;
- cmt_annots = clear_env binary_annots;
- cmt_value_dependencies = !value_deps;
- cmt_comments = Lexer.comments ();
- cmt_args = Sys.argv;
- cmt_sourcefile = sourcefile;
- cmt_builddir = Sys.getcwd ();
- cmt_loadpath = !Config.load_path;
- cmt_source_digest = source_digest;
- cmt_initial_env = if need_to_clear_env then
- keep_only_summary initial_env else initial_env;
- cmt_imports = List.sort compare (Env.imports ());
- cmt_interface_digest = this_crc;
- cmt_use_summaries = need_to_clear_env;
- } in
- output_cmt oc cmt;
- close_out oc;
+ Misc.output_to_file_via_temporary
+ ~mode:[Open_binary] filename
+ (fun temp_file_name oc ->
+ let this_crc =
+ match cmi with
+ | None -> None
+ | Some cmi -> Some (output_cmi temp_file_name oc cmi)
+ in
+ let source_digest = Misc.may_map Digest.file sourcefile in
+ let cmt = {
+ cmt_modname = modname;
+ cmt_annots = clear_env binary_annots;
+ cmt_value_dependencies = !value_deps;
+ cmt_comments = Lexer.comments ();
+ cmt_args = Sys.argv;
+ cmt_sourcefile = sourcefile;
+ cmt_builddir = Sys.getcwd ();
+ cmt_loadpath = !Config.load_path;
+ cmt_source_digest = source_digest;
+ cmt_initial_env = if need_to_clear_env then
+ keep_only_summary initial_env else initial_env;
+ cmt_imports = List.sort compare (Env.imports ());
+ cmt_interface_digest = this_crc;
+ cmt_use_summaries = need_to_clear_env;
+ } in
+ output_cmt oc cmt)
end;
clear ()