components/vim/patches/build_date.patch
changeset 7049 e8d705cba87d
child 7378 a73f22c6eecf
equal deleted inserted replaced
7048:c1d43e41adeb 7049:e8d705cba87d
       
     1 From 51ad2b56dce42fa1a44ba663946ffe04bd3e4378 Mon Sep 17 00:00:00 2001
       
     2 From: James McCoy <[email protected]>
       
     3 Date: Thu, 28 Jan 2016 10:55:11 -0500
       
     4 Subject: [PATCH] Support defining compilation date in $SOURCE_DATE_EPOCH
       
     5 
       
     6 There is an ongoing effort[0] to make FOSS software reproducibly
       
     7 buildable.  In order to make Vim build reproducibly, it is necessary to
       
     8 allow defining the date/time that is part of VIM_VERSION_LONG as part of
       
     9 the build process.
       
    10 
       
    11 This commit enables that by adding support for the SOURCE_DATE_EPOCH
       
    12 spec[1].  When the $SOURCE_DATE_EPOCH environment variable is defined,
       
    13 it will be used to populate the BUILD_DATE preprocessor define.
       
    14 
       
    15 If BUILD_DATE is not defined, the existing behavior of relying on the
       
    16 preprocessor's __DATE__/__TIME__ symbols will be used.
       
    17 
       
    18 [0]: https://reproducible-builds.org/
       
    19 [1]: https://reproducible-builds.org/specs/source-date-epoch/
       
    20 ---
       
    21  src/config.h.in  |  3 +++
       
    22  src/configure.in | 10 ++++++++++
       
    23  src/version.c    |  6 ++++++
       
    24  3 files changed, 19 insertions(+)
       
    25 
       
    26 diff --git a/src/auto/configure b/src/auto/configure
       
    27 index fea1f2c..4698269 100755
       
    28 --- a/src/auto/configure
       
    29 +++ b/src/auto/configure
       
    30 @@ -4081,6 +4081,15 @@ $as_echo "#define HAVE_SYS_WAIT_H 1" >>confdefs.h
       
    31  fi
       
    32  
       
    33  
       
    34 +if test -n "$SOURCE_DATE_EPOCH"; then
       
    35 +  DATE_FMT="%b %d %Y %H:%M:%S"
       
    36 +  BUILD_DATE=$(LC_ALL=C gdate -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")
       
    37 +  cat >>confdefs.h <<_ACEOF
       
    38 +#define BUILD_DATE "$BUILD_DATE"
       
    39 +_ACEOF
       
    40 +
       
    41 +fi
       
    42 +
       
    43  
       
    44  { $as_echo "$as_me:${as_lineno-$LINENO}: checking --enable-fail-if-missing argument" >&5
       
    45  $as_echo_n "checking --enable-fail-if-missing argument... " >&6; }
       
    46 diff --git a/src/config.h.in b/src/config.h.in
       
    47 index 8e115f5..2b64247 100644
       
    48 --- a/src/config.h.in
       
    49 +++ b/src/config.h.in
       
    50 @@ -30,6 +30,9 @@
       
    51  /* Define when __DATE__ " " __TIME__ can be used */
       
    52  #undef HAVE_DATE_TIME
       
    53  
       
    54 +/* Defined as the date of last modification */
       
    55 +#undef BUILD_DATE
       
    56 +
       
    57  /* Define when __attribute__((unused)) can be used */
       
    58  #undef HAVE_ATTRIBUTE_UNUSED
       
    59  
       
    60 diff --git a/src/configure.in b/src/configure.in
       
    61 index 92a1bb5..70367ca 100644
       
    62 --- a/src/configure.in
       
    63 +++ b/src/configure.in
       
    64 @@ -29,6 +29,16 @@ dnl in autoconf needs it, where it uses STDC_HEADERS.
       
    65  AC_HEADER_STDC
       
    66  AC_HEADER_SYS_WAIT
       
    67  
       
    68 +dnl If $SOURCE_DATE_EPOCH is present in the environment, use that as the
       
    69 +dnl "compiled" timestamp in :version's output.  Attempt to get the formatted
       
    70 +dnl date using GNU date syntax, BSD date syntax, and finally falling back to
       
    71 +dnl just using the current time.
       
    72 +if test -n "$SOURCE_DATE_EPOCH"; then
       
    73 +  DATE_FMT="%b %d %Y %H:%M:%S"
       
    74 +  BUILD_DATE=$(LC_ALL=C gdate -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")
       
    75 +  AC_DEFINE_UNQUOTED(BUILD_DATE, ["$BUILD_DATE"])
       
    76 +fi
       
    77 +
       
    78  dnl Check for the flag that fails if stuff are missing.
       
    79  
       
    80  AC_MSG_CHECKING(--enable-fail-if-missing argument)
       
    81 diff --git a/src/version.c b/src/version.c
       
    82 index 766937d..9cb6e57 100644
       
    83 --- a/src/version.c
       
    84 +++ b/src/version.c
       
    85 @@ -44,11 +44,17 @@ make_version(void)
       
    86       * VAX C can't catenate strings in the preprocessor.
       
    87       */
       
    88      strcpy(longVersion, VIM_VERSION_LONG_DATE);
       
    89 +#ifdef BUILD_DATE
       
    90 +    strcat(longVersion, BUILD_DATE);
       
    91 +#else
       
    92      strcat(longVersion, __DATE__);
       
    93      strcat(longVersion, " ");
       
    94      strcat(longVersion, __TIME__);
       
    95 +#endif
       
    96      strcat(longVersion, ")");
       
    97  }
       
    98 +# elif defined(BUILD_DATE)
       
    99 +char	*longVersion = VIM_VERSION_LONG_DATE BUILD_DATE ")";
       
   100  # else
       
   101  char	*longVersion = VIM_VERSION_LONG_DATE __DATE__ " " __TIME__ ")";
       
   102  # endif