gnu: Add kafs-client
[jackhill/guix/guix.git] / gnu / packages / patches / ocaml-enable-ocamldoc-reproducibility.patch
CommitLineData
6a8d3381
JL
1From a87c3f20e846c00e53d695497dba7038edbd12f0 Mon Sep 17 00:00:00 2001
2From: Valentin Lorentz <progval@progval.net>
3Date: Thu, 13 Aug 2015 11:59:04 +0200
4Subject: [PATCH] Enable ocamldoc to build reproducible manpages
5
6Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=794586
7Signed-off-by: Stephane Glondu <steph@glondu.net>
8---
9 ocamldoc/odoc_man.ml | 15 +++++----------
10 ocamldoc/odoc_misc.ml | 12 ++++++++++--
11 ocamldoc/odoc_misc.mli | 7 ++++++-
12 3 files changed, 21 insertions(+), 13 deletions(-)
13
14diff --git a/ocamldoc/odoc_man.ml b/ocamldoc/odoc_man.ml
15index 615c5e172..3c85aa32a 100644
16--- a/ocamldoc/odoc_man.ml
17+++ b/ocamldoc/odoc_man.ml
18@@ -864,14 +864,13 @@ class man =
19 (** Generate the man page for the given class.*)
20 method generate_for_class cl =
21 Odoc_info.reset_type_names () ;
22- let date = Unix.time () in
23 let file = self#file_name cl.cl_name in
24 try
25 let chanout = self#open_out file in
26 let b = new_buf () in
27 bs b (".TH \""^cl.cl_name^"\" ");
28 bs b !man_section ;
29- bs b (" "^(Odoc_misc.string_of_date ~hour: false date)^" ");
30+ bs b (" source: "^Odoc_misc.current_date^" ");
31 bs b "OCamldoc ";
32 bs b ("\""^(match !Global.title with Some t -> t | None -> "")^"\"\n");
33
34@@ -923,14 +922,13 @@ class man =
35 (** Generate the man page for the given class type.*)
36 method generate_for_class_type ct =
37 Odoc_info.reset_type_names () ;
38- let date = Unix.time () in
39 let file = self#file_name ct.clt_name in
40 try
41 let chanout = self#open_out file in
42 let b = new_buf () in
43 bs b (".TH \""^ct.clt_name^"\" ");
44 bs b !man_section ;
45- bs b (" "^(Odoc_misc.string_of_date ~hour: false date)^" ");
46+ bs b (" source: "^Odoc_misc.current_date^" ");
47 bs b "OCamldoc ";
48 bs b ("\""^(match !Global.title with Some t -> t | None -> "")^"\"\n");
49
50@@ -1016,14 +1014,13 @@ class man =
51 (** Generate the man file for the given module type.
52 @raise Failure if an error occurs.*)
53 method generate_for_module_type mt =
54- let date = Unix.time () in
55 let file = self#file_name mt.mt_name in
56 try
57 let chanout = self#open_out file in
58 let b = new_buf () in
59 bs b (".TH \""^mt.mt_name^"\" ");
60 bs b !man_section ;
61- bs b (" "^(Odoc_misc.string_of_date ~hour: false date)^" ");
62+ bs b (" source: "^Odoc_misc.current_date^" ");
63 bs b "OCamldoc ";
64 bs b ("\""^(match !Global.title with Some t -> t | None -> "")^"\"\n");
65
66@@ -1099,14 +1096,13 @@ class man =
67 (** Generate the man file for the given module.
68 @raise Failure if an error occurs.*)
69 method generate_for_module m =
70- let date = Unix.time () in
71 let file = self#file_name m.m_name in
72 try
73 let chanout = self#open_out file in
74 let b = new_buf () in
75 bs b (".TH \""^m.m_name^"\" ");
76 bs b !man_section ;
77- bs b (" "^(Odoc_misc.string_of_date ~hour: false date)^" ");
78+ bs b (" source: "^Odoc_misc.current_date^" ");
79 bs b "OCamldoc ";
80 bs b ("\""^(match !Global.title with Some t -> t | None -> "")^"\"\n");
81
82@@ -1206,14 +1202,13 @@ class man =
83 | Res_const (_,f) -> f.vc_name
84 )
85 in
86- let date = Unix.time () in
87 let file = self#file_name name in
88 try
89 let chanout = self#open_out file in
90 let b = new_buf () in
91 bs b (".TH \""^name^"\" ");
92 bs b !man_section ;
93- bs b (" "^(Odoc_misc.string_of_date ~hour: false date)^" ");
94+ bs b (" source: "^Odoc_misc.current_date^" ");
95 bs b "OCamldoc ";
96 bs b ("\""^(match !Global.title with Some t -> t | None -> "")^"\"\n");
97 bs b ".SH NAME\n";
98diff --git a/ocamldoc/odoc_misc.ml b/ocamldoc/odoc_misc.ml
99index 4c74476da..456225f62 100644
100--- a/ocamldoc/odoc_misc.ml
101+++ b/ocamldoc/odoc_misc.ml
102@@ -223,9 +223,9 @@ let apply_opt f v_opt =
103 None -> None
104 | Some v -> Some (f v)
105
106-let string_of_date ?(hour=true) d =
107+let string_of_date ?(absolute=false) ?(hour=true) d =
108 let add_0 s = if String.length s < 2 then "0"^s else s in
109- let t = Unix.localtime d in
110+ let t = (if absolute then Unix.gmtime else Unix.localtime) d in
111 (string_of_int (t.Unix.tm_year + 1900))^"-"^
112 (add_0 (string_of_int (t.Unix.tm_mon + 1)))^"-"^
113 (add_0 (string_of_int t.Unix.tm_mday))^
114@@ -238,6 +238,14 @@ let string_of_date ?(hour=true) d =
115 ""
116 )
117
118+let current_date =
119+ let time =
120+ try
121+ float_of_string (Sys.getenv "SOURCE_DATE_EPOCH")
122+ with
123+ Not_found -> Unix.time ()
124+ in string_of_date ~absolute: true ~hour: false time
125+
126
127 let rec text_list_concat sep l =
128 match l with
129diff --git a/ocamldoc/odoc_misc.mli b/ocamldoc/odoc_misc.mli
130index dd5a7fcb9..38ff0612b 100644
131--- a/ocamldoc/odoc_misc.mli
132+++ b/ocamldoc/odoc_misc.mli
133@@ -62,7 +62,12 @@ val apply_opt : ('a -> 'b) -> 'a option -> 'b option
134
135 (** Return a string representing a date given as a number of seconds
136 since 1970. The hour is optionnaly displayed. *)
137-val string_of_date : ?hour:bool -> float -> string
138+val string_of_date : ?absolute:bool -> ?hour:bool -> float -> string
139+
140+(* Value returned by string_of_date for current time.
141+ * Uses environment variable SOURCE_DATE_EPOCH if set; falls back to
142+ * current timestamp otherwise. *)
143+val current_date : string
144
145 (** Return the first sentence (until the first dot) of a text.
146 Don't stop in the middle of [Code], [Verbatim], [List], [Lnum],
147--
1482.17.1
149