[Git][NTPsec/ntpsec][master] 3 commits: waf: define EPOCH=[build-date], for reproducable builds.

Gary E. Miller gitlab at mg.gitlab.com
Thu Apr 20 20:26:53 UTC 2017


Gary E. Miller pushed to branch master at NTPsec / ntpsec


Commits:
2f9635e1 by Gary E. Miller at 2017-04-20T12:13:27-07:00
waf: define EPOCH=[build-date], for reproducable builds.

Sort of per: https://reproducible-builds.org/specs/source-date-epoch/

EPOCH is set to the first of:
--epoch=[seconds of UNIX epoch]
SOURCE_DATE_EPOCH from the environment
configure time seconds of UNIX epoch

The spec would prefer the last source modification for the last one,
but close enough for now.

- - - - -
62936230 by Gary E. Miller at 2017-04-20T12:26:21-07:00
EPOCH: remove REPRO_DATE and NTPD_IGNORE_BUILD_DATE.

They do not comply with the repro build spec.  Will be replaced
by EPOCH.

- - - - -
ff5c0d78 by Gary E. Miller at 2017-04-20T13:25:52-07:00
ntpcal_get_build_date: now uses EPOCH.

Another step to reproduceable build.

- - - - -


4 changed files:

- devel/ifdex-ignores
- libntp/ntp_calendar.c
- wafhelpers/configure.py
- wafhelpers/options.py


Changes:

=====================================
devel/ifdex-ignores
=====================================
--- a/devel/ifdex-ignores
+++ b/devel/ifdex-ignores
@@ -39,7 +39,6 @@ ISC_PLATFORM_USEBACKTRACE	# Use the ISC backtrace code on assertions
 ISC_UTIL_TRACEON	# Enables trace code in ISC service routines.
 HAVE_LIBCTRACE		# Some random C tracing lib - NTP Classic never sets this
 DEBUG_PARSELIB		# Enable debugging in the parse library.
-MKREPRO_DATE		# Force the build date used for time stepping
 NTP_DEBUG_LISTS		# Debug list handling
 DEBUG_PPS720		# Only in refclock_true.c
 


=====================================
libntp/ntp_calendar.c
=====================================
--- a/libntp/ntp_calendar.c
+++ b/libntp/ntp_calendar.c
@@ -58,79 +58,35 @@ ntpcal_get_build_date(
 	struct calendar * jd
 	)
 {
-	/* The C standard tells us the format of '__DATE__':
-	 *
-	 * __DATE__ The date of translation of the preprocessing
-	 * translation unit: a character string literal of the form "Mmm
-	 * dd yyyy", where the names of the months are the same as those
-	 * generated by the asctime function, and the first character of
-	 * dd is a space character if the value is less than 10. If the
-	 * date of translation is not available, an
-	 * implementation-defined valid date shall be supplied.
-	 *
-	 * __TIME__ The time of translation of the preprocessing
-	 * translation unit: a character string literal of the form
-	 * "hh:mm:ss" as in the time generated by the asctime
-	 * function. If the time of translation is not available, an
-	 * implementation-defined valid time shall be supplied.
-	 *
-	 * Note that MSVC declares DATE and TIME to be in the local time
-	 * zone, while neither the C standard nor the GCC docs make any
-	 * statement about this. As a result, we may be +/-12hrs off
-	 * UTC.  But for practical purposes, this should not be a
-	 * problem.
-	 *
-	 */
-#ifdef MKREPRO_DATE
-	static const char build[] = MKREPRO_TIME "/" MKREPRO_DATE;
-#else
-	static const char build[] = __TIME__ "/" __DATE__;
-#endif
-	static const char mlist[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
-
-	char		  monstr[4];
-	const char *	  cp;
-	unsigned short	  hour, minute, second, day, year;
- 	/* Note: The above quantities are used for sscanf 'hu' format,
-	 * so using 'uint16_t' is contra-indicated!
-	 */
-
-#ifdef DEBUG
-	static int        ignore  = 0;
-#endif
+        time_t epoch = (time_t)EPOCH;
+        struct tm *epoch_tm;
 
 	ZERO(*jd);
 	jd->year     = 1970;
 	jd->month    = 1;
 	jd->monthday = 1;
 
-#ifdef DEBUG
-	/* check environment if build date should be ignored */
-	if (0 == ignore) {
-	    const char * envstr;
-	    envstr = getenv("NTPD_IGNORE_BUILD_DATE");
-	    ignore = 1 + (envstr && (!*envstr || !strcasecmp(envstr, "yes")));
-	}
-	if (ignore > 1)
+        epoch_tm = gmtime(&epoch);
+        if ( NULL == epoch_tm ) {
+            /* bad POCH */
 	    return false;
+        }
+	/* good EOPCH */
+	jd->year     = epoch_tm->tm_year + 1900;
+	jd->yearday  = epoch_tm->tm_yday + 1;
+	jd->month    = epoch_tm->tm_mon + 1;
+	jd->monthday = epoch_tm->tm_mday;
+	jd->hour     = epoch_tm->tm_hour;
+	jd->minute   = epoch_tm->tm_min;
+	jd->second   = epoch_tm->tm_sec;
+	jd->weekday  = epoch_tm->tm_wday;
+
+#if 0
+        fprintf(stderr, "Build: %d %d %d %d %d %d %d %d\n",
+	    (int)jd->year, (int)jd->yearday, (int)jd->month, (int)jd->monthday,
+	    (int)jd->hour, (int)jd->minute, (int)jd->second, (int)jd->weekday);
 #endif
 
-	if (6 == sscanf(build, "%hu:%hu:%hu/%3s %hu %hu",
-			&hour, &minute, &second, monstr, &day, &year)) {
-		cp = strstr(mlist, monstr);
-		if (NULL != cp) {
-			jd->year     = year;
-			jd->month    = (uint8_t)((cp - mlist) / 3 + 1);
-			jd->monthday = (uint8_t)day;
-			jd->hour     = (uint8_t)hour;
-			jd->minute   = (uint8_t)minute;
-			jd->second   = (uint8_t)second;
-
-			return true;
-		}
-	}
-
-	return false;
 }
 
 


=====================================
wafhelpers/configure.py
=====================================
--- a/wafhelpers/configure.py
+++ b/wafhelpers/configure.py
@@ -1,6 +1,8 @@
 from __future__ import print_function
 
 import os
+import sys
+import time
 from wafhelpers.probes \
     import probe_header_with_prerequisites, probe_function_with_prerequisites
 from wafhelpers.util import msg, msg_setting, parse_version
@@ -809,6 +811,17 @@ int main(int argc, char **argv) {
                 msg("WARNING: This system has a 32-bit time_t.")
                 msg("WARNING: Your ntpd will fail on 2038-01-19T03:14:07Z.")
 
+    epoch = os.getenv('SOURCE_DATE_EPOCH', None)
+    if ctx.options.epoch:
+        ctx.define("EPOCH", ctx.options.epoch, comment="Using --epoch")
+    elif epoch:
+        if not epoch.isdigit():
+            msg("ERROR: malformed SOURCE_DATE_EPOCH")
+            sys.exit(1)
+        ctx.define("EPOCH", int(epoch), comment="Using SOURCE_DATE_EPOCH")
+    else:
+        ctx.define("EPOCH", int(time.time()), comment="Using default EPOCH")
+
     ctx.start_msg("Writing configuration header:")
     ctx.write_config_header("config.h")
     ctx.end_msg("config.h", "PINK")


=====================================
wafhelpers/options.py
=====================================
--- a/wafhelpers/options.py
+++ b/wafhelpers/options.py
@@ -70,8 +70,7 @@ def options_cmd(ctx, config):
     grp.add_option('--cflags', type='string', action="callback",
                    callback=callback_flags,
                    help="Users should use CFLAGS in their environment.")
-    grp.add_option( '--epoch', type='string', action="callback",
-        callback=callback_flags,
+    grp.add_option( '--epoch', type='int', default=None,
         help="Force epoch, or use SOURCE_DATE_EPOCH in environment")
     grp.add_option('--ldflags', type='string', action="callback",
                    callback=callback_flags,



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/fc6e7e280136f015763835c605a59cd291090883...ff5c0d787a20952cdf3139e86b559eaf2e551b43

---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/fc6e7e280136f015763835c605a59cd291090883...ff5c0d787a20952cdf3139e86b559eaf2e551b43
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170420/51079f32/attachment.html>


More information about the vc mailing list