Bug 61079 - allow to override timestamps
Summary: allow to override timestamps
Status: RESOLVED FIXED
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: unspecified
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: 1.9.10
Assignee: Ant Notifications List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-05-08 07:25 UTC by Bernhard M. Wiedemann
Modified: 2017-05-09 09:04 UTC (History)
0 users



Attachments
patch to implement this (1.37 KB, patch)
2017-05-08 07:25 UTC, Bernhard M. Wiedemann
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Bernhard M. Wiedemann 2017-05-08 07:25:42 UTC
Created attachment 34985 [details]
patch to implement this

To enable reproducible builds of various java packages, 
ant should allow to override the timestamps it inserts (such as 'TODAY')
Comment 1 Stefan Bodewig 2017-05-08 07:46:19 UTC
Thanks Bernhard

Traditionally Ant would use "magic" (system) properties for something like this rather than environment variables. This would also allow us to easily test the change.
Comment 2 Bernhard M. Wiedemann 2017-05-08 14:23:23 UTC
How would one use the magic properties?
And would that work without patching all ~100 packages individually
that call ant during build in openSUSE?
(we already have a patch for rpm to set the SOURCE_DATE_EPOCH variable globally
to the latest changelog date of a package)
Comment 3 Stefan Bodewig 2017-05-08 14:32:07 UTC
The magic properties would be something like -Dant.fixed.now=SOME_TS for each and every invocation. Ant's java code doesn't really use getEnv anywhere and we really want to keep it that way.

By packages I assume you are talking about SUSE packages that execute Ant to build, right?

Ant's wrapper shell script reacts to environment variables, in particular ANT_OPTS for parameters to send to the JVM (like max memory and so on) and ANT_ARGS for Ant itself. In a build farm like yours you'd set ANT_ARGS to contain the property call above.
Comment 4 Bernhard M. Wiedemann 2017-05-08 16:04:39 UTC
I tried to build jcodings with an added
export ANT_ARGS="-Dant.fixed.now=123456789"

but still get in
META-INF/MANIFEST.MF
Built-Date: 2018-06-14
Built-Time: 05:07:50

and google is not good at finding any examples for how to use this
Comment 5 Stefan Bodewig 2017-05-08 16:09:41 UTC
Oh, I'm sorry, we've been talking past each other.

I was referring to your patch and wanted to ask you to rewrite it to use a project property rather than an environment variable. The example I gave was for a time after a modified version of your patch had been applied (and ant.fixed.time would be the name of the hypothetical magic property).

I should be able to free up a bit of time tonight to add the feature to tstamp, don't bother with modifying the patch, I'll do so myself. The result will become available once 1.9.10 or 1.10.2 get released.
Comment 6 Bernhard M. Wiedemann 2017-05-08 16:17:45 UTC
ah, now I got it.
Thanks for doing the patch (I did not do much java coding after 1.0.x).

would be nice, if you could then link the patch here, so that I can also test it
before the official release.
Comment 7 Stefan Bodewig 2017-05-08 16:47:16 UTC
The property's name is ant.tstamp.now - added with git commit 966708a to master, will be in 1.9.10 and 1.10.2.
Comment 8 Stefan Bodewig 2017-05-08 16:47:44 UTC
many thanks
Comment 9 Bernhard M. Wiedemann 2017-05-08 19:58:01 UTC
I tested your patch and it works great. Thanks a lot.
Comment 10 Jan Mat 2017-05-09 06:08:28 UTC
You use "seconds sind epoch" to define 'now'.
  <target name="testMagicProperty">
    <local name="ant.tstamp.now"/>
    <property name="ant.tstamp.now" value="100000"/>
    <tstamp/>
    <au:assertPropertyEquals name="DSTAMP" value="19700102"/>
  </target>

Would it be more user friendly to use the ISO format instead/additionally?

  <target name="testMagicProperty">
    <local name="ant.tstamp.now.iso"/>
    <property name="ant.tstamp.now" value="2017-05-09T08:07"/>
    <tstamp/>
    <au:assertPropertyEquals name="DSTAMP" value="20170509"/>
  </target>
Comment 11 Stefan Bodewig 2017-05-09 06:57:00 UTC
yes, sounds reasonable.
Comment 12 Jan Mat 2017-05-09 09:04:25 UTC
I added a second MagicProperty 'ant.tstamp.now.iso'.
I used Java8 features, to a backport would require a little more work ;)