File: reproducible-textclock.patch

package info (click to toggle)
awesome 4.3-8
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 6,460 kB
  • sloc: ansic: 14,508; sh: 526; makefile: 46
file content (45 lines) | stat: -rw-r--r-- 1,761 bytes parent folder | download | duplicates (4)
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
34
35
36
37
38
39
40
41
42
43
44
45
From: Uli Schlachter <psychon@znc.in>
Subject: [PATCH] textclock: Produce reproducible output
Origin: upstream, https://github.com/awesomeWM/awesome/pull/2622

When $SOURCE_DIRECTORY is set, we are most likely currently running the
examples test, i.e. generating images. These images end up in the
documentation.

To make the images reproducible, i.e. independent from the current time,
this commit makes the textclock honor $SOURCE_DATE_EPOCH if
$SOURCE_DIRECTORY is set.

See commit 9d7eaf02 for some more details.

Signed-off-by: Uli Schlachter <psychon@znc.in>

--- a/lib/wibox/widget/textclock.lua
+++ b/lib/wibox/widget/textclock.lua
@@ -17,6 +17,17 @@
 
 local textclock = { mt = {} }
 
+local DateTime_new_now = DateTime.new_now
+
+-- When $SOURCE_DATE_EPOCH and $SOURCE_DIRECTORY are both set, then this code is
+-- most likely being run by the test runner. Ensure reproducible dates.
+local source_date_epoch = tonumber(os.getenv("SOURCE_DATE_EPOCH"))
+if source_date_epoch and os.getenv("SOURCE_DIRECTORY") then
+    DateTime_new_now = function()
+        return DateTime.new_from_unix_utc(source_date_epoch)
+    end
+end
+
 --- Set the clock's format
 -- @property format
 -- @tparam string format The new time format.  This can contain pango markup
@@ -87,7 +98,7 @@
     w._private.timezone = tzid and TimeZone.new(tzid)
 
     function w._private.textclock_update_cb()
-        local str = DateTime.new_now(w._private.timezone or TimeZone.new_local()):format(w._private.format)
+        local str = DateTime_new_now(w._private.timezone or TimeZone.new_local()):format(w._private.format)
         if str == nil then
             require("gears.debug").print_warning("textclock: "
                     .. "g_date_time_format() failed for format "