Compute a stable name for preprocessed files
authorJohannes Schauer <josch@debian.org>
Wed, 21 Dec 2016 23:36:14 +0000 (00:36 +0100)
committerStéphane Glondu <glondu@debian.org>
Tue, 6 Aug 2019 07:27:23 +0000 (09:27 +0200)
Gbp-Pq: Name 0014-Compute-a-stable-name-for-preprocessed-files.patch

driver/pparse.ml

index b00ded4077671f4f6f881347d88958ea53dbc120..13d76bc188045ce83169216b98d207b0dc865cc7 100644 (file)
@@ -21,10 +21,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