| 37 | #include "cmSystemTools.h" |
| 38 | |
| 39 | std::string cmTimestamp::CurrentTime(cm::string_view formatString, |
| 40 | bool utcFlag) const |
| 41 | { |
| 42 | // get current time with microsecond resolution |
| 43 | uv_timeval64_t timeval; |
| 44 | uv_gettimeofday(&timeval); |
| 45 | auto currentTimeT = static_cast<time_t>(timeval.tv_sec); |
| 46 | auto microseconds = static_cast<uint32_t>(timeval.tv_usec); |
| 47 | |
| 48 | // check for override via SOURCE_DATE_EPOCH for reproducible builds |
| 49 | std::string source_date_epoch; |
| 50 | cmSystemTools::GetEnv("SOURCE_DATE_EPOCH", source_date_epoch); |
| 51 | if (!source_date_epoch.empty()) { |
| 52 | std::istringstream iss(source_date_epoch); |
| 53 | iss >> currentTimeT; |
| 54 | if (iss.fail() || !iss.eof()) { |
| 55 | cmSystemTools::Error("Cannot parse SOURCE_DATE_EPOCH as integer"); |
| 56 | exit(27); |
| 57 | } |
| 58 | // SOURCE_DATE_EPOCH has only a resolution in the seconds range |
| 59 | microseconds = 0; |
| 60 | } |
| 61 | if (currentTimeT == static_cast<time_t>(-1)) { |
| 62 | return std::string(); |
| 63 | } |
| 64 | |
| 65 | return this->CreateTimestampFromTimeT(currentTimeT, microseconds, |
| 66 | static_cast<std::string>(formatString), |
| 67 | utcFlag); |
| 68 | } |
| 69 | |
| 70 | std::string cmTimestamp::FileModificationTime(char const* path, |
| 71 | cm::string_view formatString, |
nothing calls this directly
no test coverage detected