diff options
author | Alex Turbov <i.zaufi@gmail.com> | 2021-07-12 23:29:44 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-07-13 12:36:12 (GMT) |
commit | c8f298ae0808675ddd70341f7c83348bc092fb3f (patch) | |
tree | 5270c06c8677370993b92a5764fdff9b919143a8 /Source | |
parent | 7fd3134ea16d2d1fbf08fa5a5d28059d62067ad6 (diff) | |
download | CMake-c8f298ae0808675ddd70341f7c83348bc092fb3f.zip CMake-c8f298ae0808675ddd70341f7c83348bc092fb3f.tar.gz CMake-c8f298ae0808675ddd70341f7c83348bc092fb3f.tar.bz2 |
Refactor: Extract packaged files finder into a function
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CPack/cmCPackDebGenerator.cxx | 79 |
1 files changed, 34 insertions, 45 deletions
diff --git a/Source/CPack/cmCPackDebGenerator.cxx b/Source/CPack/cmCPackDebGenerator.cxx index fef8bde..70670af 100644 --- a/Source/CPack/cmCPackDebGenerator.cxx +++ b/Source/CPack/cmCPackDebGenerator.cxx @@ -8,6 +8,7 @@ #include <map> #include <ostream> #include <set> +#include <stdexcept> #include <utility> #include "cmsys/Glob.hxx" @@ -463,6 +464,23 @@ bool DebGenerator::generateDeb() const return true; } +std::vector<std::string> findFilesIn(const std::string& path) +{ + cmsys::Glob gl; + std::string findExpr = path + "/*"; + gl.RecurseOn(); + gl.SetRecurseListDirs(true); + gl.SetRecurseThroughSymlinks(false); + if (!gl.FindFiles(findExpr)) { + throw std::runtime_error( + "Cannot find any files in the installed directory"); + } + std::vector<std::string> files{ gl.GetFiles() }; + // Sort files so that they have a reproducible order + std::sort(files.begin(), files.end()); + return files; +} + } // end anonymous namespace cmCPackDebGenerator::cmCPackDebGenerator() = default; @@ -510,54 +528,34 @@ int cmCPackDebGenerator::PackageOnePack(std::string const& initialTopLevel, return 0; } - { // Isolate globbing of binaries vs. dbgsyms - cmsys::Glob gl; - std::string findExpr(this->GetOption("GEN_WDIR")); - findExpr += "/*"; - gl.RecurseOn(); - gl.SetRecurseListDirs(true); - gl.SetRecurseThroughSymlinks(false); - if (!gl.FindFiles(findExpr)) { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Cannot find any files in the installed directory" - << std::endl); - return 0; - } - this->packageFiles = gl.GetFiles(); - // Sort files so that they have a reproducible order - std::sort(this->packageFiles.begin(), this->packageFiles.end()); + try { + this->packageFiles = findFilesIn(this->GetOption("GEN_WDIR")); + } 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 packageFileName = cmStrCat(this->GetOption("CPACK_TOPLEVEL_DIRECTORY"), '/', this->GetOption("GEN_CPACK_OUTPUT_FILE_NAME")); - this->packageFileNames.push_back(std::move(packageFileName)); + this->packageFileNames.emplace_back(std::move(packageFileName)); if (this->IsOn("GEN_CPACK_DEBIAN_DEBUGINFO_PACKAGE") && this->GetOption("GEN_DBGSYMDIR")) { - cmsys::Glob gl; - std::string findExpr(this->GetOption("GEN_DBGSYMDIR")); - findExpr += "/*"; - gl.RecurseOn(); - gl.SetRecurseListDirs(true); - gl.SetRecurseThroughSymlinks(false); - if (!gl.FindFiles(findExpr)) { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Cannot find any files in the installed directory" - << std::endl); + try { + this->packageFiles = findFilesIn(this->GetOption("GEN_DBGSYMDIR")); + } catch (const std::runtime_error& ex) { + cmCPackLogger(cmCPackLog::LOG_ERROR, ex.what() << std::endl); return 0; } - this->packageFiles = gl.GetFiles(); - // Sort files so that they have a reproducible order - std::sort(this->packageFiles.begin(), this->packageFiles.end()); retval = this->createDbgsymDDeb() || retval; // add the generated package to package file names list packageFileName = cmStrCat(this->GetOption("CPACK_TOPLEVEL_DIRECTORY"), '/', this->GetOption("GEN_CPACK_DBGSYM_OUTPUT_FILE_NAME")); - this->packageFileNames.push_back(std::move(packageFileName)); + this->packageFileNames.emplace_back(std::move(packageFileName)); } return int(retval); @@ -654,27 +652,18 @@ int cmCPackDebGenerator::PackageComponentsAllInOne( return 0; } - cmsys::Glob gl; - std::string findExpr(this->GetOption("GEN_WDIR")); - findExpr += "/*"; - gl.RecurseOn(); - gl.SetRecurseListDirs(true); - gl.SetRecurseThroughSymlinks(false); - if (!gl.FindFiles(findExpr)) { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Cannot find any files in the installed directory" - << std::endl); + try { + this->packageFiles = findFilesIn(this->GetOption("GEN_WDIR")); + } catch (const std::runtime_error& ex) { + cmCPackLogger(cmCPackLog::LOG_ERROR, ex.what() << std::endl); return 0; } - this->packageFiles = gl.GetFiles(); - // Sort files so that they have a reproducible order - std::sort(this->packageFiles.begin(), this->packageFiles.end()); bool retval = this->createDeb(); // add the generated package to package file names list packageFileName = cmStrCat(this->GetOption("CPACK_TOPLEVEL_DIRECTORY"), '/', this->GetOption("GEN_CPACK_OUTPUT_FILE_NAME")); - this->packageFileNames.push_back(std::move(packageFileName)); + this->packageFileNames.emplace_back(std::move(packageFileName)); return int(retval); } |