Package: ocaml / 4.02.3-9

0014-Compute-a-stable-name-for-preprocessed-files.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
From: Johannes Schauer <josch@debian.org>
Date: Thu, 22 Dec 2016 00:36:14 +0100
Subject: Compute a stable name for preprocessed files

---
 driver/pparse.ml | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/driver/pparse.ml b/driver/pparse.ml
index b67c180..321d0cc 100644
--- a/driver/pparse.ml
+++ b/driver/pparse.ml
@@ -18,10 +18,19 @@ type error =
 
 exception Error of error
 
+external open_desc: string -> open_flag list -> int -> int = "caml_sys_open"
+external close_desc: int -> unit = "caml_sys_close"
+
 (* Optionally preprocess a source file *)
 
 let call_external_preprocessor sourcefile pp =
-      let tmpfile = Filename.temp_file "ocamlpp" "" in
+      (* do not use Filename.temp_file as the resulting temporary file name will be
+       * recorded in the debug output of the resulting binary and thus make the
+       * output random and unreproducible *)
+      let temp_dir = Filename.get_temp_dir_name () in
+      let hash = Digest.to_hex (Digest.string (sourcefile^pp)) in
+      let tmpfile = Filename.concat temp_dir ("ocamlpp"^hash) in
+      close_desc(open_desc tmpfile [Open_wronly; Open_creat; Open_excl] 0o600);
       let comm = Printf.sprintf "%s %s > %s"
                                 pp (Filename.quote sourcefile) tmpfile
       in