[PATCH] D20791: Support SOURCE_DATE_EPOCH environment variable

Ed Maste via cfe-commits cfe-commits at lists.llvm.org
Mon May 30 08:17:21 PDT 2016


emaste created this revision.
emaste added a subscriber: cfe-commits.

`SOURCE_DATE_EPOCH` specifies a UNIX timestamp (number of seconds since 01 Jan 1970 00:00:00 UTC) to be used as the timestamp input for build processes e.g. `__DATE__` and `__TIME__`

See https://reproducible-builds.org/specs/source-date-epoch/ for details, and GCC support at https://gcc.gnu.org/onlinedocs/cpp/Environment-Variables.html.




http://reviews.llvm.org/D20791

Files:
  lib/Lex/PPMacroExpansion.cpp

Index: lib/Lex/PPMacroExpansion.cpp
===================================================================
--- lib/Lex/PPMacroExpansion.cpp
+++ lib/Lex/PPMacroExpansion.cpp
@@ -1013,7 +1013,12 @@
 /// the identifier tokens inserted.
 static void ComputeDATE_TIME(SourceLocation &DATELoc, SourceLocation &TIMELoc,
                              Preprocessor &PP) {
-  time_t TT = time(nullptr);
+  time_t TT;
+  const char *envValue = getenv("SOURCE_DATE_EPOCH");
+  if (envValue != nullptr)
+    TT = strtol(envValue, nullptr, 10);
+  else
+    TT = time(nullptr);
   struct tm *TM = localtime(&TT);
 
   static const char * const Months[] = {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20791.58959.patch
Type: text/x-patch
Size: 640 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160530/cfd1441c/attachment.bin>


More information about the cfe-commits mailing list