summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDeniz Bahadir <deniz@code.bahadir.email>2024-04-30 16:36:25 (GMT)
committerDeniz Bahadir <deniz@code.bahadir.email>2024-04-30 16:36:25 (GMT)
commitd488efa0b48479e1912f9232fef2f71ce4bd65f4 (patch)
tree666b3038687d018dd225d76e83cda03d7483b558
parent5fa5bde5d63c9a5303461d038a4ab55b1bb76b51 (diff)
downloadCMake-d488efa0b48479e1912f9232fef2f71ce4bd65f4.zip
CMake-d488efa0b48479e1912f9232fef2f71ce4bd65f4.tar.gz
CMake-d488efa0b48479e1912f9232fef2f71ce4bd65f4.tar.bz2
cmCPackGenerator: Refactor generation of checksum file into own function
-rw-r--r--Source/CPack/cmCPackGenerator.cxx32
-rw-r--r--Source/CPack/cmCPackGenerator.h4
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<cm::string_view> alt = cm::nullopt);
virtual bool ConfigureFile(const std::string& inName,