From 6c7dfb3afdc366b90fbfd93dc01d4cbd36d57992 Mon Sep 17 00:00:00 2001 From: AJIOB Date: Thu, 24 Sep 2026 19:35:29 +0000 Subject: [PATCH] Source: reduce ostringstream usage for IFW --- Source/CPack/IFW/cmCPackIFWCommon.h | 7 +- Source/CPack/IFW/cmCPackIFWGenerator.cxx | 81 +++++++++--------------- Source/CPack/IFW/cmCPackIFWInstaller.cxx | 41 +++++------- Source/CPack/IFW/cmCPackIFWPackage.cxx | 42 ++++++------ 4 files changed, 68 insertions(+), 103 deletions(-) diff --git a/Source/CPack/IFW/cmCPackIFWCommon.h b/Source/CPack/IFW/cmCPackIFWCommon.h index da49c680e7..1b64e76f8b 100644 --- a/Source/CPack/IFW/cmCPackIFWCommon.h +++ b/Source/CPack/IFW/cmCPackIFWCommon.h @@ -69,12 +69,11 @@ protected: void WriteGeneratedByToStrim(cmXMLWriter& xout) const; }; -#define cmCPackIFWLogger(logType, msg) \ +#define cmCPackIFWLogger(logType, ...) \ do { \ - std::ostringstream cmCPackLog_msg; \ - cmCPackLog_msg << msg; \ if (Generator) { \ + std::string cmCPackLog_msg = cmStrCat("", __VA_ARGS__); \ Generator->Logger->Log(cmCPackLog::LOG_##logType, __FILE__, __LINE__, \ - cmCPackLog_msg.str().c_str()); \ + cmCPackLog_msg.c_str(), cmCPackLog_msg.size()); \ } \ } while (false) diff --git a/Source/CPack/IFW/cmCPackIFWGenerator.cxx b/Source/CPack/IFW/cmCPackIFWGenerator.cxx index d12d905b34..4fcdb188e6 100644 --- a/Source/CPack/IFW/cmCPackIFWGenerator.cxx +++ b/Source/CPack/IFW/cmCPackIFWGenerator.cxx @@ -28,7 +28,7 @@ cmCPackIFWGenerator::~cmCPackIFWGenerator() = default; int cmCPackIFWGenerator::PackageFiles() { - cmCPackIFWLogger(OUTPUT, "- Configuration" << std::endl); + cmCPackIFWLogger(OUTPUT, "- Configuration\n"); // Installer configuragion this->Installer.GenerateInstallerFile(); @@ -93,10 +93,9 @@ std::vector cmCPackIFWGenerator::BuildRepogenCommand() } 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); + "variable is set, but content will be skipped, " + "because this feature available only since " + "QtIFW 3.1. Please update your QtIFW instance.\n"); } } @@ -123,12 +122,11 @@ int cmCPackIFWGenerator::RunRepogen(std::string const& ifwTmpFile) } std::vector ifwCmd = this->BuildRepogenCommand(); - cmCPackIFWLogger(VERBOSE, - "Execute: " << cmSystemTools::PrintSingleCommand(ifwCmd) - << std::endl); + cmCPackIFWLogger( + VERBOSE, "Execute: ", cmSystemTools::PrintSingleCommand(ifwCmd), '\n'); std::string output; int retVal = 1; - cmCPackIFWLogger(OUTPUT, "- Generate repository" << std::endl); + cmCPackIFWLogger(OUTPUT, "- Generate repository\n"); bool res = cmSystemTools::RunSingleCommand(ifwCmd, &output, &output, &retVal, nullptr, this->GeneratorVerbose, cmDuration::zero()); @@ -138,11 +136,9 @@ int cmCPackIFWGenerator::RunRepogen(std::string const& ifwTmpFile) << std::endl << "# Output:" << std::endl << output << std::endl; - cmCPackIFWLogger( - ERROR, - "Problem running IFW command: " - << cmSystemTools::PrintSingleCommand(ifwCmd) << std::endl - << "Please check \"" << ifwTmpFile << "\" for errors" << std::endl); + cmCPackIFWLogger(ERROR, "Problem running IFW command: ", + cmSystemTools::PrintSingleCommand(ifwCmd), + "\nPlease check \"", ifwTmpFile, "\" for errors\n"); return 0; } @@ -150,14 +146,12 @@ int cmCPackIFWGenerator::RunRepogen(std::string const& ifwTmpFile) !this->Repository.PatchUpdatesXml()) { cmCPackIFWLogger(WARNING, "Problem patch IFW \"Updates\" " - << "file: \"" << this->toplevel - << "/repository/Updates.xml\"" << std::endl); + "file: \"", + this->toplevel, "/repository/Updates.xml\"\n"); } - cmCPackIFWLogger(OUTPUT, - "- repository: \"" << this->toplevel - << "/repository\" generated" - << std::endl); + cmCPackIFWLogger(OUTPUT, "- repository: \"", this->toplevel, + "/repository\" generated\n"); return 1; } @@ -225,10 +219,9 @@ std::vector cmCPackIFWGenerator::BuildBinaryCreatorCommand() } 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); + "variable is set, but content will be skipped, " + "because this feature available only since " + "QtIFW 3.1. Please update your QtIFW instance.\n"); } } @@ -277,12 +270,11 @@ std::vector cmCPackIFWGenerator::BuildBinaryCreatorCommand() int cmCPackIFWGenerator::RunBinaryCreator(std::string const& ifwTmpFile) { std::vector ifwCmd = this->BuildBinaryCreatorCommand(); - cmCPackIFWLogger(VERBOSE, - "Execute: " << cmSystemTools::PrintSingleCommand(ifwCmd) - << std::endl); + cmCPackIFWLogger( + VERBOSE, "Execute: ", cmSystemTools::PrintSingleCommand(ifwCmd), '\n'); std::string output; int retVal = 1; - cmCPackIFWLogger(OUTPUT, "- Generate package" << std::endl); + cmCPackIFWLogger(OUTPUT, "- Generate package\n"); bool res = cmSystemTools::RunSingleCommand(ifwCmd, &output, &output, &retVal, nullptr, this->GeneratorVerbose, cmDuration::zero()); @@ -292,11 +284,9 @@ int cmCPackIFWGenerator::RunBinaryCreator(std::string const& ifwTmpFile) << std::endl << "# Output:" << std::endl << output << std::endl; - cmCPackIFWLogger( - ERROR, - "Problem running IFW command: " - << cmSystemTools::PrintSingleCommand(ifwCmd) << std::endl - << "Please check \"" << ifwTmpFile << "\" for errors" << std::endl); + cmCPackIFWLogger(ERROR, "Problem running IFW command: ", + cmSystemTools::PrintSingleCommand(ifwCmd), + "\nPlease check \"", ifwTmpFile, "\" for errors\n"); return 0; } @@ -349,8 +339,7 @@ int cmCPackIFWGenerator::InitializeInternal() if (this->BinCreator.empty()) { cmCPackIFWLogger(ERROR, "Cannot find QtIFW compiler \"binarycreator\": " - "likely it is not installed, or not in your PATH" - << std::endl); + "likely it is not installed, or not in your PATH\n"); return 0; } @@ -428,8 +417,7 @@ int cmCPackIFWGenerator::InitializeInternal() if (!this->Installer.RemoteRepositories.empty() && this->RepoGen.empty()) { cmCPackIFWLogger(ERROR, "Cannot find QtIFW repository generator \"repogen\": " - "likely it is not installed, or not in your PATH" - << std::endl); + "likely it is not installed, or not in your PATH\n"); return 0; } @@ -530,10 +518,8 @@ cmCPackComponent* cmCPackIFWGenerator::GetComponent( } } else { this->Packages.erase(name); - cmCPackIFWLogger(ERROR, - "Cannot configure package \"" - << name << "\" for component \"" << component->Name - << "\"" << std::endl); + cmCPackIFWLogger(ERROR, "Cannot configure package \"", name, + "\" for component \"", component->Name, "\"\n"); } return component; @@ -566,10 +552,8 @@ cmCPackComponentGroup* cmCPackIFWGenerator::GetComponentGroup( this->BinaryPackages.insert(package); } else { this->Packages.erase(name); - cmCPackIFWLogger(ERROR, - "Cannot configure package \"" - << name << "\" for component group \"" << group->Name - << "\"" << std::endl); + cmCPackIFWLogger(ERROR, "Cannot configure package \"", name, + "\" for component group \"", group->Name, "\"\n"); } return group; } @@ -705,11 +689,8 @@ cmCPackIFWRepository* cmCPackIFWGenerator::GetRepository( } else { this->Repositories.erase(repositoryName); repository = nullptr; - cmCPackIFWLogger(WARNING, - "Invalid repository \"" - << repositoryName << "\"" - << " configuration. Repository will be skipped." - << std::endl); + cmCPackIFWLogger(WARNING, "Invalid repository \"", repositoryName, + "\" configuration. Repository will be skipped.\n"); } return repository; } diff --git a/Source/CPack/IFW/cmCPackIFWInstaller.cxx b/Source/CPack/IFW/cmCPackIFWInstaller.cxx index 717eb55217..83ba9f4743 100644 --- a/Source/CPack/IFW/cmCPackIFWInstaller.cxx +++ b/Source/CPack/IFW/cmCPackIFWInstaller.cxx @@ -4,7 +4,6 @@ #include #include -#include #include #include "cmCPackIFWCommon.h" @@ -26,11 +25,8 @@ void cmCPackIFWInstaller::printSkippedOptionWarning( std::string const& optionName, std::string const& optionValue) { cmCPackIFWLogger( - WARNING, - "Option " - << optionName << " contains the value \"" << optionValue - << "\" but will be skipped because the specified file does not exist." - << std::endl); + WARNING, "Option ", optionName, " contains the value \"", optionValue, + "\" but will be skipped because the specified file does not exist.\n"); } void cmCPackIFWInstaller::ConfigureFromOptions() @@ -149,10 +145,8 @@ void cmCPackIFWInstaller::ConfigureFromOptions() if (this->WizardStyle != "Modern" && this->WizardStyle != "Aero" && this->WizardStyle != "Mac" && this->WizardStyle != "Classic") { cmCPackIFWLogger( - WARNING, - "Option CPACK_IFW_PACKAGE_WIZARD_STYLE has unknown value \"" - << option << "\". Expected values are: Modern, Aero, Mac, Classic." - << std::endl); + WARNING, "Option CPACK_IFW_PACKAGE_WIZARD_STYLE has unknown value \"", + option, "\". Expected values are: Modern, Aero, Mac, Classic.\n"); } } @@ -198,12 +192,11 @@ void cmCPackIFWInstaller::ConfigureFromOptions() currentVersionMsg = "an older QtIFW version"; } cmCPackIFWLogger( - WARNING, - "Option CPACK_IFW_PACKAGE_WIZARD_SHOW_PAGE_LIST is set to \"" - << option - << "\", but it is only supported with QtIFW version 4.0 or later. " - "It is being ignored because you are using " - << currentVersionMsg << std::endl); + WARNING, "Option CPACK_IFW_PACKAGE_WIZARD_SHOW_PAGE_LIST is set to \"", + option, + "\", but it is only supported with QtIFW version 4.0 or later. " + "It is being ignored because you are using ", + currentVersionMsg, '\n'); } } @@ -332,11 +325,10 @@ void cmCPackIFWInstaller::ConfigureFromOptions() cmCPackIFWLogger( WARNING, "Option \"CPACK_IFW_PACKAGE_PRODUCT_IMAGE_URLS\" will be skipped " - "because it contains " - << this->ProductImageUrls.size() - << " elements while \"CPACK_IFW_PACKAGE_PRODUCT_IMAGES\" " - "contains " - << this->ProductImages.size() << " elements." << std::endl); + "because it contains ", + this->ProductImageUrls.size(), + " elements while \"CPACK_IFW_PACKAGE_PRODUCT_IMAGES\" contains ", + this->ProductImages.size(), " elements.\n"); this->ProductImageUrls.clear(); } } @@ -667,10 +659,9 @@ void cmCPackIFWInstaller::GenerateInstallerFile() cmsys::SystemTools::CopyFileIfDifferent(this->Resources[i], path); resources.push_back(std::move(name)); } else { - cmCPackIFWLogger(WARNING, - "Can't copy resources from \"" - << this->Resources[i] - << "\". Resource will be skipped." << std::endl); + cmCPackIFWLogger(WARNING, "Can't copy resources from \"", + this->Resources[i], + "\". Resource will be skipped.\n"); } } this->Resources = resources; diff --git a/Source/CPack/IFW/cmCPackIFWPackage.cxx b/Source/CPack/IFW/cmCPackIFWPackage.cxx index 1d7a97d54c..cf842bd79c 100644 --- a/Source/CPack/IFW/cmCPackIFWPackage.cxx +++ b/Source/CPack/IFW/cmCPackIFWPackage.cxx @@ -239,10 +239,9 @@ int cmCPackIFWPackage::ConfigureFromComponent(cmCPackComponent* component) cmExpandList(option, this->Licenses); if (this->Licenses.size() % 2 != 0) { cmCPackIFWLogger( - WARNING, - prefix << "LICENSES" - << " should contain pairs of and ." - << std::endl); + WARNING, prefix, + "LICENSES" + " should contain pairs of and .\n"); this->Licenses.clear(); } } @@ -251,11 +250,10 @@ int cmCPackIFWPackage::ConfigureFromComponent(cmCPackComponent* component) if (cmValue option = this->GetOption(prefix + "PRIORITY")) { this->SortingPriority = *option; cmCPackIFWLogger( - WARNING, - "The \"PRIORITY\" option is set " - << "for component \"" << component->Name << "\", but there option is " - << "deprecated. Please use \"SORTING_PRIORITY\" option instead." - << std::endl); + WARNING, "The \"PRIORITY\" option is set for component \"", + component->Name, + "\", but there option is " + "deprecated. Please use \"SORTING_PRIORITY\" option instead.\n"); } // Default @@ -318,10 +316,9 @@ int cmCPackIFWPackage::ConfigureFromGroup(cmCPackComponentGroup* group) cmExpandList(option, this->Licenses); if (this->Licenses.size() % 2 != 0) { cmCPackIFWLogger( - WARNING, - prefix << "LICENSES" - << " should contain pairs of and ." - << std::endl); + WARNING, prefix, + "LICENSES" + " should contain pairs of and .\n"); this->Licenses.clear(); } } @@ -330,12 +327,10 @@ int cmCPackIFWPackage::ConfigureFromGroup(cmCPackComponentGroup* group) if (cmValue option = this->GetOption(prefix + "PRIORITY")) { this->SortingPriority = *option; cmCPackIFWLogger( - WARNING, - "The \"PRIORITY\" option is set " - << "for component group \"" << group->Name - << "\", but there option is " - << "deprecated. Please use \"SORTING_PRIORITY\" option instead." - << std::endl); + WARNING, "The \"PRIORITY\" option is set for component group \"", + group->Name, + "\", but there option is " + "deprecated. Please use \"SORTING_PRIORITY\" option instead.\n"); } return this->ConfigureFromPrefix(prefix); @@ -690,11 +685,10 @@ void cmCPackIFWPackage::GeneratePackageFile() if (warnUnsupportedNames) { cmCPackIFWLogger( - WARNING, - "The dependencies for component \"" - << this->Name << "\" specify names that contain hyphens. " - << "This requires QtIFW 3.1 or later, but you are using version " - << this->Generator->FrameworkVersion << std::endl); + WARNING, "The dependencies for component \"", this->Name, + "\" specify names that contain hyphens. " + "This requires QtIFW 3.1 or later, but you are using version ", + this->Generator->FrameworkVersion, '\n'); } // Licenses (copy to meta dir)