Merge topic 'reproducible-tarballs'

548ac51d8e CPack/Deb: Support SOURCE_DATE_EPOCH when packaging files

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2226
This commit is contained in:
Brad King
2018-07-27 14:06:35 +00:00
committed by Kitware Robot
9 changed files with 112 additions and 4 deletions
+26 -2
View File
@@ -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)