diff options
Diffstat (limited to 'Source/CPack/IFW/cmCPackIFWGenerator.cxx')
-rw-r--r-- | Source/CPack/IFW/cmCPackIFWGenerator.cxx | 296 |
1 files changed, 183 insertions, 113 deletions
diff --git a/Source/CPack/IFW/cmCPackIFWGenerator.cxx b/Source/CPack/IFW/cmCPackIFWGenerator.cxx index 226ea0a29..509ac6507 100644 --- a/Source/CPack/IFW/cmCPackIFWGenerator.cxx +++ b/Source/CPack/IFW/cmCPackIFWGenerator.cxx @@ -2,6 +2,9 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmCPackIFWGenerator.h" +#include <sstream> +#include <utility> + #include "cmCPackComponentGroup.h" #include "cmCPackGenerator.h" #include "cmCPackIFWCommon.h" @@ -9,20 +12,17 @@ #include "cmCPackIFWPackage.h" #include "cmCPackIFWRepository.h" #include "cmCPackLog.h" // IWYU pragma: keep +#include "cmDuration.h" #include "cmGeneratedFileStream.h" +#include "cmStringAlgorithms.h" #include "cmSystemTools.h" -#include <sstream> -#include <utility> - cmCPackIFWGenerator::cmCPackIFWGenerator() { this->Generator = this; } -cmCPackIFWGenerator::~cmCPackIFWGenerator() -{ -} +cmCPackIFWGenerator::~cmCPackIFWGenerator() = default; int cmCPackIFWGenerator::PackageFiles() { @@ -35,152 +35,202 @@ int cmCPackIFWGenerator::PackageFiles() this->Installer.GeneratePackageFiles(); std::string ifwTLD = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); - std::string ifwTmpFile = ifwTLD; - ifwTmpFile += "/IFWOutput.log"; + std::string ifwTmpFile = cmStrCat(ifwTLD, "/IFWOutput.log"); // Run repogen if (!this->Installer.RemoteRepositories.empty()) { - std::string ifwCmd = this->RepoGen; + std::vector<std::string> ifwCmd; + std::string ifwArg; + + ifwCmd.emplace_back(this->RepoGen); if (this->IsVersionLess("2.0.0")) { - ifwCmd += " -c " + this->toplevel + "/config/config.xml"; + ifwCmd.emplace_back("-c"); + ifwCmd.emplace_back(this->toplevel + "/config/config.xml"); } - ifwCmd += " -p " + this->toplevel + "/packages"; + ifwCmd.emplace_back("-p"); + ifwCmd.emplace_back(this->toplevel + "/packages"); if (!this->PkgsDirsVector.empty()) { - for (std::vector<std::string>::iterator it = - this->PkgsDirsVector.begin(); - it != this->PkgsDirsVector.end(); ++it) { - ifwCmd += " -p " + *it; + for (std::string const& it : this->PkgsDirsVector) { + ifwCmd.emplace_back("-p"); + ifwCmd.emplace_back(it); + } + } + + if (!this->RepoDirsVector.empty()) { + if (!this->IsVersionLess("3.1")) { + for (std::string const& rd : this->RepoDirsVector) { + ifwCmd.emplace_back("--repository"); + ifwCmd.emplace_back(rd); + } + } else { + cmCPackIFWLogger(WARNING, + "The \"CPACK_IFW_REPOSITORIES_DIRECTORIES\" " + << "variable is set, but content will be skipped, " + << "because this feature available only since " + << "QtIFW 3.1. Please update your QtIFW instance." + << std::endl); } } if (!this->OnlineOnly && !this->DownloadedPackages.empty()) { - ifwCmd += " -i "; - std::set<cmCPackIFWPackage*>::iterator it = - this->DownloadedPackages.begin(); - ifwCmd += (*it)->Name; + ifwCmd.emplace_back("-i"); + auto it = this->DownloadedPackages.begin(); + ifwArg = (*it)->Name; ++it; while (it != this->DownloadedPackages.end()) { - ifwCmd += "," + (*it)->Name; + ifwArg += "," + (*it)->Name; ++it; } + ifwCmd.emplace_back(ifwArg); } - ifwCmd += " " + this->toplevel + "/repository"; - cmCPackIFWLogger(VERBOSE, "Execute: " << ifwCmd << std::endl); + ifwCmd.emplace_back(this->toplevel + "/repository"); + cmCPackIFWLogger(VERBOSE, + "Execute: " << cmSystemTools::PrintSingleCommand(ifwCmd) + << std::endl); std::string output; int retVal = 1; cmCPackIFWLogger(OUTPUT, "- Generate repository" << std::endl); - bool res = cmSystemTools::RunSingleCommand(ifwCmd.c_str(), &output, - &output, &retVal, CM_NULLPTR, - this->GeneratorVerbose, 0); + bool res = cmSystemTools::RunSingleCommand( + ifwCmd, &output, &output, &retVal, nullptr, this->GeneratorVerbose, + cmDuration::zero()); if (!res || retVal) { - cmGeneratedFileStream ofs(ifwTmpFile.c_str()); - ofs << "# Run command: " << ifwCmd << std::endl + cmGeneratedFileStream ofs(ifwTmpFile); + ofs << "# Run command: " << cmSystemTools::PrintSingleCommand(ifwCmd) + << std::endl << "# Output:" << std::endl << output << std::endl; - cmCPackIFWLogger(ERROR, "Problem running IFW command: " - << ifwCmd << std::endl - << "Please check " << ifwTmpFile << " for errors" - << std::endl); + cmCPackIFWLogger( + ERROR, + "Problem running IFW command: " + << cmSystemTools::PrintSingleCommand(ifwCmd) << std::endl + << "Please check \"" << ifwTmpFile << "\" for errors" << std::endl); return 0; } if (!this->Repository.RepositoryUpdate.empty() && !this->Repository.PatchUpdatesXml()) { - cmCPackIFWLogger(WARNING, "Problem patch IFW \"Updates\" " - << "file: " - << this->toplevel + "/repository/Updates.xml" - << std::endl); + cmCPackIFWLogger(WARNING, + "Problem patch IFW \"Updates\" " + << "file: \"" << this->toplevel + << "/repository/Updates.xml\"" << std::endl); } - cmCPackIFWLogger(OUTPUT, "- repository: " << this->toplevel - << "/repository generated" - << std::endl); + cmCPackIFWLogger(OUTPUT, + "- repository: \"" << this->toplevel + << "/repository\" generated" + << std::endl); } // Run binary creator { - std::string ifwCmd = this->BinCreator; - ifwCmd += " -c " + this->toplevel + "/config/config.xml"; + std::vector<std::string> ifwCmd; + std::string ifwArg; + + ifwCmd.emplace_back(this->BinCreator); + + ifwCmd.emplace_back("-c"); + ifwCmd.emplace_back(this->toplevel + "/config/config.xml"); if (!this->Installer.Resources.empty()) { - ifwCmd += " -r "; - std::vector<std::string>::iterator it = - this->Installer.Resources.begin(); + ifwCmd.emplace_back("-r"); + auto it = this->Installer.Resources.begin(); std::string path = this->toplevel + "/resources/"; - ifwCmd += path + *it; + ifwArg = path + *it; ++it; while (it != this->Installer.Resources.end()) { - ifwCmd += "," + path + *it; + ifwArg += "," + path + *it; ++it; } + ifwCmd.emplace_back(ifwArg); } - ifwCmd += " -p " + this->toplevel + "/packages"; + ifwCmd.emplace_back("-p"); + ifwCmd.emplace_back(this->toplevel + "/packages"); if (!this->PkgsDirsVector.empty()) { - for (std::vector<std::string>::iterator it = - this->PkgsDirsVector.begin(); - it != this->PkgsDirsVector.end(); ++it) { - ifwCmd += " -p " + *it; + for (std::string const& it : this->PkgsDirsVector) { + ifwCmd.emplace_back("-p"); + ifwCmd.emplace_back(it); + } + } + + if (!this->RepoDirsVector.empty()) { + if (!this->IsVersionLess("3.1")) { + for (std::string const& rd : this->RepoDirsVector) { + ifwCmd.emplace_back("--repository"); + ifwCmd.emplace_back(rd); + } + } else { + cmCPackIFWLogger(WARNING, + "The \"CPACK_IFW_REPOSITORIES_DIRECTORIES\" " + << "variable is set, but content will be skipped, " + << "because this feature available only since " + << "QtIFW 3.1. Please update your QtIFW instance." + << std::endl); } } if (this->OnlineOnly) { - ifwCmd += " --online-only"; + ifwCmd.emplace_back("--online-only"); } else if (!this->DownloadedPackages.empty() && !this->Installer.RemoteRepositories.empty()) { - ifwCmd += " -e "; - std::set<cmCPackIFWPackage*>::iterator it = - this->DownloadedPackages.begin(); - ifwCmd += (*it)->Name; + ifwCmd.emplace_back("-e"); + auto it = this->DownloadedPackages.begin(); + ifwArg = (*it)->Name; ++it; while (it != this->DownloadedPackages.end()) { - ifwCmd += "," + (*it)->Name; + ifwArg += "," + (*it)->Name; ++it; } + ifwCmd.emplace_back(ifwArg); } else if (!this->DependentPackages.empty()) { - ifwCmd += " -i "; + ifwCmd.emplace_back("-i"); + ifwArg.clear(); // Binary - std::set<cmCPackIFWPackage*>::iterator bit = - this->BinaryPackages.begin(); + auto bit = this->BinaryPackages.begin(); while (bit != this->BinaryPackages.end()) { - ifwCmd += (*bit)->Name + ","; + ifwArg += (*bit)->Name + ","; ++bit; } // Depend - DependenceMap::iterator it = this->DependentPackages.begin(); - ifwCmd += it->second.Name; + auto it = this->DependentPackages.begin(); + ifwArg += it->second.Name; ++it; while (it != this->DependentPackages.end()) { - ifwCmd += "," + it->second.Name; + ifwArg += "," + it->second.Name; ++it; } + ifwCmd.emplace_back(ifwArg); } // TODO: set correct name for multipackages if (!this->packageFileNames.empty()) { - ifwCmd += " " + this->packageFileNames[0]; + ifwCmd.emplace_back(this->packageFileNames[0]); } else { - ifwCmd += " installer"; + ifwCmd.emplace_back("installer" + this->OutputExtension); } - cmCPackIFWLogger(VERBOSE, "Execute: " << ifwCmd << std::endl); + cmCPackIFWLogger(VERBOSE, + "Execute: " << cmSystemTools::PrintSingleCommand(ifwCmd) + << std::endl); std::string output; int retVal = 1; cmCPackIFWLogger(OUTPUT, "- Generate package" << std::endl); - bool res = cmSystemTools::RunSingleCommand(ifwCmd.c_str(), &output, - &output, &retVal, CM_NULLPTR, - this->GeneratorVerbose, 0); + bool res = cmSystemTools::RunSingleCommand( + ifwCmd, &output, &output, &retVal, nullptr, this->GeneratorVerbose, + cmDuration::zero()); if (!res || retVal) { - cmGeneratedFileStream ofs(ifwTmpFile.c_str()); - ofs << "# Run command: " << ifwCmd << std::endl + cmGeneratedFileStream ofs(ifwTmpFile); + ofs << "# Run command: " << cmSystemTools::PrintSingleCommand(ifwCmd) + << std::endl << "# Output:" << std::endl << output << std::endl; - cmCPackIFWLogger(ERROR, "Problem running IFW command: " - << ifwCmd << std::endl - << "Please check " << ifwTmpFile << " for errors" - << std::endl); + cmCPackIFWLogger( + ERROR, + "Problem running IFW command: " + << cmSystemTools::PrintSingleCommand(ifwCmd) << std::endl + << "Please check \"" << ifwTmpFile << "\" for errors" << std::endl); return 0; } } @@ -205,7 +255,7 @@ const char* cmCPackIFWGenerator::GetPackagingInstallPrefix() const char* cmCPackIFWGenerator::GetOutputExtension() { - return this->ExecutableSuffix.c_str(); + return this->OutputExtension.c_str(); } int cmCPackIFWGenerator::InitializeInternal() @@ -224,15 +274,16 @@ int cmCPackIFWGenerator::InitializeInternal() // Look 'binarycreator' executable (needs) const char* BinCreatorStr = this->GetOption(BinCreatorOpt); - if (!BinCreatorStr || cmSystemTools::IsNOTFOUND(BinCreatorStr)) { - this->BinCreator = ""; + if (!BinCreatorStr || cmIsNOTFOUND(BinCreatorStr)) { + this->BinCreator.clear(); } else { this->BinCreator = BinCreatorStr; } if (this->BinCreator.empty()) { - cmCPackIFWLogger(ERROR, "Cannot find QtIFW compiler \"binarycreator\": " - "likely it is not installed, or not in your PATH" + cmCPackIFWLogger(ERROR, + "Cannot find QtIFW compiler \"binarycreator\": " + "likely it is not installed, or not in your PATH" << std::endl); return 0; } @@ -240,8 +291,8 @@ int cmCPackIFWGenerator::InitializeInternal() // Look 'repogen' executable (optional) const char* RepoGenStr = this->GetOption(RepoGenOpt); - if (!RepoGenStr || cmSystemTools::IsNOTFOUND(RepoGenStr)) { - this->RepoGen = ""; + if (!RepoGenStr || cmIsNOTFOUND(RepoGenStr)) { + this->RepoGen.clear(); } else { this->RepoGen = RepoGenStr; } @@ -262,7 +313,14 @@ int cmCPackIFWGenerator::InitializeInternal() // Additional packages dirs this->PkgsDirsVector.clear(); if (const char* dirs = this->GetOption("CPACK_IFW_PACKAGES_DIRECTORIES")) { - cmSystemTools::ExpandListArgument(dirs, this->PkgsDirsVector); + cmExpandList(dirs, this->PkgsDirsVector); + } + + // Additional repositories dirs + this->RepoDirsVector.clear(); + if (const char* dirs = + this->GetOption("CPACK_IFW_REPOSITORIES_DIRECTORIES")) { + cmExpandList(dirs, this->RepoDirsVector); } // Installer @@ -279,19 +337,17 @@ int cmCPackIFWGenerator::InitializeInternal() // Repositories if (const char* RepoAllStr = this->GetOption("CPACK_IFW_REPOSITORIES_ALL")) { - std::vector<std::string> RepoAllVector; - cmSystemTools::ExpandListArgument(RepoAllStr, RepoAllVector); - for (std::vector<std::string>::iterator rit = RepoAllVector.begin(); - rit != RepoAllVector.end(); ++rit) { - this->GetRepository(*rit); + std::vector<std::string> RepoAllVector = cmExpandedList(RepoAllStr); + for (std::string const& r : RepoAllVector) { + this->GetRepository(r); } } if (const char* ifwDownloadAll = this->GetOption("CPACK_IFW_DOWNLOAD_ALL")) { - this->OnlineOnly = cmSystemTools::IsOn(ifwDownloadAll); + this->OnlineOnly = cmIsOn(ifwDownloadAll); } else if (const char* cpackDownloadAll = this->GetOption("CPACK_DOWNLOAD_ALL")) { - this->OnlineOnly = cmSystemTools::IsOn(cpackDownloadAll); + this->OnlineOnly = cmIsOn(cpackDownloadAll); } else { this->OnlineOnly = false; } @@ -305,16 +361,29 @@ int cmCPackIFWGenerator::InitializeInternal() } // Executable suffix - if (const char* optExeSuffix = this->GetOption("CMAKE_EXECUTABLE_SUFFIX")) { - this->ExecutableSuffix = optExeSuffix; - if (this->ExecutableSuffix.empty()) { - std::string sysName(this->GetOption("CMAKE_SYSTEM_NAME")); - if (sysName == "Linux") { - this->ExecutableSuffix = ".run"; - } - } + std::string exeSuffix(this->GetOption("CMAKE_EXECUTABLE_SUFFIX")); + std::string sysName(this->GetOption("CMAKE_SYSTEM_NAME")); + if (sysName == "Linux") { + this->ExecutableSuffix = ".run"; + } else if (sysName == "Windows") { + this->ExecutableSuffix = ".exe"; + } else if (sysName == "Darwin") { + this->ExecutableSuffix = ".app"; } else { - this->ExecutableSuffix = this->cmCPackGenerator::GetOutputExtension(); + this->ExecutableSuffix = exeSuffix; + } + + // Output extension + if (const char* optOutExt = + this->GetOption("CPACK_IFW_PACKAGE_FILE_EXTENSION")) { + this->OutputExtension = optOutExt; + } else if (sysName == "Darwin") { + this->OutputExtension = ".dmg"; + } else { + this->OutputExtension = this->ExecutableSuffix; + } + if (this->OutputExtension.empty()) { + this->OutputExtension = this->cmCPackGenerator::GetOutputExtension(); } return this->Superclass::InitializeInternal(); @@ -337,7 +406,7 @@ std::string cmCPackIFWGenerator::GetComponentInstallDirNameSuffix( cmCPackComponent* cmCPackIFWGenerator::GetComponent( const std::string& projectName, const std::string& componentName) { - ComponentsMap::iterator cit = this->Components.find(componentName); + auto cit = this->Components.find(componentName); if (cit != this->Components.end()) { return &(cit->second); } @@ -349,7 +418,7 @@ cmCPackComponent* cmCPackIFWGenerator::GetComponent( } std::string name = this->GetComponentPackageName(component); - PackagesMap::iterator pit = this->Packages.find(name); + auto pit = this->Packages.find(name); if (pit != this->Packages.end()) { return component; } @@ -370,7 +439,8 @@ cmCPackComponent* cmCPackIFWGenerator::GetComponent( } } else { this->Packages.erase(name); - cmCPackIFWLogger(ERROR, "Cannot configure package \"" + cmCPackIFWLogger(ERROR, + "Cannot configure package \"" << name << "\" for component \"" << component->Name << "\"" << std::endl); } @@ -388,7 +458,7 @@ cmCPackComponentGroup* cmCPackIFWGenerator::GetComponentGroup( } std::string name = this->GetGroupPackageName(group); - PackagesMap::iterator pit = this->Packages.find(name); + auto pit = this->Packages.find(name); if (pit != this->Packages.end()) { return group; } @@ -405,7 +475,8 @@ cmCPackComponentGroup* cmCPackIFWGenerator::GetComponentGroup( this->BinaryPackages.insert(package); } else { this->Packages.erase(name); - cmCPackIFWLogger(ERROR, "Cannot configure package \"" + cmCPackIFWLogger(ERROR, + "Cannot configure package \"" << name << "\" for component group \"" << group->Name << "\"" << std::endl); } @@ -518,23 +589,21 @@ std::string cmCPackIFWGenerator::GetComponentPackageName( cmCPackIFWPackage* cmCPackIFWGenerator::GetGroupPackage( cmCPackComponentGroup* group) const { - std::map<cmCPackComponentGroup*, cmCPackIFWPackage*>::const_iterator pit = - this->GroupPackages.find(group); - return pit != this->GroupPackages.end() ? pit->second : CM_NULLPTR; + auto pit = this->GroupPackages.find(group); + return pit != this->GroupPackages.end() ? pit->second : nullptr; } cmCPackIFWPackage* cmCPackIFWGenerator::GetComponentPackage( cmCPackComponent* component) const { - std::map<cmCPackComponent*, cmCPackIFWPackage*>::const_iterator pit = - this->ComponentPackages.find(component); - return pit != this->ComponentPackages.end() ? pit->second : CM_NULLPTR; + auto pit = this->ComponentPackages.find(component); + return pit != this->ComponentPackages.end() ? pit->second : nullptr; } cmCPackIFWRepository* cmCPackIFWGenerator::GetRepository( const std::string& repositoryName) { - RepositoriesMap::iterator rit = this->Repositories.find(repositoryName); + auto rit = this->Repositories.find(repositoryName); if (rit != this->Repositories.end()) { return &(rit->second); } @@ -550,8 +619,9 @@ cmCPackIFWRepository* cmCPackIFWGenerator::GetRepository( } } else { this->Repositories.erase(repositoryName); - repository = CM_NULLPTR; - cmCPackIFWLogger(WARNING, "Invalid repository \"" + repository = nullptr; + cmCPackIFWLogger(WARNING, + "Invalid repository \"" << repositoryName << "\"" << " configuration. Repository will be skipped." << std::endl); |