mirror of
https://github.com/reactos/CMake.git
synced 2024-12-13 14:27:23 +00:00
cmTimestamp: Support SOURCE_DATE_EPOCH to override current time
See https://reproducible-builds.org/ for why this is good and https://reproducible-builds.org/specs/source-date-epoch/ for the definition of this variable.
This commit is contained in:
parent
a007f15344
commit
243aed525a
@ -329,6 +329,12 @@ If no explicit ``<format string>`` is given it will default to:
|
||||
|
||||
Write a string which can be used as an identifier in C.
|
||||
|
||||
.. note::
|
||||
|
||||
If the ``SOURCE_DATE_EPOCH`` environment variable is set,
|
||||
its value will be used instead of the current time.
|
||||
See https://reproducible-builds.org/specs/source-date-epoch/ for details.
|
||||
|
||||
UUID
|
||||
""""
|
||||
|
||||
|
5
Help/release/dev/SOURCE_DATE_EPOCH.rst
Normal file
5
Help/release/dev/SOURCE_DATE_EPOCH.rst
Normal file
@ -0,0 +1,5 @@
|
||||
SOURCE_DATE_EPOCH
|
||||
-----------------
|
||||
|
||||
* The :command:`string(TIMESTAMP)` will now honor the ``SOURCE_DATE_EPOCH``
|
||||
environment variable and use its value instead of the current time.
|
@ -5,6 +5,7 @@
|
||||
#include <cmConfigure.h>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "cmSystemTools.h"
|
||||
|
||||
@ -12,6 +13,16 @@ std::string cmTimestamp::CurrentTime(const std::string& formatString,
|
||||
bool utcFlag)
|
||||
{
|
||||
time_t currentTimeT = time(CM_NULLPTR);
|
||||
std::string source_date_epoch;
|
||||
cmSystemTools::GetEnv("SOURCE_DATE_EPOCH", source_date_epoch);
|
||||
if (!source_date_epoch.empty()) {
|
||||
std::istringstream iss(source_date_epoch);
|
||||
iss >> currentTimeT;
|
||||
if (iss.fail() || !iss.eof()) {
|
||||
cmSystemTools::Error("Cannot parse SOURCE_DATE_EPOCH as integer");
|
||||
exit(27);
|
||||
}
|
||||
}
|
||||
if (currentTimeT == time_t(-1)) {
|
||||
return std::string();
|
||||
}
|
||||
|
@ -6,6 +6,11 @@ run_cmake(AppendNoArgs)
|
||||
run_cmake(Concat)
|
||||
run_cmake(ConcatNoArgs)
|
||||
|
||||
run_cmake(Timestamp)
|
||||
run_cmake(TimestampEmpty)
|
||||
run_cmake(TimestampInvalid)
|
||||
run_cmake(TimestampInvalid2)
|
||||
|
||||
run_cmake(Uuid)
|
||||
run_cmake(UuidMissingNamespace)
|
||||
run_cmake(UuidMissingNamespaceValue)
|
||||
|
1
Tests/RunCMake/string/Timestamp-result.txt
Normal file
1
Tests/RunCMake/string/Timestamp-result.txt
Normal file
@ -0,0 +1 @@
|
||||
0
|
1
Tests/RunCMake/string/Timestamp-stderr.txt
Normal file
1
Tests/RunCMake/string/Timestamp-stderr.txt
Normal file
@ -0,0 +1 @@
|
||||
RESULT=2005-08-07 23:19:49 Sun Aug 05 day=219 wd=0 week=32 %%I=11
|
3
Tests/RunCMake/string/Timestamp.cmake
Normal file
3
Tests/RunCMake/string/Timestamp.cmake
Normal file
@ -0,0 +1,3 @@
|
||||
set(ENV{SOURCE_DATE_EPOCH} "1123456789")
|
||||
string(TIMESTAMP RESULT "%Y-%m-%d %H:%M:%S %a %b %y day=%j wd=%w week=%U %%I=%I" UTC)
|
||||
message("RESULT=${RESULT}")
|
1
Tests/RunCMake/string/TimestampEmpty-result.txt
Normal file
1
Tests/RunCMake/string/TimestampEmpty-result.txt
Normal file
@ -0,0 +1 @@
|
||||
0
|
1
Tests/RunCMake/string/TimestampEmpty-stderr.txt
Normal file
1
Tests/RunCMake/string/TimestampEmpty-stderr.txt
Normal file
@ -0,0 +1 @@
|
||||
RESULT=2
|
3
Tests/RunCMake/string/TimestampEmpty.cmake
Normal file
3
Tests/RunCMake/string/TimestampEmpty.cmake
Normal file
@ -0,0 +1,3 @@
|
||||
set(ENV{SOURCE_DATE_EPOCH} "")
|
||||
string(TIMESTAMP RESULT "%Y-%m-%d %H:%M:%S" UTC)
|
||||
message("RESULT=${RESULT}")
|
1
Tests/RunCMake/string/TimestampInvalid-result.txt
Normal file
1
Tests/RunCMake/string/TimestampInvalid-result.txt
Normal file
@ -0,0 +1 @@
|
||||
27
|
1
Tests/RunCMake/string/TimestampInvalid-stderr.txt
Normal file
1
Tests/RunCMake/string/TimestampInvalid-stderr.txt
Normal file
@ -0,0 +1 @@
|
||||
CMake Error: Cannot parse SOURCE_DATE_EPOCH as integer
|
3
Tests/RunCMake/string/TimestampInvalid.cmake
Normal file
3
Tests/RunCMake/string/TimestampInvalid.cmake
Normal file
@ -0,0 +1,3 @@
|
||||
set(ENV{SOURCE_DATE_EPOCH} "invalid-integer")
|
||||
string(TIMESTAMP RESULT "%Y-%m-%d %H:%M:%S" UTC)
|
||||
message("RESULT=${RESULT}")
|
1
Tests/RunCMake/string/TimestampInvalid2-result.txt
Normal file
1
Tests/RunCMake/string/TimestampInvalid2-result.txt
Normal file
@ -0,0 +1 @@
|
||||
27
|
1
Tests/RunCMake/string/TimestampInvalid2-stderr.txt
Normal file
1
Tests/RunCMake/string/TimestampInvalid2-stderr.txt
Normal file
@ -0,0 +1 @@
|
||||
CMake Error: Cannot parse SOURCE_DATE_EPOCH as integer
|
3
Tests/RunCMake/string/TimestampInvalid2.cmake
Normal file
3
Tests/RunCMake/string/TimestampInvalid2.cmake
Normal file
@ -0,0 +1,3 @@
|
||||
set(ENV{SOURCE_DATE_EPOCH} "123trailing-garbage")
|
||||
string(TIMESTAMP RESULT "%Y-%m-%d %H:%M:%S" UTC)
|
||||
message("RESULT=${RESULT}")
|
Loading…
Reference in New Issue
Block a user