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[] = {


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[] = {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to