REPRODUCIBLE_BUILD

Take the 4-5 line Debian patch and turn it into six dozen lines of
new code.  The submitted patch introduces use of several C library
routines that aren't presently in use, so would need testing by all
functional or nearly-functional ports to verify that it wouldn't
break anything.  It also switched the formatted build date+time
from localtime to UTC.  This makes the code conditional so it can
be ignored by anybody and avoid the risk of breakage.  And a lot of
the increase in size is comments attempting to explain what the new
conditional is for:  when REPRODUCIBLE_BUILD is defined, makedefs
will use getenv("SOURCE_DATE_EPOCH") (whose value is an integer
representing seconds since 1-Jan-1970) instead of current date+time
when generating date.h.  The purpose is to be able to rebuild at a
later date and produce an identical program, which doesn't happen
when compile time gets incorporated into the binary.

I've added some sanity checking to try to make sure the getenv()
value obtained isn't bogus.  And the version string put into date.h
will be slightly different, allowing someone who sees date.h or 'v'
output to tell whether SOURCE_DATE_EPOCH was involved:  showing
"<port> NetHack <version> last revision <date>" instead of the
usual "... last build <date>".

To test, checkout a new branch for building, make any local edits
to unixconf.h and config.h, including enabling REPRODUCIBLE_BUILD,
git add+commit them, then use
  SOURCE_DATE_EPOCH=`git log -1 --pretty=%ct` make install
Other ports will need a bit more work to set up the environment,
but can still use git to track file dates and supply the latest.
Building with alternate configurations could be accomplished by
using tags instead of 'log -1' or by using distinct build branches
where nothing is commited/merged/rebased after completed build.

Unresolved issue:  BUILD_DATE, VERSION_ID, and COPYRIGHT_BANNER_C
contain formatted date+time but omit timezone.  SOURCE_DATE_EPOCH
is assumed to be UTC but the formatted values don't say so, so it
might appear to be incorrect when compared with local time.  We
definitely don't want to start mucking about with timezones within
nethack, so I think we just live with this.  It's not an issue for
default configruation where REPRODUCIBLE_BUILD is left disabled.
This commit is contained in:
PatR
2016-03-31 17:56:11 -07:00
parent 9e0a9d96f9
commit c3ef98c4d1
3 changed files with 122 additions and 15 deletions

View File

@@ -11,6 +11,7 @@
* For "UNIX" select BSD, ULTRIX, SYSV, or HPUX in unixconf.h.
* A "VMS" option is not needed since the VMS C-compilers
* provide it (no need to change sec#1, vmsconf.h handles it).
* MacOSX uses the UNIX configruation, not the old MAC one.
*/
#define UNIX /* delete if no fork(), exec() available */
@@ -304,6 +305,28 @@
*/
/* #define DLB */ /* not supported on all platforms */
/*
* Defining REPRODUCIBLE_BUILD causes 'util/makedefs -v' to construct
* date+time in include/date.h (to be shown by nethack's 'v' command)
* from SOURCE_DATE_EPOCH in the build environment rather than use
* current date+time when makedefs is run.
*
* [The version string will show "last revision <date><time>" instead
* of "last build <date><time>" if SOURCE_DATE_EPOCH has a value
* which seems valid at the time date.h is generated. The person
* building the program is responsible for setting it correctly,
* and the value should be in UTC rather than local time. NetHack
* normally uses local time and doesn't display timezone so toggling
* REPRODUCIBLE_BUILD on or off might yield a date+time that appears
* to be incorrect relative to what the other setting produced.]
*
* Intent is to be able to rebuild the program with the same value
* and obtain an identical copy as was produced by a previous build.
* Not necessary for normal game play....
*/
/* #define REPRODUCIBLE_BUILD */ /* use getenv("SOURCE_DATE_EPOCH") instead
of current time when creating date.h */
/*
* Defining INSURANCE slows down level changes, but allows games that
* died due to program or system crashes to be resumed from the point