You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.7 KiB

  1. From: James McCoy <jamessan@jamessan.com>
  2. Date: Thu, 28 Jan 2016 10:55:11 -0500
  3. Subject: Support defining compilation date in $SOURCE_DATE_EPOCH
  4. There is an ongoing effort[0] to make FOSS software reproducibly
  5. buildable. In order to make Vim build reproducibly, it is necessary to
  6. allow defining the date/time that is part of VIM_VERSION_LONG as part of
  7. the build process.
  8. This commit enables that by adding support for the SOURCE_DATE_EPOCH
  9. spec[1]. When the $SOURCE_DATE_EPOCH environment variable is defined,
  10. it will be used to populate the BUILD_DATE preprocessor define.
  11. If BUILD_DATE is not defined, the existing behavior of relying on the
  12. preprocessor's __DATE__/__TIME__ symbols will be used.
  13. [0]: https://reproducible-builds.org/
  14. [1]: https://reproducible-builds.org/specs/source-date-epoch/
  15. ---
  16. src/config.h.in | 3 +++
  17. src/configure.ac | 10 ++++++++++
  18. src/version.c | 8 ++++++++
  19. 3 files changed, 21 insertions(+)
  20. --- a/src/config.h.in
  21. +++ b/src/config.h.in
  22. @@ -30,6 +30,9 @@
  23. /* Define when __DATE__ " " __TIME__ can be used */
  24. #undef HAVE_DATE_TIME
  25. +/* Defined as the date of last modification */
  26. +#undef BUILD_DATE
  27. +
  28. /* Define when __attribute__((unused)) can be used */
  29. #undef HAVE_ATTRIBUTE_UNUSED
  30. --- a/src/configure.ac
  31. +++ b/src/configure.ac
  32. @@ -62,6 +62,16 @@ if test x"$ac_cv_prog_cc_c99" != xno; th
  33. fi
  34. fi
  35. +dnl If $SOURCE_DATE_EPOCH is present in the environment, use that as the
  36. +dnl "compiled" timestamp in :version's output. Attempt to get the formatted
  37. +dnl date using GNU date syntax, BSD date syntax, and finally falling back to
  38. +dnl just using the current time.
  39. +if test -n "$SOURCE_DATE_EPOCH"; then
  40. + DATE_FMT="%b %d %Y %H:%M:%S"
  41. + 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")
  42. + AC_DEFINE_UNQUOTED(BUILD_DATE, ["$BUILD_DATE"])
  43. +fi
  44. +
  45. dnl Check for the flag that fails if stuff are missing.
  46. AC_MSG_CHECKING(--enable-fail-if-missing argument)
  47. --- a/src/version.c
  48. +++ b/src/version.c
  49. @@ -44,9 +44,13 @@ init_longVersion(void)
  50. * VAX C can't concatenate strings in the preprocessor.
  51. */
  52. strcpy(longVersion, VIM_VERSION_LONG_DATE);
  53. +#ifdef BUILD_DATE
  54. + strcat(longVersion, BUILD_DATE);
  55. +#else
  56. strcat(longVersion, __DATE__);
  57. strcat(longVersion, " ");
  58. strcat(longVersion, __TIME__);
  59. +#endif
  60. strcat(longVersion, ")");
  61. }
  62. @@ -54,7 +58,11 @@ init_longVersion(void)
  63. void
  64. init_longVersion(void)
  65. {
  66. +#ifdef BUILD_DATE
  67. + char *date_time = BUILD_DATE;
  68. +#else
  69. char *date_time = __DATE__ " " __TIME__;
  70. +#endif
  71. char *msg = _("%s (%s, compiled %s)");
  72. size_t len = strlen(msg)
  73. + strlen(VIM_VERSION_LONG_ONLY)