diff options
author | Jaikiran Pai <jaikiran@apache.org> | 2019-10-20 18:30:01 +0530 |
---|---|---|
committer | Jaikiran Pai <jaikiran@apache.org> | 2019-10-20 18:30:01 +0530 |
commit | 1bfa7880afc7cbbc1e3d73be5cfa77dc2fd216d2 (patch) | |
tree | 7a112c0be0523808550b4c8287368c20ed39bb1f | |
parent | 8511719cf38cfe9be3c000e89d448f7f13f49cba (diff) | |
download | ant-1bfa7880afc7cbbc1e3d73be5cfa77dc2fd216d2.tar.gz |
bz-62617 tstamp task - Honor SOURCE_DATE_EPOCH to allow reproducible builds
-rw-r--r-- | CONTRIBUTORS | 1 | ||||
-rw-r--r-- | WHATSNEW | 4 | ||||
-rw-r--r-- | contributors.xml | 4 | ||||
-rw-r--r-- | manual/Tasks/tstamp.html | 7 | ||||
-rw-r--r-- | src/main/org/apache/tools/ant/taskdefs/Tstamp.java | 19 |
5 files changed, 33 insertions, 2 deletions
diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 4d7a8cf6a..80171e788 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -221,6 +221,7 @@ Joseph Walton Josh Lucas Juerg Wanner Julian Simpson +Julien Lepiller Justin Vallon Justyna Horwat Karl Jansen @@ -20,6 +20,10 @@ Other changes: * The runant.py script should now work with Python 3. Github Pull Request #96 + * tstamp task now honors SOURCE_DATE_EPOCH environment variable for + reproducible builds (https://reproducible-builds.org/specs/source-date-epoch/#idm55) + Bugzilla Report 62617 + Changes from Ant 1.10.6 TO Ant 1.10.7 ===================================== diff --git a/contributors.xml b/contributors.xml index e73660bc9..61040c2bd 100644 --- a/contributors.xml +++ b/contributors.xml @@ -924,6 +924,10 @@ <last>Simpson</last> </name> <name> + <first>Julien</first> + <last>Lepiller</last> + </name> + <name> <first>Justin</first> <last>Vallon</last> </name> diff --git a/manual/Tasks/tstamp.html b/manual/Tasks/tstamp.html index 43609596f..1661392a1 100644 --- a/manual/Tasks/tstamp.html +++ b/manual/Tasks/tstamp.html @@ -44,6 +44,13 @@ you could also specify that value in ISO-8601 format (<code>1972-04-17T08:07:00Z specify a value in an invalid format an INFO message will be logged and the value will be ignored.</p> +<p> + <em>Since Ant 1.10.8</em> the <code>SOURCE_DATE_EPOCH</code> environment variable value (if set) + will be honoured for <a href="https://reproducible-builds.org/specs/source-date-epoch/#idm55">reproducible builds</a>. + Ant will log a DEBUG message if an invalid value (value that cannot be parsed to an integer), is specified + for that environment variable and will instead use the "current" date. +</p> + <h3>Parameters</h3> <table class="attr"> <tr> diff --git a/src/main/org/apache/tools/ant/taskdefs/Tstamp.java b/src/main/org/apache/tools/ant/taskdefs/Tstamp.java index 226419c31..077052d44 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Tstamp.java +++ b/src/main/org/apache/tools/ant/taskdefs/Tstamp.java @@ -50,6 +50,8 @@ import org.apache.tools.ant.types.EnumeratedAttribute; */ public class Tstamp extends Task { + private static final String ENV_SOURCE_DATE_EPOCH = "SOURCE_DATE_EPOCH"; + private List<CustomFormat> customFormats = new Vector<>(); private String prefix = ""; @@ -75,8 +77,21 @@ public class Tstamp extends Task { public void execute() throws BuildException { try { Date d = getNow(); - - customFormats.forEach(cts -> cts.execute(getProject(), d, getLocation())); + // Honour reproducible builds https://reproducible-builds.org/specs/source-date-epoch/#idm55 + 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(Integer.parseInt(epoch) * 1000); + } + log("Honouring environment variable " + ENV_SOURCE_DATE_EPOCH + " which has been set to " + epoch); + } catch(NumberFormatException e) { + // ignore + log("Ignoring invalid value '" + epoch + "' for " + ENV_SOURCE_DATE_EPOCH + + " environment variable", Project.MSG_DEBUG); + } + final Date date = d; + customFormats.forEach(cts -> cts.execute(getProject(), date, getLocation())); SimpleDateFormat dstamp = new SimpleDateFormat("yyyyMMdd"); setProperty("DSTAMP", dstamp.format(d)); |