diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2021-10-08 09:13:08 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2021-10-08 09:13:08 +0900 |
commit | 488e9638b71b8b9cdb3055835815d77720eae06b (patch) | |
tree | f023cbc75da671dd2b75d3143cde8a066d5a93aa /Source/CPack | |
parent | f152fd464ac355590a5bb95451d4cd1ca1079d3c (diff) | |
download | cmake-488e9638b71b8b9cdb3055835815d77720eae06b.tar.gz cmake-488e9638b71b8b9cdb3055835815d77720eae06b.tar.bz2 cmake-488e9638b71b8b9cdb3055835815d77720eae06b.zip |
Imported Upstream version 3.10.0upstream/3.10.0
Diffstat (limited to 'Source/CPack')
55 files changed, 1094 insertions, 976 deletions
diff --git a/Source/CPack/IFW/cmCPackIFWCommon.cxx b/Source/CPack/IFW/cmCPackIFWCommon.cxx index e8f05bd50..1e7264156 100644 --- a/Source/CPack/IFW/cmCPackIFWCommon.cxx +++ b/Source/CPack/IFW/cmCPackIFWCommon.cxx @@ -15,14 +15,14 @@ #include <vector> cmCPackIFWCommon::cmCPackIFWCommon() - : Generator(CM_NULLPTR) + : Generator(nullptr) { } const char* cmCPackIFWCommon::GetOption(const std::string& op) const { return this->Generator ? this->Generator->cmCPackGenerator::GetOption(op) - : CM_NULLPTR; + : nullptr; } bool cmCPackIFWCommon::IsOn(const std::string& op) const diff --git a/Source/CPack/IFW/cmCPackIFWGenerator.cxx b/Source/CPack/IFW/cmCPackIFWGenerator.cxx index 226ea0a29..825a88804 100644 --- a/Source/CPack/IFW/cmCPackIFWGenerator.cxx +++ b/Source/CPack/IFW/cmCPackIFWGenerator.cxx @@ -49,10 +49,22 @@ int cmCPackIFWGenerator::PackageFiles() ifwCmd += " -p " + 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 += " -p " + it; + } + } + + if (!this->RepoDirsVector.empty()) { + if (!this->IsVersionLess("3.1")) { + for (std::string const& rd : this->RepoDirsVector) { + ifwCmd += " --repository " + rd; + } + } else { + cmCPackIFWLogger(WARNING, "The \"CPACK_IFW_REPOSITORIES_DIRECTORIES\" " + << "variable is set, but content will be skiped, " + << "because this feature available only since " + << "QtIFW 3.1. Please update your QtIFW instance." + << std::endl); } } @@ -73,7 +85,7 @@ int cmCPackIFWGenerator::PackageFiles() int retVal = 1; cmCPackIFWLogger(OUTPUT, "- Generate repository" << std::endl); bool res = cmSystemTools::RunSingleCommand(ifwCmd.c_str(), &output, - &output, &retVal, CM_NULLPTR, + &output, &retVal, nullptr, this->GeneratorVerbose, 0); if (!res || retVal) { cmGeneratedFileStream ofs(ifwTmpFile.c_str()); @@ -121,10 +133,22 @@ int cmCPackIFWGenerator::PackageFiles() ifwCmd += " -p " + 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 += " -p " + it; + } + } + + if (!this->RepoDirsVector.empty()) { + if (!this->IsVersionLess("3.1")) { + for (std::string const& rd : this->RepoDirsVector) { + ifwCmd += " --repository " + 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); } } @@ -164,13 +188,14 @@ int cmCPackIFWGenerator::PackageFiles() ifwCmd += " " + this->packageFileNames[0]; } else { ifwCmd += " installer"; + ifwCmd += this->OutputExtension; } cmCPackIFWLogger(VERBOSE, "Execute: " << 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, + &output, &retVal, nullptr, this->GeneratorVerbose, 0); if (!res || retVal) { cmGeneratedFileStream ofs(ifwTmpFile.c_str()); @@ -205,7 +230,7 @@ const char* cmCPackIFWGenerator::GetPackagingInstallPrefix() const char* cmCPackIFWGenerator::GetOutputExtension() { - return this->ExecutableSuffix.c_str(); + return this->OutputExtension.c_str(); } int cmCPackIFWGenerator::InitializeInternal() @@ -225,7 +250,7 @@ int cmCPackIFWGenerator::InitializeInternal() const char* BinCreatorStr = this->GetOption(BinCreatorOpt); if (!BinCreatorStr || cmSystemTools::IsNOTFOUND(BinCreatorStr)) { - this->BinCreator = ""; + this->BinCreator.clear(); } else { this->BinCreator = BinCreatorStr; } @@ -241,7 +266,7 @@ int cmCPackIFWGenerator::InitializeInternal() const char* RepoGenStr = this->GetOption(RepoGenOpt); if (!RepoGenStr || cmSystemTools::IsNOTFOUND(RepoGenStr)) { - this->RepoGen = ""; + this->RepoGen.clear(); } else { this->RepoGen = RepoGenStr; } @@ -265,6 +290,13 @@ int cmCPackIFWGenerator::InitializeInternal() cmSystemTools::ExpandListArgument(dirs, this->PkgsDirsVector); } + // Additional repositories dirs + this->RepoDirsVector.clear(); + if (const char* dirs = + this->GetOption("CPACK_IFW_REPOSITORIES_DIRECTORIES")) { + cmSystemTools::ExpandListArgument(dirs, this->RepoDirsVector); + } + // Installer this->Installer.Generator = this; this->Installer.ConfigureFromOptions(); @@ -281,9 +313,8 @@ int cmCPackIFWGenerator::InitializeInternal() 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); + for (std::string const& r : RepoAllVector) { + this->GetRepository(r); } } @@ -305,16 +336,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(); @@ -520,7 +564,7 @@ cmCPackIFWPackage* cmCPackIFWGenerator::GetGroupPackage( { std::map<cmCPackComponentGroup*, cmCPackIFWPackage*>::const_iterator pit = this->GroupPackages.find(group); - return pit != this->GroupPackages.end() ? pit->second : CM_NULLPTR; + return pit != this->GroupPackages.end() ? pit->second : nullptr; } cmCPackIFWPackage* cmCPackIFWGenerator::GetComponentPackage( @@ -528,7 +572,7 @@ cmCPackIFWPackage* cmCPackIFWGenerator::GetComponentPackage( { std::map<cmCPackComponent*, cmCPackIFWPackage*>::const_iterator pit = this->ComponentPackages.find(component); - return pit != this->ComponentPackages.end() ? pit->second : CM_NULLPTR; + return pit != this->ComponentPackages.end() ? pit->second : nullptr; } cmCPackIFWRepository* cmCPackIFWGenerator::GetRepository( @@ -550,7 +594,7 @@ cmCPackIFWRepository* cmCPackIFWGenerator::GetRepository( } } else { this->Repositories.erase(repositoryName); - repository = CM_NULLPTR; + repository = nullptr; cmCPackIFWLogger(WARNING, "Invalid repository \"" << repositoryName << "\"" << " configuration. Repository will be skipped." diff --git a/Source/CPack/IFW/cmCPackIFWGenerator.h b/Source/CPack/IFW/cmCPackIFWGenerator.h index 8348ceeec..919dd4678 100644 --- a/Source/CPack/IFW/cmCPackIFWGenerator.h +++ b/Source/CPack/IFW/cmCPackIFWGenerator.h @@ -47,7 +47,7 @@ public: /** * Destruct IFW generator */ - ~cmCPackIFWGenerator() CM_OVERRIDE; + ~cmCPackIFWGenerator() override; protected: // cmCPackGenerator reimplementation @@ -56,18 +56,18 @@ protected: * @brief Initialize generator * @return 0 on failure */ - int InitializeInternal() CM_OVERRIDE; - int PackageFiles() CM_OVERRIDE; - const char* GetPackagingInstallPrefix() CM_OVERRIDE; + int InitializeInternal() override; + int PackageFiles() override; + const char* GetPackagingInstallPrefix() override; /** - * @brief Extension of binary installer - * @return Executable suffix or value from default implementation + * @brief Target binary extension + * @return Executable suffix or disk image format */ - const char* GetOutputExtension() CM_OVERRIDE; + const char* GetOutputExtension() override; std::string GetComponentInstallDirNameSuffix( - const std::string& componentName) CM_OVERRIDE; + const std::string& componentName) override; /** * @brief Get Component @@ -79,7 +79,7 @@ protected: * @return Pointer to component */ cmCPackComponent* GetComponent(const std::string& projectName, - const std::string& componentName) CM_OVERRIDE; + const std::string& componentName) override; /** * @brief Get group of component @@ -91,12 +91,12 @@ protected: * @return Pointer to component group */ cmCPackComponentGroup* GetComponentGroup( - const std::string& projectName, const std::string& groupName) CM_OVERRIDE; + const std::string& projectName, const std::string& groupName) override; - enum cmCPackGenerator::CPackSetDestdirSupport SupportsSetDestdir() const - CM_OVERRIDE; - bool SupportsAbsoluteDestination() const CM_OVERRIDE; - bool SupportsComponentInstallation() const CM_OVERRIDE; + enum cmCPackGenerator::CPackSetDestdirSupport SupportsSetDestdir() + const override; + bool SupportsAbsoluteDestination() const override; + bool SupportsComponentInstallation() const override; protected: // Methods @@ -143,10 +143,12 @@ private: std::string BinCreator; std::string FrameworkVersion; std::string ExecutableSuffix; + std::string OutputExtension; bool OnlineOnly; bool ResolveDuplicateNames; std::vector<std::string> PkgsDirsVector; + std::vector<std::string> RepoDirsVector; }; #endif diff --git a/Source/CPack/IFW/cmCPackIFWInstaller.cxx b/Source/CPack/IFW/cmCPackIFWInstaller.cxx index 288e924e5..422f5d5e7 100644 --- a/Source/CPack/IFW/cmCPackIFWInstaller.cxx +++ b/Source/CPack/IFW/cmCPackIFWInstaller.cxx @@ -262,7 +262,7 @@ public: std::string path, basePath; protected: - void StartElement(const std::string& name, const char** /*atts*/) CM_OVERRIDE + void StartElement(const std::string& name, const char** /*atts*/) override { this->file = name == "file"; if (file) { @@ -270,7 +270,7 @@ protected: } } - void CharacterDataHandler(const char* data, int length) CM_OVERRIDE + void CharacterDataHandler(const char* data, int length) override { if (this->file) { std::string content(data, data + length); @@ -284,7 +284,7 @@ protected: } } - void EndElement(const std::string& /*name*/) CM_OVERRIDE {} + void EndElement(const std::string& /*name*/) override {} }; void cmCPackIFWInstaller::GenerateInstallerFile() @@ -406,9 +406,8 @@ void cmCPackIFWInstaller::GenerateInstallerFile() // Remote repositories if (!this->RemoteRepositories.empty()) { xout.StartElement("RemoteRepositories"); - for (RepositoriesVector::iterator rit = this->RemoteRepositories.begin(); - rit != this->RemoteRepositories.end(); ++rit) { - (*rit)->WriteRepositoryConfig(xout); + for (cmCPackIFWRepository* r : this->RemoteRepositories) { + r->WriteRepositoryConfig(xout); } xout.EndElement(); } @@ -492,9 +491,8 @@ void cmCPackIFWInstaller::GeneratePackageFiles() } // Generate packages meta information - for (PackagesMap::iterator pit = this->Packages.begin(); - pit != this->Packages.end(); ++pit) { - cmCPackIFWPackage* package = pit->second; + for (auto& p : this->Packages) { + cmCPackIFWPackage* package = p.second; package->GeneratePackageFile(); } } diff --git a/Source/CPack/IFW/cmCPackIFWPackage.cxx b/Source/CPack/IFW/cmCPackIFWPackage.cxx index c5311c31c..d3ce15c86 100644 --- a/Source/CPack/IFW/cmCPackIFWPackage.cxx +++ b/Source/CPack/IFW/cmCPackIFWPackage.cxx @@ -92,7 +92,7 @@ std::string cmCPackIFWPackage::DependenceStruct::NameWithCompare() const //------------------------------------------------------ cmCPackIFWPackage --- cmCPackIFWPackage::cmCPackIFWPackage() - : Installer(CM_NULLPTR) + : Installer(nullptr) { } @@ -111,19 +111,19 @@ void cmCPackIFWPackage::DefaultConfiguration() { this->DisplayName.clear(); this->Description.clear(); - this->Version = ""; - this->ReleaseDate = ""; - this->Script = ""; + this->Version.clear(); + this->ReleaseDate.clear(); + this->Script.clear(); this->Licenses.clear(); this->UserInterfaces.clear(); this->Translations.clear(); - this->SortingPriority = ""; - this->UpdateText = ""; - this->Default = ""; - this->Essential = ""; - this->Virtual = ""; - this->ForcedInstallation = ""; - this->RequiresAdminRights = ""; + this->SortingPriority.clear(); + this->UpdateText.clear(); + this->Default.clear(); + this->Essential.clear(); + this->Virtual.clear(); + this->ForcedInstallation.clear(); + this->RequiresAdminRights.clear(); } // Defaul configuration (all in one package) @@ -203,10 +203,8 @@ int cmCPackIFWPackage::ConfigureFromComponent(cmCPackComponent* component) // CMake dependencies if (!component->Dependencies.empty()) { - std::vector<cmCPackComponent*>::iterator dit; - for (dit = component->Dependencies.begin(); - dit != component->Dependencies.end(); ++dit) { - this->Dependencies.insert(this->Generator->ComponentPackages[*dit]); + for (cmCPackComponent* dep : component->Dependencies) { + this->Dependencies.insert(this->Generator->ComponentPackages[dep]); } } @@ -413,9 +411,8 @@ int cmCPackIFWPackage::ConfigureFromPrefix(const std::string& prefix) if (const char* value = this->GetOption(option)) { cmSystemTools::ExpandListArgument(value, deps); } - for (std::vector<std::string>::iterator dit = deps.begin(); - dit != deps.end(); ++dit) { - DependenceStruct dep(*dit); + for (std::string const& d : deps) { + DependenceStruct dep(d); if (this->Generator->Packages.count(dep.Name)) { cmCPackIFWPackage& depPkg = this->Generator->Packages[dep.Name]; dep.Name = depPkg.Name; @@ -435,9 +432,8 @@ int cmCPackIFWPackage::ConfigureFromPrefix(const std::string& prefix) } else if (const char* value = this->GetOption(option)) { std::vector<std::string> depsOn; cmSystemTools::ExpandListArgument(value, depsOn); - for (std::vector<std::string>::iterator dit = depsOn.begin(); - dit != depsOn.end(); ++dit) { - DependenceStruct dep(*dit); + for (std::string const& d : depsOn) { + DependenceStruct dep(d); if (this->Generator->Packages.count(dep.Name)) { cmCPackIFWPackage& depPkg = this->Generator->Packages[dep.Name]; dep.Name = depPkg.Name; @@ -486,6 +482,15 @@ int cmCPackIFWPackage::ConfigureFromPrefix(const std::string& prefix) this->ForcedInstallation = "false"; } + // Replaces + option = prefix + "REPLACES"; + if (this->IsSetToEmpty(option)) { + this->Replaces.clear(); + } else if (const char* value = this->GetOption(option)) { + this->Replaces.clear(); + cmSystemTools::ExpandListArgument(value, this->Replaces); + } + // Requires admin rights option = prefix + "REQUIRES_ADMIN_RIGHTS"; if (this->IsSetToEmpty(option)) { @@ -496,6 +501,16 @@ int cmCPackIFWPackage::ConfigureFromPrefix(const std::string& prefix) this->RequiresAdminRights = "false"; } + // Checkable + option = prefix + "CHECKABLE"; + if (this->IsSetToEmpty(option)) { + this->Checkable.clear(); + } else if (this->IsOn(option)) { + this->Checkable = "true"; + } else if (this->IsSetToOff(option)) { + this->Checkable = "false"; + } + return 1; } @@ -521,26 +536,22 @@ void cmCPackIFWPackage::GeneratePackageFile() xout.StartElement("Package"); // DisplayName (with translations) - for (std::map<std::string, std::string>::iterator it = - this->DisplayName.begin(); - it != this->DisplayName.end(); ++it) { + for (auto const& dn : this->DisplayName) { xout.StartElement("DisplayName"); - if (!it->first.empty()) { - xout.Attribute("xml:lang", it->first); + if (!dn.first.empty()) { + xout.Attribute("xml:lang", dn.first); } - xout.Content(it->second); + xout.Content(dn.second); xout.EndElement(); } // Description (with translations) - for (std::map<std::string, std::string>::iterator it = - this->Description.begin(); - it != this->Description.end(); ++it) { + for (auto const& d : this->Description) { xout.StartElement("Description"); - if (!it->first.empty()) { - xout.Attribute("xml:lang", it->first); + if (!d.first.empty()) { + xout.Attribute("xml:lang", d.first); } - xout.Content(it->second); + xout.Content(d.second); xout.EndElement(); } @@ -568,46 +579,43 @@ void cmCPackIFWPackage::GeneratePackageFile() // User Interfaces (copy to meta dir) std::vector<std::string> userInterfaces = UserInterfaces; - for (size_t i = 0; i < userInterfaces.size(); i++) { - std::string name = cmSystemTools::GetFilenameName(userInterfaces[i]); + for (std::string& userInterface : userInterfaces) { + std::string name = cmSystemTools::GetFilenameName(userInterface); std::string path = this->Directory + "/meta/" + name; - cmsys::SystemTools::CopyFileIfDifferent(userInterfaces[i], path); - userInterfaces[i] = name; + cmsys::SystemTools::CopyFileIfDifferent(userInterface, path); + userInterface = name; } if (!userInterfaces.empty()) { xout.StartElement("UserInterfaces"); - for (size_t i = 0; i < userInterfaces.size(); i++) { - xout.Element("UserInterface", userInterfaces[i]); + for (std::string const& userInterface : userInterfaces) { + xout.Element("UserInterface", userInterface); } xout.EndElement(); } // Translations (copy to meta dir) std::vector<std::string> translations = Translations; - for (size_t i = 0; i < translations.size(); i++) { - std::string name = cmSystemTools::GetFilenameName(translations[i]); + for (std::string& translation : translations) { + std::string name = cmSystemTools::GetFilenameName(translation); std::string path = this->Directory + "/meta/" + name; - cmsys::SystemTools::CopyFileIfDifferent(translations[i], path); - translations[i] = name; + cmsys::SystemTools::CopyFileIfDifferent(translation, path); + translation = name; } if (!translations.empty()) { xout.StartElement("Translations"); - for (size_t i = 0; i < translations.size(); i++) { - xout.Element("Translation", translations[i]); + for (std::string const& translation : translations) { + xout.Element("Translation", translation); } xout.EndElement(); } // Dependencies std::set<DependenceStruct> compDepSet; - for (std::set<DependenceStruct*>::iterator ait = - this->AlienDependencies.begin(); - ait != this->AlienDependencies.end(); ++ait) { - compDepSet.insert(*(*ait)); + for (DependenceStruct* ad : this->AlienDependencies) { + compDepSet.insert(*ad); } - for (std::set<cmCPackIFWPackage*>::iterator it = this->Dependencies.begin(); - it != this->Dependencies.end(); ++it) { - compDepSet.insert(DependenceStruct((*it)->Name)); + for (cmCPackIFWPackage* d : this->Dependencies) { + compDepSet.insert(DependenceStruct(d->Name)); } // Write dependencies if (!compDepSet.empty()) { @@ -624,10 +632,8 @@ void cmCPackIFWPackage::GeneratePackageFile() // Automatic dependency on std::set<DependenceStruct> compAutoDepSet; - for (std::set<DependenceStruct*>::iterator ait = - this->AlienAutoDependOn.begin(); - ait != this->AlienAutoDependOn.end(); ++ait) { - compAutoDepSet.insert(*(*ait)); + for (DependenceStruct* aad : this->AlienAutoDependOn) { + compAutoDepSet.insert(*aad); } // Write automatic dependency on if (!compAutoDepSet.empty()) { @@ -665,6 +671,19 @@ void cmCPackIFWPackage::GeneratePackageFile() xout.Element("ForcedInstallation", this->ForcedInstallation); } + // Replaces + if (!this->Replaces.empty()) { + std::ostringstream replaces; + std::vector<std::string>::iterator it = this->Replaces.begin(); + replaces << *it; + ++it; + while (it != this->Replaces.end()) { + replaces << "," << *it; + ++it; + } + xout.Element("Replaces", replaces.str()); + } + if (!this->RequiresAdminRights.empty()) { xout.Element("RequiresAdminRights", this->RequiresAdminRights); } @@ -685,6 +704,11 @@ void cmCPackIFWPackage::GeneratePackageFile() xout.Element("SortingPriority", this->SortingPriority); } + // Checkable + if (!this->Checkable.empty()) { + xout.Element("Checkable", this->Checkable); + } + xout.EndElement(); xout.EndDocument(); } diff --git a/Source/CPack/IFW/cmCPackIFWPackage.h b/Source/CPack/IFW/cmCPackIFWPackage.h index cec59b03c..ae411462a 100644 --- a/Source/CPack/IFW/cmCPackIFWPackage.h +++ b/Source/CPack/IFW/cmCPackIFWPackage.h @@ -114,9 +114,15 @@ public: /// Determines that the package must always be installed std::string ForcedInstallation; + /// List of components to replace + std::vector<std::string> Replaces; + /// Package needs to be installed with elevated permissions std::string RequiresAdminRights; + /// Set to false if you want to hide the checkbox for an item + std::string Checkable; + public: // Internal implementation diff --git a/Source/CPack/IFW/cmCPackIFWRepository.cxx b/Source/CPack/IFW/cmCPackIFWRepository.cxx index b115db057..a01fc4ed3 100644 --- a/Source/CPack/IFW/cmCPackIFWRepository.cxx +++ b/Source/CPack/IFW/cmCPackIFWRepository.cxx @@ -62,49 +62,49 @@ bool cmCPackIFWRepository::ConfigureFromOptions() if (const char* url = this->GetOption(prefix + "URL")) { this->Url = url; } else { - this->Url = ""; + this->Url.clear(); } // Old url if (const char* oldUrl = this->GetOption(prefix + "OLD_URL")) { this->OldUrl = oldUrl; } else { - this->OldUrl = ""; + this->OldUrl.clear(); } // New url if (const char* newUrl = this->GetOption(prefix + "NEW_URL")) { this->NewUrl = newUrl; } else { - this->NewUrl = ""; + this->NewUrl.clear(); } // Enabled if (this->IsOn(prefix + "DISABLED")) { this->Enabled = "0"; } else { - this->Enabled = ""; + this->Enabled.clear(); } // Username if (const char* username = this->GetOption(prefix + "USERNAME")) { this->Username = username; } else { - this->Username = ""; + this->Username.clear(); } // Password if (const char* password = this->GetOption(prefix + "PASSWORD")) { this->Password = password; } else { - this->Password = ""; + this->Password.clear(); } // DisplayName if (const char* displayName = this->GetOption(prefix + "DISPLAY_NAME")) { this->DisplayName = displayName; } else { - this->DisplayName = ""; + this->DisplayName.clear(); } return this->IsValid(); @@ -128,7 +128,7 @@ public: bool patched; protected: - void StartElement(const std::string& name, const char** atts) CM_OVERRIDE + void StartElement(const std::string& name, const char** atts) override { this->xout.StartElement(name); this->StartFragment(atts); @@ -143,7 +143,7 @@ protected: } } - void EndElement(const std::string& name) CM_OVERRIDE + void EndElement(const std::string& name) override { if (name == "Updates" && !this->patched) { this->repository->WriteRepositoryUpdates(this->xout); @@ -159,10 +159,10 @@ protected: } } - void CharacterDataHandler(const char* data, int length) CM_OVERRIDE + void CharacterDataHandler(const char* data, int length) override { std::string content(data, data + length); - if (content == "" || content == " " || content == " " || + if (content.empty() || content == " " || content == " " || content == "\n") { return; } @@ -279,9 +279,8 @@ void cmCPackIFWRepository::WriteRepositoryUpdates(cmXMLWriter& xout) { if (!this->RepositoryUpdate.empty()) { xout.StartElement("RepositoryUpdate"); - for (RepositoriesVector::iterator rit = this->RepositoryUpdate.begin(); - rit != this->RepositoryUpdate.end(); ++rit) { - (*rit)->WriteRepositoryUpdate(xout); + for (cmCPackIFWRepository* r : this->RepositoryUpdate) { + r->WriteRepositoryUpdate(xout); } xout.EndElement(); } diff --git a/Source/CPack/OSXScriptLauncher.cxx b/Source/CPack/OSXScriptLauncher.cxx index b48bf1214..d3de02b47 100644 --- a/Source/CPack/OSXScriptLauncher.cxx +++ b/Source/CPack/OSXScriptLauncher.cxx @@ -34,7 +34,7 @@ int main(int argc, char* argv[]) } fileName = CFSTR("RuntimeScript"); if (!(scriptFileURL = - CFBundleCopyResourceURL(appBundle, fileName, NULL, NULL))) { + CFBundleCopyResourceURL(appBundle, fileName, nullptr, nullptr))) { DebugError("CFBundleCopyResourceURL failed"); return 1; } @@ -71,7 +71,7 @@ int main(int argc, char* argv[]) for (cc = 1; cc < argc; ++cc) { args.push_back(argv[cc]); } - args.push_back(0); + args.push_back(nullptr); cmsysProcess* cp = cmsysProcess_New(); cmsysProcess_SetCommand(cp, &*args.begin()); @@ -83,7 +83,7 @@ int main(int argc, char* argv[]) std::vector<char> tempOutput; char* data; int length; - while (cmsysProcess_WaitForData(cp, &data, &length, 0)) { + while (cmsysProcess_WaitForData(cp, &data, &length, nullptr)) { // Translate NULL characters in the output into valid text. for (int i = 0; i < length; ++i) { if (data[i] == '\0') { @@ -93,7 +93,7 @@ int main(int argc, char* argv[]) std::cout.write(data, length); } - cmsysProcess_WaitForExit(cp, 0); + cmsysProcess_WaitForExit(cp, nullptr); bool result = true; if (cmsysProcess_GetState(cp) == cmsysProcess_State_Exited) { diff --git a/Source/CPack/WiX/cmCPackWIXGenerator.cxx b/Source/CPack/WiX/cmCPackWIXGenerator.cxx index 274dfd0ce..ba07d0863 100644 --- a/Source/CPack/WiX/cmCPackWIXGenerator.cxx +++ b/Source/CPack/WiX/cmCPackWIXGenerator.cxx @@ -89,9 +89,8 @@ bool cmCPackWIXGenerator::RunCandleCommand(std::string const& sourceFile, command << " -arch " << GetArchitecture(); command << " -out " << QuotePath(objectFile); - for (extension_set_t::const_iterator i = CandleExtensions.begin(); - i != CandleExtensions.end(); ++i) { - command << " -ext " << QuotePath(*i); + for (std::string const& ext : CandleExtensions) { + command << " -ext " << QuotePath(ext); } AddCustomFlags("CPACK_WIX_CANDLE_EXTRA_FLAGS", command); @@ -113,9 +112,8 @@ bool cmCPackWIXGenerator::RunLightCommand(std::string const& objectFiles) command << " -nologo"; command << " -out " << QuotePath(packageFileNames.at(0)); - for (extension_set_t::const_iterator i = this->LightExtensions.begin(); - i != this->LightExtensions.end(); ++i) { - command << " -ext " << QuotePath(*i); + for (std::string const& ext : this->LightExtensions) { + command << " -ext " << QuotePath(ext); } const char* const cultures = GetOption("CPACK_WIX_CULTURES"); @@ -219,8 +217,8 @@ bool cmCPackWIXGenerator::InitializeWiXConfiguration() std::vector<std::string> patchFilePaths; cmSystemTools::ExpandListArgument(patchFilePath, patchFilePaths); - for (size_t i = 0; i < patchFilePaths.size(); ++i) { - if (!this->Patch->LoadFragments(patchFilePaths[i])) { + for (std::string const& p : patchFilePaths) { + if (!this->Patch->LoadFragments(p)) { return false; } } @@ -254,9 +252,7 @@ bool cmCPackWIXGenerator::PackageFilesImpl() std::set<std::string> usedBaseNames; std::ostringstream objectFiles; - for (size_t i = 0; i < this->WixSources.size(); ++i) { - std::string const& sourceFilename = this->WixSources[i]; - + for (std::string const& sourceFilename : this->WixSources) { std::string baseName = cmSystemTools::GetFilenameWithoutLastExtension(sourceFilename); @@ -306,8 +302,8 @@ void cmCPackWIXGenerator::AppendUserSuppliedExtraObjects(std::ostream& stream) cmSystemTools::ExpandListArgument(cpackWixExtraObjects, expandedExtraObjects); - for (size_t i = 0; i < expandedExtraObjects.size(); ++i) { - stream << " " << QuotePath(expandedExtraObjects[i]); + for (std::string const& obj : expandedExtraObjects) { + stream << " " << QuotePath(obj); } } @@ -345,9 +341,7 @@ void cmCPackWIXGenerator::CreateWiXPropertiesIncludeFile() std::string prefix = "CPACK_WIX_PROPERTY_"; std::vector<std::string> options = GetOptions(); - for (size_t i = 0; i < options.size(); ++i) { - std::string const& name = options[i]; - + for (std::string const& name : options) { if (name.length() > prefix.length() && name.substr(0, prefix.length()) == prefix) { std::string id = name.substr(prefix.length()); @@ -503,16 +497,14 @@ bool cmCPackWIXGenerator::CreateWiXSourceFiles() globalShortcuts.AddShortcutTypes(emittedShortcutTypes); } else { - for (std::map<std::string, cmCPackComponent>::const_iterator i = - this->Components.begin(); - i != this->Components.end(); ++i) { - cmCPackComponent const& component = i->second; + for (auto const& i : this->Components) { + cmCPackComponent const& component = i.second; std::string componentPath = toplevel; componentPath += "/"; componentPath += component.Name; - std::string componentFeatureId = "CM_C_" + component.Name; + std::string const componentFeatureId = "CM_C_" + component.Name; cmWIXShortcuts featureShortcuts; AddComponentsToFeature(componentPath, componentFeatureId, @@ -623,19 +615,15 @@ bool cmCPackWIXGenerator::GenerateMainSourceFileFromTemplate() bool cmCPackWIXGenerator::CreateFeatureHierarchy( cmWIXFeaturesSourceWriter& featureDefinitions) { - for (std::map<std::string, cmCPackComponentGroup>::const_iterator i = - ComponentGroups.begin(); - i != ComponentGroups.end(); ++i) { - cmCPackComponentGroup const& group = i->second; + for (auto const& i : ComponentGroups) { + cmCPackComponentGroup const& group = i.second; if (group.ParentGroup == 0) { featureDefinitions.EmitFeatureForComponentGroup(group, *this->Patch); } } - for (std::map<std::string, cmCPackComponent>::const_iterator i = - this->Components.begin(); - i != this->Components.end(); ++i) { - cmCPackComponent const& component = i->second; + for (auto const& i : this->Components) { + cmCPackComponent const& component = i.second; if (!component.Group) { featureDefinitions.EmitFeatureForComponent(component, *this->Patch); @@ -1135,9 +1123,8 @@ void cmCPackWIXGenerator::AddCustomFlags(std::string const& variableName, std::vector<std::string> list; cmSystemTools::ExpandListArgument(variableContent, list); - for (std::vector<std::string>::const_iterator i = list.begin(); - i != list.end(); ++i) { - stream << " " << QuotePath(*i); + for (std::string const& i : list) { + stream << " " << QuotePath(i); } } diff --git a/Source/CPack/WiX/cmWIXAccessControlList.cxx b/Source/CPack/WiX/cmWIXAccessControlList.cxx index 744a93298..1603bf868 100644 --- a/Source/CPack/WiX/cmWIXAccessControlList.cxx +++ b/Source/CPack/WiX/cmWIXAccessControlList.cxx @@ -20,8 +20,8 @@ bool cmWIXAccessControlList::Apply() std::vector<std::string> entries; this->InstalledFile.GetPropertyAsList("CPACK_WIX_ACL", entries); - for (size_t i = 0; i < entries.size(); ++i) { - this->CreatePermissionElement(entries[i]); + for (std::string const& entry : entries) { + this->CreatePermissionElement(entry); } return true; @@ -56,9 +56,9 @@ void cmWIXAccessControlList::CreatePermissionElement(std::string const& entry) if (!domain.empty()) { this->SourceWriter.AddAttribute("Domain", domain); } - for (size_t i = 0; i < permissions.size(); ++i) { + for (std::string const& permission : permissions) { this->EmitBooleanAttribute(entry, - cmSystemTools::TrimWhitespace(permissions[i])); + cmSystemTools::TrimWhitespace(permission)); } this->SourceWriter.EndElement("Permission"); } diff --git a/Source/CPack/WiX/cmWIXFeaturesSourceWriter.cxx b/Source/CPack/WiX/cmWIXFeaturesSourceWriter.cxx index 0be43776e..a7a064881 100644 --- a/Source/CPack/WiX/cmWIXFeaturesSourceWriter.cxx +++ b/Source/CPack/WiX/cmWIXFeaturesSourceWriter.cxx @@ -46,16 +46,12 @@ void cmWIXFeaturesSourceWriter::EmitFeatureForComponentGroup( patch.ApplyFragment("CM_G_" + group.Name, *this); - for (std::vector<cmCPackComponentGroup*>::const_iterator i = - group.Subgroups.begin(); - i != group.Subgroups.end(); ++i) { - EmitFeatureForComponentGroup(**i, patch); + for (cmCPackComponentGroup* subgroup : group.Subgroups) { + EmitFeatureForComponentGroup(*subgroup, patch); } - for (std::vector<cmCPackComponent*>::const_iterator i = - group.Components.begin(); - i != group.Components.end(); ++i) { - EmitFeatureForComponent(**i, patch); + for (cmCPackComponent* component : group.Components) { + EmitFeatureForComponent(*component, patch); } EndElement("Feature"); diff --git a/Source/CPack/WiX/cmWIXPatch.cxx b/Source/CPack/WiX/cmWIXPatch.cxx index 287a644bb..dec95fb6e 100644 --- a/Source/CPack/WiX/cmWIXPatch.cxx +++ b/Source/CPack/WiX/cmWIXPatch.cxx @@ -29,10 +29,8 @@ void cmWIXPatch::ApplyFragment(std::string const& id, return; const cmWIXPatchElement& fragment = i->second; - for (cmWIXPatchElement::attributes_t::const_iterator attr_i = - fragment.attributes.begin(); - attr_i != fragment.attributes.end(); ++attr_i) { - writer.AddAttribute(attr_i->first, attr_i->second); + for (auto const& attr : fragment.attributes) { + writer.AddAttribute(attr.first, attr.second); } this->ApplyElementChildren(fragment, writer); @@ -42,11 +40,7 @@ void cmWIXPatch::ApplyFragment(std::string const& id, void cmWIXPatch::ApplyElementChildren(const cmWIXPatchElement& element, cmWIXSourceWriter& writer) { - for (cmWIXPatchElement::child_list_t::const_iterator j = - element.children.begin(); - j != element.children.end(); ++j) { - cmWIXPatchNode* node = *j; - + for (cmWIXPatchNode* node : element.children) { switch (node->type()) { case cmWIXPatchNode::ELEMENT: ApplyElement(dynamic_cast<const cmWIXPatchElement&>(*node), writer); @@ -63,10 +57,8 @@ void cmWIXPatch::ApplyElement(const cmWIXPatchElement& element, { writer.BeginElement(element.name); - for (cmWIXPatchElement::attributes_t::const_iterator i = - element.attributes.begin(); - i != element.attributes.end(); ++i) { - writer.AddAttribute(i->first, i->second); + for (auto const& attr : element.attributes) { + writer.AddAttribute(attr.first, attr.second); } this->ApplyElementChildren(element, writer); @@ -77,14 +69,13 @@ void cmWIXPatch::ApplyElement(const cmWIXPatchElement& element, bool cmWIXPatch::CheckForUnappliedFragments() { std::string fragmentList; - for (cmWIXPatchParser::fragment_map_t::const_iterator i = Fragments.begin(); - i != Fragments.end(); ++i) { + for (auto const& fragment : Fragments) { if (!fragmentList.empty()) { fragmentList += ", "; } fragmentList += "'"; - fragmentList += i->first; + fragmentList += fragment.first; fragmentList += "'"; } diff --git a/Source/CPack/WiX/cmWIXPatchParser.cxx b/Source/CPack/WiX/cmWIXPatchParser.cxx index 0dcc74ae0..e6aeed325 100644 --- a/Source/CPack/WiX/cmWIXPatchParser.cxx +++ b/Source/CPack/WiX/cmWIXPatchParser.cxx @@ -22,8 +22,8 @@ cmWIXPatchNode::~cmWIXPatchNode() cmWIXPatchElement::~cmWIXPatchElement() { - for (child_list_t::iterator i = children.begin(); i != children.end(); ++i) { - delete *i; + for (cmWIXPatchNode* child : children) { + delete child; } } @@ -72,7 +72,7 @@ void cmWIXPatchParser::StartElement(const std::string& name, const char** atts) void cmWIXPatchParser::StartFragment(const char** attributes) { - cmWIXPatchElement* new_element = CM_NULLPTR; + cmWIXPatchElement* new_element = nullptr; /* find the id of for fragment */ for (size_t i = 0; attributes[i]; i += 2) { const std::string key = attributes[i]; diff --git a/Source/CPack/WiX/cmWIXRichTextFormatWriter.h b/Source/CPack/WiX/cmWIXRichTextFormatWriter.h index 30df87814..21be8ee66 100644 --- a/Source/CPack/WiX/cmWIXRichTextFormatWriter.h +++ b/Source/CPack/WiX/cmWIXRichTextFormatWriter.h @@ -3,7 +3,7 @@ #ifndef cmWIXRichTextFormatWriter_h #define cmWIXRichTextFormatWriter_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmsys/FStream.hxx" #include <string> diff --git a/Source/CPack/WiX/cmWIXShortcut.cxx b/Source/CPack/WiX/cmWIXShortcut.cxx index e5dea94c4..cd1988a1c 100644 --- a/Source/CPack/WiX/cmWIXShortcut.cxx +++ b/Source/CPack/WiX/cmWIXShortcut.cxx @@ -47,10 +47,9 @@ bool cmWIXShortcuts::EmitShortcuts( return false; } - for (shortcut_id_map_t::const_iterator j = id_map.begin(); j != id_map.end(); - ++j) { - std::string const& id = j->first; - shortcut_list_t const& shortcutList = j->second; + for (auto const& j : id_map) { + std::string const& id = j.first; + shortcut_list_t const& shortcutList = j.second; for (size_t shortcutListIndex = 0; shortcutListIndex < shortcutList.size(); ++shortcutListIndex) { @@ -68,9 +67,8 @@ bool cmWIXShortcuts::EmitShortcuts( void cmWIXShortcuts::AddShortcutTypes(std::set<Type>& types) { - for (shortcut_type_map_t::const_iterator i = this->Shortcuts.begin(); - i != this->Shortcuts.end(); ++i) { - types.insert(i->first); + for (auto const& shortcut : this->Shortcuts) { + types.insert(shortcut.first); } } @@ -96,9 +94,9 @@ void cmWIXShortcuts::CreateFromProperty(std::string const& propertyName, std::vector<std::string> list; installedFile.GetPropertyAsList(propertyName, list); - for (size_t i = 0; i < list.size(); ++i) { + for (std::string const& label : list) { cmWIXShortcut shortcut; - shortcut.label = list[i]; + shortcut.label = label; shortcut.workingDirectoryId = directoryId; insert(type, id, shortcut); } diff --git a/Source/CPack/WiX/cmWIXSourceWriter.cxx b/Source/CPack/WiX/cmWIXSourceWriter.cxx index a86e28d1c..dc730e00c 100644 --- a/Source/CPack/WiX/cmWIXSourceWriter.cxx +++ b/Source/CPack/WiX/cmWIXSourceWriter.cxx @@ -158,9 +158,7 @@ std::string cmWIXSourceWriter::EscapeAttributeValue(std::string const& value) std::string result; result.reserve(value.size()); - char c = 0; - for (size_t i = 0; i < value.size(); ++i) { - c = value[i]; + for (char c : value) { switch (c) { case '<': result += "<"; diff --git a/Source/CPack/cmCPack7zGenerator.h b/Source/CPack/cmCPack7zGenerator.h index 42a47810c..8af4c4a4d 100644 --- a/Source/CPack/cmCPack7zGenerator.h +++ b/Source/CPack/cmCPack7zGenerator.h @@ -3,7 +3,7 @@ #ifndef cmCPack7zGenerator_h #define cmCPack7zGenerator_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmCPackArchiveGenerator.h" #include "cmCPackGenerator.h" @@ -20,10 +20,10 @@ public: * Construct generator */ cmCPack7zGenerator(); - ~cmCPack7zGenerator() CM_OVERRIDE; + ~cmCPack7zGenerator() override; protected: - const char* GetOutputExtension() CM_OVERRIDE { return ".7z"; } + const char* GetOutputExtension() override { return ".7z"; } }; #endif diff --git a/Source/CPack/cmCPackArchiveGenerator.cxx b/Source/CPack/cmCPackArchiveGenerator.cxx index 575c94924..641be3861 100644 --- a/Source/CPack/cmCPackArchiveGenerator.cxx +++ b/Source/CPack/cmCPackArchiveGenerator.cxx @@ -9,7 +9,6 @@ #include "cmSystemTools.h" #include "cmWorkingDirectory.h" -#include <map> #include <ostream> #include <utility> #include <vector> @@ -74,12 +73,10 @@ int cmCPackArchiveGenerator::addOneComponentToArchive( filePrefix += installPrefix + 1; filePrefix += "/"; } - std::vector<std::string>::const_iterator fileIt; - for (fileIt = component->Files.begin(); fileIt != component->Files.end(); - ++fileIt) { - std::string rp = filePrefix + *fileIt; + for (std::string const& file : component->Files) { + std::string rp = filePrefix + file; cmCPackLogger(cmCPackLog::LOG_DEBUG, "Adding file: " << rp << std::endl); - archive.Add(rp, 0, CM_NULLPTR, false); + archive.Add(rp, 0, nullptr, false); if (!archive) { cmCPackLogger(cmCPackLog::LOG_ERROR, "ERROR while packaging files: " << archive.GetError() << std::endl); @@ -117,53 +114,47 @@ int cmCPackArchiveGenerator::PackageComponents(bool ignoreGroup) // The default behavior is to have one package by component group // unless CPACK_COMPONENTS_IGNORE_GROUP is specified. if (!ignoreGroup) { - std::map<std::string, cmCPackComponentGroup>::iterator compGIt; - for (compGIt = this->ComponentGroups.begin(); - compGIt != this->ComponentGroups.end(); ++compGIt) { - cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Packaging component group: " - << compGIt->first << std::endl); + for (auto const& compG : this->ComponentGroups) { + cmCPackLogger(cmCPackLog::LOG_VERBOSE, + "Packaging component group: " << compG.first << std::endl); // Begin the archive for this group std::string packageFileName = std::string(toplevel) + "/" + - this->GetArchiveComponentFileName(compGIt->first, true); + this->GetArchiveComponentFileName(compG.first, true); // open a block in order to automatically close archive // at the end of the block { DECLARE_AND_OPEN_ARCHIVE(packageFileName, archive); // now iterate over the component of this group - std::vector<cmCPackComponent*>::iterator compIt; - for (compIt = (compGIt->second).Components.begin(); - compIt != (compGIt->second).Components.end(); ++compIt) { + for (cmCPackComponent* comp : (compG.second).Components) { // Add the files of this component to the archive - addOneComponentToArchive(archive, *compIt); + addOneComponentToArchive(archive, comp); } } // add the generated package to package file names list packageFileNames.push_back(packageFileName); } // Handle Orphan components (components not belonging to any groups) - std::map<std::string, cmCPackComponent>::iterator compIt; - for (compIt = this->Components.begin(); compIt != this->Components.end(); - ++compIt) { + for (auto& comp : this->Components) { // Does the component belong to a group? - if (compIt->second.Group == CM_NULLPTR) { + if (comp.second.Group == nullptr) { cmCPackLogger( cmCPackLog::LOG_VERBOSE, "Component <" - << compIt->second.Name + << comp.second.Name << "> does not belong to any group, package it separately." << std::endl); std::string localToplevel( this->GetOption("CPACK_TEMPORARY_DIRECTORY")); std::string packageFileName = std::string(toplevel); - localToplevel += "/" + compIt->first; + localToplevel += "/" + comp.first; packageFileName += - "/" + this->GetArchiveComponentFileName(compIt->first, false); + "/" + this->GetArchiveComponentFileName(comp.first, false); { DECLARE_AND_OPEN_ARCHIVE(packageFileName, archive); // Add the files of this component to the archive - addOneComponentToArchive(archive, &(compIt->second)); + addOneComponentToArchive(archive, &(comp.second)); } // add the generated package to package file names list packageFileNames.push_back(packageFileName); @@ -173,20 +164,18 @@ int cmCPackArchiveGenerator::PackageComponents(bool ignoreGroup) // CPACK_COMPONENTS_IGNORE_GROUPS is set // We build 1 package per component else { - std::map<std::string, cmCPackComponent>::iterator compIt; - for (compIt = this->Components.begin(); compIt != this->Components.end(); - ++compIt) { + for (auto& comp : this->Components) { std::string localToplevel(this->GetOption("CPACK_TEMPORARY_DIRECTORY")); std::string packageFileName = std::string(toplevel); - localToplevel += "/" + compIt->first; + localToplevel += "/" + comp.first; packageFileName += - "/" + this->GetArchiveComponentFileName(compIt->first, false); + "/" + this->GetArchiveComponentFileName(comp.first, false); { DECLARE_AND_OPEN_ARCHIVE(packageFileName, archive); // Add the files of this component to the archive - addOneComponentToArchive(archive, &(compIt->second)); + addOneComponentToArchive(archive, &(comp.second)); } // add the generated package to package file names list packageFileNames.push_back(packageFileName); @@ -217,11 +206,9 @@ int cmCPackArchiveGenerator::PackageComponentsAllInOne() DECLARE_AND_OPEN_ARCHIVE(packageFileNames[0], archive); // The ALL COMPONENTS in ONE package case - std::map<std::string, cmCPackComponent>::iterator compIt; - for (compIt = this->Components.begin(); compIt != this->Components.end(); - ++compIt) { + for (auto& comp : this->Components) { // Add the files of this component to the archive - addOneComponentToArchive(archive, &(compIt->second)); + addOneComponentToArchive(archive, &(comp.second)); } // archive goes out of scope so it will finalized and closed. @@ -249,16 +236,15 @@ int cmCPackArchiveGenerator::PackageFiles() // CASE 3 : NON COMPONENT package. DECLARE_AND_OPEN_ARCHIVE(packageFileNames[0], archive); - std::vector<std::string>::const_iterator fileIt; cmWorkingDirectory workdir(toplevel); - for (fileIt = files.begin(); fileIt != files.end(); ++fileIt) { + for (std::string const& file : files) { // Get the relative path to the file std::string rp = - cmSystemTools::RelativePath(toplevel.c_str(), fileIt->c_str()); - archive.Add(rp, 0, CM_NULLPTR, false); + cmSystemTools::RelativePath(toplevel.c_str(), file.c_str()); + archive.Add(rp, 0, nullptr, false); if (!archive) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem while adding file< " - << *fileIt << "> to archive <" << packageFileNames[0] + << file << "> to archive <" << packageFileNames[0] << "> .ERROR =" << archive.GetError() << std::endl); return 0; } diff --git a/Source/CPack/cmCPackArchiveGenerator.h b/Source/CPack/cmCPackArchiveGenerator.h index e7116c466..998385432 100644 --- a/Source/CPack/cmCPackArchiveGenerator.h +++ b/Source/CPack/cmCPackArchiveGenerator.h @@ -3,7 +3,7 @@ #ifndef cmCPackArchiveGenerator_h #define cmCPackArchiveGenerator_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmArchiveWrite.h" #include "cmCPackGenerator.h" @@ -28,11 +28,11 @@ public: * Construct generator */ cmCPackArchiveGenerator(cmArchiveWrite::Compress, std::string const& format); - ~cmCPackArchiveGenerator() CM_OVERRIDE; + ~cmCPackArchiveGenerator() override; // Used to add a header to the archive virtual int GenerateHeader(std::ostream* os); // component support - bool SupportsComponentInstallation() const CM_OVERRIDE; + bool SupportsComponentInstallation() const override; private: // get archive component filename @@ -40,7 +40,7 @@ private: bool isGroupName); protected: - int InitializeInternal() CM_OVERRIDE; + int InitializeInternal() override; /** * Add the files belonging to the specified component * to the provided (already opened) archive. @@ -56,7 +56,7 @@ protected: * method will call either PackageComponents or * PackageComponentsAllInOne. */ - int PackageFiles() CM_OVERRIDE; + int PackageFiles() override; /** * The method used to package files when component * install is used. This will create one @@ -68,7 +68,7 @@ protected: * components will be put in a single installer. */ int PackageComponentsAllInOne(); - const char* GetOutputExtension() CM_OVERRIDE = 0; + const char* GetOutputExtension() override = 0; cmArchiveWrite::Compress Compress; std::string ArchiveFormat; }; diff --git a/Source/CPack/cmCPackBundleGenerator.cxx b/Source/CPack/cmCPackBundleGenerator.cxx index d5389014a..f47ca7a74 100644 --- a/Source/CPack/cmCPackBundleGenerator.cxx +++ b/Source/CPack/cmCPackBundleGenerator.cxx @@ -19,7 +19,7 @@ cmCPackBundleGenerator::~cmCPackBundleGenerator() int cmCPackBundleGenerator::InitializeInternal() { const char* name = this->GetOption("CPACK_BUNDLE_NAME"); - if (0 == name) { + if (nullptr == name) { cmCPackLogger(cmCPackLog::LOG_ERROR, "CPACK_BUNDLE_NAME must be set to use the Bundle generator." << std::endl); @@ -213,8 +213,7 @@ int cmCPackBundleGenerator::SignBundle(const std::string& src_dir) cmSystemTools::ExpandListArgument(sign_files, relFiles); // sign the files supplied by the user, ie. frameworks. - for (std::vector<std::string>::iterator it = relFiles.begin(); - it != relFiles.end(); ++it) { + for (auto const& file : relFiles) { std::ostringstream temp_sign_file_cmd; temp_sign_file_cmd << this->GetOption("CPACK_COMMAND_CODESIGN"); temp_sign_file_cmd << " " << sign_parameter << " -s \"" @@ -223,11 +222,11 @@ int cmCPackBundleGenerator::SignBundle(const std::string& src_dir) temp_sign_file_cmd << this->GetOption("CPACK_APPLE_BUNDLE_ID"); temp_sign_file_cmd << " \""; temp_sign_file_cmd << bundle_path; - temp_sign_file_cmd << *it << "\""; + temp_sign_file_cmd << file << "\""; if (!this->RunCommand(temp_sign_file_cmd, &output)) { cmCPackLogger(cmCPackLog::LOG_ERROR, - "Error signing file:" << bundle_path << *it << std::endl + "Error signing file:" << bundle_path << file << std::endl << output << std::endl); return 0; diff --git a/Source/CPack/cmCPackBundleGenerator.h b/Source/CPack/cmCPackBundleGenerator.h index 861fe4b09..27bac3a5a 100644 --- a/Source/CPack/cmCPackBundleGenerator.h +++ b/Source/CPack/cmCPackBundleGenerator.h @@ -3,7 +3,7 @@ #ifndef cmCPackBundleGenerator_h #define cmCPackBundleGenerator_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include <string> @@ -21,15 +21,15 @@ public: cmCPackTypeMacro(cmCPackBundleGenerator, cmCPackDragNDropGenerator); cmCPackBundleGenerator(); - virtual ~cmCPackBundleGenerator(); + ~cmCPackBundleGenerator() override; protected: - int InitializeInternal() CM_OVERRIDE; - const char* GetPackagingInstallPrefix() CM_OVERRIDE; + int InitializeInternal() override; + const char* GetPackagingInstallPrefix() override; int ConstructBundle(); int SignBundle(const std::string& src_dir); - int PackageFiles() CM_OVERRIDE; - bool SupportsComponentInstallation() const CM_OVERRIDE; + int PackageFiles() override; + bool SupportsComponentInstallation() const override; std::string InstallPrefix; }; diff --git a/Source/CPack/cmCPackComponentGroup.cxx b/Source/CPack/cmCPackComponentGroup.cxx index e39398ad5..f888a5f5d 100644 --- a/Source/CPack/cmCPackComponentGroup.cxx +++ b/Source/CPack/cmCPackComponentGroup.cxx @@ -5,7 +5,6 @@ #include "cmSystemTools.h" #include <string> -#include <vector> unsigned long cmCPackComponent::GetInstalledSize( const std::string& installDir) const @@ -14,11 +13,10 @@ unsigned long cmCPackComponent::GetInstalledSize( return this->TotalSize; } - std::vector<std::string>::const_iterator fileIt; - for (fileIt = this->Files.begin(); fileIt != this->Files.end(); ++fileIt) { + for (std::string const& file : this->Files) { std::string path = installDir; path += '/'; - path += *fileIt; + path += file; this->TotalSize += cmSystemTools::FileLength(path); } diff --git a/Source/CPack/cmCPackComponentGroup.h b/Source/CPack/cmCPackComponentGroup.h index 26d69ba68..f2907db20 100644 --- a/Source/CPack/cmCPackComponentGroup.h +++ b/Source/CPack/cmCPackComponentGroup.h @@ -3,7 +3,7 @@ #ifndef cmCPackComponentGroup_h #define cmCPackComponentGroup_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include <string> #include <vector> @@ -36,7 +36,7 @@ class cmCPackComponent { public: cmCPackComponent() - : Group(CM_NULLPTR) + : Group(nullptr) , IsRequired(true) , IsHidden(false) , IsDisabledByDefault(false) @@ -114,7 +114,7 @@ class cmCPackComponentGroup { public: cmCPackComponentGroup() - : ParentGroup(CM_NULLPTR) + : ParentGroup(nullptr) { } diff --git a/Source/CPack/cmCPackCygwinBinaryGenerator.h b/Source/CPack/cmCPackCygwinBinaryGenerator.h index 58e80bda7..f87a1343b 100644 --- a/Source/CPack/cmCPackCygwinBinaryGenerator.h +++ b/Source/CPack/cmCPackCygwinBinaryGenerator.h @@ -17,7 +17,7 @@ public: * Construct generator */ cmCPackCygwinBinaryGenerator(); - virtual ~cmCPackCygwinBinaryGenerator(); + ~cmCPackCygwinBinaryGenerator() override; protected: virtual int InitializeInternal(); diff --git a/Source/CPack/cmCPackCygwinSourceGenerator.h b/Source/CPack/cmCPackCygwinSourceGenerator.h index 896de1d3e..a909b1595 100644 --- a/Source/CPack/cmCPackCygwinSourceGenerator.h +++ b/Source/CPack/cmCPackCygwinSourceGenerator.h @@ -17,7 +17,7 @@ public: * Construct generator */ cmCPackCygwinSourceGenerator(); - virtual ~cmCPackCygwinSourceGenerator(); + ~cmCPackCygwinSourceGenerator() override; protected: const char* GetPackagingInstallPrefix(); diff --git a/Source/CPack/cmCPackDebGenerator.cxx b/Source/CPack/cmCPackDebGenerator.cxx index af54fce33..7fc3c26de 100644 --- a/Source/CPack/cmCPackDebGenerator.cxx +++ b/Source/CPack/cmCPackDebGenerator.cxx @@ -6,28 +6,17 @@ #include "cmCPackComponentGroup.h" #include "cmCPackGenerator.h" #include "cmCPackLog.h" +#include "cmCryptoHash.h" #include "cmGeneratedFileStream.h" #include "cmSystemTools.h" #include "cm_sys_stat.h" #include "cmsys/Glob.hxx" -#include <limits.h> -#include <map> #include <ostream> #include <set> -#include <stdio.h> #include <string.h> #include <utility> -// NOTE: -// A debian package .deb is simply an 'ar' archive. The only subtle difference -// is that debian uses the BSD ar style archive whereas most Linux distro have -// a GNU ar. -// See http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=161593 for more info -// Therefore we provide our own implementation of a BSD-ar: -static int ar_append(const char* archive, - const std::vector<std::string>& files); - cmCPackDebGenerator::cmCPackDebGenerator() { } @@ -115,37 +104,31 @@ int cmCPackDebGenerator::PackageComponents(bool ignoreGroup) // The default behavior is to have one package by component group // unless CPACK_COMPONENTS_IGNORE_GROUP is specified. if (!ignoreGroup) { - std::map<std::string, cmCPackComponentGroup>::iterator compGIt; - for (compGIt = this->ComponentGroups.begin(); - compGIt != this->ComponentGroups.end(); ++compGIt) { - cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Packaging component group: " - << compGIt->first << std::endl); + for (auto const& compG : this->ComponentGroups) { + cmCPackLogger(cmCPackLog::LOG_VERBOSE, + "Packaging component group: " << compG.first << std::endl); // Begin the archive for this group - retval &= PackageOnePack(initialTopLevel, compGIt->first); + retval &= PackageOnePack(initialTopLevel, compG.first); } // Handle Orphan components (components not belonging to any groups) - std::map<std::string, cmCPackComponent>::iterator compIt; - for (compIt = this->Components.begin(); compIt != this->Components.end(); - ++compIt) { + for (auto const& comp : this->Components) { // Does the component belong to a group? - if (compIt->second.Group == CM_NULLPTR) { + if (comp.second.Group == nullptr) { cmCPackLogger( cmCPackLog::LOG_VERBOSE, "Component <" - << compIt->second.Name + << comp.second.Name << "> does not belong to any group, package it separately." << std::endl); // Begin the archive for this orphan component - retval &= PackageOnePack(initialTopLevel, compIt->first); + retval &= PackageOnePack(initialTopLevel, comp.first); } } } // CPACK_COMPONENTS_IGNORE_GROUPS is set // We build 1 package per component else { - std::map<std::string, cmCPackComponent>::iterator compIt; - for (compIt = this->Components.begin(); compIt != this->Components.end(); - ++compIt) { - retval &= PackageOnePack(initialTopLevel, compIt->first); + for (auto const& comp : this->Components) { + retval &= PackageOnePack(initialTopLevel, comp.first); } } return retval; @@ -346,10 +329,8 @@ int cmCPackDebGenerator::createDeb() { std::string dirName = this->GetOption("CPACK_TEMPORARY_DIRECTORY"); dirName += '/'; - for (std::vector<std::string>::const_iterator fileIt = - packageFiles.begin(); - fileIt != packageFiles.end(); ++fileIt) { - totalSize += cmSystemTools::FileLength(*fileIt); + for (std::string const& file : packageFiles) { + totalSize += cmSystemTools::FileLength(file); } } out << "Installed-Size: " << (totalSize + 1023) / 1024 << "\n"; @@ -410,7 +391,7 @@ int cmCPackDebGenerator::createDeb() compression_suffix = ".gz"; tar_compression_type = cmArchiveWrite::CompressGZip; } else if (!strcmp(debian_compression_type, "none")) { - compression_suffix = ""; + compression_suffix.clear(); tar_compression_type = cmArchiveWrite::CompressNone; } else { cmCPackLogger(cmCPackLog::LOG_ERROR, @@ -456,10 +437,7 @@ int cmCPackDebGenerator::createDeb() // we have to reconstruct the parent folders as well - for (std::vector<std::string>::const_iterator fileIt = - packageFiles.begin(); - fileIt != packageFiles.end(); ++fileIt) { - std::string currentPath = *fileIt; + for (std::string currentPath : packageFiles) { while (currentPath != strGenWDIR) { // the last one IS strGenWDIR, but we do not want this one: // XXX/application/usr/bin/myprogram with GEN_WDIR=XXX/application @@ -469,22 +447,40 @@ int cmCPackDebGenerator::createDeb() } } - for (std::set<std::string>::const_iterator fileIt = orderedFiles.begin(); - fileIt != orderedFiles.end(); ++fileIt) { - cmCPackLogger(cmCPackLog::LOG_DEBUG, "FILEIT: \"" << *fileIt << "\"" + for (std::string const& file : orderedFiles) { + cmCPackLogger(cmCPackLog::LOG_DEBUG, "FILEIT: \"" << file << "\"" << std::endl); - std::string::size_type slashPos = fileIt->find('/', topLevelLength + 1); + std::string::size_type slashPos = file.find('/', topLevelLength + 1); std::string relativeDir = - fileIt->substr(topLevelLength, slashPos - topLevelLength); + file.substr(topLevelLength, slashPos - topLevelLength); cmCPackLogger(cmCPackLog::LOG_DEBUG, "RELATIVEDIR: \"" << relativeDir << "\"" << std::endl); +#ifdef WIN32 + std::string mode_t_adt_filename = file + ":cmake_mode_t"; + cmsys::ifstream permissionStream(mode_t_adt_filename.c_str()); + + mode_t permissions = 0; + + if (permissionStream) { + permissionStream >> std::oct >> permissions; + } + + if (permissions != 0) { + data_tar.SetPermissions(permissions); + } else if (cmSystemTools::FileIsDirectory(file)) { + data_tar.SetPermissions(0755); + } else { + data_tar.ClearPermissions(); + } +#endif + // do not recurse because the loop will do it - if (!data_tar.Add(*fileIt, topLevelLength, ".", false)) { + if (!data_tar.Add(file, topLevelLength, ".", false)) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem adding file to tar:" << std::endl << "#top level directory: " << strGenWDIR << std::endl - << "#file: " << *fileIt << std::endl + << "#file: " << file << std::endl << "#error:" << data_tar.GetError() << std::endl); return 0; } @@ -499,25 +495,21 @@ int cmCPackDebGenerator::createDeb() std::string topLevelWithTrailingSlash = this->GetOption("CPACK_TEMPORARY_DIRECTORY"); topLevelWithTrailingSlash += '/'; - for (std::vector<std::string>::const_iterator fileIt = - packageFiles.begin(); - fileIt != packageFiles.end(); ++fileIt) { + for (std::string const& file : packageFiles) { // hash only regular files - if (cmSystemTools::FileIsDirectory(*fileIt) || - cmSystemTools::FileIsSymlink(*fileIt)) { + if (cmSystemTools::FileIsDirectory(file) || + cmSystemTools::FileIsSymlink(file)) { continue; } - char md5sum[33]; - if (!cmSystemTools::ComputeFileMD5(*fileIt, md5sum)) { + std::string output = + cmSystemTools::ComputeFileHash(file, cmCryptoHash::AlgoMD5); + if (output.empty()) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem computing the md5 of " - << *fileIt << std::endl); + << file << std::endl); } - md5sum[32] = 0; - - std::string output(md5sum); - output += " " + *fileIt + "\n"; + output += " " + file + "\n"; // debian md5sums entries are like this: // 014f3604694729f3bf19263bac599765 usr/bin/ccmake // thus strip the full path (with the trailing slash) @@ -553,8 +545,8 @@ int cmCPackDebGenerator::createDeb() and https://lintian.debian.org/tags/control-file-has-bad-permissions.html */ - const mode_t permission644 = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; - const mode_t permissionExecute = S_IXUSR | S_IXGRP | S_IXOTH; + const mode_t permission644 = 0644; + const mode_t permissionExecute = 0111; const mode_t permission755 = permission644 | permissionExecute; // for md5sum and control (that we have generated here), we use 644 @@ -634,9 +626,8 @@ int cmCPackDebGenerator::createDeb() std::vector<std::string> controlExtraList; cmSystemTools::ExpandListArgument(controlExtra, controlExtraList); - for (std::vector<std::string>::iterator i = controlExtraList.begin(); - i != controlExtraList.end(); ++i) { - std::string filenamename = cmsys::SystemTools::GetFilenameName(*i); + for (std::string const& i : controlExtraList) { + std::string filenamename = cmsys::SystemTools::GetFilenameName(i); std::string localcopy = strGenWDIR + "/" + filenamename; if (permissionStrictPolicy) { @@ -646,7 +637,7 @@ int cmCPackDebGenerator::createDeb() } // if we can copy the file, it means it does exist, let's add it: - if (cmsys::SystemTools::CopyFileIfDifferent(*i, localcopy)) { + if (cmsys::SystemTools::CopyFileIfDifferent(i, localcopy)) { control_tar.Add(localcopy, strGenWDIR.length(), "."); } } @@ -654,23 +645,25 @@ int cmCPackDebGenerator::createDeb() } // ar -r your-package-name.deb debian-binary control.tar.* data.tar.* - // since debian packages require BSD ar (most Linux distros and even - // FreeBSD and NetBSD ship GNU ar) we use a copy of OpenBSD ar here. - std::vector<std::string> arFiles; - std::string topLevelString = strGenWDIR + "/"; - arFiles.push_back(topLevelString + "debian-binary"); - arFiles.push_back(topLevelString + "control.tar.gz"); - arFiles.push_back(topLevelString + "data.tar" + compression_suffix); - std::string outputFileName = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); - outputFileName += "/"; - outputFileName += this->GetOption("GEN_CPACK_OUTPUT_FILE_NAME"); - int res = ar_append(outputFileName.c_str(), arFiles); - if (res != 0) { - std::string tmpFile = - this->GetOption("GEN_CPACK_TEMPORARY_PACKAGE_FILE_NAME"); - tmpFile += "/Deb.log"; - cmGeneratedFileStream ofs(tmpFile.c_str()); - ofs << "# Problem creating archive using: " << res << std::endl; + // A debian package .deb is simply an 'ar' archive. The only subtle + // difference is that debian uses the BSD ar style archive whereas most + // Linux distro have a GNU ar. + // See http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=161593 for more info + std::string const outputDir = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); + std::string const outputName = this->GetOption("GEN_CPACK_OUTPUT_FILE_NAME"); + std::string const outputPath = outputDir + "/" + outputName; + std::string const tlDir = strGenWDIR + "/"; + cmGeneratedFileStream debStream; + debStream.Open(outputPath.c_str(), false, true); + cmArchiveWrite deb(debStream, cmArchiveWrite::CompressNone, "arbsd"); + if (!deb.Add(tlDir + "debian-binary", tlDir.length()) || + !deb.Add(tlDir + "control.tar.gz", tlDir.length()) || + !deb.Add(tlDir + "data.tar" + compression_suffix, tlDir.length())) { + cmCPackLogger(cmCPackLog::LOG_ERROR, "Error creating debian package:" + << std::endl + << "#top level directory: " << outputDir << std::endl + << "#file: " << outputName << std::endl + << "#error:" << deb.GetError() << std::endl); return 0; } return 1; @@ -695,252 +688,8 @@ std::string cmCPackDebGenerator::GetComponentInstallDirNameSuffix( // the current COMPONENT belongs to. std::string groupVar = "CPACK_COMPONENT_" + cmSystemTools::UpperCase(componentName) + "_GROUP"; - if (CM_NULLPTR != GetOption(groupVar)) { + if (nullptr != GetOption(groupVar)) { return std::string(GetOption(groupVar)); } return componentName; } - -// The following code is taken from OpenBSD ar: -// http://www.openbsd.org/cgi-bin/cvsweb/src/usr.bin/ar/ -// It has been slightly modified: -// -return error codes instead exit() in functions -// -use the stdio file I/O functions instead the file descriptor based ones -// -merged into one cxx file -// -no additional options supported -// The coding style hasn't been modified. - -/*- - * Copyright (c) 1990, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Hugh Smith at The University of Guelph. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#define ARMAG "!<arch>\n" /* ar "magic number" */ -#define SARMAG 8 /* strlen(ARMAG); */ - -#define AR_EFMT1 "#1/" /* extended format #1 */ -#define ARFMAG "`\n" - -/* Header format strings. */ -#define HDR1 "%s%-13d%-12ld%-6u%-6u%-8o%-10lld%2s" -#define HDR2 "%-16.16s%-12ld%-6u%-6u%-8o%-10lld%2s" - -struct ar_hdr -{ - char ar_name[16]; /* name */ - char ar_date[12]; /* modification time */ - char ar_uid[6]; /* user id */ - char ar_gid[6]; /* group id */ - char ar_mode[8]; /* octal file permissions */ - char ar_size[10]; /* size in bytes */ - char ar_fmag[2]; /* consistency check */ -}; - -/* Set up file copy. */ -#define SETCF(from, fromname, to, toname, pad) \ - { \ - cf.rFile = from; \ - cf.rname = fromname; \ - cf.wFile = to; \ - cf.wname = toname; \ - cf.flags = pad; \ - } - -/* File copy structure. */ -typedef struct -{ - FILE* rFile; /* read file descriptor */ - const char* rname; /* read name */ - FILE* wFile; /* write file descriptor */ - const char* wname; /* write name */ -#define NOPAD 0x00 /* don't pad */ -#define WPAD 0x02 /* pad on writes */ - unsigned int flags; /* pad flags */ -} CF; - -/* misc.c */ - -static const char* ar_rname(const char* path) -{ - const char* ind = strrchr(path, '/'); - return (ind) ? ind + 1 : path; -} - -/* archive.c */ - -typedef struct ar_hdr HDR; -static char ar_hb[sizeof(HDR) + 1]; /* real header */ - -static size_t ar_already_written; - -/* copy_ar -- - * Copy size bytes from one file to another - taking care to handle the - * extra byte (for odd size files) when reading archives and writing an - * extra byte if necessary when adding files to archive. The length of - * the object is the long name plus the object itself; the variable - * already_written gets set if a long name was written. - * - * The padding is really unnecessary, and is almost certainly a remnant - * of early archive formats where the header included binary data which - * a PDP-11 required to start on an even byte boundary. (Or, perhaps, - * because 16-bit word addressed copies were faster?) Anyhow, it should - * have been ripped out long ago. - */ -static int copy_ar(CF* cfp, off_t size) -{ - static char pad = '\n'; - off_t sz = size; - size_t nr, nw; - char buf[8 * 1024]; - - if (sz == 0) { - return 0; - } - - FILE* from = cfp->rFile; - FILE* to = cfp->wFile; - while (sz && - (nr = fread(buf, 1, sz < static_cast<off_t>(sizeof(buf)) - ? static_cast<size_t>(sz) - : sizeof(buf), - from)) > 0) { - sz -= nr; - for (size_t off = 0; off < nr; nr -= off, off += nw) { - if ((nw = fwrite(buf + off, 1, nr, to)) < nr) { - return -1; - } - } - } - if (sz) { - return -2; - } - - if (cfp->flags & WPAD && (size + ar_already_written) & 1 && - fwrite(&pad, 1, 1, to) != 1) { - return -4; - } - - return 0; -} - -/* put_arobj -- Write an archive member to a file. */ -static int put_arobj(CF* cfp, struct stat* sb) -{ - int result = 0; - struct ar_hdr* hdr; - - /* If passed an sb structure, reading a file from disk. Get stat(2) - * information, build a name and construct a header. (Files are named - * by their last component in the archive.) */ - const char* name = ar_rname(cfp->rname); - (void)stat(cfp->rname, sb); - - /* If not truncating names and the name is too long or contains - * a space, use extended format 1. */ - size_t lname = strlen(name); - uid_t uid = sb->st_uid; - gid_t gid = sb->st_gid; - if (uid > USHRT_MAX) { - uid = USHRT_MAX; - } - if (gid > USHRT_MAX) { - gid = USHRT_MAX; - } - if (lname > sizeof(hdr->ar_name) || strchr(name, ' ')) { - (void)sprintf(ar_hb, HDR1, AR_EFMT1, (int)lname, (long int)sb->st_mtime, - (unsigned)uid, (unsigned)gid, (unsigned)sb->st_mode, - (long long)sb->st_size + lname, ARFMAG); - } else { - lname = 0; - (void)sprintf(ar_hb, HDR2, name, (long int)sb->st_mtime, (unsigned)uid, - (unsigned)gid, (unsigned)sb->st_mode, (long long)sb->st_size, - ARFMAG); - } - off_t size = sb->st_size; - - if (fwrite(ar_hb, 1, sizeof(HDR), cfp->wFile) != sizeof(HDR)) { - return -1; - } - - if (lname) { - if (fwrite(name, 1, lname, cfp->wFile) != lname) { - return -2; - } - ar_already_written = lname; - } - result = copy_ar(cfp, size); - ar_already_written = 0; - return result; -} - -/* append.c */ - -/* append -- - * Append files to the archive - modifies original archive or creates - * a new archive if named archive does not exist. - */ -static int ar_append(const char* archive, - const std::vector<std::string>& files) -{ - int eval = 0; - FILE* aFile = cmSystemTools::Fopen(archive, "wb+"); - if (aFile != CM_NULLPTR) { - fwrite(ARMAG, SARMAG, 1, aFile); - if (fseek(aFile, 0, SEEK_END) != -1) { - CF cf; - struct stat sb; - /* Read from disk, write to an archive; pad on write. */ - SETCF(CM_NULLPTR, CM_NULLPTR, aFile, archive, WPAD); - for (std::vector<std::string>::const_iterator fileIt = files.begin(); - fileIt != files.end(); ++fileIt) { - const char* filename = fileIt->c_str(); - FILE* file = cmSystemTools::Fopen(filename, "rb"); - if (file == CM_NULLPTR) { - eval = -1; - continue; - } - cf.rFile = file; - cf.rname = filename; - int result = put_arobj(&cf, &sb); - (void)fclose(file); - if (result != 0) { - eval = -2; - break; - } - } - } else { - eval = -3; - } - fclose(aFile); - } else { - eval = -4; - } - return eval; -} diff --git a/Source/CPack/cmCPackDebGenerator.h b/Source/CPack/cmCPackDebGenerator.h index e7cde1145..b4f0c7972 100644 --- a/Source/CPack/cmCPackDebGenerator.h +++ b/Source/CPack/cmCPackDebGenerator.h @@ -3,7 +3,7 @@ #ifndef cmCPackDebGenerator_h #define cmCPackDebGenerator_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmCPackGenerator.h" @@ -23,7 +23,7 @@ public: * Construct generator */ cmCPackDebGenerator(); - ~cmCPackDebGenerator() CM_OVERRIDE; + ~cmCPackDebGenerator() override; static bool CanGenerate() { @@ -40,7 +40,7 @@ public: } protected: - int InitializeInternal() CM_OVERRIDE; + int InitializeInternal() override; /** * This method factors out the work done in component packaging case. */ @@ -57,11 +57,11 @@ protected: * components will be put in a single installer. */ int PackageComponentsAllInOne(const std::string& compInstDirName); - int PackageFiles() CM_OVERRIDE; - const char* GetOutputExtension() CM_OVERRIDE { return ".deb"; } - bool SupportsComponentInstallation() const CM_OVERRIDE; + int PackageFiles() override; + const char* GetOutputExtension() override { return ".deb"; } + bool SupportsComponentInstallation() const override; std::string GetComponentInstallDirNameSuffix( - const std::string& componentName) CM_OVERRIDE; + const std::string& componentName) override; private: int createDeb(); diff --git a/Source/CPack/cmCPackDragNDropGenerator.cxx b/Source/CPack/cmCPackDragNDropGenerator.cxx index d26d5bc1a..1e1543f9d 100644 --- a/Source/CPack/cmCPackDragNDropGenerator.cxx +++ b/Source/CPack/cmCPackDragNDropGenerator.cxx @@ -136,17 +136,17 @@ int cmCPackDragNDropGenerator::InitializeInternal() "CPACK_DMG_SLA_LANGUAGES set but empty" << std::endl); return 0; } - for (size_t i = 0; i < languages.size(); ++i) { - std::string license = slaDirectory + "/" + languages[i] + ".license.txt"; + for (auto const& language : languages) { + std::string license = slaDirectory + "/" + language + ".license.txt"; if (!singleLicense && !cmSystemTools::FileExists(license)) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Missing license file " - << languages[i] << ".license.txt" << std::endl); + << language << ".license.txt" << std::endl); return 0; } - std::string menu = slaDirectory + "/" + languages[i] + ".menu.txt"; + std::string menu = slaDirectory + "/" + language + ".menu.txt"; if (!cmSystemTools::FileExists(menu)) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Missing menu file " - << languages[i] << ".menu.txt" << std::endl); + << language << ".menu.txt" << std::endl); return 0; } } @@ -185,19 +185,19 @@ int cmCPackDragNDropGenerator::PackageFiles() // loop to create dmg files packageFileNames.clear(); - for (size_t i = 0; i < package_files.size(); i++) { + for (auto const& package_file : package_files) { std::string full_package_name = std::string(toplevel) + std::string("/"); - if (package_files[i] == "ALL_IN_ONE") { + if (package_file == "ALL_IN_ONE") { full_package_name += this->GetOption("CPACK_PACKAGE_FILE_NAME"); } else { - full_package_name += package_files[i]; + full_package_name += package_file; } full_package_name += std::string(GetOutputExtension()); packageFileNames.push_back(full_package_name); std::string src_dir = toplevel; src_dir += "/"; - src_dir += package_files[i]; + src_dir += package_file; if (0 == this->CreateDMG(src_dir, full_package_name)) { return 0; @@ -226,14 +226,14 @@ bool cmCPackDragNDropGenerator::CreateEmptyFile(std::ostringstream& target, cmsys::ofstream fout(target.str().c_str(), std::ios::out | std::ios::binary); if (!fout) { return false; - } else { - // Seek to desired size - 1 byte - fout.seekp(size - 1, std::ios::beg); - char byte = 0; - // Write one byte to ensure file grows - fout.write(&byte, 1); } + // Seek to desired size - 1 byte + fout.seekp(size - 1, std::ios::beg); + char byte = 0; + // Write one byte to ensure file grows + fout.write(&byte, 1); + return true; } @@ -242,9 +242,9 @@ bool cmCPackDragNDropGenerator::RunCommand(std::ostringstream& command, { int exit_code = 1; - bool result = - cmSystemTools::RunSingleCommand(command.str().c_str(), output, output, - &exit_code, 0, this->GeneratorVerbose, 0); + bool result = cmSystemTools::RunSingleCommand(command.str().c_str(), output, + output, &exit_code, nullptr, + this->GeneratorVerbose, 0); if (!result || exit_code) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Error executing: " << command.str() @@ -417,6 +417,7 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir, temp_image_command << " -ov"; temp_image_command << " -srcfolder \"" << staging.str() << "\""; temp_image_command << " -volname \"" << cpack_dmg_volume_name << "\""; + temp_image_command << " -fs HFS+"; temp_image_command << " -format " << temp_image_format; temp_image_command << " \"" << temp_image << "\""; @@ -448,6 +449,8 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir, cmsys::RegularExpression mountpoint_regex(".*(/Volumes/[^\n]+)\n.*"); mountpoint_regex.find(attach_output.c_str()); std::string const temp_mount = mountpoint_regex.match(1); + std::string const temp_mount_name = + temp_mount.substr(sizeof("/Volumes/") - 1); // Remove dummy padding file so we have enough space on RW image ... std::ostringstream dummy_padding; @@ -481,7 +484,7 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir, std::ostringstream setup_script_command; setup_script_command << "osascript" << " \"" << cpack_dmg_ds_store_setup_script << "\"" - << " \"" << cpack_dmg_volume_name << "\""; + << " \"" << temp_mount_name << "\""; std::string error; if (!this->RunCommand(setup_script_command, &error)) { cmCPackLogger(cmCPackLog::LOG_ERROR, @@ -551,16 +554,17 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir, header_data.push_back(languages.size()); for (size_t i = 0; i < languages.size(); ++i) { CFStringRef language_cfstring = CFStringCreateWithCString( - NULL, languages[i].c_str(), kCFStringEncodingUTF8); + nullptr, languages[i].c_str(), kCFStringEncodingUTF8); CFStringRef iso_language = CFLocaleCreateCanonicalLanguageIdentifierFromString( - NULL, language_cfstring); + nullptr, language_cfstring); if (!iso_language) { cmCPackLogger(cmCPackLog::LOG_ERROR, languages[i] << " is not a recognized language" << std::endl); } - char* iso_language_cstr = (char*)malloc(65); - CFStringGetCString(iso_language, iso_language_cstr, 64, + char iso_language_cstr[65]; + CFStringGetCString(iso_language, iso_language_cstr, + sizeof(iso_language_cstr) - 1, kCFStringEncodingMacRoman); LangCode lang = 0; RegionCode region = 0; @@ -573,11 +577,9 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir, cmCPackLogger(cmCPackLog::LOG_ERROR, "No language/region code available for " << iso_language_cstr << std::endl); - free(iso_language_cstr); return 0; } #ifdef HAVE_CoreServices - free(iso_language_cstr); header_data.push_back(region); header_data.push_back(i); header_data.push_back(0); @@ -767,7 +769,8 @@ std::string cmCPackDragNDropGenerator::GetComponentInstallDirNameSuffix( bool cmCPackDragNDropGenerator::WriteLicense( cmGeneratedFileStream& outputStream, int licenseNumber, - std::string licenseLanguage, std::string licenseFile, std::string* error) + std::string licenseLanguage, const std::string& licenseFile, + std::string* error) { if (!licenseFile.empty() && !singleLicense) { licenseNumber = 5002; @@ -793,8 +796,8 @@ bool cmCPackDragNDropGenerator::WriteLicense( if (!this->BreakLongLine(line, lines, error)) { return false; } - for (size_t i = 0; i < lines.size(); ++i) { - outputStream << " \"" << lines[i] << "\"\n"; + for (auto const& l : lines) { + outputStream << " \"" << l << "\"\n"; } } outputStream << " \"\\n\"\n"; @@ -863,10 +866,11 @@ bool cmCPackDragNDropGenerator::BreakLongLine(const std::string& line, size_t line_length = max_line_length; if (i + line_length > line.size()) { line_length = line.size() - i; - } else + } else { while (line_length > 0 && line[i + line_length - 1] != ' ') { line_length = line_length - 1; } + } if (line_length == 0) { *error = "Please make sure there are no words " diff --git a/Source/CPack/cmCPackDragNDropGenerator.h b/Source/CPack/cmCPackDragNDropGenerator.h index ae2cc173f..d8c5c8337 100644 --- a/Source/CPack/cmCPackDragNDropGenerator.h +++ b/Source/CPack/cmCPackDragNDropGenerator.h @@ -3,7 +3,7 @@ #ifndef cmCPackDragNDropGenerator_h #define cmCPackDragNDropGenerator_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include <sstream> #include <stddef.h> @@ -23,32 +23,30 @@ public: cmCPackTypeMacro(cmCPackDragNDropGenerator, cmCPackGenerator); cmCPackDragNDropGenerator(); - virtual ~cmCPackDragNDropGenerator(); + ~cmCPackDragNDropGenerator() override; protected: - int InitializeInternal() CM_OVERRIDE; - const char* GetOutputExtension() CM_OVERRIDE; - int PackageFiles() CM_OVERRIDE; - bool SupportsComponentInstallation() const CM_OVERRIDE; + int InitializeInternal() override; + const char* GetOutputExtension() override; + int PackageFiles() override; + bool SupportsComponentInstallation() const override; bool CopyFile(std::ostringstream& source, std::ostringstream& target); bool CreateEmptyFile(std::ostringstream& target, size_t size); bool RunCommand(std::ostringstream& command, std::string* output = 0); std::string GetComponentInstallDirNameSuffix( - const std::string& componentName) CM_OVERRIDE; + const std::string& componentName) override; int CreateDMG(const std::string& src_dir, const std::string& output_file); - std::string InstallPrefix; - private: std::string slaDirectory; bool singleLicense; bool WriteLicense(cmGeneratedFileStream& outputStream, int licenseNumber, - std::string licenseLanguage, std::string licenseFile, - std::string* error); + std::string licenseLanguage, + const std::string& licenseFile, std::string* error); bool BreakLongLine(const std::string& line, std::vector<std::string>& lines, std::string* error); void EscapeQuotesAndBackslashes(std::string& line); diff --git a/Source/CPack/cmCPackFreeBSDGenerator.cxx b/Source/CPack/cmCPackFreeBSDGenerator.cxx new file mode 100644 index 000000000..91ae1a23f --- /dev/null +++ b/Source/CPack/cmCPackFreeBSDGenerator.cxx @@ -0,0 +1,359 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmCPackFreeBSDGenerator.h" + +#include "cmArchiveWrite.h" +#include "cmCPackArchiveGenerator.h" +#include "cmCPackLog.h" +#include "cmGeneratedFileStream.h" +#include "cmSystemTools.h" + +// Needed for ::open() and ::stat() +#include <fcntl.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <unistd.h> + +#include <pkg.h> + +#include <algorithm> + +cmCPackFreeBSDGenerator::cmCPackFreeBSDGenerator() + : cmCPackArchiveGenerator(cmArchiveWrite::CompressXZ, "paxr") +{ +} + +int cmCPackFreeBSDGenerator::InitializeInternal() +{ + this->SetOptionIfNotSet("CPACK_PACKAGING_INSTALL_PREFIX", "/usr/local"); + this->SetOption("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "0"); + return this->Superclass::InitializeInternal(); +} + +cmCPackFreeBSDGenerator::~cmCPackFreeBSDGenerator() +{ +} + +// This is a wrapper, for use only in stream-based output, +// that will output a string in UCL escaped fashion (in particular, +// quotes and backslashes are escaped). The list of characters +// to escape is taken from https://github.com/vstakhov/libucl +// (which is the reference implementation pkg(8) refers to). +class EscapeQuotes +{ +public: + const std::string& value; + + EscapeQuotes(const std::string& s) + : value(s) + { + } +}; + +// Output a string as "string" with escaping applied. +cmGeneratedFileStream& operator<<(cmGeneratedFileStream& s, + const EscapeQuotes& v) +{ + s << '"'; + for (std::string::size_type i = 0; i < v.value.length(); ++i) { + char c = v.value[i]; + switch (c) { + case '\n': + s << "\\n"; + break; + case '\r': + s << "\\r"; + break; + case '\b': + s << "\\b"; + break; + case '\t': + s << "\\t"; + break; + case '\f': + s << "\\f"; + break; + case '\\': + s << "\\\\"; + break; + case '"': + s << "\\\""; + break; + default: + s << c; + break; + } + } + s << '"'; + return s; +} + +// The following classes are all helpers for writing out the UCL +// manifest file (it also looks like JSON). ManifestKey just has +// a (string-valued) key; subclasses add a specific kind of +// value-type to the key, and implement write_value() to output +// the corresponding UCL. +class ManifestKey +{ +public: + std::string key; + + ManifestKey(const std::string& k) + : key(k) + { + } + + virtual ~ManifestKey() {} + + // Output the value associated with this key to the stream @p s. + // Format is to be decided by subclasses. + virtual void write_value(cmGeneratedFileStream& s) const = 0; +}; + +// Basic string-value (e.g. "name": "cmake") +class ManifestKeyValue : public ManifestKey +{ +public: + std::string value; + + ManifestKeyValue(const std::string& k, const std::string& v) + : ManifestKey(k) + , value(v) + { + } + + void write_value(cmGeneratedFileStream& s) const override + { + s << EscapeQuotes(value); + } +}; + +// List-of-strings values (e.g. "licenses": ["GPLv2", "LGPLv2"]) +class ManifestKeyListValue : public ManifestKey +{ +public: + typedef std::vector<std::string> VList; + VList value; + + ManifestKeyListValue(const std::string& k) + : ManifestKey(k) + { + } + + ManifestKeyListValue& operator<<(const std::string& v) + { + value.push_back(v); + return *this; + } + + ManifestKeyListValue& operator<<(const std::vector<std::string>& v) + { + for (VList::const_iterator it = v.begin(); it != v.end(); ++it) { + (*this) << (*it); + } + return *this; + } + + void write_value(cmGeneratedFileStream& s) const override + { + bool with_comma = false; + + s << '['; + for (VList::const_iterator it = value.begin(); it != value.end(); ++it) { + s << (with_comma ? ',' : ' '); + s << EscapeQuotes(*it); + with_comma = true; + } + s << " ]"; + } +}; + +// Deps: actually a dictionary, but we'll treat it as a +// list so we only name the deps, and produce dictionary- +// like output via write_value() +class ManifestKeyDepsValue : public ManifestKeyListValue +{ +public: + ManifestKeyDepsValue(const std::string& k) + : ManifestKeyListValue(k) + { + } + + void write_value(cmGeneratedFileStream& s) const override + { + s << "{\n"; + for (VList::const_iterator it = value.begin(); it != value.end(); ++it) { + s << " \"" << *it << "\": {\"origin\": \"" << *it << "\"},\n"; + } + s << '}'; + } +}; + +// Write one of the key-value classes (above) to the stream @p s +cmGeneratedFileStream& operator<<(cmGeneratedFileStream& s, + const ManifestKey& v) +{ + s << '"' << v.key << "\": "; + v.write_value(s); + s << ",\n"; + return s; +} + +// Look up variable; if no value is set, returns an empty string; +// basically a wrapper that handles the NULL-ptr return from GetOption(). +std::string cmCPackFreeBSDGenerator::var_lookup(const char* var_name) +{ + const char* pv = this->GetOption(var_name); + if (!pv) { + return std::string(); + } else { + return pv; + } +} + +// Produce UCL in the given @p manifest file for the common +// manifest fields (common to the compact and regular formats), +// by reading the CPACK_FREEBSD_* variables. +void cmCPackFreeBSDGenerator::write_manifest_fields( + cmGeneratedFileStream& manifest) +{ + manifest << ManifestKeyValue("name", + var_lookup("CPACK_FREEBSD_PACKAGE_NAME")); + manifest << ManifestKeyValue("origin", + var_lookup("CPACK_FREEBSD_PACKAGE_ORIGIN")); + manifest << ManifestKeyValue("version", + var_lookup("CPACK_FREEBSD_PACKAGE_VERSION")); + manifest << ManifestKeyValue("maintainer", + var_lookup("CPACK_FREEBSD_PACKAGE_MAINTAINER")); + manifest << ManifestKeyValue("comment", + var_lookup("CPACK_FREEBSD_PACKAGE_COMMENT")); + manifest << ManifestKeyValue( + "desc", var_lookup("CPACK_FREEBSD_PACKAGE_DESCRIPTION")); + manifest << ManifestKeyValue("www", var_lookup("CPACK_FREEBSD_PACKAGE_WWW")); + std::vector<std::string> licenses; + cmSystemTools::ExpandListArgument( + var_lookup("CPACK_FREEBSD_PACKAGE_LICENSE"), licenses); + std::string licenselogic("single"); + if (licenses.size() < 1) { + cmSystemTools::SetFatalErrorOccured(); + } else if (licenses.size() > 1) { + licenselogic = var_lookup("CPACK_FREEBSD_PACKAGE_LICENSE_LOGIC"); + } + manifest << ManifestKeyValue("licenselogic", licenselogic); + manifest << (ManifestKeyListValue("licenses") << licenses); + std::vector<std::string> categories; + cmSystemTools::ExpandListArgument( + var_lookup("CPACK_FREEBSD_PACKAGE_CATEGORIES"), categories); + manifest << (ManifestKeyListValue("categories") << categories); + manifest << ManifestKeyValue("prefix", var_lookup("CMAKE_INSTALL_PREFIX")); + std::vector<std::string> deps; + cmSystemTools::ExpandListArgument(var_lookup("CPACK_FREEBSD_PACKAGE_DEPS"), + deps); + if (deps.size() > 0) { + manifest << (ManifestKeyDepsValue("deps") << deps); + } +} + +// Package only actual files; others are ignored (in particular, +// intermediate subdirectories are ignored). +static bool ignore_file(const std::string& filename) +{ + struct stat statbuf; + + if (!((stat(filename.c_str(), &statbuf) >= 0) && + ((statbuf.st_mode & S_IFMT) == S_IFREG))) { + return true; + } + // May be other reasons to return false + return false; +} + +// Write the given list of @p files to the manifest stream @p s, +// as the UCL field "files" (which is dictionary-valued, to +// associate filenames with hashes). All the files are transformed +// to paths relative to @p toplevel, with a leading / (since the paths +// in FreeBSD package files are supposed to be absolute). +void write_manifest_files(cmGeneratedFileStream& s, + const std::string& toplevel, + const std::vector<std::string>& files) +{ + const char* c_toplevel = toplevel.c_str(); + std::vector<std::string>::const_iterator it; + + s << "\"files\": {\n"; + for (it = files.begin(); it != files.end(); ++it) { + s << " \"/" << cmSystemTools::RelativePath(c_toplevel, it->c_str()) + << "\": \"" + << "<sha256>" + << "\",\n"; + } + s << " },\n"; +} + +static bool has_suffix(const std::string& str, const std::string& suffix) +{ + return str.size() >= suffix.size() && + str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0; +} + +int cmCPackFreeBSDGenerator::PackageFiles() +{ + if (!this->ReadListFile("CPackFreeBSD.cmake")) { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Error while execution CPackFreeBSD.cmake" << std::endl); + return 0; + } + + std::vector<std::string>::const_iterator fileIt; + std::string dir = cmSystemTools::GetCurrentWorkingDirectory(); + cmSystemTools::ChangeDirectory(toplevel); + + files.erase(std::remove_if(files.begin(), files.end(), ignore_file), + files.end()); + + std::string manifestname = toplevel + "/+MANIFEST"; + { + cmGeneratedFileStream manifest(manifestname.c_str()); + manifest << "{\n"; + write_manifest_fields(manifest); + write_manifest_files(manifest, toplevel, files); + manifest << "}\n"; + } + + cmCPackLogger(cmCPackLog::LOG_DEBUG, "Toplevel: " << toplevel << std::endl); + + if (WantsComponentInstallation()) { + // CASE 1 : COMPONENT ALL-IN-ONE package + // If ALL COMPONENTS in ONE package has been requested + // then the package file is unique and should be open here. + if (componentPackageMethod == ONE_PACKAGE) { + return PackageComponentsAllInOne(); + } + // CASE 2 : COMPONENT CLASSICAL package(s) (i.e. not all-in-one) + // There will be 1 package for each component group + // however one may require to ignore component group and + // in this case you'll get 1 package for each component. + return PackageComponents(componentPackageMethod == + ONE_PACKAGE_PER_COMPONENT); + } + + std::string output_dir = + cmSystemTools::CollapseCombinedPath(toplevel, "../"); + pkg_create_from_manifest(output_dir.c_str(), ::TXZ, toplevel.c_str(), + manifestname.c_str(), NULL); + + std::string broken_suffix = std::string("-") + + var_lookup("CPACK_TOPLEVEL_TAG") + std::string(GetOutputExtension()); + for (std::vector<std::string>::iterator it = packageFileNames.begin(); + it != packageFileNames.end(); ++it) { + cmCPackLogger(cmCPackLog::LOG_DEBUG, "Packagefile " << *it << std::endl); + if (has_suffix(*it, broken_suffix)) { + it->replace(it->size() - broken_suffix.size(), std::string::npos, + GetOutputExtension()); + break; + } + } + + cmSystemTools::ChangeDirectory(dir); + return 1; +} diff --git a/Source/CPack/cmCPackFreeBSDGenerator.h b/Source/CPack/cmCPackFreeBSDGenerator.h new file mode 100644 index 000000000..99d2e2421 --- /dev/null +++ b/Source/CPack/cmCPackFreeBSDGenerator.h @@ -0,0 +1,37 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cmCPackFreeBSDGenerator_h +#define cmCPackFreeBSDGenerator_h + +#include <cmConfigure.h> + +#include "cmCPackArchiveGenerator.h" +#include "cmCPackGenerator.h" + +class cmGeneratedFileStream; + +/** \class cmCPackFreeBSDGenerator + * \brief A generator for FreeBSD package files (TXZ with a manifest) + * + */ +class cmCPackFreeBSDGenerator : public cmCPackArchiveGenerator +{ +public: + cmCPackTypeMacro(cmCPackFreeBSDGenerator, cmCPackArchiveGenerator); + /** + * Construct generator + */ + cmCPackFreeBSDGenerator(); + ~cmCPackFreeBSDGenerator() override; + + int InitializeInternal() override; + int PackageFiles() override; + +protected: + const char* GetOutputExtension() override { return ".txz"; } + + std::string var_lookup(const char* var_name); + void write_manifest_fields(cmGeneratedFileStream&); +}; + +#endif diff --git a/Source/CPack/cmCPackGenerator.cxx b/Source/CPack/cmCPackGenerator.cxx index d8e2753cf..ecb5adb47 100644 --- a/Source/CPack/cmCPackGenerator.cxx +++ b/Source/CPack/cmCPackGenerator.cxx @@ -6,6 +6,7 @@ #include "cmsys/Glob.hxx" #include "cmsys/RegularExpression.hxx" #include <algorithm> +#include <memory> // IWYU pragma: keep #include <utility> #include "cmCPackComponentGroup.h" @@ -17,7 +18,6 @@ #include "cmStateSnapshot.h" #include "cmWorkingDirectory.h" #include "cmXMLSafe.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" #if defined(__HAIKU__) @@ -28,14 +28,14 @@ cmCPackGenerator::cmCPackGenerator() { this->GeneratorVerbose = cmSystemTools::OUTPUT_NONE; - this->MakefileMap = CM_NULLPTR; - this->Logger = CM_NULLPTR; + this->MakefileMap = nullptr; + this->Logger = nullptr; this->componentPackageMethod = ONE_PACKAGE_PER_GROUP; } cmCPackGenerator::~cmCPackGenerator() { - this->MakefileMap = CM_NULLPTR; + this->MakefileMap = nullptr; } void cmCPackGeneratorProgress(const char* msg, float prog, void* ptr) @@ -156,7 +156,7 @@ int cmCPackGenerator::PrepareNames() } const char* algoSignature = this->GetOption("CPACK_PACKAGE_CHECKSUM"); if (algoSignature) { - if (cmCryptoHash::New(algoSignature).get() == CM_NULLPTR) { + if (!cmCryptoHash::New(algoSignature)) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot recognize algorithm: " << algoSignature << std::endl); return 0; @@ -248,25 +248,23 @@ int cmCPackGenerator::InstallProjectViaInstallCommands( cmSystemTools::PutEnv(tempInstallDirectoryEnv); std::vector<std::string> installCommandsVector; cmSystemTools::ExpandListArgument(installCommands, installCommandsVector); - std::vector<std::string>::iterator it; - for (it = installCommandsVector.begin(); it != installCommandsVector.end(); - ++it) { - cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << *it << std::endl); + for (std::string const& ic : installCommandsVector) { + cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << ic << std::endl); std::string output; int retVal = 1; bool resB = - cmSystemTools::RunSingleCommand(it->c_str(), &output, &output, &retVal, - CM_NULLPTR, this->GeneratorVerbose, 0); + cmSystemTools::RunSingleCommand(ic.c_str(), &output, &output, &retVal, + nullptr, this->GeneratorVerbose, 0); if (!resB || retVal) { std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY"); tmpFile += "/InstallOutput.log"; cmGeneratedFileStream ofs(tmpFile.c_str()); - ofs << "# Run command: " << *it << std::endl + ofs << "# Run command: " << ic << std::endl << "# Output:" << std::endl << output << std::endl; cmCPackLogger( cmCPackLog::LOG_ERROR, "Problem running install command: " - << *it << std::endl + << ic << std::endl << "Please check " << tmpFile << " for errors" << std::endl); return 0; } @@ -286,12 +284,10 @@ int cmCPackGenerator::InstallProjectViaInstalledDirectories( std::vector<std::string> ignoreFilesRegexString; cmSystemTools::ExpandListArgument(cpackIgnoreFiles, ignoreFilesRegexString); - std::vector<std::string>::iterator it; - for (it = ignoreFilesRegexString.begin(); - it != ignoreFilesRegexString.end(); ++it) { + for (std::string const& ifr : ignoreFilesRegexString) { cmCPackLogger(cmCPackLog::LOG_VERBOSE, - "Create ignore files regex for: " << *it << std::endl); - ignoreFilesRegex.push_back(it->c_str()); + "Create ignore files regex for: " << ifr << std::endl); + ignoreFilesRegex.push_back(ifr.c_str()); } } const char* installDirectories = @@ -313,7 +309,7 @@ int cmCPackGenerator::InstallProjectViaInstalledDirectories( const std::string& tempDir = tempInstallDirectory; for (it = installDirectoriesVector.begin(); it != installDirectoriesVector.end(); ++it) { - std::vector<std::pair<std::string, std::string> > symlinkedFiles; + std::vector<std::pair<std::string, std::string>> symlinkedFiles; cmCPackLogger(cmCPackLog::LOG_DEBUG, "Find files" << std::endl); cmsys::Glob gl; std::string top = *it; @@ -334,15 +330,14 @@ int cmCPackGenerator::InstallProjectViaInstalledDirectories( files = gl.GetFiles(); std::vector<std::string>::iterator gfit; std::vector<cmsys::RegularExpression>::iterator regIt; - for (gfit = files.begin(); gfit != files.end(); ++gfit) { + for (std::string const& gf : files) { bool skip = false; - std::string inFile = *gfit; - if (cmSystemTools::FileIsDirectory(*gfit)) { + std::string inFile = gf; + if (cmSystemTools::FileIsDirectory(gf)) { inFile += '/'; } - for (regIt = ignoreFilesRegex.begin(); regIt != ignoreFilesRegex.end(); - ++regIt) { - if (regIt->find(inFile.c_str())) { + for (cmsys::RegularExpression& reg : ignoreFilesRegex) { + if (reg.find(inFile.c_str())) { cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Ignore file: " << inFile << std::endl); skip = true; @@ -353,7 +348,7 @@ int cmCPackGenerator::InstallProjectViaInstalledDirectories( } std::string filePath = tempDir; filePath += "/" + subdir + "/" + - cmSystemTools::RelativePath(top.c_str(), gfit->c_str()); + cmSystemTools::RelativePath(top.c_str(), gf.c_str()); cmCPackLogger(cmCPackLog::LOG_DEBUG, "Copy file: " << inFile << " -> " << filePath << std::endl); /* If the file is a symlink we will have to re-create it */ @@ -377,33 +372,30 @@ int cmCPackGenerator::InstallProjectViaInstalledDirectories( } /* rebuild symlinks in the installed tree */ if (!symlinkedFiles.empty()) { - std::vector<std::pair<std::string, std::string> >::iterator - symlinkedIt; std::string curDir = cmSystemTools::GetCurrentWorkingDirectory(); std::string goToDir = tempDir; goToDir += "/" + subdir; cmCPackLogger(cmCPackLog::LOG_DEBUG, "Change dir to: " << goToDir << std::endl); cmWorkingDirectory workdir(goToDir); - for (symlinkedIt = symlinkedFiles.begin(); - symlinkedIt != symlinkedFiles.end(); ++symlinkedIt) { + for (auto const& symlinked : symlinkedFiles) { cmCPackLogger(cmCPackLog::LOG_DEBUG, "Will create a symlink: " - << symlinkedIt->second << "--> " - << symlinkedIt->first << std::endl); + << symlinked.second << "--> " << symlinked.first + << std::endl); // make sure directory exists for symlink std::string destDir = - cmSystemTools::GetFilenamePath(symlinkedIt->second); + cmSystemTools::GetFilenamePath(symlinked.second); if (!destDir.empty() && !cmSystemTools::MakeDirectory(destDir)) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot create dir: " << destDir << "\nTrying to create symlink: " - << symlinkedIt->second << "--> " - << symlinkedIt->first << std::endl); + << symlinked.second << "--> " << symlinked.first + << std::endl); } - if (!cmSystemTools::CreateSymlink(symlinkedIt->first, - symlinkedIt->second)) { + if (!cmSystemTools::CreateSymlink(symlinked.first, + symlinked.second)) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot create symlink: " - << symlinkedIt->second << "--> " - << symlinkedIt->first << std::endl); + << symlinked.second << "--> " << symlinked.first + << std::endl); return 0; } } @@ -424,10 +416,7 @@ int cmCPackGenerator::InstallProjectViaInstallScript( << std::endl); std::vector<std::string> cmakeScriptsVector; cmSystemTools::ExpandListArgument(cmakeScripts, cmakeScriptsVector); - std::vector<std::string>::iterator it; - for (it = cmakeScriptsVector.begin(); it != cmakeScriptsVector.end(); - ++it) { - std::string installScript = *it; + for (std::string const& installScript : cmakeScriptsVector) { cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- Install script: " << installScript << std::endl); @@ -533,10 +522,8 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( if (installTypes && *installTypes) { std::vector<std::string> installTypesVector; cmSystemTools::ExpandListArgument(installTypes, installTypesVector); - std::vector<std::string>::iterator installTypeIt; - for (installTypeIt = installTypesVector.begin(); - installTypeIt != installTypesVector.end(); ++installTypeIt) { - this->GetInstallationType(installProjectName, *installTypeIt); + for (std::string const& installType : installTypesVector) { + this->GetInstallationType(installProjectName, installType); } } @@ -546,10 +533,8 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( const char* components = this->GetOption(componentsVar); if (components && *components) { cmSystemTools::ExpandListArgument(components, componentsVector); - std::vector<std::string>::iterator compIt; - for (compIt = componentsVector.begin(); - compIt != componentsVector.end(); ++compIt) { - GetComponent(installProjectName, *compIt); + for (std::string const& comp : componentsVector) { + GetComponent(installProjectName, comp); } componentInstall = true; } @@ -610,11 +595,9 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( "- Install project: " << installProjectName << std::endl); // Run the installation for each component - std::vector<std::string>::iterator componentIt; - for (componentIt = componentsVector.begin(); - componentIt != componentsVector.end(); ++componentIt) { + for (std::string const& component : componentsVector) { std::string tempInstallDirectory = baseTempInstallDirectory; - installComponent = *componentIt; + installComponent = component; if (componentInstall) { cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- Install component: " << installComponent << std::endl); @@ -627,8 +610,7 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( cm.AddCMakePaths(); cm.SetProgressCallback(cmCPackGeneratorProgress, this); cmGlobalGenerator gg(&cm); - CM_AUTO_PTR<cmMakefile> mf( - new cmMakefile(&gg, cm.GetCurrentSnapshot())); + cmMakefile mf(&gg, cm.GetCurrentSnapshot()); if (!installSubDirectory.empty() && installSubDirectory != "/" && installSubDirectory != ".") { tempInstallDirectory += installSubDirectory; @@ -674,11 +656,11 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( if (this->GetOption("CPACK_INSTALL_PREFIX")) { dir += this->GetOption("CPACK_INSTALL_PREFIX"); } - mf->AddDefinition("CMAKE_INSTALL_PREFIX", dir.c_str()); + mf.AddDefinition("CMAKE_INSTALL_PREFIX", dir.c_str()); cmCPackLogger( cmCPackLog::LOG_DEBUG, - "- Using DESTDIR + CPACK_INSTALL_PREFIX... (mf->AddDefinition)" + "- Using DESTDIR + CPACK_INSTALL_PREFIX... (mf.AddDefinition)" << std::endl); cmCPackLogger(cmCPackLog::LOG_DEBUG, "- Setting CMAKE_INSTALL_PREFIX to '" << dir << "'" @@ -715,8 +697,8 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( return 0; } } else { - mf->AddDefinition("CMAKE_INSTALL_PREFIX", - tempInstallDirectory.c_str()); + mf.AddDefinition("CMAKE_INSTALL_PREFIX", + tempInstallDirectory.c_str()); if (!cmsys::SystemTools::MakeDirectory( tempInstallDirectory.c_str())) { @@ -727,7 +709,7 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( } cmCPackLogger(cmCPackLog::LOG_DEBUG, - "- Using non-DESTDIR install... (mf->AddDefinition)" + "- Using non-DESTDIR install... (mf.AddDefinition)" << std::endl); cmCPackLogger(cmCPackLog::LOG_DEBUG, "- Setting CMAKE_INSTALL_PREFIX to '" @@ -735,19 +717,19 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( } if (!buildConfig.empty()) { - mf->AddDefinition("BUILD_TYPE", buildConfig.c_str()); + mf.AddDefinition("BUILD_TYPE", buildConfig.c_str()); } std::string installComponentLowerCase = cmSystemTools::LowerCase(installComponent); if (installComponentLowerCase != "all") { - mf->AddDefinition("CMAKE_INSTALL_COMPONENT", - installComponent.c_str()); + mf.AddDefinition("CMAKE_INSTALL_COMPONENT", + installComponent.c_str()); } // strip on TRUE, ON, 1, one or several file names, but not on // FALSE, OFF, 0 and an empty string if (!cmSystemTools::IsOff(this->GetOption("CPACK_STRIP_FILES"))) { - mf->AddDefinition("CMAKE_INSTALL_DO_STRIP", "1"); + mf.AddDefinition("CMAKE_INSTALL_DO_STRIP", "1"); } // Remember the list of files before installation // of the current component (if we are in component install) @@ -767,7 +749,7 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( // If CPack was asked to warn on ABSOLUTE INSTALL DESTINATION // then forward request to cmake_install.cmake script if (this->IsOn("CPACK_WARN_ON_ABSOLUTE_INSTALL_DESTINATION")) { - mf->AddDefinition("CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION", "1"); + mf.AddDefinition("CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION", "1"); } // If current CPack generator does support // ABSOLUTE INSTALL DESTINATION or CPack has been asked for @@ -775,18 +757,17 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( // as soon as it occurs (before installing file) if (!SupportsAbsoluteDestination() || this->IsOn("CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION")) { - mf->AddDefinition("CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION", - "1"); + mf.AddDefinition("CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION", "1"); } // do installation - int res = mf->ReadListFile(installFile.c_str()); + int res = mf.ReadListFile(installFile.c_str()); // forward definition of CMAKE_ABSOLUTE_DESTINATION_FILES // to CPack (may be used by generators like CPack RPM or DEB) // in order to transparently handle ABSOLUTE PATH - if (mf->GetDefinition("CMAKE_ABSOLUTE_DESTINATION_FILES")) { - mf->AddDefinition( + if (mf.GetDefinition("CMAKE_ABSOLUTE_DESTINATION_FILES")) { + mf.AddDefinition( "CPACK_ABSOLUTE_DESTINATION_FILES", - mf->GetDefinition("CMAKE_ABSOLUTE_DESTINATION_FILES")); + mf.GetDefinition("CMAKE_ABSOLUTE_DESTINATION_FILES")); } // Now rebuild the list of files after installation @@ -820,13 +801,12 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( } } - if (CM_NULLPTR != - mf->GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES")) { + if (nullptr != mf.GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES")) { if (!absoluteDestFiles.empty()) { absoluteDestFiles += ";"; } absoluteDestFiles += - mf->GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES"); + mf.GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES"); cmCPackLogger(cmCPackLog::LOG_DEBUG, "Got some ABSOLUTE DESTINATION FILES: " << absoluteDestFiles << std::endl); @@ -835,18 +815,18 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( std::string absoluteDestFileComponent = std::string("CPACK_ABSOLUTE_DESTINATION_FILES") + "_" + GetComponentInstallDirNameSuffix(installComponent); - if (CM_NULLPTR != this->GetOption(absoluteDestFileComponent)) { + if (nullptr != this->GetOption(absoluteDestFileComponent)) { std::string absoluteDestFilesListComponent = this->GetOption(absoluteDestFileComponent); absoluteDestFilesListComponent += ";"; absoluteDestFilesListComponent += - mf->GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES"); + mf.GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES"); this->SetOption(absoluteDestFileComponent, absoluteDestFilesListComponent.c_str()); } else { this->SetOption( absoluteDestFileComponent, - mf->GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES")); + mf.GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES")); } } } @@ -982,7 +962,7 @@ int cmCPackGenerator::DoPackage() /* Prepare checksum algorithm*/ const char* algo = this->GetOption("CPACK_PACKAGE_CHECKSUM"); - CM_AUTO_PTR<cmCryptoHash> crypto = cmCryptoHash::New(algo ? algo : ""); + std::unique_ptr<cmCryptoHash> crypto = cmCryptoHash::New(algo ? algo : ""); /* * Copy the generated packages to final destination @@ -992,12 +972,11 @@ int cmCPackGenerator::DoPackage() */ cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Copying final package(s) [" << packageFileNames.size() << "]:" << std::endl); - std::vector<std::string>::iterator it; /* now copy package one by one */ - for (it = packageFileNames.begin(); it != packageFileNames.end(); ++it) { + for (std::string const& pkgFileName : packageFileNames) { std::string tmpPF(this->GetOption("CPACK_OUTPUT_FILE_PREFIX")); - std::string filename(cmSystemTools::GetFilenameName(*it)); - tempPackageFileName = it->c_str(); + std::string filename(cmSystemTools::GetFilenameName(pkgFileName)); + tempPackageFileName = pkgFileName.c_str(); tmpPF += "/" + filename; const char* packageFileName = tmpPF.c_str(); cmCPackLogger(cmCPackLog::LOG_DEBUG, "Copy final package(s): " @@ -1016,10 +995,9 @@ int cmCPackGenerator::DoPackage() << packageFileName << " generated." << std::endl); /* Generate checksum file */ - if (crypto.get() != CM_NULLPTR) { + if (crypto) { std::string hashFile(this->GetOption("CPACK_OUTPUT_FILE_PREFIX")); - hashFile += - "/" + filename.substr(0, filename.rfind(this->GetOutputExtension())); + hashFile += "/" + filename; hashFile += "." + cmSystemTools::LowerCase(algo); cmsys::ofstream outF(hashFile.c_str()); if (!outF) { @@ -1225,7 +1203,7 @@ int cmCPackGenerator::PrepareGroupingKind() std::string groupingType; // Second way to specify grouping - if (CM_NULLPTR != this->GetOption("CPACK_COMPONENTS_GROUPING")) { + if (nullptr != this->GetOption("CPACK_COMPONENTS_GROUPING")) { groupingType = this->GetOption("CPACK_COMPONENTS_GROUPING"); } @@ -1407,7 +1385,7 @@ cmCPackComponent* cmCPackGenerator::GetComponent( component->Group = GetComponentGroup(projectName, groupName); component->Group->Components.push_back(component); } else { - component->Group = CM_NULLPTR; + component->Group = nullptr; } const char* description = this->GetOption(macroPrefix + "_DESCRIPTION"); @@ -1421,10 +1399,9 @@ cmCPackComponent* cmCPackGenerator::GetComponent( std::vector<std::string> installTypesVector; cmSystemTools::ExpandListArgument(installTypes, installTypesVector); std::vector<std::string>::iterator installTypesIt; - for (installTypesIt = installTypesVector.begin(); - installTypesIt != installTypesVector.end(); ++installTypesIt) { + for (std::string const& installType : installTypesVector) { component->InstallationTypes.push_back( - this->GetInstallationType(projectName, *installTypesIt)); + this->GetInstallationType(projectName, installType)); } } @@ -1434,9 +1411,8 @@ cmCPackComponent* cmCPackGenerator::GetComponent( std::vector<std::string> dependsVector; cmSystemTools::ExpandListArgument(depends, dependsVector); std::vector<std::string>::iterator dependIt; - for (dependIt = dependsVector.begin(); dependIt != dependsVector.end(); - ++dependIt) { - cmCPackComponent* child = GetComponent(projectName, *dependIt); + for (std::string const& depend : dependsVector) { + cmCPackComponent* child = GetComponent(projectName, depend); component->Dependencies.push_back(child); child->ReverseDependencies.push_back(component); } @@ -1475,7 +1451,7 @@ cmCPackComponentGroup* cmCPackGenerator::GetComponentGroup( group->ParentGroup = GetComponentGroup(projectName, parentGroupName); group->ParentGroup->Subgroups.push_back(group); } else { - group->ParentGroup = CM_NULLPTR; + group->ParentGroup = nullptr; } } return group; diff --git a/Source/CPack/cmCPackGenerator.h b/Source/CPack/cmCPackGenerator.h index 45777fa05..4e3a6e038 100644 --- a/Source/CPack/cmCPackGenerator.h +++ b/Source/CPack/cmCPackGenerator.h @@ -3,7 +3,7 @@ #ifndef cmCPackGenerator_h #define cmCPackGenerator_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include <map> #include <sstream> @@ -105,7 +105,7 @@ protected: cmInstalledFile const* GetInstalledFile(std::string const& name) const; virtual const char* GetOutputExtension() { return ".cpack"; } - virtual const char* GetOutputPostfix() { return CM_NULLPTR; } + virtual const char* GetOutputPostfix() { return nullptr; } /** * Prepare requested grouping kind from CPACK_xxx vars @@ -299,7 +299,7 @@ private: #define cmCPackTypeMacro(klass, superclass) \ typedef superclass Superclass; \ - const char* GetNameOfClass() CM_OVERRIDE { return #klass; } \ + const char* GetNameOfClass() override { return #klass; } \ static cmCPackGenerator* CreateGenerator() { return new klass; } \ class cmCPackTypeMacro_UseTrailingSemicolon diff --git a/Source/CPack/cmCPackGeneratorFactory.cxx b/Source/CPack/cmCPackGeneratorFactory.cxx index 31f48c7e3..4b81bbc5f 100644 --- a/Source/CPack/cmCPackGeneratorFactory.cxx +++ b/Source/CPack/cmCPackGeneratorFactory.cxx @@ -2,13 +2,16 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmCPackGeneratorFactory.h" -#include "cmConfigure.h" #include <ostream> #include <utility> #include "IFW/cmCPackIFWGenerator.h" #include "cmAlgorithms.h" #include "cmCPack7zGenerator.h" +#ifdef HAVE_FREEBSD_PKG +#include "cmCPackFreeBSDGenerator.h" +#endif +#include "cmCPackDebGenerator.h" #include "cmCPackGenerator.h" #include "cmCPackLog.h" #include "cmCPackNSISGenerator.h" @@ -34,7 +37,6 @@ #if !defined(_WIN32) && !defined(__QNXNTO__) && !defined(__BEOS__) && \ !defined(__HAIKU__) -#include "cmCPackDebGenerator.h" #include "cmCPackRPMGenerator.h" #endif @@ -99,6 +101,10 @@ cmCPackGeneratorFactory::cmCPackGeneratorFactory() this->RegisterGenerator("TZ", "Tar Compress compression", cmCPackTarCompressGenerator::CreateGenerator); } + if (cmCPackDebGenerator::CanGenerate()) { + this->RegisterGenerator("DEB", "Debian packages", + cmCPackDebGenerator::CreateGenerator); + } #ifdef __APPLE__ if (cmCPackDragNDropGenerator::CanGenerate()) { this->RegisterGenerator("DragNDrop", "Mac OSX Drag And Drop", @@ -123,15 +129,17 @@ cmCPackGeneratorFactory::cmCPackGeneratorFactory() #endif #if !defined(_WIN32) && !defined(__QNXNTO__) && !defined(__BEOS__) && \ !defined(__HAIKU__) - if (cmCPackDebGenerator::CanGenerate()) { - this->RegisterGenerator("DEB", "Debian packages", - cmCPackDebGenerator::CreateGenerator); - } if (cmCPackRPMGenerator::CanGenerate()) { this->RegisterGenerator("RPM", "RPM packages", cmCPackRPMGenerator::CreateGenerator); } #endif +#ifdef HAVE_FREEBSD_PKG + if (cmCPackFreeBSDGenerator::CanGenerate()) { + this->RegisterGenerator("FREEBSD", "FreeBSD pkg(8) packages", + cmCPackFreeBSDGenerator::CreateGenerator); + } +#endif } cmCPackGeneratorFactory::~cmCPackGeneratorFactory() @@ -144,7 +152,7 @@ cmCPackGenerator* cmCPackGeneratorFactory::NewGenerator( { cmCPackGenerator* gen = this->NewGeneratorInternal(name); if (!gen) { - return CM_NULLPTR; + return nullptr; } this->Generators.push_back(gen); gen->SetLogger(this->Logger); @@ -157,7 +165,7 @@ cmCPackGenerator* cmCPackGeneratorFactory::NewGeneratorInternal( cmCPackGeneratorFactory::t_GeneratorCreatorsMap::iterator it = this->GeneratorCreators.find(name); if (it == this->GeneratorCreators.end()) { - return CM_NULLPTR; + return nullptr; } return (it->second)(); } diff --git a/Source/CPack/cmCPackLog.cxx b/Source/CPack/cmCPackLog.cxx index 5c7123959..a3ca4b590 100644 --- a/Source/CPack/cmCPackLog.cxx +++ b/Source/CPack/cmCPackLog.cxx @@ -2,7 +2,6 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmCPackLog.h" -#include "cmConfigure.h" #include <iostream> #include "cmGeneratedFileStream.h" @@ -19,13 +18,13 @@ cmCPackLog::cmCPackLog() this->DefaultOutput = &std::cout; this->DefaultError = &std::cerr; - this->LogOutput = CM_NULLPTR; + this->LogOutput = nullptr; this->LogOutputCleanup = false; } cmCPackLog::~cmCPackLog() { - this->SetLogOutputStream(CM_NULLPTR); + this->SetLogOutputStream(nullptr); } void cmCPackLog::SetLogOutputStream(std::ostream* os) @@ -39,13 +38,13 @@ void cmCPackLog::SetLogOutputStream(std::ostream* os) bool cmCPackLog::SetLogOutputFile(const char* fname) { - cmGeneratedFileStream* cg = CM_NULLPTR; + cmGeneratedFileStream* cg = nullptr; if (fname) { cg = new cmGeneratedFileStream(fname); } if (cg && !*cg) { delete cg; - cg = CM_NULLPTR; + cg = nullptr; } this->SetLogOutputStream(cg); if (!cg) { diff --git a/Source/CPack/cmCPackNSISGenerator.cxx b/Source/CPack/cmCPackNSISGenerator.cxx index 9697a3832..ddf104c93 100644 --- a/Source/CPack/cmCPackNSISGenerator.cxx +++ b/Source/CPack/cmCPackNSISGenerator.cxx @@ -59,11 +59,10 @@ int cmCPackNSISGenerator::PackageFiles() std::string nsisInstallOptions = nsisFileName + "/NSIS.InstallOptions.ini"; nsisFileName += "/project.nsi"; std::ostringstream str; - std::vector<std::string>::const_iterator it; - for (it = files.begin(); it != files.end(); ++it) { + for (std::string const& file : files) { std::string outputDir = "$INSTDIR"; std::string fileN = - cmSystemTools::RelativePath(toplevel.c_str(), it->c_str()); + cmSystemTools::RelativePath(toplevel.c_str(), file.c_str()); if (!this->Components.empty()) { const std::string::size_type pos = fileN.find('/'); @@ -87,12 +86,11 @@ int cmCPackNSISGenerator::PackageFiles() this->SetOptionIfNotSet("CPACK_NSIS_DELETE_FILES", str.str().c_str()); std::vector<std::string> dirs; this->GetListOfSubdirectories(toplevel.c_str(), dirs); - std::vector<std::string>::const_iterator sit; std::ostringstream dstr; - for (sit = dirs.begin(); sit != dirs.end(); ++sit) { + for (std::string const& dir : dirs) { std::string componentName; std::string fileN = - cmSystemTools::RelativePath(toplevel.c_str(), sit->c_str()); + cmSystemTools::RelativePath(toplevel.c_str(), dir.c_str()); if (fileN.empty()) { continue; } @@ -205,65 +203,57 @@ int cmCPackNSISGenerator::PackageFiles() // in a vector based on the indices, and print them in that order. std::vector<cmCPackInstallationType*> installTypes( this->InstallationTypes.size()); - std::map<std::string, cmCPackInstallationType>::iterator installTypeIt; - for (installTypeIt = this->InstallationTypes.begin(); - installTypeIt != this->InstallationTypes.end(); ++installTypeIt) { - installTypes[installTypeIt->second.Index - 1] = &installTypeIt->second; - } - std::vector<cmCPackInstallationType*>::iterator installTypeIt2; - for (installTypeIt2 = installTypes.begin(); - installTypeIt2 != installTypes.end(); ++installTypeIt2) { + for (auto& installType : this->InstallationTypes) { + installTypes[installType.second.Index - 1] = &installType.second; + } + for (cmCPackInstallationType* installType : installTypes) { installTypesCode += "InstType \""; - installTypesCode += (*installTypeIt2)->DisplayName; + installTypesCode += installType->DisplayName; installTypesCode += "\"\n"; } // Create installation groups first - std::map<std::string, cmCPackComponentGroup>::iterator groupIt; - for (groupIt = this->ComponentGroups.begin(); - groupIt != this->ComponentGroups.end(); ++groupIt) { - if (groupIt->second.ParentGroup == CM_NULLPTR) { + for (auto& group : this->ComponentGroups) { + if (group.second.ParentGroup == nullptr) { componentCode += - this->CreateComponentGroupDescription(&groupIt->second, macrosOut); + this->CreateComponentGroupDescription(&group.second, macrosOut); } // Add the group description, if any. - if (!groupIt->second.Description.empty()) { + if (!group.second.Description.empty()) { groupDescriptions += " !insertmacro MUI_DESCRIPTION_TEXT ${" + - groupIt->first + "} \"" + - this->TranslateNewlines(groupIt->second.Description) + "\"\n"; + group.first + "} \"" + + this->TranslateNewlines(group.second.Description) + "\"\n"; } } // Create the remaining components, which aren't associated with groups. - std::map<std::string, cmCPackComponent>::iterator compIt; - for (compIt = this->Components.begin(); compIt != this->Components.end(); - ++compIt) { - if (compIt->second.Files.empty()) { + for (auto& comp : this->Components) { + if (comp.second.Files.empty()) { // NSIS cannot cope with components that have no files. continue; } anyDownloadedComponents = - anyDownloadedComponents || compIt->second.IsDownloaded; + anyDownloadedComponents || comp.second.IsDownloaded; - if (!compIt->second.Group) { + if (!comp.second.Group) { componentCode += - this->CreateComponentDescription(&compIt->second, macrosOut); + this->CreateComponentDescription(&comp.second, macrosOut); } // Add this component to the various section lists. sectionList += " !insertmacro \"${MacroName}\" \""; - sectionList += compIt->first; + sectionList += comp.first; sectionList += "\"\n"; - selectedVarsList += "Var " + compIt->first + "_selected\n"; - selectedVarsList += "Var " + compIt->first + "_was_installed\n"; + selectedVarsList += "Var " + comp.first + "_selected\n"; + selectedVarsList += "Var " + comp.first + "_was_installed\n"; // Add the component description, if any. - if (!compIt->second.Description.empty()) { + if (!comp.second.Description.empty()) { componentDescriptions += " !insertmacro MUI_DESCRIPTION_TEXT ${" + - compIt->first + "} \"" + - this->TranslateNewlines(compIt->second.Description) + "\"\n"; + comp.first + "} \"" + + this->TranslateNewlines(comp.second.Description) + "\"\n"; } } @@ -313,7 +303,7 @@ int cmCPackNSISGenerator::PackageFiles() int retVal = 1; bool res = cmSystemTools::RunSingleCommand(nsisCmd.c_str(), &output, &output, &retVal, - CM_NULLPTR, this->GeneratorVerbose, 0); + nullptr, this->GeneratorVerbose, 0); if (!res || retVal) { cmGeneratedFileStream ofs(tmpFile.c_str()); ofs << "# Run command: " << nsisCmd << std::endl @@ -337,7 +327,7 @@ int cmCPackNSISGenerator::InitializeInternal() "NSIS Generator cannot work with CPACK_INCLUDE_TOPLEVEL_DIRECTORY set. " "This option will be reset to 0 (for this generator only)." << std::endl); - this->SetOption("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", CM_NULLPTR); + this->SetOption("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", nullptr); } cmCPackLogger(cmCPackLog::LOG_DEBUG, "cmCPackNSISGenerator::Initialize()" @@ -412,7 +402,7 @@ int cmCPackNSISGenerator::InitializeInternal() int retVal = 1; bool resS = cmSystemTools::RunSingleCommand(nsisCmd.c_str(), &output, &output, &retVal, - CM_NULLPTR, this->GeneratorVerbose, 0); + nullptr, this->GeneratorVerbose, 0); cmsys::RegularExpression versionRex("v([0-9]+.[0-9]+)"); cmsys::RegularExpression versionRexCVS("v(.*)\\.cvs"); if (!resS || retVal || @@ -463,11 +453,9 @@ int cmCPackNSISGenerator::InitializeInternal() cmSystemTools::ExpandListArgument(cpackPackageDeskTopLinks, cpackPackageDesktopLinksVector); - for (std::vector<std::string>::iterator i = - cpackPackageDesktopLinksVector.begin(); - i != cpackPackageDesktopLinksVector.end(); ++i) { + for (std::string const& cpdl : cpackPackageDesktopLinksVector) { cmCPackLogger(cmCPackLog::LOG_DEBUG, - "CPACK_CREATE_DESKTOP_LINKS: " << *i << std::endl); + "CPACK_CREATE_DESKTOP_LINKS: " << cpdl << std::endl); } } else { cmCPackLogger(cmCPackLog::LOG_DEBUG, "CPACK_CREATE_DESKTOP_LINKS: " @@ -647,11 +635,9 @@ std::string cmCPackNSISGenerator::CreateComponentDescription( componentCode += " SectionIn RO\n"; } else if (!component->InstallationTypes.empty()) { std::ostringstream out; - std::vector<cmCPackInstallationType*>::iterator installTypeIter; - for (installTypeIter = component->InstallationTypes.begin(); - installTypeIter != component->InstallationTypes.end(); - ++installTypeIter) { - out << " " << (*installTypeIter)->Index; + for (cmCPackInstallationType const* installType : + component->InstallationTypes) { + out << " " << installType->Index; } componentCode += " SectionIn" + out.str() + "\n"; } @@ -730,19 +716,17 @@ std::string cmCPackNSISGenerator::CreateComponentDescription( unsigned long totalSize = 0; { // the scope is needed for cmGeneratedFileStream cmGeneratedFileStream out(zipListFileName.c_str()); - std::vector<std::string>::iterator fileIt; - for (fileIt = component->Files.begin(); fileIt != component->Files.end(); - ++fileIt) { + for (std::string const& file : component->Files) { if (needQuotesInFile) { out << "\""; } - out << *fileIt; + out << file; if (needQuotesInFile) { out << "\""; } out << std::endl; - totalSize += cmSystemTools::FileLength(dirName + *fileIt); + totalSize += cmSystemTools::FileLength(dirName + file); } } @@ -798,17 +782,14 @@ std::string cmCPackNSISGenerator::CreateComponentDescription( macrosOut << "!macro Remove_${" << component->Name << "}\n"; macrosOut << " IntCmp $" << component->Name << "_was_installed 0 noremove_" << component->Name << "\n"; - std::vector<std::string>::iterator pathIt; std::string path; - for (pathIt = component->Files.begin(); pathIt != component->Files.end(); - ++pathIt) { - path = *pathIt; + for (std::string const& pathIt : component->Files) { + path = pathIt; std::replace(path.begin(), path.end(), '/', '\\'); macrosOut << " Delete \"" << componentOutputDir << "\\" << path << "\"\n"; } - for (pathIt = component->Directories.begin(); - pathIt != component->Directories.end(); ++pathIt) { - path = *pathIt; + for (std::string const& pathIt : component->Directories) { + path = pathIt; std::replace(path.begin(), path.end(), '/', '\\'); macrosOut << " RMDir \"" << componentOutputDir << "\\" << path << "\"\n"; } @@ -841,17 +822,14 @@ std::string cmCPackNSISGenerator::CreateSelectionDependenciesDescription( visited.insert(component); std::ostringstream out; - std::vector<cmCPackComponent*>::iterator dependIt; - for (dependIt = component->Dependencies.begin(); - dependIt != component->Dependencies.end(); ++dependIt) { + for (cmCPackComponent* depend : component->Dependencies) { // Write NSIS code to select this dependency - out << " SectionGetFlags ${" << (*dependIt)->Name << "} $0\n"; + out << " SectionGetFlags ${" << depend->Name << "} $0\n"; out << " IntOp $0 $0 | ${SF_SELECTED}\n"; - out << " SectionSetFlags ${" << (*dependIt)->Name << "} $0\n"; - out << " IntOp $" << (*dependIt)->Name - << "_selected 0 + ${SF_SELECTED}\n"; + out << " SectionSetFlags ${" << depend->Name << "} $0\n"; + out << " IntOp $" << depend->Name << "_selected 0 + ${SF_SELECTED}\n"; // Recurse - out << CreateSelectionDependenciesDescription(*dependIt, visited).c_str(); + out << CreateSelectionDependenciesDescription(depend, visited).c_str(); } return out.str(); @@ -867,19 +845,16 @@ std::string cmCPackNSISGenerator::CreateDeselectionDependenciesDescription( visited.insert(component); std::ostringstream out; - std::vector<cmCPackComponent*>::iterator dependIt; - for (dependIt = component->ReverseDependencies.begin(); - dependIt != component->ReverseDependencies.end(); ++dependIt) { + for (cmCPackComponent* depend : component->ReverseDependencies) { // Write NSIS code to deselect this dependency - out << " SectionGetFlags ${" << (*dependIt)->Name << "} $0\n"; + out << " SectionGetFlags ${" << depend->Name << "} $0\n"; out << " IntOp $1 ${SF_SELECTED} ~\n"; out << " IntOp $0 $0 & $1\n"; - out << " SectionSetFlags ${" << (*dependIt)->Name << "} $0\n"; - out << " IntOp $" << (*dependIt)->Name << "_selected 0 + 0\n"; + out << " SectionSetFlags ${" << depend->Name << "} $0\n"; + out << " IntOp $" << depend->Name << "_selected 0 + 0\n"; // Recurse - out - << CreateDeselectionDependenciesDescription(*dependIt, visited).c_str(); + out << CreateDeselectionDependenciesDescription(depend, visited).c_str(); } return out.str(); @@ -903,20 +878,16 @@ std::string cmCPackNSISGenerator::CreateComponentGroupDescription( code += "\"" + group->DisplayName + "\" " + group->Name + "\n"; } - std::vector<cmCPackComponentGroup*>::iterator groupIt; - for (groupIt = group->Subgroups.begin(); groupIt != group->Subgroups.end(); - ++groupIt) { - code += this->CreateComponentGroupDescription(*groupIt, macrosOut); + for (cmCPackComponentGroup* g : group->Subgroups) { + code += this->CreateComponentGroupDescription(g, macrosOut); } - std::vector<cmCPackComponent*>::iterator comp; - for (comp = group->Components.begin(); comp != group->Components.end(); - ++comp) { - if ((*comp)->Files.empty()) { + for (cmCPackComponent* comp : group->Components) { + if (comp->Files.empty()) { continue; } - code += this->CreateComponentDescription(*comp, macrosOut); + code += this->CreateComponentDescription(comp, macrosOut); } code += "SectionGroupEnd\n"; return code; diff --git a/Source/CPack/cmCPackNSISGenerator.h b/Source/CPack/cmCPackNSISGenerator.h index 77be3256d..fc9ad9ace 100644 --- a/Source/CPack/cmCPackNSISGenerator.h +++ b/Source/CPack/cmCPackNSISGenerator.h @@ -3,7 +3,7 @@ #ifndef cmCPackNSISGenerator_h #define cmCPackNSISGenerator_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmCPackGenerator.h" @@ -34,22 +34,22 @@ public: * Construct generator */ cmCPackNSISGenerator(bool nsis64 = false); - ~cmCPackNSISGenerator() CM_OVERRIDE; + ~cmCPackNSISGenerator() override; protected: - int InitializeInternal() CM_OVERRIDE; + int InitializeInternal() override; void CreateMenuLinks(std::ostream& str, std::ostream& deleteStr); - int PackageFiles() CM_OVERRIDE; - const char* GetOutputExtension() CM_OVERRIDE { return ".exe"; } - const char* GetOutputPostfix() CM_OVERRIDE { return "win32"; } + int PackageFiles() override; + const char* GetOutputExtension() override { return ".exe"; } + const char* GetOutputPostfix() override { return "win32"; } bool GetListOfSubdirectories(const char* dir, std::vector<std::string>& dirs); - enum cmCPackGenerator::CPackSetDestdirSupport SupportsSetDestdir() const - CM_OVERRIDE; - bool SupportsAbsoluteDestination() const CM_OVERRIDE; - bool SupportsComponentInstallation() const CM_OVERRIDE; + enum cmCPackGenerator::CPackSetDestdirSupport SupportsSetDestdir() + const override; + bool SupportsAbsoluteDestination() const override; + bool SupportsComponentInstallation() const override; /// Produce a string that contains the NSIS code to describe a /// particular component. Any added macros will be emitted via diff --git a/Source/CPack/cmCPackOSXX11Generator.cxx b/Source/CPack/cmCPackOSXX11Generator.cxx index 8ea88a87a..8d3c40c5c 100644 --- a/Source/CPack/cmCPackOSXX11Generator.cxx +++ b/Source/CPack/cmCPackOSXX11Generator.cxx @@ -144,8 +144,8 @@ int cmCPackOSXX11Generator::PackageFiles() tmpFile += "/hdiutilOutput.log"; std::ostringstream dmgCmd; dmgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM_DISK_IMAGE") - << "\" create -ov -format UDZO -srcfolder \"" << diskImageDirectory - << "\" \"" << packageFileNames[0] << "\""; + << "\" create -ov -fs HFS+ -format UDZO -srcfolder \"" + << diskImageDirectory << "\" \"" << packageFileNames[0] << "\""; cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Compress disk image using command: " << dmgCmd.str() << std::endl); // since we get random dashboard failures with this one @@ -154,9 +154,9 @@ int cmCPackOSXX11Generator::PackageFiles() int numTries = 10; bool res = false; while (numTries > 0) { - res = - cmSystemTools::RunSingleCommand(dmgCmd.str().c_str(), &output, &output, - &retVal, 0, this->GeneratorVerbose, 0); + res = cmSystemTools::RunSingleCommand(dmgCmd.str().c_str(), &output, + &output, &retVal, nullptr, + this->GeneratorVerbose, 0); if (res && !retVal) { numTries = -1; break; diff --git a/Source/CPack/cmCPackOSXX11Generator.h b/Source/CPack/cmCPackOSXX11Generator.h index 0eebc6dd1..a6461c854 100644 --- a/Source/CPack/cmCPackOSXX11Generator.h +++ b/Source/CPack/cmCPackOSXX11Generator.h @@ -3,7 +3,7 @@ #ifndef cmCPackOSXX11Generator_h #define cmCPackOSXX11Generator_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include <string> @@ -23,13 +23,13 @@ public: * Construct generator */ cmCPackOSXX11Generator(); - virtual ~cmCPackOSXX11Generator(); + ~cmCPackOSXX11Generator() override; protected: - virtual int InitializeInternal() CM_OVERRIDE; - int PackageFiles() CM_OVERRIDE; - const char* GetPackagingInstallPrefix() CM_OVERRIDE; - const char* GetOutputExtension() CM_OVERRIDE { return ".dmg"; } + virtual int InitializeInternal() override; + int PackageFiles() override; + const char* GetPackagingInstallPrefix() override; + const char* GetOutputExtension() override { return ".dmg"; } // bool CopyCreateResourceFile(const std::string& name, // const std::string& dir); diff --git a/Source/CPack/cmCPackPKGGenerator.cxx b/Source/CPack/cmCPackPKGGenerator.cxx index 70ae267fb..4f5b2a05a 100644 --- a/Source/CPack/cmCPackPKGGenerator.cxx +++ b/Source/CPack/cmCPackPKGGenerator.cxx @@ -42,9 +42,9 @@ std::string cmCPackPKGGenerator::GetPackageName( out << cmSystemTools::GetFilenameWithoutLastExtension(packagesDir) << "-" << component.Name << ".pkg"; return out.str(); - } else { - return component.ArchiveFile + ".pkg"; } + + return component.ArchiveFile + ".pkg"; } void cmCPackPKGGenerator::WriteDistributionFile(const char* metapackageFile) @@ -70,7 +70,7 @@ void cmCPackPKGGenerator::WriteDistributionFile(const char* metapackageFile) std::map<std::string, cmCPackComponentGroup>::iterator groupIt; for (groupIt = this->ComponentGroups.begin(); groupIt != this->ComponentGroups.end(); ++groupIt) { - if (groupIt->second.ParentGroup == 0) { + if (groupIt->second.ParentGroup == nullptr) { CreateChoiceOutline(groupIt->second, xout); } } diff --git a/Source/CPack/cmCPackPKGGenerator.h b/Source/CPack/cmCPackPKGGenerator.h index f873c5936..69286ffde 100644 --- a/Source/CPack/cmCPackPKGGenerator.h +++ b/Source/CPack/cmCPackPKGGenerator.h @@ -3,7 +3,7 @@ #ifndef cmCPackPKGGenerator_h #define cmCPackPKGGenerator_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include <set> #include <sstream> @@ -27,13 +27,13 @@ public: * Construct generator */ cmCPackPKGGenerator(); - virtual ~cmCPackPKGGenerator(); + ~cmCPackPKGGenerator() override; - bool SupportsComponentInstallation() const CM_OVERRIDE; + bool SupportsComponentInstallation() const override; protected: - int InitializeInternal() CM_OVERRIDE; - const char* GetOutputPostfix() CM_OVERRIDE { return "darwin"; } + int InitializeInternal() override; + const char* GetOutputPostfix() override { return "darwin"; } // Copies or creates the resource file with the given name to the // package or package staging directory dirName. The variable diff --git a/Source/CPack/cmCPackPackageMakerGenerator.cxx b/Source/CPack/cmCPackPackageMakerGenerator.cxx index 8db7cfb3d..dbcb02231 100644 --- a/Source/CPack/cmCPackPackageMakerGenerator.cxx +++ b/Source/CPack/cmCPackPackageMakerGenerator.cxx @@ -275,8 +275,9 @@ int cmCPackPackageMakerGenerator::PackageFiles() if (this->PackageMakerVersion > 2.0) { pkgCmd << " -v"; } - if (!RunPackageMaker(pkgCmd.str().c_str(), packageDirFileName.c_str())) + if (!RunPackageMaker(pkgCmd.str().c_str(), packageDirFileName.c_str())) { return 0; + } } else { // We have built the package in place. Generate the // distribution.dist file to describe it for the installer. @@ -287,16 +288,16 @@ int cmCPackPackageMakerGenerator::PackageFiles() tmpFile += "/hdiutilOutput.log"; std::ostringstream dmgCmd; dmgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM_DISK_IMAGE") - << "\" create -ov -format UDZO -srcfolder \"" << packageDirFileName - << "\" \"" << packageFileNames[0] << "\""; + << "\" create -ov -fs HFS+ -format UDZO -srcfolder \"" + << packageDirFileName << "\" \"" << packageFileNames[0] << "\""; std::string output; int retVal = 1; int numTries = 10; bool res = false; while (numTries > 0) { - res = - cmSystemTools::RunSingleCommand(dmgCmd.str().c_str(), &output, &output, - &retVal, 0, this->GeneratorVerbose, 0); + res = cmSystemTools::RunSingleCommand(dmgCmd.str().c_str(), &output, + &output, &retVal, nullptr, + this->GeneratorVerbose, 0); if (res && !retVal) { numTries = -1; break; @@ -466,7 +467,7 @@ bool cmCPackPackageMakerGenerator::RunPackageMaker(const char* command, std::string output; int retVal = 1; bool res = cmSystemTools::RunSingleCommand( - command, &output, &output, &retVal, 0, this->GeneratorVerbose, 0); + command, &output, &output, &retVal, nullptr, this->GeneratorVerbose, 0); cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Done running package maker" << std::endl); if (!res || retVal) { diff --git a/Source/CPack/cmCPackPackageMakerGenerator.h b/Source/CPack/cmCPackPackageMakerGenerator.h index 62745152b..0575587d5 100644 --- a/Source/CPack/cmCPackPackageMakerGenerator.h +++ b/Source/CPack/cmCPackPackageMakerGenerator.h @@ -3,7 +3,7 @@ #ifndef cmCPackPackageMakerGenerator_h #define cmCPackPackageMakerGenerator_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmCPackGenerator.h" #include "cmCPackPKGGenerator.h" @@ -25,13 +25,13 @@ public: * Construct generator */ cmCPackPackageMakerGenerator(); - virtual ~cmCPackPackageMakerGenerator(); - bool SupportsComponentInstallation() const CM_OVERRIDE; + ~cmCPackPackageMakerGenerator() override; + bool SupportsComponentInstallation() const override; protected: - int InitializeInternal() CM_OVERRIDE; - int PackageFiles() CM_OVERRIDE; - const char* GetOutputExtension() CM_OVERRIDE { return ".dmg"; } + int InitializeInternal() override; + int PackageFiles() override; + const char* GetOutputExtension() override { return ".dmg"; } // Run PackageMaker with the given command line, which will (if // successful) produce the given package file. Returns true if diff --git a/Source/CPack/cmCPackProductBuildGenerator.cxx b/Source/CPack/cmCPackProductBuildGenerator.cxx index 1389eaa5a..6a6dc828f 100644 --- a/Source/CPack/cmCPackProductBuildGenerator.cxx +++ b/Source/CPack/cmCPackProductBuildGenerator.cxx @@ -54,7 +54,7 @@ int cmCPackProductBuildGenerator::PackageFiles() } else { if (!this->GenerateComponentPackage(basePackageDir, this->GetOption("CPACK_PACKAGE_NAME"), - toplevel, NULL)) { + toplevel, nullptr)) { return 0; } } @@ -145,9 +145,9 @@ bool cmCPackProductBuildGenerator::RunProductBuild(const std::string& command) cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << command << std::endl); std::string output, error_output; int retVal = 1; - bool res = - cmSystemTools::RunSingleCommand(command.c_str(), &output, &error_output, - &retVal, 0, this->GeneratorVerbose, 0); + bool res = cmSystemTools::RunSingleCommand(command.c_str(), &output, + &error_output, &retVal, nullptr, + this->GeneratorVerbose, 0); cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Done running command" << std::endl); if (!res || retVal) { cmGeneratedFileStream ofs(tmpFile.c_str()); @@ -174,7 +174,7 @@ bool cmCPackProductBuildGenerator::GenerateComponentPackage( cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- Building component package: " << packageFile << std::endl); - const char* comp_name = component ? component->Name.c_str() : NULL; + const char* comp_name = component ? component->Name.c_str() : nullptr; const char* preflight = this->GetComponentScript("PREFLIGHT", comp_name); const char* postflight = this->GetComponentScript("POSTFLIGHT", comp_name); @@ -190,7 +190,7 @@ bool cmCPackProductBuildGenerator::GenerateComponentPackage( cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem creating installer directory: " << scriptDir << std::endl); - return 0; + return false; } // if preflight, postflight, or postupgrade are set diff --git a/Source/CPack/cmCPackProductBuildGenerator.h b/Source/CPack/cmCPackProductBuildGenerator.h index 12093a0e8..015fe4ace 100644 --- a/Source/CPack/cmCPackProductBuildGenerator.h +++ b/Source/CPack/cmCPackProductBuildGenerator.h @@ -3,7 +3,7 @@ #ifndef cmCPackProductBuildGenerator_h #define cmCPackProductBuildGenerator_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include <string> @@ -25,12 +25,12 @@ public: * Construct generator */ cmCPackProductBuildGenerator(); - virtual ~cmCPackProductBuildGenerator(); + ~cmCPackProductBuildGenerator() override; protected: - int InitializeInternal() CM_OVERRIDE; - int PackageFiles() CM_OVERRIDE; - const char* GetOutputExtension() CM_OVERRIDE { return ".pkg"; } + int InitializeInternal() override; + int PackageFiles() override; + const char* GetOutputExtension() override { return ".pkg"; } // Run ProductBuild with the given command line, which will (if // successful) produce the given package file. Returns true if diff --git a/Source/CPack/cmCPackRPMGenerator.cxx b/Source/CPack/cmCPackRPMGenerator.cxx index 8ec03c236..e40b74d7e 100644 --- a/Source/CPack/cmCPackRPMGenerator.cxx +++ b/Source/CPack/cmCPackRPMGenerator.cxx @@ -148,7 +148,7 @@ int cmCPackRPMGenerator::PackageComponents(bool ignoreGroup) for (compIt = this->Components.begin(); compIt != this->Components.end(); ++compIt) { // Does the component belong to a group? - if (compIt->second.Group == CM_NULLPTR) { + if (compIt->second.Group == nullptr) { std::string component(compIt->first); std::transform(component.begin(), component.end(), component.begin(), ::toupper); @@ -214,7 +214,7 @@ int cmCPackRPMGenerator::PackageComponents(bool ignoreGroup) for (compIt = this->Components.begin(); compIt != this->Components.end(); ++compIt) { // Does the component belong to a group? - if (compIt->second.Group == CM_NULLPTR) { + if (compIt->second.Group == nullptr) { std::string component(compIt->first); std::transform(component.begin(), component.end(), component.begin(), ::toupper); @@ -299,7 +299,7 @@ int cmCPackRPMGenerator::PackageComponents(bool ignoreGroup) for (compIt = this->Components.begin(); compIt != this->Components.end(); ++compIt) { // Does the component belong to a group? - if (compIt->second.Group == CM_NULLPTR) { + if (compIt->second.Group == nullptr) { cmCPackLogger( cmCPackLog::LOG_VERBOSE, "Component <" << compIt->second.Name @@ -430,7 +430,7 @@ std::string cmCPackRPMGenerator::GetComponentInstallDirNameSuffix( // the current COMPONENT belongs to. std::string groupVar = "CPACK_COMPONENT_" + cmSystemTools::UpperCase(componentName) + "_GROUP"; - if (CM_NULLPTR != GetOption(groupVar)) { + if (nullptr != GetOption(groupVar)) { return std::string(GetOption(groupVar)); } return componentName; diff --git a/Source/CPack/cmCPackRPMGenerator.h b/Source/CPack/cmCPackRPMGenerator.h index 52cfc13ed..27d3b6339 100644 --- a/Source/CPack/cmCPackRPMGenerator.h +++ b/Source/CPack/cmCPackRPMGenerator.h @@ -3,7 +3,7 @@ #ifndef cmCPackRPMGenerator_h #define cmCPackRPMGenerator_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmCPackGenerator.h" @@ -26,7 +26,7 @@ public: * Construct generator */ cmCPackRPMGenerator(); - ~cmCPackRPMGenerator() CM_OVERRIDE; + ~cmCPackRPMGenerator() override; static bool CanGenerate() { @@ -43,8 +43,8 @@ public: } protected: - int InitializeInternal() CM_OVERRIDE; - int PackageFiles() CM_OVERRIDE; + int InitializeInternal() override; + int PackageFiles() override; /** * This method factors out the work done in component packaging case. */ @@ -61,10 +61,10 @@ protected: * components will be put in a single installer. */ int PackageComponentsAllInOne(const std::string& compInstDirName); - const char* GetOutputExtension() CM_OVERRIDE { return ".rpm"; } - bool SupportsComponentInstallation() const CM_OVERRIDE; + const char* GetOutputExtension() override { return ".rpm"; } + bool SupportsComponentInstallation() const override; std::string GetComponentInstallDirNameSuffix( - const std::string& componentName) CM_OVERRIDE; + const std::string& componentName) override; void AddGeneratedPackageNames(); }; diff --git a/Source/CPack/cmCPackSTGZGenerator.cxx b/Source/CPack/cmCPackSTGZGenerator.cxx index c54161426..3d7fd3c14 100644 --- a/Source/CPack/cmCPackSTGZGenerator.cxx +++ b/Source/CPack/cmCPackSTGZGenerator.cxx @@ -6,7 +6,6 @@ #include <sstream> #include <stdio.h> #include <string> -#include <vector> #include "cmCPackGenerator.h" #include "cmCPackLog.h" @@ -48,9 +47,8 @@ int cmCPackSTGZGenerator::PackageFiles() * have generated several packages (component packaging) * so we must iterate over generated packages. */ - for (std::vector<std::string>::iterator it = packageFileNames.begin(); - it != packageFileNames.end(); ++it) { - retval &= cmSystemTools::SetPermissions((*it).c_str(), + for (std::string const& pfn : packageFileNames) { + retval &= cmSystemTools::SetPermissions(pfn.c_str(), #if defined(_MSC_VER) || defined(__MINGW32__) S_IREAD | S_IWRITE | S_IEXEC #else diff --git a/Source/CPack/cmCPackSTGZGenerator.h b/Source/CPack/cmCPackSTGZGenerator.h index 8304e8076..9cf184b19 100644 --- a/Source/CPack/cmCPackSTGZGenerator.h +++ b/Source/CPack/cmCPackSTGZGenerator.h @@ -3,7 +3,7 @@ #ifndef cmCPackSTGZGenerator_h #define cmCPackSTGZGenerator_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmCPackGenerator.h" #include "cmCPackTGZGenerator.h" @@ -23,13 +23,13 @@ public: * Construct generator */ cmCPackSTGZGenerator(); - ~cmCPackSTGZGenerator() CM_OVERRIDE; + ~cmCPackSTGZGenerator() override; protected: - int PackageFiles() CM_OVERRIDE; - int InitializeInternal() CM_OVERRIDE; - int GenerateHeader(std::ostream* os) CM_OVERRIDE; - const char* GetOutputExtension() CM_OVERRIDE { return ".sh"; } + int PackageFiles() override; + int InitializeInternal() override; + int GenerateHeader(std::ostream* os) override; + const char* GetOutputExtension() override { return ".sh"; } }; #endif diff --git a/Source/CPack/cmCPackTGZGenerator.h b/Source/CPack/cmCPackTGZGenerator.h index 9426b3a01..7be3d9d33 100644 --- a/Source/CPack/cmCPackTGZGenerator.h +++ b/Source/CPack/cmCPackTGZGenerator.h @@ -3,7 +3,7 @@ #ifndef cmCPackTGZGenerator_h #define cmCPackTGZGenerator_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmCPackArchiveGenerator.h" #include "cmCPackGenerator.h" @@ -20,10 +20,10 @@ public: * Construct generator */ cmCPackTGZGenerator(); - ~cmCPackTGZGenerator() CM_OVERRIDE; + ~cmCPackTGZGenerator() override; protected: - const char* GetOutputExtension() CM_OVERRIDE { return ".tar.gz"; } + const char* GetOutputExtension() override { return ".tar.gz"; } }; #endif diff --git a/Source/CPack/cmCPackTXZGenerator.h b/Source/CPack/cmCPackTXZGenerator.h index 3b96e2d78..4aa59730e 100644 --- a/Source/CPack/cmCPackTXZGenerator.h +++ b/Source/CPack/cmCPackTXZGenerator.h @@ -3,7 +3,7 @@ #ifndef cmCPackTXZGenerator_h #define cmCPackTXZGenerator_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmCPackArchiveGenerator.h" #include "cmCPackGenerator.h" @@ -20,10 +20,10 @@ public: * Construct generator */ cmCPackTXZGenerator(); - ~cmCPackTXZGenerator() CM_OVERRIDE; + ~cmCPackTXZGenerator() override; protected: - const char* GetOutputExtension() CM_OVERRIDE { return ".tar.xz"; } + const char* GetOutputExtension() override { return ".tar.xz"; } }; #endif diff --git a/Source/CPack/cmCPackTarBZip2Generator.h b/Source/CPack/cmCPackTarBZip2Generator.h index 9b4b8f4ff..7975ddaee 100644 --- a/Source/CPack/cmCPackTarBZip2Generator.h +++ b/Source/CPack/cmCPackTarBZip2Generator.h @@ -3,7 +3,7 @@ #ifndef cmCPackTarBZip2Generator_h #define cmCPackTarBZip2Generator_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmCPackArchiveGenerator.h" #include "cmCPackGenerator.h" @@ -19,10 +19,10 @@ public: * Construct generator */ cmCPackTarBZip2Generator(); - ~cmCPackTarBZip2Generator() CM_OVERRIDE; + ~cmCPackTarBZip2Generator() override; protected: - const char* GetOutputExtension() CM_OVERRIDE { return ".tar.bz2"; } + const char* GetOutputExtension() override { return ".tar.bz2"; } }; #endif diff --git a/Source/CPack/cmCPackTarCompressGenerator.h b/Source/CPack/cmCPackTarCompressGenerator.h index 381d6eb2f..37c7f48c8 100644 --- a/Source/CPack/cmCPackTarCompressGenerator.h +++ b/Source/CPack/cmCPackTarCompressGenerator.h @@ -3,7 +3,7 @@ #ifndef cmCPackTarCompressGenerator_h #define cmCPackTarCompressGenerator_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmCPackArchiveGenerator.h" #include "cmCPackGenerator.h" @@ -19,10 +19,10 @@ public: * Construct generator */ cmCPackTarCompressGenerator(); - ~cmCPackTarCompressGenerator() CM_OVERRIDE; + ~cmCPackTarCompressGenerator() override; protected: - const char* GetOutputExtension() CM_OVERRIDE { return ".tar.Z"; } + const char* GetOutputExtension() override { return ".tar.Z"; } }; #endif diff --git a/Source/CPack/cmCPackZIPGenerator.h b/Source/CPack/cmCPackZIPGenerator.h index 00c872029..58ec79ef1 100644 --- a/Source/CPack/cmCPackZIPGenerator.h +++ b/Source/CPack/cmCPackZIPGenerator.h @@ -3,7 +3,7 @@ #ifndef cmCPackZIPGenerator_h #define cmCPackZIPGenerator_h -#include "cmConfigure.h" +#include "cmConfigure.h" // IWYU pragma: keep #include "cmCPackArchiveGenerator.h" #include "cmCPackGenerator.h" @@ -20,10 +20,10 @@ public: * Construct generator */ cmCPackZIPGenerator(); - ~cmCPackZIPGenerator() CM_OVERRIDE; + ~cmCPackZIPGenerator() override; protected: - const char* GetOutputExtension() CM_OVERRIDE { return ".zip"; } + const char* GetOutputExtension() override { return ".zip"; } }; #endif diff --git a/Source/CPack/cpack.cxx b/Source/CPack/cpack.cxx index a44bc3d68..addb54ea0 100644 --- a/Source/CPack/cpack.cxx +++ b/Source/CPack/cpack.cxx @@ -1,11 +1,11 @@ /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying file Copyright.txt or https://cmake.org/licensing for details. */ -#include "cmConfigure.h" #include "cmsys/CommandLineArguments.hxx" #include "cmsys/Encoding.hxx" #include <iostream> #include <map> +#include <memory> // IWYU pragma: keep #include <sstream> #include <stddef.h> #include <string> @@ -25,17 +25,16 @@ #include "cmMakefile.h" #include "cmStateSnapshot.h" #include "cmSystemTools.h" -#include "cm_auto_ptr.hxx" #include "cmake.h" static const char* cmDocumentationName[][2] = { - { CM_NULLPTR, " cpack - Packaging driver provided by CMake." }, - { CM_NULLPTR, CM_NULLPTR } + { nullptr, " cpack - Packaging driver provided by CMake." }, + { nullptr, nullptr } }; static const char* cmDocumentationUsage[][2] = { - { CM_NULLPTR, " cpack -G <generator> [options]" }, - { CM_NULLPTR, CM_NULLPTR } + { nullptr, " cpack -G <generator> [options]" }, + { nullptr, nullptr } }; static const char* cmDocumentationOptions[][2] = { @@ -49,7 +48,7 @@ static const char* cmDocumentationOptions[][2] = { { "-R <package version>", "override/define CPACK_PACKAGE_VERSION" }, { "-B <package directory>", "override/define CPACK_PACKAGE_DIRECTORY" }, { "--vendor <vendor name>", "override/define CPACK_PACKAGE_VENDOR" }, - { CM_NULLPTR, CM_NULLPTR } + { nullptr, nullptr } }; int cpackUnknownArgument(const char* /*unused*/, void* /*unused*/) @@ -136,7 +135,7 @@ int main(int argc, char const* const* argv) cpackDefinitions definitions; definitions.Log = &log; - cpackConfigFile = ""; + cpackConfigFile.clear(); cmsys::CommandLineArguments arg; arg.Initialize(argc, argv); @@ -193,10 +192,9 @@ int main(int argc, char const* const* argv) cminst.SetHomeOutputDirectory(""); cminst.GetCurrentSnapshot().SetDefaultDefinitions(); cmGlobalGenerator cmgg(&cminst); - CM_AUTO_PTR<cmMakefile> globalMF( - new cmMakefile(&cmgg, cminst.GetCurrentSnapshot())); + cmMakefile globalMF(&cmgg, cminst.GetCurrentSnapshot()); #if defined(__CYGWIN__) - globalMF->AddDefinition("CMAKE_LEGACY_CYGWIN_WIN32", "0"); + globalMF.AddDefinition("CMAKE_LEGACY_CYGWIN_WIN32", "0"); #endif bool cpackConfigFileSpecified = true; @@ -208,7 +206,7 @@ int main(int argc, char const* const* argv) cmCPackGeneratorFactory generators; generators.SetLogger(&log); - cmCPackGenerator* cpackGenerator = CM_NULLPTR; + cmCPackGenerator* cpackGenerator = nullptr; cmDocumentation doc; doc.addCPackStandardDocSections(); @@ -226,16 +224,16 @@ int main(int argc, char const* const* argv) // find out which system cpack is running on, so it can setup the search // paths, so FIND_XXX() commands can be used in scripts std::string systemFile = - globalMF->GetModulesFile("CMakeDetermineSystem.cmake"); - if (!globalMF->ReadListFile(systemFile.c_str())) { + globalMF.GetModulesFile("CMakeDetermineSystem.cmake"); + if (!globalMF.ReadListFile(systemFile.c_str())) { cmCPack_Log(&log, cmCPackLog::LOG_ERROR, "Error reading CMakeDetermineSystem.cmake" << std::endl); return 1; } systemFile = - globalMF->GetModulesFile("CMakeSystemSpecificInformation.cmake"); - if (!globalMF->ReadListFile(systemFile.c_str())) { + globalMF.GetModulesFile("CMakeSystemSpecificInformation.cmake"); + if (!globalMF.ReadListFile(systemFile.c_str())) { cmCPack_Log(&log, cmCPackLog::LOG_ERROR, "Error reading CMakeSystemSpecificInformation.cmake" << std::endl); @@ -243,7 +241,7 @@ int main(int argc, char const* const* argv) } if (!cpackBuildConfig.empty()) { - globalMF->AddDefinition("CPACK_BUILD_CONFIG", cpackBuildConfig.c_str()); + globalMF.AddDefinition("CPACK_BUILD_CONFIG", cpackBuildConfig.c_str()); } if (cmSystemTools::FileExists(cpackConfigFile.c_str())) { @@ -251,7 +249,7 @@ int main(int argc, char const* const* argv) cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE, "Read CPack configuration file: " << cpackConfigFile << std::endl); - if (!globalMF->ReadListFile(cpackConfigFile.c_str())) { + if (!globalMF.ReadListFile(cpackConfigFile.c_str())) { cmCPack_Log(&log, cmCPackLog::LOG_ERROR, "Problem reading CPack config file: \"" << cpackConfigFile << "\"" << std::endl); @@ -265,58 +263,53 @@ int main(int argc, char const* const* argv) } if (!generator.empty()) { - globalMF->AddDefinition("CPACK_GENERATOR", generator.c_str()); + globalMF.AddDefinition("CPACK_GENERATOR", generator.c_str()); } if (!cpackProjectName.empty()) { - globalMF->AddDefinition("CPACK_PACKAGE_NAME", cpackProjectName.c_str()); + globalMF.AddDefinition("CPACK_PACKAGE_NAME", cpackProjectName.c_str()); } if (!cpackProjectVersion.empty()) { - globalMF->AddDefinition("CPACK_PACKAGE_VERSION", - cpackProjectVersion.c_str()); + globalMF.AddDefinition("CPACK_PACKAGE_VERSION", + cpackProjectVersion.c_str()); } if (!cpackProjectVendor.empty()) { - globalMF->AddDefinition("CPACK_PACKAGE_VENDOR", - cpackProjectVendor.c_str()); + globalMF.AddDefinition("CPACK_PACKAGE_VENDOR", + cpackProjectVendor.c_str()); } // if this is not empty it has been set on the command line // go for it. Command line override values set in config file. if (!cpackProjectDirectory.empty()) { - globalMF->AddDefinition("CPACK_PACKAGE_DIRECTORY", - cpackProjectDirectory.c_str()); + globalMF.AddDefinition("CPACK_PACKAGE_DIRECTORY", + cpackProjectDirectory.c_str()); } // The value has not been set on the command line else { // get a default value (current working directory) cpackProjectDirectory = cmsys::SystemTools::GetCurrentWorkingDirectory(); // use default value iff no value has been provided by the config file - if (!globalMF->IsSet("CPACK_PACKAGE_DIRECTORY")) { - globalMF->AddDefinition("CPACK_PACKAGE_DIRECTORY", - cpackProjectDirectory.c_str()); + if (!globalMF.IsSet("CPACK_PACKAGE_DIRECTORY")) { + globalMF.AddDefinition("CPACK_PACKAGE_DIRECTORY", + cpackProjectDirectory.c_str()); } } - cpackDefinitions::MapType::iterator cdit; - for (cdit = definitions.Map.begin(); cdit != definitions.Map.end(); - ++cdit) { - globalMF->AddDefinition(cdit->first, cdit->second.c_str()); + for (auto const& cd : definitions.Map) { + globalMF.AddDefinition(cd.first, cd.second.c_str()); } - const char* cpackModulesPath = - globalMF->GetDefinition("CPACK_MODULE_PATH"); + const char* cpackModulesPath = globalMF.GetDefinition("CPACK_MODULE_PATH"); if (cpackModulesPath) { - globalMF->AddDefinition("CMAKE_MODULE_PATH", cpackModulesPath); + globalMF.AddDefinition("CMAKE_MODULE_PATH", cpackModulesPath); } - const char* genList = globalMF->GetDefinition("CPACK_GENERATOR"); + const char* genList = globalMF.GetDefinition("CPACK_GENERATOR"); if (!genList) { cmCPack_Log(&log, cmCPackLog::LOG_ERROR, "CPack generator not specified" << std::endl); } else { std::vector<std::string> generatorsVector; cmSystemTools::ExpandListArgument(genList, generatorsVector); - std::vector<std::string>::iterator it; - for (it = generatorsVector.begin(); it != generatorsVector.end(); ++it) { - const char* gen = it->c_str(); - cmMakefile::ScopePushPop raii(globalMF.get()); - cmMakefile* mf = globalMF.get(); + for (std::string const& gen : generatorsVector) { + cmMakefile::ScopePushPop raii(&globalMF); + cmMakefile* mf = &globalMF; cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE, "Specified generator: " << gen << std::endl); if (parsed && !mf->GetDefinition("CPACK_PACKAGE_NAME")) { @@ -355,13 +348,14 @@ int main(int argc, char const* const* argv) } if (!mf->GetDefinition("CPACK_INSTALL_COMMANDS") && + !mf->GetDefinition("CPACK_INSTALL_SCRIPT") && !mf->GetDefinition("CPACK_INSTALLED_DIRECTORIES") && !mf->GetDefinition("CPACK_INSTALL_CMAKE_PROJECTS")) { cmCPack_Log( &log, cmCPackLog::LOG_ERROR, "Please specify build tree of the project that uses CMake " "using CPACK_INSTALL_CMAKE_PROJECTS, specify " - "CPACK_INSTALL_COMMANDS, or specify " + "CPACK_INSTALL_COMMANDS, CPACK_INSTALL_SCRIPT, or " "CPACK_INSTALLED_DIRECTORIES." << std::endl); parsed = 0; @@ -414,12 +408,10 @@ int main(int argc, char const* const* argv) doc.PrependSection("Options", cmDocumentationOptions); std::vector<cmDocumentationEntry> v; - cmCPackGeneratorFactory::DescriptionsMap::const_iterator generatorIt; - for (generatorIt = generators.GetGeneratorsList().begin(); - generatorIt != generators.GetGeneratorsList().end(); ++generatorIt) { + for (auto const& g : generators.GetGeneratorsList()) { cmDocumentationEntry e; - e.Name = generatorIt->first; - e.Brief = generatorIt->second; + e.Name = g.first; + e.Brief = g.second; v.push_back(e); } doc.SetSection("Generators", v); |