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.

89 lines
2.9 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. diff --git a/src/config.h.in b/src/config.h.in
  21. index 5c8c7e5..436a0b7 100644
  22. --- a/src/config.h.in
  23. +++ b/src/config.h.in
  24. @@ -30,6 +30,9 @@
  25. /* Define when __DATE__ " " __TIME__ can be used */
  26. #undef HAVE_DATE_TIME
  27. +/* Defined as the date of last modification */
  28. +#undef BUILD_DATE
  29. +
  30. /* Define when __attribute__((unused)) can be used */
  31. #undef HAVE_ATTRIBUTE_UNUSED
  32. diff --git a/src/configure.ac b/src/configure.ac
  33. index 8751b2e..cd43387 100644
  34. --- a/src/configure.ac
  35. +++ b/src/configure.ac
  36. @@ -62,6 +62,16 @@ if test x"$ac_cv_prog_cc_c99" != xno; then
  37. fi
  38. fi
  39. +dnl If $SOURCE_DATE_EPOCH is present in the environment, use that as the
  40. +dnl "compiled" timestamp in :version's output. Attempt to get the formatted
  41. +dnl date using GNU date syntax, BSD date syntax, and finally falling back to
  42. +dnl just using the current time.
  43. +if test -n "$SOURCE_DATE_EPOCH"; then
  44. + DATE_FMT="%b %d %Y %H:%M:%S"
  45. + 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")
  46. + AC_DEFINE_UNQUOTED(BUILD_DATE, ["$BUILD_DATE"])
  47. +fi
  48. +
  49. dnl Check for the flag that fails if stuff are missing.
  50. AC_MSG_CHECKING(--enable-fail-if-missing argument)
  51. diff --git a/src/version.c b/src/version.c
  52. index c8361eb..e51c738 100644
  53. --- a/src/version.c
  54. +++ b/src/version.c
  55. @@ -44,9 +44,13 @@ init_longVersion(void)
  56. * VAX C can't concatenate strings in the preprocessor.
  57. */
  58. strcpy(longVersion, VIM_VERSION_LONG_DATE);
  59. +#ifdef BUILD_DATE
  60. + strcat(longVersion, BUILD_DATE);
  61. +#else
  62. strcat(longVersion, __DATE__);
  63. strcat(longVersion, " ");
  64. strcat(longVersion, __TIME__);
  65. +#endif
  66. strcat(longVersion, ")");
  67. }
  68. @@ -54,7 +58,11 @@ init_longVersion(void)
  69. void
  70. init_longVersion(void)
  71. {
  72. +#ifdef BUILD_DATE
  73. + char *date_time = BUILD_DATE;
  74. +#else
  75. char *date_time = __DATE__ " " __TIME__;
  76. +#endif
  77. char *msg = _("%s (%s, compiled %s)");
  78. size_t len = strlen(msg)
  79. + strlen(VIM_VERSION_LONG_ONLY)