diff options
author | Asit Dhal <dhal.asitk@gmail.com> | 2019-09-15 17:11:02 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2019-09-18 18:18:46 (GMT) |
commit | 9dba84cfa5e85e51ee6d6799f03a26656063ef8b (patch) | |
tree | 22fb29536def399e2ab763ac202a52467d45d7e2 /Source/cmInstallCommand.cxx | |
parent | 1423507a71199fd76b457ad9b215a6caca70ee58 (diff) | |
download | CMake-9dba84cfa5e85e51ee6d6799f03a26656063ef8b.zip CMake-9dba84cfa5e85e51ee6d6799f03a26656063ef8b.tar.gz CMake-9dba84cfa5e85e51ee6d6799f03a26656063ef8b.tar.bz2 |
Refactor: Use cmStrCat to construct error strings
Replace string construction using std::stringstream with cmStrCat and
cmWrap.
Diffstat (limited to 'Source/cmInstallCommand.cxx')
-rw-r--r-- | Source/cmInstallCommand.cxx | 314 |
1 files changed, 124 insertions, 190 deletions
diff --git a/Source/cmInstallCommand.cxx b/Source/cmInstallCommand.cxx index 9b931f7..e7bb1ac 100644 --- a/Source/cmInstallCommand.cxx +++ b/Source/cmInstallCommand.cxx @@ -293,9 +293,8 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args) if (!unknownArgs.empty()) { // Unknown argument. - std::ostringstream e; - e << "TARGETS given unknown argument \"" << unknownArgs[0] << "\"."; - this->SetError(e.str()); + this->SetError( + cmStrCat("TARGETS given unknown argument \"", unknownArgs[0], "\".")); return false; } @@ -391,9 +390,8 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args) for (std::string const& tgt : targetList) { if (this->Makefile->IsAlias(tgt)) { - std::ostringstream e; - e << "TARGETS given target \"" << tgt << "\" which is an alias."; - this->SetError(e.str()); + this->SetError( + cmStrCat("TARGETS given target \"", tgt, "\" which is an alias.")); return false; } // Lookup this target in the current directory. @@ -414,19 +412,17 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args) target->GetType() != cmStateEnums::MODULE_LIBRARY && target->GetType() != cmStateEnums::OBJECT_LIBRARY && target->GetType() != cmStateEnums::INTERFACE_LIBRARY) { - std::ostringstream e; - e << "TARGETS given target \"" << tgt - << "\" which is not an executable, library, or module."; - this->SetError(e.str()); + this->SetError( + cmStrCat("TARGETS given target \"", tgt, + "\" which is not an executable, library, or module.")); return false; } // Store the target in the list to be installed. targets.push_back(target); } else { // Did not find the target. - std::ostringstream e; - e << "TARGETS given target \"" << tgt << "\" which does not exist."; - this->SetError(e.str()); + this->SetError( + cmStrCat("TARGETS given target \"", tgt, "\" which does not exist.")); return false; } } @@ -507,11 +503,10 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args) frameworkGenerator = CreateInstallTargetGenerator( target, frameworkArgs, false, this->Makefile->GetBacktrace()); } else { - std::ostringstream e; - e << "TARGETS given no FRAMEWORK DESTINATION for shared library " - "FRAMEWORK target \"" - << target.GetName() << "\"."; - this->SetError(e.str()); + this->SetError( + cmStrCat("TARGETS given no FRAMEWORK DESTINATION for shared " + "library FRAMEWORK target \"", + target.GetName(), "\".")); return false; } } else { @@ -549,11 +544,11 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args) frameworkGenerator = CreateInstallTargetGenerator( target, frameworkArgs, false, this->Makefile->GetBacktrace()); } else { - std::ostringstream e; - e << "TARGETS given no FRAMEWORK DESTINATION for static library " - "FRAMEWORK target \"" - << target.GetName() << "\"."; - this->SetError(e.str()); + this->SetError( + cmStrCat("TARGETS given no FRAMEWORK DESTINATION for static " + "library FRAMEWORK target \"", + target.GetName(), "\".")); + return false; } } else { @@ -572,10 +567,10 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args) namelinkOnly = (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly); } else { - std::ostringstream e; - e << "TARGETS given no LIBRARY DESTINATION for module target \"" - << target.GetName() << "\"."; - this->SetError(e.str()); + this->SetError( + cmStrCat("TARGETS given no LIBRARY DESTINATION for module " + "target \"", + target.GetName(), "\".")); return false; } } break; @@ -586,10 +581,9 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args) std::string reason; if (!this->Makefile->GetGlobalGenerator() ->HasKnownObjectFileLocation(&reason)) { - std::ostringstream e; - e << "TARGETS given OBJECT library \"" << target.GetName() - << "\" whose objects may not be installed" << reason << "."; - this->SetError(e.str()); + this->SetError( + cmStrCat("TARGETS given OBJECT library \"", target.GetName(), + "\" whose objects may not be installed", reason, ".")); return false; } @@ -619,11 +613,9 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args) } } if (!bundleGenerator) { - std::ostringstream e; - e << "TARGETS given no BUNDLE DESTINATION for MACOSX_BUNDLE " - "executable target \"" - << target.GetName() << "\"."; - this->SetError(e.str()); + this->SetError(cmStrCat("TARGETS given no BUNDLE DESTINATION for " + "MACOSX_BUNDLE executable target \"", + target.GetName(), "\".")); return false; } } else { @@ -708,10 +700,10 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args) resourceGenerator = CreateInstallFilesGenerator( this->Makefile, absFiles, resourceArgs, false); } else { - std::ostringstream e; - e << "INSTALL TARGETS - target " << target.GetName() << " has " - << "RESOURCE files but no RESOURCE DESTINATION."; - cmSystemTools::Message(e.str(), "Warning"); + cmSystemTools::Message( + cmStrCat("INSTALL TARGETS - target ", target.GetName(), + " has RESOURCE files but no RESOURCE DESTINATION."), + "Warning"); } } } @@ -820,17 +812,15 @@ bool cmInstallCommand::HandleFilesMode(std::vector<std::string> const& args) if (!unknownArgs.empty()) { // Unknown argument. - std::ostringstream e; - e << args[0] << " given unknown argument \"" << unknownArgs[0] << "\"."; - this->SetError(e.str()); + this->SetError( + cmStrCat(args[0], " given unknown argument \"", unknownArgs[0], "\".")); return false; } std::string type = ica.GetType(); if (!type.empty() && allowedTypes.count(type) == 0) { - std::ostringstream e; - e << args[0] << " given non-type \"" << type << "\" with TYPE argument."; - this->SetError(e.str()); + this->SetError( + cmStrCat(args[0], " given non-type \"", type, "\" with TYPE argument.")); return false; } @@ -843,9 +833,8 @@ bool cmInstallCommand::HandleFilesMode(std::vector<std::string> const& args) if (!ica.GetRename().empty() && filesVector.size() > 1) { // The rename option works only with one file. - std::ostringstream e; - e << args[0] << " given RENAME option with more than one file."; - this->SetError(e.str()); + this->SetError( + cmStrCat(args[0], " given RENAME option with more than one file.")); return false; } @@ -897,20 +886,16 @@ bool cmInstallCommand::HandleFilesMode(std::vector<std::string> const& args) } if (!type.empty() && !ica.GetDestination().empty()) { - std::ostringstream e; - e << args[0] - << " given both TYPE and DESTINATION arguments. You may only specify " - "one."; - this->SetError(e.str()); + this->SetError(cmStrCat(args[0], + " given both TYPE and DESTINATION arguments. " + "You may only specify one.")); return false; } std::string destination = this->GetDestinationForType(&ica, type); if (destination.empty()) { // A destination is required. - std::ostringstream e; - e << args[0] << " given no DESTINATION!"; - this->SetError(e.str()); + this->SetError(cmStrCat(args[0], " given no DESTINATION!")); return false; } @@ -959,10 +944,8 @@ bool cmInstallCommand::HandleDirectoryMode( for (unsigned int i = 1; i < args.size(); ++i) { if (args[i] == "DESTINATION") { if (in_match_mode) { - std::ostringstream e; - e << args[0] << " does not allow \"" << args[i] - << "\" after PATTERN or REGEX."; - this->SetError(e.str()); + this->SetError(cmStrCat(args[0], " does not allow \"", args[i], + "\" after PATTERN or REGEX.")); return false; } @@ -970,10 +953,8 @@ bool cmInstallCommand::HandleDirectoryMode( doing = DoingDestination; } else if (args[i] == "TYPE") { if (in_match_mode) { - std::ostringstream e; - e << args[0] << " does not allow \"" << args[i] - << "\" after PATTERN or REGEX."; - this->SetError(e.str()); + this->SetError(cmStrCat(args[0], " does not allow \"", args[i], + "\" after PATTERN or REGEX.")); return false; } @@ -981,10 +962,8 @@ bool cmInstallCommand::HandleDirectoryMode( doing = DoingType; } else if (args[i] == "OPTIONAL") { if (in_match_mode) { - std::ostringstream e; - e << args[0] << " does not allow \"" << args[i] - << "\" after PATTERN or REGEX."; - this->SetError(e.str()); + this->SetError(cmStrCat(args[0], " does not allow \"", args[i], + "\" after PATTERN or REGEX.")); return false; } @@ -993,10 +972,8 @@ bool cmInstallCommand::HandleDirectoryMode( doing = DoingNone; } else if (args[i] == "MESSAGE_NEVER") { if (in_match_mode) { - std::ostringstream e; - e << args[0] << " does not allow \"" << args[i] - << "\" after PATTERN or REGEX."; - this->SetError(e.str()); + this->SetError(cmStrCat(args[0], " does not allow \"", args[i], + "\" after PATTERN or REGEX.")); return false; } @@ -1014,20 +991,16 @@ bool cmInstallCommand::HandleDirectoryMode( } else if (args[i] == "EXCLUDE") { // Add this property to the current match rule. if (!in_match_mode || doing == DoingPattern || doing == DoingRegex) { - std::ostringstream e; - e << args[0] << " does not allow \"" << args[i] - << "\" before a PATTERN or REGEX is given."; - this->SetError(e.str()); + this->SetError(cmStrCat(args[0], " does not allow \"", args[i], + "\" before a PATTERN or REGEX is given.")); return false; } literal_args += " EXCLUDE"; doing = DoingNone; } else if (args[i] == "PERMISSIONS") { if (!in_match_mode) { - std::ostringstream e; - e << args[0] << " does not allow \"" << args[i] - << "\" before a PATTERN or REGEX is given."; - this->SetError(e.str()); + this->SetError(cmStrCat(args[0], " does not allow \"", args[i], + "\" before a PATTERN or REGEX is given.")); return false; } @@ -1036,10 +1009,8 @@ bool cmInstallCommand::HandleDirectoryMode( doing = DoingPermsMatch; } else if (args[i] == "FILE_PERMISSIONS") { if (in_match_mode) { - std::ostringstream e; - e << args[0] << " does not allow \"" << args[i] - << "\" after PATTERN or REGEX."; - this->SetError(e.str()); + this->SetError(cmStrCat(args[0], " does not allow \"", args[i], + "\" after PATTERN or REGEX.")); return false; } @@ -1047,10 +1018,8 @@ bool cmInstallCommand::HandleDirectoryMode( doing = DoingPermsFile; } else if (args[i] == "DIRECTORY_PERMISSIONS") { if (in_match_mode) { - std::ostringstream e; - e << args[0] << " does not allow \"" << args[i] - << "\" after PATTERN or REGEX."; - this->SetError(e.str()); + this->SetError(cmStrCat(args[0], " does not allow \"", args[i], + "\" after PATTERN or REGEX.")); return false; } @@ -1058,10 +1027,8 @@ bool cmInstallCommand::HandleDirectoryMode( doing = DoingPermsDir; } else if (args[i] == "USE_SOURCE_PERMISSIONS") { if (in_match_mode) { - std::ostringstream e; - e << args[0] << " does not allow \"" << args[i] - << "\" after PATTERN or REGEX."; - this->SetError(e.str()); + this->SetError(cmStrCat(args[0], " does not allow \"", args[i], + "\" after PATTERN or REGEX.")); return false; } @@ -1070,10 +1037,8 @@ bool cmInstallCommand::HandleDirectoryMode( doing = DoingNone; } else if (args[i] == "FILES_MATCHING") { if (in_match_mode) { - std::ostringstream e; - e << args[0] << " does not allow \"" << args[i] - << "\" after PATTERN or REGEX."; - this->SetError(e.str()); + this->SetError(cmStrCat(args[0], " does not allow \"", args[i], + "\" after PATTERN or REGEX.")); return false; } @@ -1082,10 +1047,8 @@ bool cmInstallCommand::HandleDirectoryMode( doing = DoingNone; } else if (args[i] == "CONFIGURATIONS") { if (in_match_mode) { - std::ostringstream e; - e << args[0] << " does not allow \"" << args[i] - << "\" after PATTERN or REGEX."; - this->SetError(e.str()); + this->SetError(cmStrCat(args[0], " does not allow \"", args[i], + "\" after PATTERN or REGEX.")); return false; } @@ -1093,10 +1056,8 @@ bool cmInstallCommand::HandleDirectoryMode( doing = DoingConfigurations; } else if (args[i] == "COMPONENT") { if (in_match_mode) { - std::ostringstream e; - e << args[0] << " does not allow \"" << args[i] - << "\" after PATTERN or REGEX."; - this->SetError(e.str()); + this->SetError(cmStrCat(args[0], " does not allow \"", args[i], + "\" after PATTERN or REGEX.")); return false; } @@ -1104,10 +1065,8 @@ bool cmInstallCommand::HandleDirectoryMode( doing = DoingComponent; } else if (args[i] == "EXCLUDE_FROM_ALL") { if (in_match_mode) { - std::ostringstream e; - e << args[0] << " does not allow \"" << args[i] - << "\" after PATTERN or REGEX."; - this->SetError(e.str()); + this->SetError(cmStrCat(args[0], " does not allow \"", args[i], + "\" after PATTERN or REGEX.")); return false; } exclude_from_all = true; @@ -1124,10 +1083,8 @@ bool cmInstallCommand::HandleDirectoryMode( // Make sure the name is a directory. if (cmSystemTools::FileExists(dir) && !cmSystemTools::FileIsDirectory(dir)) { - std::ostringstream e; - e << args[0] << " given non-directory \"" << args[i] - << "\" to install."; - this->SetError(e.str()); + this->SetError(cmStrCat(args[0], " given non-directory \"", args[i], + "\" to install.")); return false; } @@ -1140,10 +1097,8 @@ bool cmInstallCommand::HandleDirectoryMode( doing = DoingNone; } else if (doing == DoingType) { if (allowedTypes.count(args[i]) == 0) { - std::ostringstream e; - e << args[0] << " given non-type \"" << args[i] - << "\" with TYPE argument."; - this->SetError(e.str()); + this->SetError(cmStrCat(args[0], " given non-type \"", args[i], + "\" with TYPE argument.")); return false; } @@ -1179,36 +1134,30 @@ bool cmInstallCommand::HandleDirectoryMode( // Check the requested permission. if (!cmInstallCommandArguments::CheckPermissions(args[i], permissions_file)) { - std::ostringstream e; - e << args[0] << " given invalid file permission \"" << args[i] - << "\"."; - this->SetError(e.str()); + this->SetError(cmStrCat(args[0], " given invalid file permission \"", + args[i], "\".")); return false; } } else if (doing == DoingPermsDir) { // Check the requested permission. if (!cmInstallCommandArguments::CheckPermissions(args[i], permissions_dir)) { - std::ostringstream e; - e << args[0] << " given invalid directory permission \"" << args[i] - << "\"."; - this->SetError(e.str()); + this->SetError(cmStrCat( + args[0], " given invalid directory permission \"", args[i], "\".")); return false; } } else if (doing == DoingPermsMatch) { // Check the requested permission. if (!cmInstallCommandArguments::CheckPermissions(args[i], literal_args)) { - std::ostringstream e; - e << args[0] << " given invalid permission \"" << args[i] << "\"."; - this->SetError(e.str()); + this->SetError( + cmStrCat(args[0], " given invalid permission \"", args[i], "\".")); return false; } } else { // Unknown argument. - std::ostringstream e; - e << args[0] << " given unknown argument \"" << args[i] << "\"."; - this->SetError(e.str()); + this->SetError( + cmStrCat(args[0], " given unknown argument \"", args[i], "\".")); return false; } } @@ -1226,19 +1175,15 @@ bool cmInstallCommand::HandleDirectoryMode( if (!destination) { if (type.empty()) { // A destination is required. - std::ostringstream e; - e << args[0] << " given no DESTINATION!"; - this->SetError(e.str()); + this->SetError(cmStrCat(args[0], " given no DESTINATION!")); return false; } destinationStr = this->GetDestinationForType(nullptr, type); destination = destinationStr.c_str(); } else if (!type.empty()) { - std::ostringstream e; - e << args[0] - << " given both TYPE and DESTINATION arguments. You may only specify " - "one."; - this->SetError(e.str()); + this->SetError(cmStrCat(args[0], + " given both TYPE and DESTINATION " + "arguments. You may only specify one.")); return false; } @@ -1280,9 +1225,8 @@ bool cmInstallCommand::HandleExportAndroidMKMode( if (!unknownArgs.empty()) { // Unknown argument. - std::ostringstream e; - e << args[0] << " given unknown argument \"" << unknownArgs[0] << "\"."; - this->SetError(e.str()); + this->SetError( + cmStrCat(args[0], " given unknown argument \"", unknownArgs[0], "\".")); return false; } @@ -1293,39 +1237,35 @@ bool cmInstallCommand::HandleExportAndroidMKMode( // Make sure there is a destination. if (ica.GetDestination().empty()) { // A destination is required. - std::ostringstream e; - e << args[0] << " given no DESTINATION!"; - this->SetError(e.str()); + this->SetError(cmStrCat(args[0], " given no DESTINATION!")); return false; } // Check the file name. std::string fname = filename; if (fname.find_first_of(":/\\") != std::string::npos) { - std::ostringstream e; - e << args[0] << " given invalid export file name \"" << fname << "\". " - << "The FILE argument may not contain a path. " - << "Specify the path in the DESTINATION argument."; - this->SetError(e.str()); + this->SetError(cmStrCat(args[0], " given invalid export file name \"", + fname, + "\". The FILE argument may not contain a path. " + "Specify the path in the DESTINATION argument.")); return false; } // Check the file extension. if (!fname.empty() && cmSystemTools::GetFilenameLastExtension(fname) != ".mk") { - std::ostringstream e; - e << args[0] << " given invalid export file name \"" << fname << "\". " - << "The FILE argument must specify a name ending in \".mk\"."; - this->SetError(e.str()); + this->SetError(cmStrCat( + args[0], " given invalid export file name \"", fname, + R"(". The FILE argument must specify a name ending in ".mk".)")); return false; } if (fname.find_first_of(":/\\") != std::string::npos) { - std::ostringstream e; - e << args[0] << " given export name \"" << exp << "\". " - << "This name cannot be safely converted to a file name. " - << "Specify a different export name or use the FILE option to set " - << "a file name explicitly."; - this->SetError(e.str()); + this->SetError( + cmStrCat(args[0], " given export name \"", exp, + "\". " + "This name cannot be safely converted to a file name. " + "Specify a different export name or use the FILE option to set " + "a file name explicitly.")); return false; } // Use the default name @@ -1375,9 +1315,8 @@ bool cmInstallCommand::HandleExportMode(std::vector<std::string> const& args) if (!unknownArgs.empty()) { // Unknown argument. - std::ostringstream e; - e << args[0] << " given unknown argument \"" << unknownArgs[0] << "\"."; - this->SetError(e.str()); + this->SetError( + cmStrCat(args[0], " given unknown argument \"", unknownArgs[0], "\".")); return false; } @@ -1388,30 +1327,28 @@ bool cmInstallCommand::HandleExportMode(std::vector<std::string> const& args) // Make sure there is a destination. if (ica.GetDestination().empty()) { // A destination is required. - std::ostringstream e; - e << args[0] << " given no DESTINATION!"; - this->SetError(e.str()); + this->SetError(cmStrCat(args[0], " given no DESTINATION!")); return false; } // Check the file name. std::string fname = filename; if (fname.find_first_of(":/\\") != std::string::npos) { - std::ostringstream e; - e << args[0] << " given invalid export file name \"" << fname << "\". " - << "The FILE argument may not contain a path. " - << "Specify the path in the DESTINATION argument."; - this->SetError(e.str()); + this->SetError(cmStrCat(args[0], " given invalid export file name \"", + fname, + "\". " + "The FILE argument may not contain a path. " + "Specify the path in the DESTINATION argument.")); return false; } // Check the file extension. if (!fname.empty() && cmSystemTools::GetFilenameLastExtension(fname) != ".cmake") { - std::ostringstream e; - e << args[0] << " given invalid export file name \"" << fname << "\". " - << "The FILE argument must specify a name ending in \".cmake\"."; - this->SetError(e.str()); + this->SetError( + cmStrCat(args[0], " given invalid export file name \"", fname, + "\". " + "The FILE argument must specify a name ending in \".cmake\".")); return false; } @@ -1420,12 +1357,12 @@ bool cmInstallCommand::HandleExportMode(std::vector<std::string> const& args) fname = cmStrCat(exp, ".cmake"); if (fname.find_first_of(":/\\") != std::string::npos) { - std::ostringstream e; - e << args[0] << " given export name \"" << exp << "\". " - << "This name cannot be safely converted to a file name. " - << "Specify a different export name or use the FILE option to set " - << "a file name explicitly."; - this->SetError(e.str()); + this->SetError(cmStrCat( + args[0], " given export name \"", exp, + "\". " + "This name cannot be safely converted to a file name. " + "Specify a different export name or use the FILE option to set " + "a file name explicitly.")); return false; } } @@ -1441,12 +1378,10 @@ bool cmInstallCommand::HandleExportMode(std::vector<std::string> const& args) tgt->GetPolicyStatusCMP0022() != cmPolicies::OLD); if (!newCMP0022Behavior) { - std::ostringstream e; - e << "INSTALL(EXPORT) given keyword \"" - << "EXPORT_LINK_INTERFACE_LIBRARIES" - << "\", but target \"" << te->TargetName - << "\" does not have policy CMP0022 set to NEW."; - this->SetError(e.str()); + this->SetError(cmStrCat( + "INSTALL(EXPORT) given keyword \"" + "EXPORT_LINK_INTERFACE_LIBRARIES\", but target \"", + te->TargetName, "\" does not have policy CMP0022 set to NEW.")); return false; } } @@ -1480,9 +1415,8 @@ bool cmInstallCommand::MakeFilesFullPath( // Make sure the file is not a directory. if (gpos == std::string::npos && cmSystemTools::FileIsDirectory(file)) { - std::ostringstream e; - e << modeName << " given directory \"" << relFile << "\" to install."; - this->SetError(e.str()); + this->SetError( + cmStrCat(modeName, " given directory \"", relFile, "\" to install.")); return false; } // Store the file for installation. |