Package: glassfish
Version: 1:2.1.1-b31g+dfsg1-2
Severity: wishlist
Tags: patch
User: reproducible-bui...@lists.alioth.debian.org
Usertags: timestamps

glassfish is currently not a reproducible backage because of an embedded
datestamp in a couple places in toplink-essentials.  See:

  https://reproducible.debian.net/rb-pkg/unstable/amd64/glassfish.html

Below is a diagnosis and a patch.

entity-persistence/build.xml contains the following use of the ant
<tstamp> task (https://ant.apache.org/manual/Tasks/tstamp.html), which
ends up populating the properties build_number_string and
full_version_string:

--------------
    <tstamp>
       <format property="build_date" pattern="MM/dd/yyyy"/>
    </tstamp>
    <condition property="build_number" value="${build_id}">
        <not>
            <or>
                <equals arg1="${build_id}" arg2="" trim="true"/>
                <equals arg1="${build_id}" arg2="local" trim="true"/>
            </or>
        </not>
    </condition>
    <property name="build_number" value="SNAPSHOT"/>
    <property name="build_number_string" value="${build_number} 
(${build_date})"/>
    <property name="full_version" value="${release.version}-${build_number}"/>
    <property name="full_version_string" value="${full_version} 
(${build_date})"/>
--------------


those two properties are used in replacements during the build:

--------------
    <!-- prepare manifest files for jars -->
    <target name="cook-manifest" depends="init"
            description="Generate MANIFEST.MF files">
        <mkdir dir="${build.dir}/manifest"/>
        <copy todir="${build.dir}/manifest">
            <fileset dir="." includes="*.mf" />
            <filterset>
                <filter token="VERSION" value="${full_version_string}"/>
            </filterset>
        </copy>
    </target>
---------------

---------------
    <target name="compile" depends="init, antlr-generate"
            description="Compile TopLink Essentials sources">  
        <copy file="${src.dir}/oracle/toplink/essentials/Version.java" 
              
tofile="${component.classes.dir}/oracle/toplink/essentials/Version.java"/>
        <replace 
file="${component.classes.dir}/oracle/toplink/essentials/Version.java">
            <replacefilter token="@VERSION@" value="${release.version}"/>
            <replacefilter token="@BUILD_NUMBER@" 
value="${build_number_string}"/>
        </replace>

---------------

As a result, "VERSION" in the .mf files and @BUILD_NUMBER@ in the rest
of the code end up including the datestamp:

0 dkg@alice:~/src/glassfish/glassfish/entity-persistence$ find . -name '*.mf' 
-print0 | xargs -0 grep VERSION
./toplink-essentials-agent.mf:Implementation-Version: @VERSION@
./toplink-essentials.mf:Implementation-Version: @VERSION@
0 dkg@alice:~/src/glassfish/glassfish/entity-persistence$ git grep 
'@BUILD_NUMBER@'
build.xml:            <replacefilter token="@BUILD_NUMBER@" 
value="${build_number_string}"/>
src/java/oracle/toplink/essentials/Version.java:    private static final String 
buildNumber = "@BUILD_NUMBER@";
0 dkg@alice:~/src/glassfish/glassfish/entity-persistence$



The attached patch should make it possible to use an environment
variable $BUILD_DATE instead of the timestamp gathered by ant, if that
environment variable is set.  It also sets the environment variable in
debian/rules.

I am not an ant guru.  If you see a better way to do this, please
improve upon my patch!

        --dkg

From ddfc332ecd01f5d15a4f1fbd1f663390b0fe5c72 Mon Sep 17 00:00:00 2001
From: Daniel Kahn Gillmor <d...@fifthhorseman.net>
Date: Tue, 19 May 2015 10:46:25 -0400
Subject: [PATCH] make build reproducible

---
 ...TE-is-set-use-it-instead-of-the-current-t.patch | 28 ++++++++++++++++++++++
 debian/patches/series                              |  1 +
 debian/rules                                       |  4 ++++
 3 files changed, 33 insertions(+)
 create mode 100644 debian/patches/0006-if-BUILD_DATE-is-set-use-it-instead-of-the-current-t.patch

diff --git a/debian/patches/0006-if-BUILD_DATE-is-set-use-it-instead-of-the-current-t.patch b/debian/patches/0006-if-BUILD_DATE-is-set-use-it-instead-of-the-current-t.patch
new file mode 100644
index 0000000..4521b0d
--- /dev/null
+++ b/debian/patches/0006-if-BUILD_DATE-is-set-use-it-instead-of-the-current-t.patch
@@ -0,0 +1,28 @@
+From: Daniel Kahn Gillmor <d...@fifthhorseman.net>
+Date: Tue, 19 May 2015 10:32:15 -0400
+Subject: if $BUILD_DATE is set, use it instead of the current time
+
+This enables us to make the build reproducible by setting an
+environment variable before the build begins.
+---
+ entity-persistence/build.xml | 6 +++++-
+ 1 file changed, 5 insertions(+), 1 deletion(-)
+
+diff --git a/entity-persistence/build.xml b/entity-persistence/build.xml
+index 0262047..c77adee 100644
+--- a/entity-persistence/build.xml
++++ b/entity-persistence/build.xml
+@@ -66,8 +66,12 @@
+     <!-- versioning -->
+     <!-- ${build_id} will be given by the build system. Manual build is SNAPSHOT. --> 
+     <tstamp>
+-       <format property="build_date" pattern="MM/dd/yyyy"/>
++       <format property="build_date_now" pattern="MM/dd/yyyy"/>
+     </tstamp>
++    <property environment="env"/>
++    <condition property="build_date" value="${env.BUILD_DATE}" else="${build_date_now}">
++      <isset property="env.BUILD_DATE"/>
++    </condition>
+     <condition property="build_number" value="${build_id}">
+         <not>
+             <or>
diff --git a/debian/patches/series b/debian/patches/series
index bc4666b..ac7967c 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -3,3 +3,4 @@
 0003-Disable-SQL-exceptions.patch
 java7-compat.patch
 jaxp.patch
+0006-if-BUILD_DATE-is-set-use-it-instead-of-the-current-t.patch
diff --git a/debian/rules b/debian/rules
index 420f4c1..4a3cf4e 100755
--- a/debian/rules
+++ b/debian/rules
@@ -3,6 +3,10 @@
 include /usr/share/cdbs/1/class/ant.mk
 include /usr/share/cdbs/1/rules/debhelper.mk
 
+LAST_CHANGE=$(shell dpkg-parsechangelog -S Date)
+BUILD_DATE=$(shell LC_ALL=C date -u "+%m/%d/%Y" -d "$(LAST_CHANGE)")
+export BUILD_DATE
+
 JAVA_HOME               := /usr/lib/jvm/default-java
 DEB_ANT_BUILDFILE	:= debian/build.xml
 DEB_DESTDIR		:= $(CURDIR)/debian/tmp
-- 
2.1.4

Attachment: signature.asc
Description: PGP signature

Reply via email to