summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Gross <jgross@mit.edu>2022-06-23 20:19:49 (GMT)
committerJason Gross <jgross@mit.edu>2022-06-23 20:19:49 (GMT)
commitbebc99540f5dce458c16870273ce9c24aa3a0748 (patch)
tree6347f7247b62b35af16adb0e6bdb8d60f20452ac
parent06b2f46bd1066335e4e21fe20c8584a1cb6c355d (diff)
parent0a069d65575a26399d029a69797a9c1d6118b952 (diff)
downloadcoq-v8.11.zip
coq-v8.11.tar.gz
coq-v8.11.tar.bz2
Merge PR #16234: [v8.11] Backport #15271: Delay removing native_compute .ml files until exitv8.11
-rw-r--r--kernel/nativelib.ml11
1 files changed, 9 insertions, 2 deletions
diff --git a/kernel/nativelib.ml b/kernel/nativelib.ml
index 97ec634..8305185 100644
--- a/kernel/nativelib.ml
+++ b/kernel/nativelib.ml
@@ -47,6 +47,11 @@ let () = at_exit (fun () ->
Pp.(str "Native compile: failed to cleanup: " ++
str(Printexc.to_string e) ++ fnl()))
+let delay_cleanup_file =
+ let toclean = ref [] in
+ let () = at_exit (fun () -> List.iter (fun f -> if Sys.file_exists f then Sys.remove f) !toclean) in
+ fun f -> if not !Flags.debug then toclean := f :: !toclean
+
(* We have to delay evaluation of include_dirs because coqlib cannot
be guessed until flags have been properly initialized. It also lets
us avoid forcing [my_temp_dir] if we don't need it (eg stdlib file
@@ -131,7 +136,9 @@ let call_compiler ?profile:(profile=false) ml_filename =
let compile fn code ~profile:profile =
write_ml_code fn code;
let r = call_compiler ~profile fn in
- if (not !Flags.debug) && Sys.file_exists fn then Sys.remove fn;
+ (* NB: to prevent reusing the same filename we MUST NOT remove the file until exit
+ cf #15263 *)
+ delay_cleanup_file fn;
r
let compile_library dir code fn =
@@ -147,7 +154,7 @@ let compile_library dir code fn =
let fn = dirname / basename in
write_ml_code fn ~header code;
let _ = call_compiler fn in
- if (not !Flags.debug) && Sys.file_exists fn then Sys.remove fn
+ delay_cleanup_file fn
let native_symbols = ref Names.DPmap.empty