Refactor: Deduplicate code of createDebPackages()

Also, fix incorrect `retval` accumulation.
This commit is contained in:
Alex Turbov
2021-07-13 04:50:32 +03:00
committed by Brad King
parent 593ff734b0
commit 7add10f288
+19 -22
View File
@@ -648,35 +648,32 @@ int cmCPackDebGenerator::PackageFiles()
bool cmCPackDebGenerator::createDebPackages() bool cmCPackDebGenerator::createDebPackages()
{ {
try { auto make_package = [this](const char* const path, const char* const output,
this->packageFiles = findFilesIn(this->GetOption("GEN_WDIR")); bool (cmCPackDebGenerator::*creator)()) -> bool {
} catch (const std::runtime_error& ex) {
cmCPackLogger(cmCPackLog::LOG_ERROR, ex.what() << std::endl);
return 0;
}
bool retval = this->createDeb();
// add the generated package to package file names list
this->packageFileNames.emplace_back(
cmStrCat(this->GetOption("CPACK_TOPLEVEL_DIRECTORY"), '/',
this->GetOption("GEN_CPACK_OUTPUT_FILE_NAME")));
if (this->IsOn("GEN_CPACK_DEBIAN_DEBUGINFO_PACKAGE") &&
this->GetOption("GEN_DBGSYMDIR")) {
try { try {
this->packageFiles = findFilesIn(this->GetOption("GEN_DBGSYMDIR")); this->packageFiles = findFilesIn(this->GetOption(path));
} catch (const std::runtime_error& ex) { } catch (const std::runtime_error& ex) {
cmCPackLogger(cmCPackLog::LOG_ERROR, ex.what() << std::endl); cmCPackLogger(cmCPackLog::LOG_ERROR, ex.what() << std::endl);
return 0; return 0;
} }
retval = this->createDbgsymDDeb() || retval; if ((this->*creator)()) {
// add the generated package to package file names list // add the generated package to package file names list
this->packageFileNames.emplace_back( this->packageFileNames.emplace_back(
cmStrCat(this->GetOption("CPACK_TOPLEVEL_DIRECTORY"), '/', cmStrCat(this->GetOption("CPACK_TOPLEVEL_DIRECTORY"), '/',
this->GetOption("GEN_CPACK_DBGSYM_OUTPUT_FILE_NAME"))); this->GetOption(output)));
return true;
}
return false;
};
bool retval = make_package("GEN_WDIR", "GEN_CPACK_OUTPUT_FILE_NAME",
&cmCPackDebGenerator::createDeb);
if (this->IsOn("GEN_CPACK_DEBIAN_DEBUGINFO_PACKAGE") &&
this->GetOption("GEN_DBGSYMDIR")) {
retval = make_package("GEN_DBGSYMDIR", "GEN_CPACK_DBGSYM_OUTPUT_FILE_NAME",
&cmCPackDebGenerator::createDbgsymDDeb) &&
retval;
} }
return int(retval); return int(retval);
} }