diff options
author | Brad King <brad.king@kitware.com> | 2018-07-27 14:06:35 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2018-07-27 14:06:44 (GMT) |
commit | bccbf9a737785c34e0b23b2b456fbb4e112d42fb (patch) | |
tree | 318b97c65f19e6e6d6934ff8d9a48de328232192 /Source | |
parent | 131fcf65f667ab23b3bcd31c6d82b5bd01a44683 (diff) | |
parent | 548ac51d8ea319c65abefa0a771636893c45014c (diff) | |
download | CMake-bccbf9a737785c34e0b23b2b456fbb4e112d42fb.zip CMake-bccbf9a737785c34e0b23b2b456fbb4e112d42fb.tar.gz CMake-bccbf9a737785c34e0b23b2b456fbb4e112d42fb.tar.bz2 |
Merge topic 'reproducible-tarballs'
548ac51d8e CPack/Deb: Support SOURCE_DATE_EPOCH when packaging files
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2226
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmArchiveWrite.cxx | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/Source/cmArchiveWrite.cxx b/Source/cmArchiveWrite.cxx index 1dd7734..6031781 100644 --- a/Source/cmArchiveWrite.cxx +++ b/Source/cmArchiveWrite.cxx @@ -10,6 +10,7 @@ #include "cmsys/Encoding.hxx" #include "cmsys/FStream.hxx" #include <iostream> +#include <sstream> #include <string.h> #include <time.h> @@ -94,13 +95,25 @@ cmArchiveWrite::cmArchiveWrite(std::ostream& os, Compress c, return; } break; - case CompressGZip: + case CompressGZip: { if (archive_write_add_filter_gzip(this->Archive) != ARCHIVE_OK) { this->Error = "archive_write_add_filter_gzip: "; this->Error += cm_archive_error_string(this->Archive); return; } - break; + std::string source_date_epoch; + cmSystemTools::GetEnv("SOURCE_DATE_EPOCH", source_date_epoch); + if (!source_date_epoch.empty()) { + // We're not able to specify an arbitrary timestamp for gzip. + // The next best thing is to omit the timestamp entirely. + if (archive_write_set_filter_option(this->Archive, "gzip", "timestamp", + nullptr) != ARCHIVE_OK) { + this->Error = "archive_write_set_filter_option: "; + this->Error += cm_archive_error_string(this->Archive); + return; + } + } + } break; case CompressBZip2: if (archive_write_add_filter_bzip2(this->Archive) != ARCHIVE_OK) { this->Error = "archive_write_add_filter_bzip2: "; @@ -243,6 +256,17 @@ bool cmArchiveWrite::AddFile(const char* file, size_t skip, const char* prefix) return false; } archive_entry_set_mtime(e, t, 0); + } else { + std::string source_date_epoch; + cmSystemTools::GetEnv("SOURCE_DATE_EPOCH", source_date_epoch); + if (!source_date_epoch.empty()) { + std::istringstream iss(source_date_epoch); + time_t epochTime; + iss >> epochTime; + if (iss.eof() && !iss.fail()) { + archive_entry_set_mtime(e, epochTime, 0); + } + } } // manages the uid/guid of the entry (if any) |