changeset 20713:5ddd4df27068 v8.2.0910

patch 8.2.0910: Vim is not reproducibly buildable Commit: https://github.com/vim/vim/commit/8f1dde5021d9623a951d1ccbc78cf1b1a55ccd7a Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jun 5 23:16:29 2020 +0200 patch 8.2.0910: Vim is not reproducibly buildable Problem: Vim is not reproducibly buildable. Solution: Use the $SOURCE_DATE_EPOCH environment variable in configure. (James McCoy, closes #513) Give a warning about using it.
author Bram Moolenaar <Bram@vim.org>
date Fri, 05 Jun 2020 23:30:04 +0200
parents f65c7bc846b2
children f8370a101a36
files src/Makefile src/auto/configure src/config.h.in src/config.mk.in src/configure.ac src/version.c
diffstat 6 files changed, 44 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/Makefile
+++ b/src/Makefile
@@ -2130,6 +2130,7 @@ CCC = $(CCC_NF) $(ALL_CFLAGS)
 # A shell script is used to try linking without unnecessary libraries.
 $(VIMTARGET): auto/config.mk objects $(OBJ) version.c version.h
 	$(CCC) version.c -o objects/version.o
+	@$(BUILD_DATE_MSG)
 	@LINK="$(PURIFY) $(SHRPENV) $(CClink) $(ALL_LIB_DIRS) $(LDFLAGS) \
 		-o $(VIMTARGET) $(OBJ) $(ALL_LIBS)" \
 		MAKE="$(MAKE)" LINK_AS_NEEDED=$(LINK_AS_NEEDED) \
--- a/src/auto/configure
+++ b/src/auto/configure
@@ -721,6 +721,7 @@ OS_EXTRA_SRC
 XCODE_SELECT
 CPP_MM
 CROSS_COMPILING
+BUILD_DATE_MSG
 STRIP
 AWK
 FGREP
@@ -4455,6 +4456,17 @@ See \`config.log' for more details" "$LI
   fi
 fi
 
+if test -n "$SOURCE_DATE_EPOCH"; then
+  DATE_FMT="%b %d %Y %H:%M:%S"
+  BUILD_DATE=$(LC_ALL=C date -u -d "@$SOURCE_DATE_EPOCH" "+$DATE_FMT" 2>/dev/null || LC_ALL=C date -u -r "$SOURCE_DATE_EPOCH" "+$DATE_FMT" 2>/dev/null || LC_ALL=C date -u "+$DATE_FMT")
+  cat >>confdefs.h <<_ACEOF
+#define BUILD_DATE "$BUILD_DATE"
+_ACEOF
+
+  BUILD_DATE_MSG=-"echo -e '=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\nNOTE: build date/time is fixed: $BUILD_DATE\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-='"
+
+fi
+
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking --enable-fail-if-missing argument" >&5
 $as_echo_n "checking --enable-fail-if-missing argument... " >&6; }
--- a/src/config.h.in
+++ b/src/config.h.in
@@ -30,6 +30,9 @@
 /* Define when __DATE__ " " __TIME__ can be used */
 #undef HAVE_DATE_TIME
 
+/* Defined from $SOURCE_DATE_EPOCH, used as the build date */
+#undef BUILD_DATE
+
 /* Define when __attribute__((unused)) can be used */
 #undef HAVE_ATTRIBUTE_UNUSED
 
--- a/src/config.mk.in
+++ b/src/config.mk.in
@@ -169,6 +169,10 @@ MAKEMO		= @MAKEMO@
 MSGFMT		= @MSGFMT@
 MSGFMT_DESKTOP	= @MSGFMT_DESKTOP@
 
+### set if $SOURCE_DATE_EPOCH was set when running configure
+BUILD_DATE_MSG	= @BUILD_DATE_MSG@
+
+
 # Make sure that "make first" will run "make all" once configure has done its
 # work.  This is needed when using the Makefile in the top directory.
 first: all
--- a/src/configure.ac
+++ b/src/configure.ac
@@ -62,6 +62,18 @@ if test x"$ac_cv_prog_cc_c99" != xno; th
   fi
 fi
 
+dnl If $SOURCE_DATE_EPOCH is present in the environment, use that as the
+dnl "compiled" timestamp in :version's output.  Attempt to get the formatted
+dnl date using GNU date syntax, BSD date syntax, and finally falling back to
+dnl just using the current time.
+if test -n "$SOURCE_DATE_EPOCH"; then
+  DATE_FMT="%b %d %Y %H:%M:%S"
+  BUILD_DATE=$(LC_ALL=C date -u -d "@$SOURCE_DATE_EPOCH" "+$DATE_FMT" 2>/dev/null || LC_ALL=C date -u -r "$SOURCE_DATE_EPOCH" "+$DATE_FMT" 2>/dev/null || LC_ALL=C date -u "+$DATE_FMT")
+  AC_DEFINE_UNQUOTED(BUILD_DATE, ["$BUILD_DATE"])
+  BUILD_DATE_MSG=-"echo -e '=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\nNOTE: build date/time is fixed: $BUILD_DATE\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-='"
+  AC_SUBST(BUILD_DATE_MSG)
+fi
+
 dnl Check for the flag that fails if stuff are missing.
 
 AC_MSG_CHECKING(--enable-fail-if-missing argument)
--- a/src/version.c
+++ b/src/version.c
@@ -44,9 +44,13 @@ init_longVersion(void)
      * VAX C can't concatenate strings in the preprocessor.
      */
     strcpy(longVersion, VIM_VERSION_LONG_DATE);
+#ifdef BUILD_DATE
+    strcat(longVersion, BUILD_DATE);
+#else
     strcat(longVersion, __DATE__);
     strcat(longVersion, " ");
     strcat(longVersion, __TIME__);
+#endif
     strcat(longVersion, ")");
 }
 
@@ -56,7 +60,15 @@ init_longVersion(void)
 {
     if (longVersion == NULL)
     {
+#ifdef BUILD_DATE
+	char *date_time = BUILD_DATE;
+#else
+#ifdef BUILD_DATE
+	char *date_time = BUILD_DATE;
+#else
 	char *date_time = __DATE__ " " __TIME__;
+#endif
+#endif
 	char *msg = _("%s (%s, compiled %s)");
 	size_t len = strlen(msg)
 		    + strlen(VIM_VERSION_LONG_ONLY)