Skip to content

Commit

Permalink
build.xml: Add SOURCE_DATE_EPOCH support
Browse files Browse the repository at this point in the history
Set the "timestamp" attribute to the current time. When using
Ant >= 1.10.8, it can be overridden with the SOURCE_DATE_EPOCH
environment variable. With Ant >= 1.10.2, the ant.tstamp.now
property does the same thing.

Use <jar modificationtime="${timestamp}"> to set file timestamps
inside JARs.

Reproducible builds should now be possible by setting SOURCE_DATE_EPOCH
to a known value. Timestamps in JARs are in local timezone, thus
setting also TZ=UTC0 can be useful. For example, the committer date
of the latest commit provides a reasonable timestamp:

    $ SOURCE_DATE_EPOCH=$(git log -n1 --pretty=%ct) TZ=UTC0 ant
  • Loading branch information
Larhzu committed Jul 28, 2024
1 parent 5689e64 commit 39b7371
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ Building with Apache Ant

Notes about old build environments:

* If you are using Ant older than 1.10.2:

Edit `build.xml` and remove the `modificationtime="${timestamp}"`
attributes from the `<jar>` elements.

* If you are using Ant older than 1.9.8:

Edit `build.xml` and remove the release attributes from the
Expand Down
38 changes: 29 additions & 9 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

<property file="build.properties"/>

<tstamp>
<format property="timestamp" pattern="yyyy-MM-dd'T'HH:mm:ssXXX"/>
</tstamp>

<target name="clean"
description="Deletes all generated files">
<delete dir="${build_dir}"/>
Expand Down Expand Up @@ -71,7 +75,7 @@
description="Creates JAR packages">
<mkdir dir="${jar_dir}"/>

<jar destfile="${jar_dir}/xz.jar">
<jar destfile="${jar_dir}/xz.jar" modificationtime="${timestamp}">
<fileset dir="${classes_dir}" includes="org/tukaani/xz/**"/>
<zipfileset prefix="META-INF/versions/9/" dir="${classes9_dir}"
unless:true="${java8only}"/>
Expand All @@ -95,55 +99,69 @@
</manifest>
</jar>

<jar destfile="${jar_dir}/TestAllocSpeed.jar" basedir="${classes_dir}"
<jar destfile="${jar_dir}/TestAllocSpeed.jar"
modificationtime="${timestamp}"
basedir="${classes_dir}"
includes="TestAllocSpeed.class">
<manifest>
<attribute name="Main-Class" value="TestAllocSpeed"/>
<attribute name="Class-Path" value="xz.jar"/>
</manifest>
</jar>

<jar destfile="${jar_dir}/XZEncDemo.jar" basedir="${classes_dir}"
<jar destfile="${jar_dir}/XZEncDemo.jar"
modificationtime="${timestamp}"
basedir="${classes_dir}"
includes="XZEncDemo.class">
<manifest>
<attribute name="Main-Class" value="XZEncDemo"/>
<attribute name="Class-Path" value="xz.jar"/>
</manifest>
</jar>

<jar destfile="${jar_dir}/XZDecDemo.jar" basedir="${classes_dir}"
<jar destfile="${jar_dir}/XZDecDemo.jar"
modificationtime="${timestamp}"
basedir="${classes_dir}"
includes="XZDecDemo.class">
<manifest>
<attribute name="Main-Class" value="XZDecDemo"/>
<attribute name="Class-Path" value="xz.jar"/>
</manifest>
</jar>

<jar destfile="${jar_dir}/XZSeekEncDemo.jar" basedir="${classes_dir}"
<jar destfile="${jar_dir}/XZSeekEncDemo.jar"
modificationtime="${timestamp}"
basedir="${classes_dir}"
includes="XZSeekEncDemo.class">
<manifest>
<attribute name="Main-Class" value="XZSeekEncDemo"/>
<attribute name="Class-Path" value="xz.jar"/>
</manifest>
</jar>

<jar destfile="${jar_dir}/XZSeekDecDemo.jar" basedir="${classes_dir}"
<jar destfile="${jar_dir}/XZSeekDecDemo.jar"
modificationtime="${timestamp}"
basedir="${classes_dir}"
includes="XZSeekDecDemo.class">
<manifest>
<attribute name="Main-Class" value="XZSeekDecDemo"/>
<attribute name="Class-Path" value="xz.jar"/>
</manifest>
</jar>

<jar destfile="${jar_dir}/LZMAEncDemo.jar" basedir="${classes_dir}"
<jar destfile="${jar_dir}/LZMAEncDemo.jar"
modificationtime="${timestamp}"
basedir="${classes_dir}"
includes="LZMAEncDemo.class">
<manifest>
<attribute name="Main-Class" value="LZMAEncDemo"/>
<attribute name="Class-Path" value="xz.jar"/>
</manifest>
</jar>

<jar destfile="${jar_dir}/LZMADecDemo.jar" basedir="${classes_dir}"
<jar destfile="${jar_dir}/LZMADecDemo.jar"
modificationtime="${timestamp}"
basedir="${classes_dir}"
includes="LZMADecDemo.class">
<manifest>
<attribute name="Main-Class" value="LZMADecDemo"/>
Expand Down Expand Up @@ -176,9 +194,11 @@
preservelastmodified="true" overwrite="true"/>

<jar destfile="${maven_dir}/xz-${version}-javadoc.jar"
modificationtime="${timestamp}"
basedir="${doc_dir}"/>

<jar destfile="${maven_dir}/xz-${version}-sources.jar">
<jar destfile="${maven_dir}/xz-${version}-sources.jar"
modificationtime="${timestamp}">
<fileset dir="${src_dir}" includes="org/tukaani/xz/**"/>
<zipfileset prefix="META-INF/versions/9/" dir="${src9_dir}"/>
</jar>
Expand Down

0 comments on commit 39b7371

Please sign in to comment.