File: 0009-reproducible-timestamp-task.patch

package info (click to toggle)
ant 1.10.15-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 22,624 kB
  • sloc: java: 146,950; xml: 39,939; sh: 504; perl: 135; javascript: 65; python: 53; jsp: 38; makefile: 35
file content (78 lines) | stat: -rw-r--r-- 3,029 bytes parent folder | download | duplicates (3)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
Description: Add support for the SOURCE_DATE_EPOCH variable in the Tstamp task
Author: Emmanuel Bourg <ebourg@apache.org>
Forwarded: no
--- a/src/main/org/apache/tools/ant/taskdefs/Tstamp.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Tstamp.java
@@ -78,11 +78,13 @@
         try {
             Date d = getNow();
             // Honour reproducible builds https://reproducible-builds.org/specs/source-date-epoch/#idm55
+            boolean reproducibleBuild = false;
             final String epoch = System.getenv(ENV_SOURCE_DATE_EPOCH);
             try {
                 if (epoch != null) {
                     // Value of SOURCE_DATE_EPOCH will be an integer, representing seconds.
                     d = new Date(Long.parseLong(epoch) * 1000L);
+                    reproducibleBuild = true;
                     log("Honouring environment variable " + ENV_SOURCE_DATE_EPOCH + " which has been set to " + epoch);
                 }
             } catch(NumberFormatException e) {
@@ -91,16 +93,35 @@
                         + " environment variable", Project.MSG_DEBUG);
             }
             final Date date = d;
-            customFormats.forEach(cts -> cts.execute(getProject(), date, getLocation()));
+            for (CustomFormat cts : customFormats) {
+                if (reproducibleBuild) {
+                    if (cts.getTimezone() == null) {
+                        cts.setTimezone("UTC");
+                    }
+                    if (cts.getLanguage() == null) {
+                        cts.setLocale("en_US");
+                    }
+                }
+                cts.execute(getProject(), d, getLocation());
+            }
 
             SimpleDateFormat dstamp = new SimpleDateFormat("yyyyMMdd");
+            if (reproducibleBuild) {
+                dstamp.setTimeZone(java.util.TimeZone.getTimeZone("UTC"));
+            }
             setProperty("DSTAMP", dstamp.format(d));
 
             SimpleDateFormat tstamp = new SimpleDateFormat("HHmm");
+            if (reproducibleBuild) {
+                tstamp.setTimeZone(java.util.TimeZone.getTimeZone("UTC"));
+            }
             setProperty("TSTAMP", tstamp.format(d));
 
             SimpleDateFormat today
                 = new SimpleDateFormat("MMMM d yyyy", Locale.US);
+            if (reproducibleBuild) {
+                today.setTimeZone(java.util.TimeZone.getTimeZone("UTC"));
+            }
             setProperty("TODAY", today.format(d));
 
         } catch (Exception e) {
@@ -235,6 +256,10 @@
             }
         }
 
+        String getLanguage() {
+            return language;
+        }
+
         /**
          * The timezone to use for displaying time.
          * The values are as defined by the Java TimeZone class.
@@ -245,6 +270,10 @@
             timeZone = TimeZone.getTimeZone(id);
         }
 
+        TimeZone getTimezone() {
+            return timeZone;
+        }
+
         /**
          * The numeric offset to the current time.
          * @param offset the offset to use.