diff options
author | Brad King <brad.king@kitware.com> | 2021-01-27 14:02:28 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2021-01-27 14:02:35 (GMT) |
commit | 7ab6d1e8317f61761ca7e57bc5cf774462a851ba (patch) | |
tree | 5403db3ecd0963882a6c27c770a3532d89c563a4 /Source | |
parent | eff0f75bd2478f56bae68cab25c5892063feb950 (diff) | |
parent | bdf30bdad8dfad258bbc8d387a91f66bee3d0c0f (diff) | |
download | CMake-7ab6d1e8317f61761ca7e57bc5cf774462a851ba.zip CMake-7ab6d1e8317f61761ca7e57bc5cf774462a851ba.tar.gz CMake-7ab6d1e8317f61761ca7e57bc5cf774462a851ba.tar.bz2 |
Merge topic 'cpack-compression-threads'
bdf30bdad8 CPack: add CPACK_THREADS variable to control compression threads
bcdb5b52a0 libarchive: Fix lzma_stream_encoder_mt detection
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !5716
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CPack/cmCPackArchiveGenerator.cxx | 4 | ||||
-rw-r--r-- | Source/CPack/cmCPackDebGenerator.cxx | 28 | ||||
-rw-r--r-- | Source/cmArchiveWrite.cxx | 16 | ||||
-rw-r--r-- | Source/cmArchiveWrite.h | 3 |
4 files changed, 46 insertions, 5 deletions
diff --git a/Source/CPack/cmCPackArchiveGenerator.cxx b/Source/CPack/cmCPackArchiveGenerator.cxx index 5348f86..7fd12dd 100644 --- a/Source/CPack/cmCPackArchiveGenerator.cxx +++ b/Source/CPack/cmCPackArchiveGenerator.cxx @@ -353,8 +353,12 @@ bool cmCPackArchiveGenerator::SetArchiveOptions(cmArchiveWrite* archive) // cause spurious errors to be raised from `strtoull`. if (this->Compress == cmArchiveWrite::CompressXZ) { const char* threads = "1"; + + // CPACK_ARCHIVE_THREADS overrides CPACK_THREADS if (this->IsSet("CPACK_ARCHIVE_THREADS")) { threads = this->GetOption("CPACK_ARCHIVE_THREADS"); + } else if (this->IsSet("CPACK_THREADS")) { + threads = this->GetOption("CPACK_THREADS"); } if (!archive->SetFilterOption("xz", "threads", threads)) { diff --git a/Source/CPack/cmCPackDebGenerator.cxx b/Source/CPack/cmCPackDebGenerator.cxx index 1220514..e7bcfac 100644 --- a/Source/CPack/cmCPackDebGenerator.cxx +++ b/Source/CPack/cmCPackDebGenerator.cxx @@ -2,6 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmCPackDebGenerator.h" +#include <cstdlib> #include <cstring> #include <map> #include <ostream> @@ -28,7 +29,7 @@ class DebGenerator public: DebGenerator(cmCPackLog* logger, std::string outputName, std::string workDir, std::string topLevelDir, std::string temporaryDir, - const char* debianCompressionType, + const char* debianCompressionType, const char* numThreads, const char* debianArchiveType, std::map<std::string, std::string> controlValues, bool genShLibs, std::string shLibsFilename, bool genPostInst, @@ -53,6 +54,7 @@ private: const std::string TopLevelDir; const std::string TemporaryDir; const char* DebianArchiveType; + int NumThreads; const std::map<std::string, std::string> ControlValues; const bool GenShLibs; const std::string ShLibsFilename; @@ -69,7 +71,8 @@ private: DebGenerator::DebGenerator( cmCPackLog* logger, std::string outputName, std::string workDir, std::string topLevelDir, std::string temporaryDir, - const char* debianCompressionType, const char* debianArchiveType, + const char* debianCompressionType, const char* numThreads, + const char* debianArchiveType, std::map<std::string, std::string> controlValues, bool genShLibs, std::string shLibsFilename, bool genPostInst, std::string postInst, bool genPostRm, std::string postRm, const char* controlExtra, @@ -115,6 +118,23 @@ DebGenerator::DebGenerator( "Error unrecognized compression type: " << debianCompressionType << std::endl); } + + if (numThreads == nullptr) { + numThreads = "1"; + } + + char* endptr; + this->NumThreads = static_cast<int>(strtol(numThreads, &endptr, 10)); + if (numThreads != endptr && *endptr != '\0') { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Unrecognized number of threads: " << numThreads + << std::endl); + } + + if (this->NumThreads < 0) { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Number of threads cannot be negative" << std::endl); + } } bool DebGenerator::generate() const @@ -173,7 +193,7 @@ bool DebGenerator::generateDataTar() const return false; } cmArchiveWrite data_tar(fileStream_data_tar, this->TarCompressionType, - this->DebianArchiveType); + this->DebianArchiveType, 0, this->NumThreads); data_tar.Open(); // uid/gid should be the one of the root user, and this root user has @@ -807,6 +827,7 @@ int cmCPackDebGenerator::createDeb() this->GetOption("CPACK_TOPLEVEL_DIRECTORY"), this->GetOption("CPACK_TEMPORARY_DIRECTORY"), this->GetOption("GEN_CPACK_DEBIAN_COMPRESSION_TYPE"), + this->GetOption("CPACK_THREADS"), this->GetOption("GEN_CPACK_DEBIAN_ARCHIVE_TYPE"), controlValues, gen_shibs, shlibsfilename, this->IsOn("GEN_CPACK_DEBIAN_GENERATE_POSTINST"), postinst, this->IsOn("GEN_CPACK_DEBIAN_GENERATE_POSTRM"), postrm, @@ -864,6 +885,7 @@ int cmCPackDebGenerator::createDbgsymDDeb() this->GetOption("CPACK_TOPLEVEL_DIRECTORY"), this->GetOption("CPACK_TEMPORARY_DIRECTORY"), this->GetOption("GEN_CPACK_DEBIAN_COMPRESSION_TYPE"), + this->GetOption("CPACK_THREADS"), this->GetOption("GEN_CPACK_DEBIAN_ARCHIVE_TYPE"), controlValues, false, "", false, "", false, "", nullptr, this->IsSet("GEN_CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION"), diff --git a/Source/cmArchiveWrite.cxx b/Source/cmArchiveWrite.cxx index 356089b..b685b73 100644 --- a/Source/cmArchiveWrite.cxx +++ b/Source/cmArchiveWrite.cxx @@ -2,6 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmArchiveWrite.h" +#include <cstdio> #include <cstring> #include <ctime> #include <iostream> @@ -81,7 +82,8 @@ struct cmArchiveWrite::Callback }; cmArchiveWrite::cmArchiveWrite(std::ostream& os, Compress c, - std::string const& format, int compressionLevel) + std::string const& format, int compressionLevel, + int numThreads) : Stream(os) , Archive(archive_write_new()) , Disk(archive_read_disk_new()) @@ -142,6 +144,18 @@ cmArchiveWrite::cmArchiveWrite(std::ostream& os, Compress c, cm_archive_error_string(this->Archive)); return; } + { + char sNumThreads[8]; + snprintf(sNumThreads, sizeof(sNumThreads), "%d", numThreads); + sNumThreads[7] = '\0'; // for safety + if (archive_write_set_filter_option(this->Archive, "xz", "threads", + sNumThreads) != ARCHIVE_OK) { + this->Error = cmStrCat("archive_compressor_xz_options: ", + cm_archive_error_string(this->Archive)); + return; + } + } + break; case CompressZstd: if (archive_write_add_filter_zstd(this->Archive) != ARCHIVE_OK) { diff --git a/Source/cmArchiveWrite.h b/Source/cmArchiveWrite.h index 168d30e..34aafe9 100644 --- a/Source/cmArchiveWrite.h +++ b/Source/cmArchiveWrite.h @@ -54,7 +54,8 @@ public: /** Construct with output stream to which to write archive. */ cmArchiveWrite(std::ostream& os, Compress c = CompressNone, - std::string const& format = "paxr", int compressionLevel = 0); + std::string const& format = "paxr", int compressionLevel = 0, + int numThreads = 1); ~cmArchiveWrite(); |