Browse Source

bz-62617 tstamp task - Honor SOURCE_DATE_EPOCH to allow reproducible builds

master
Jaikiran Pai 5 years ago
parent
commit
1bfa7880af
5 changed files with 33 additions and 2 deletions
  1. +1
    -0
      CONTRIBUTORS
  2. +4
    -0
      WHATSNEW
  3. +4
    -0
      contributors.xml
  4. +7
    -0
      manual/Tasks/tstamp.html
  5. +17
    -2
      src/main/org/apache/tools/ant/taskdefs/Tstamp.java

+ 1
- 0
CONTRIBUTORS View File

@@ -221,6 +221,7 @@ Joseph Walton
Josh Lucas
Juerg Wanner
Julian Simpson
Julien Lepiller
Justin Vallon
Justyna Horwat
Karl Jansen


+ 4
- 0
WHATSNEW View File

@@ -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
=====================================



+ 4
- 0
contributors.xml View File

@@ -923,6 +923,10 @@
<first>Julian</first>
<last>Simpson</last>
</name>
<name>
<first>Julien</first>
<last>Lepiller</last>
</name>
<name>
<first>Justin</first>
<last>Vallon</last>


+ 7
- 0
manual/Tasks/tstamp.html View File

@@ -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>


+ 17
- 2
src/main/org/apache/tools/ant/taskdefs/Tstamp.java View File

@@ -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));


Loading…
Cancel
Save