summaryrefslogtreecommitdiffstats
path: root/debian/patches/upstream/Support-defining-compilation-date-in-SOURCE_DATE_EPOCH.patch
blob: 2615e36f1c218cd8ae52128ca43fe16d6bf9a977 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
From: James McCoy <jamessan@jamessan.com>
Date: Thu, 28 Jan 2016 10:55:11 -0500
Subject: Support defining compilation date in $SOURCE_DATE_EPOCH

There is an ongoing effort[0] to make FOSS software reproducibly
buildable.  In order to make Vim build reproducibly, it is necessary to
allow defining the date/time that is part of VIM_VERSION_LONG as part of
the build process.

This commit enables that by adding support for the SOURCE_DATE_EPOCH
spec[1].  When the $SOURCE_DATE_EPOCH environment variable is defined,
it will be used to populate the BUILD_DATE preprocessor define.

If BUILD_DATE is not defined, the existing behavior of relying on the
preprocessor's __DATE__/__TIME__ symbols will be used.

[0]: https://reproducible-builds.org/
[1]: https://reproducible-builds.org/specs/source-date-epoch/
---
 src/config.h.in  |  3 +++
 src/configure.ac | 10 ++++++++++
 src/version.c    |  8 ++++++++
 3 files changed, 21 insertions(+)

--- 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 as the date of last modification */
+#undef BUILD_DATE
+
 /* Define when __attribute__((unused)) can be used */
 #undef HAVE_ATTRIBUTE_UNUSED
 
--- a/src/configure.ac
+++ b/src/configure.ac
@@ -62,6 +62,16 @@ 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"])
+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 catenate 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, ")");
 }
 
@@ -54,7 +58,11 @@ init_longVersion(void)
     void
 init_longVersion(void)
 {
+#ifdef BUILD_DATE
+    char *date_time = BUILD_DATE;
+#else
     char *date_time = __DATE__ " " __TIME__;
+#endif
     char *msg = _("%s (%s, compiled %s)");
     size_t len = strlen(msg)
 		+ strlen(VIM_VERSION_LONG_ONLY)