From d488efa0b48479e1912f9232fef2f71ce4bd65f4 Mon Sep 17 00:00:00 2001 From: Deniz Bahadir Date: Tue, 30 Apr 2024 18:36:25 +0200 Subject: cmCPackGenerator: Refactor generation of checksum file into own function --- Source/CPack/cmCPackGenerator.cxx | 32 ++++++++++++++++++++------------ Source/CPack/cmCPackGenerator.h | 4 ++++ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/Source/CPack/cmCPackGenerator.cxx b/Source/CPack/cmCPackGenerator.cxx index 6889656..38aa2ba 100644 --- a/Source/CPack/cmCPackGenerator.cxx +++ b/Source/CPack/cmCPackGenerator.cxx @@ -974,6 +974,25 @@ int cmCPackGenerator::InstallCMakeProject( return 1; } +bool cmCPackGenerator::GenerateChecksumFile(cmCryptoHash& crypto, + cm::string_view filename) const +{ + std::string packageFileName = + cmStrCat(this->GetOption("CPACK_OUTPUT_FILE_PREFIX"), "/", filename); + std::string hashFile = cmStrCat( + packageFileName, "." + cmSystemTools::LowerCase(crypto.GetHashAlgoName())); + cmsys::ofstream outF(hashFile.c_str()); + if (!outF) { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Cannot create checksum file: " << hashFile << std::endl); + return false; + } + outF << crypto.HashFile(packageFileName) << " " << filename << "\n"; + cmCPackLogger(cmCPackLog::LOG_OUTPUT, + "- checksum file: " << hashFile << " generated." << std::endl); + return true; +} + bool cmCPackGenerator::ReadListFile(const char* moduleName) { bool retval; @@ -1177,20 +1196,9 @@ int cmCPackGenerator::DoPackage() /* Generate checksum file */ if (crypto) { - std::string hashFile(this->GetOption("CPACK_OUTPUT_FILE_PREFIX")); - hashFile += "/" + filename; - hashFile += "." + cmSystemTools::LowerCase(algo); - cmsys::ofstream outF(hashFile.c_str()); - if (!outF) { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Cannot create checksum file: " << hashFile - << std::endl); + if (!this->GenerateChecksumFile(*crypto, filename)) { return 0; } - outF << crypto->HashFile(packageFileName) << " " << filename << "\n"; - cmCPackLogger(cmCPackLog::LOG_OUTPUT, - "- checksum file: " << hashFile << " generated." - << std::endl); } } diff --git a/Source/CPack/cmCPackGenerator.h b/Source/CPack/cmCPackGenerator.h index 223b720..be945c4 100644 --- a/Source/CPack/cmCPackGenerator.h +++ b/Source/CPack/cmCPackGenerator.h @@ -19,6 +19,7 @@ #include "cmValue.h" class cmCPackLog; +class cmCryptoHash; class cmGlobalGenerator; class cmInstalledFile; class cmMakefile; @@ -182,6 +183,9 @@ protected: virtual const char* GetInstallPath(); virtual const char* GetPackagingInstallPrefix(); + bool GenerateChecksumFile(cmCryptoHash& crypto, + cm::string_view filename) const; + std::string FindTemplate(cm::string_view name, cm::optional alt = cm::nullopt); virtual bool ConfigureFile(const std::string& inName, -- cgit v0.12