From 4e315e9449735fc0f246c8cc838613693e849296 Mon Sep 17 00:00:00 2001 From: Vitaly Stakhovsky Date: Wed, 20 Feb 2019 13:50:00 -0500 Subject: cmSystemTools: More functions accept `std::string` params --- Source/CPack/cmCPackGenerator.cxx | 3 +-- Source/CTest/cmCTestBZR.cxx | 2 +- Source/CTest/cmCTestBuildHandler.cxx | 11 ++++++----- Source/CTest/cmCTestBuildHandler.h | 2 +- Source/CTest/cmCTestCVS.cxx | 2 +- Source/CTest/cmCTestConfigureHandler.cxx | 2 +- Source/CTest/cmCTestCoverageHandler.cxx | 4 ++-- Source/CTest/cmCTestGIT.cxx | 2 +- Source/CTest/cmCTestHG.cxx | 2 +- Source/CTest/cmCTestMemCheckHandler.cxx | 2 +- Source/CTest/cmCTestP4.cxx | 5 ++--- Source/CTest/cmCTestSVN.cxx | 4 ++-- Source/cmCTest.cxx | 2 +- Source/cmCTest.h | 5 +++-- Source/cmComputeLinkInformation.cxx | 2 +- Source/cmExecProgramCommand.cxx | 2 +- Source/cmGhsMultiTargetGenerator.cxx | 10 ++++------ Source/cmGlobalGenerator.cxx | 2 +- Source/cmLocalGenerator.cxx | 2 +- Source/cmSystemTools.cxx | 12 ++++++------ Source/cmSystemTools.h | 8 ++++---- Source/cmTryRunCommand.cxx | 5 ++--- 22 files changed, 44 insertions(+), 47 deletions(-) diff --git a/Source/CPack/cmCPackGenerator.cxx b/Source/CPack/cmCPackGenerator.cxx index 575254e..127bcf9 100644 --- a/Source/CPack/cmCPackGenerator.cxx +++ b/Source/CPack/cmCPackGenerator.cxx @@ -1255,9 +1255,8 @@ bool cmCPackGenerator::ConfigureFile(const std::string& inName, int cmCPackGenerator::CleanTemporaryDirectory() { - std::string tempInstallDirectoryWithPostfix = + std::string tempInstallDirectory = this->GetOption("CPACK_TEMPORARY_INSTALL_DIRECTORY"); - const char* tempInstallDirectory = tempInstallDirectoryWithPostfix.c_str(); if (cmsys::SystemTools::FileExists(tempInstallDirectory)) { cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- Clean temporary : " << tempInstallDirectory << std::endl); diff --git a/Source/CTest/cmCTestBZR.cxx b/Source/CTest/cmCTestBZR.cxx index b154caf..83aeb64 100644 --- a/Source/CTest/cmCTestBZR.cxx +++ b/Source/CTest/cmCTestBZR.cxx @@ -365,7 +365,7 @@ bool cmCTestBZR::UpdateImpl() if (opts.empty()) { opts = this->CTest->GetCTestConfiguration("BZRUpdateOptions"); } - std::vector args = cmSystemTools::ParseArguments(opts.c_str()); + std::vector args = cmSystemTools::ParseArguments(opts); // TODO: if(this->CTest->GetTestModel() == cmCTest::NIGHTLY) diff --git a/Source/CTest/cmCTestBuildHandler.cxx b/Source/CTest/cmCTestBuildHandler.cxx index c75f4d4..07bc7e7 100644 --- a/Source/CTest/cmCTestBuildHandler.cxx +++ b/Source/CTest/cmCTestBuildHandler.cxx @@ -418,8 +418,8 @@ int cmCTestBuildHandler::ProcessHandler() int retVal = 0; int res = cmsysProcess_State_Exited; if (!this->CTest->GetShowOnly()) { - res = this->RunMakeCommand(makeCommand.c_str(), &retVal, - buildDirectory.c_str(), 0, ofs); + res = this->RunMakeCommand(makeCommand, &retVal, buildDirectory.c_str(), 0, + ofs); } else { cmCTestOptionalLog(this->CTest, DEBUG, "Build with command: " << makeCommand << std::endl, @@ -766,9 +766,10 @@ void cmCTestBuildHandler::LaunchHelper::WriteScrapeMatchers( } } -int cmCTestBuildHandler::RunMakeCommand(const char* command, int* retVal, - const char* dir, int timeout, - std::ostream& ofs, Encoding encoding) +int cmCTestBuildHandler::RunMakeCommand(const std::string& command, + int* retVal, const char* dir, + int timeout, std::ostream& ofs, + Encoding encoding) { // First generate the command and arguments std::vector args = cmSystemTools::ParseArguments(command); diff --git a/Source/CTest/cmCTestBuildHandler.h b/Source/CTest/cmCTestBuildHandler.h index a9b121b..722c590 100644 --- a/Source/CTest/cmCTestBuildHandler.h +++ b/Source/CTest/cmCTestBuildHandler.h @@ -52,7 +52,7 @@ private: //! Run command specialized for make and configure. Returns process status // and retVal is return value or exception. - int RunMakeCommand(const char* command, int* retVal, const char* dir, + int RunMakeCommand(const std::string& command, int* retVal, const char* dir, int timeout, std::ostream& ofs, Encoding encoding = cmProcessOutput::Auto); diff --git a/Source/CTest/cmCTestCVS.cxx b/Source/CTest/cmCTestCVS.cxx index 6e8f73f..9c03839 100644 --- a/Source/CTest/cmCTestCVS.cxx +++ b/Source/CTest/cmCTestCVS.cxx @@ -78,7 +78,7 @@ bool cmCTestCVS::UpdateImpl() opts = "-dP"; } } - std::vector args = cmSystemTools::ParseArguments(opts.c_str()); + std::vector args = cmSystemTools::ParseArguments(opts); // Specify the start time for nightly testing. if (this->CTest->GetTestModel() == cmCTest::NIGHTLY) { diff --git a/Source/CTest/cmCTestConfigureHandler.cxx b/Source/CTest/cmCTestConfigureHandler.cxx index 6b7601b..7e93189 100644 --- a/Source/CTest/cmCTestConfigureHandler.cxx +++ b/Source/CTest/cmCTestConfigureHandler.cxx @@ -61,7 +61,7 @@ int cmCTestConfigureHandler::ProcessHandler() cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Configure with command: " << cCommand << std::endl, this->Quiet); - res = this->CTest->RunMakeCommand(cCommand.c_str(), output, &retVal, + res = this->CTest->RunMakeCommand(cCommand, output, &retVal, buildDirectory.c_str(), cmDuration::zero(), ofs); diff --git a/Source/CTest/cmCTestCoverageHandler.cxx b/Source/CTest/cmCTestCoverageHandler.cxx index 4dda9ad..d76bd2a 100644 --- a/Source/CTest/cmCTestCoverageHandler.cxx +++ b/Source/CTest/cmCTestCoverageHandler.cxx @@ -1004,7 +1004,7 @@ int cmCTestCoverageHandler::HandleGCovCoverage( static_cast(locale_C); std::vector basecovargs = - cmSystemTools::ParseArguments(gcovExtraFlags.c_str()); + cmSystemTools::ParseArguments(gcovExtraFlags); basecovargs.insert(basecovargs.begin(), gcovCommand); basecovargs.emplace_back("-o"); @@ -1377,7 +1377,7 @@ int cmCTestCoverageHandler::HandleLCovCoverage( static_cast(locale_C); std::vector covargs = - cmSystemTools::ParseArguments(lcovExtraFlags.c_str()); + cmSystemTools::ParseArguments(lcovExtraFlags); covargs.insert(covargs.begin(), lcovCommand); const std::string command = joinCommandLine(covargs); diff --git a/Source/CTest/cmCTestGIT.cxx b/Source/CTest/cmCTestGIT.cxx index 210abe5..11cd005 100644 --- a/Source/CTest/cmCTestGIT.cxx +++ b/Source/CTest/cmCTestGIT.cxx @@ -162,7 +162,7 @@ bool cmCTestGIT::UpdateByFetchAndReset() if (opts.empty()) { opts = this->CTest->GetCTestConfiguration("GITUpdateOptions"); } - std::vector args = cmSystemTools::ParseArguments(opts.c_str()); + std::vector args = cmSystemTools::ParseArguments(opts); for (std::string const& arg : args) { git_fetch.push_back(arg.c_str()); } diff --git a/Source/CTest/cmCTestHG.cxx b/Source/CTest/cmCTestHG.cxx index 6fb99d8..727c59c 100644 --- a/Source/CTest/cmCTestHG.cxx +++ b/Source/CTest/cmCTestHG.cxx @@ -144,7 +144,7 @@ bool cmCTestHG::UpdateImpl() if (opts.empty()) { opts = this->CTest->GetCTestConfiguration("HGUpdateOptions"); } - std::vector args = cmSystemTools::ParseArguments(opts.c_str()); + std::vector args = cmSystemTools::ParseArguments(opts); for (std::string const& arg : args) { hg_update.push_back(arg.c_str()); } diff --git a/Source/CTest/cmCTestMemCheckHandler.cxx b/Source/CTest/cmCTestMemCheckHandler.cxx index 954f5bb..22c8469 100644 --- a/Source/CTest/cmCTestMemCheckHandler.cxx +++ b/Source/CTest/cmCTestMemCheckHandler.cxx @@ -520,7 +520,7 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking() this->CTest->GetCTestConfiguration("ValgrindCommandOptions"); } this->MemoryTesterOptions = - cmSystemTools::ParseArguments(memoryTesterOptions.c_str()); + cmSystemTools::ParseArguments(memoryTesterOptions); this->MemoryTesterOutputFile = this->CTest->GetBinaryDir() + "/Testing/Temporary/MemoryChecker.??.log"; diff --git a/Source/CTest/cmCTestP4.cxx b/Source/CTest/cmCTestP4.cxx index ac4753c..315f498 100644 --- a/Source/CTest/cmCTestP4.cxx +++ b/Source/CTest/cmCTestP4.cxx @@ -324,8 +324,7 @@ void cmCTestP4::SetP4Options(std::vector& CommandOptions) // The CTEST_P4_OPTIONS variable adds additional Perforce command line // options before the main command std::string opts = this->CTest->GetCTestConfiguration("P4Options"); - std::vector args = - cmSystemTools::ParseArguments(opts.c_str()); + std::vector args = cmSystemTools::ParseArguments(opts); P4Options.insert(P4Options.end(), args.begin(), args.end()); } @@ -501,7 +500,7 @@ bool cmCTestP4::UpdateImpl() if (opts.empty()) { opts = this->CTest->GetCTestConfiguration("P4UpdateOptions"); } - std::vector args = cmSystemTools::ParseArguments(opts.c_str()); + std::vector args = cmSystemTools::ParseArguments(opts); for (std::string const& arg : args) { p4_sync.push_back(arg.c_str()); } diff --git a/Source/CTest/cmCTestSVN.cxx b/Source/CTest/cmCTestSVN.cxx index 3bf66ca..b7a4e4c 100644 --- a/Source/CTest/cmCTestSVN.cxx +++ b/Source/CTest/cmCTestSVN.cxx @@ -242,7 +242,7 @@ bool cmCTestSVN::UpdateImpl() if (opts.empty()) { opts = this->CTest->GetCTestConfiguration("SVNUpdateOptions"); } - std::vector args = cmSystemTools::ParseArguments(opts.c_str()); + std::vector args = cmSystemTools::ParseArguments(opts); // Specify the start time for nightly testing. if (this->CTest->GetTestModel() == cmCTest::NIGHTLY) { @@ -277,7 +277,7 @@ bool cmCTestSVN::RunSVNCommand(std::vector const& parameters, std::string userOptions = this->CTest->GetCTestConfiguration("SVNOptions"); std::vector parsedUserOptions = - cmSystemTools::ParseArguments(userOptions.c_str()); + cmSystemTools::ParseArguments(userOptions); for (std::string const& opt : parsedUserOptions) { args.push_back(opt.c_str()); } diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index ba2fe6c..c77bb97 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -1009,7 +1009,7 @@ int cmCTest::GetTestModelFromString(const char* str) //###################################################################### //###################################################################### -int cmCTest::RunMakeCommand(const char* command, std::string& output, +int cmCTest::RunMakeCommand(const std::string& command, std::string& output, int* retVal, const char* dir, cmDuration timeout, std::ostream& ofs, Encoding encoding) { diff --git a/Source/cmCTest.h b/Source/cmCTest.h index 7dbf4d5..a765fed 100644 --- a/Source/cmCTest.h +++ b/Source/cmCTest.h @@ -280,8 +280,9 @@ public: * Run command specialized for make and configure. Returns process status * and retVal is return value or exception. */ - int RunMakeCommand(const char* command, std::string& output, int* retVal, - const char* dir, cmDuration timeout, std::ostream& ofs, + int RunMakeCommand(const std::string& command, std::string& output, + int* retVal, const char* dir, cmDuration timeout, + std::ostream& ofs, Encoding encoding = cmProcessOutput::Auto); /** Return the current tag */ diff --git a/Source/cmComputeLinkInformation.cxx b/Source/cmComputeLinkInformation.cxx index 3d61665..eef93f8 100644 --- a/Source/cmComputeLinkInformation.cxx +++ b/Source/cmComputeLinkInformation.cxx @@ -1266,7 +1266,7 @@ void cmComputeLinkInformation::AddFrameworkItem(std::string const& item) void cmComputeLinkInformation::AddDirectoryItem(std::string const& item) { if (this->Makefile->IsOn("APPLE") && - cmSystemTools::IsPathToFramework(item.c_str())) { + cmSystemTools::IsPathToFramework(item)) { this->AddFrameworkItem(item); } else { this->DropDirectoryItem(item); diff --git a/Source/cmExecProgramCommand.cxx b/Source/cmExecProgramCommand.cxx index 75a7786..f4a9a9e 100644 --- a/Source/cmExecProgramCommand.cxx +++ b/Source/cmExecProgramCommand.cxx @@ -67,7 +67,7 @@ bool cmExecProgramCommand::InitialPass(std::vector const& args, std::string command; if (!arguments.empty()) { - command = cmSystemTools::ConvertToRunCommandPath(args[0].c_str()); + command = cmSystemTools::ConvertToRunCommandPath(args[0]); command += " "; command += arguments; } else { diff --git a/Source/cmGhsMultiTargetGenerator.cxx b/Source/cmGhsMultiTargetGenerator.cxx index c63e01a..9f8f12b 100644 --- a/Source/cmGhsMultiTargetGenerator.cxx +++ b/Source/cmGhsMultiTargetGenerator.cxx @@ -210,7 +210,7 @@ void cmGhsMultiTargetGenerator::WriteCompilerFlags(std::ostream& fout, if (flagsByLangI != this->FlagsByLanguage.end()) { if (!flagsByLangI->second.empty()) { std::vector ghsCompFlags = - cmSystemTools::ParseArguments(flagsByLangI->second.c_str()); + cmSystemTools::ParseArguments(flagsByLangI->second); for (auto& f : ghsCompFlags) { fout << " " << f << std::endl; } @@ -265,16 +265,14 @@ void cmGhsMultiTargetGenerator::WriteTargetLinkLine(std::ostream& fout, frameworkPath, linkPath, this->GeneratorTarget); // write out link options - std::vector lopts = - cmSystemTools::ParseArguments(linkFlags.c_str()); + std::vector lopts = cmSystemTools::ParseArguments(linkFlags); for (auto& l : lopts) { fout << " " << l << std::endl; } // write out link search paths // must be quoted for paths that contain spaces - std::vector lpath = - cmSystemTools::ParseArguments(linkPath.c_str()); + std::vector lpath = cmSystemTools::ParseArguments(linkPath); for (auto& l : lpath) { fout << " -L\"" << l << "\"" << std::endl; } @@ -284,7 +282,7 @@ void cmGhsMultiTargetGenerator::WriteTargetLinkLine(std::ostream& fout, std::string cbd = this->LocalGenerator->GetCurrentBinaryDirectory(); std::vector llibs = - cmSystemTools::ParseArguments(linkLibraries.c_str()); + cmSystemTools::ParseArguments(linkLibraries); for (auto& l : llibs) { if (l.compare(0, 2, "-l") == 0) { fout << " \"" << l << "\"" << std::endl; diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index fa0ffcc..3a56589 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -2200,7 +2200,7 @@ cmGeneratorTarget* cmGlobalGenerator::FindGeneratorTarget( bool cmGlobalGenerator::NameResolvesToFramework( const std::string& libname) const { - if (cmSystemTools::IsPathToFramework(libname.c_str())) { + if (cmSystemTools::IsPathToFramework(libname)) { return true; } diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 8393165..1921e30 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -776,7 +776,7 @@ std::string cmLocalGenerator::GetIncludeFlags( #endif for (std::string const& i : includes) { if (fwSearchFlag && *fwSearchFlag && this->Makefile->IsOn("APPLE") && - cmSystemTools::IsPathToFramework(i.c_str())) { + cmSystemTools::IsPathToFramework(i)) { std::string frameworkDir = i; frameworkDir += "/../"; frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir); diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index f0e8077..28a6564 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -571,13 +571,14 @@ std::vector cmSystemTools::HandleResponseFile( return arg_full; } -std::vector cmSystemTools::ParseArguments(const char* command) +std::vector cmSystemTools::ParseArguments(const std::string& cmd) { std::vector args; std::string arg; bool win_path = false; + const char* command = cmd.c_str(); if (command[0] && command[1] && ((command[0] != '/' && command[1] == ':' && command[2] == '\\') || (command[0] == '\"' && command[1] != '/' && command[2] == ':' && @@ -878,8 +879,7 @@ bool cmSystemTools::RunSingleCommand(const std::string& command, outputflag = OUTPUT_NONE; } - std::vector args = - cmSystemTools::ParseArguments(command.c_str()); + std::vector args = cmSystemTools::ParseArguments(command); if (args.empty()) { return false; @@ -1411,7 +1411,7 @@ void cmSystemTools::ConvertToOutputSlashes(std::string& path) #endif } -std::string cmSystemTools::ConvertToRunCommandPath(const char* path) +std::string cmSystemTools::ConvertToRunCommandPath(const std::string& path) { #if defined(_WIN32) && !defined(__CYGWIN__) return cmSystemTools::ConvertToWindowsOutputPath(path); @@ -1614,7 +1614,7 @@ void cmSystemTools::EnableVSConsoleOutput() #endif } -bool cmSystemTools::IsPathToFramework(const char* path) +bool cmSystemTools::IsPathToFramework(const std::string& path) { return (cmSystemTools::FileIsFullPath(path) && cmHasLiteralSuffix(path, ".framework")); @@ -3005,7 +3005,7 @@ bool cmSystemTools::CheckRPath(std::string const& file, #endif } -bool cmSystemTools::RepeatedRemoveDirectory(const char* dir) +bool cmSystemTools::RepeatedRemoveDirectory(const std::string& dir) { // Windows sometimes locks files temporarily so try a few times. for (int i = 0; i < 10; ++i) { diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index 82e4f01..60e8c18 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -141,7 +141,7 @@ public: ///! Return true if value is NOTFOUND or ends in -NOTFOUND. static bool IsNOTFOUND(const char* value); ///! Return true if the path is a framework - static bool IsPathToFramework(const char* value); + static bool IsPathToFramework(const std::string& value); static bool DoesFileExistWithExtensions( const std::string& name, const std::vector& sourceExts); @@ -242,7 +242,7 @@ public: /** * Parse arguments out of a single string command */ - static std::vector ParseArguments(const char* command); + static std::vector ParseArguments(const std::string& command); /** Parse arguments out of a windows command line string. */ static void ParseWindowsCommandLine(const char* command, @@ -353,7 +353,7 @@ public: // ConvertToRunCommandPath does not use s_ForceUnixPaths and should // be used when RunCommand is called from cmake, because the // running cmake needs paths to be in its format - static std::string ConvertToRunCommandPath(const char* path); + static std::string ConvertToRunCommandPath(const std::string& path); /** compute the relative path from local to remote. local must be a directory. remote can be a file or a directory. @@ -488,7 +488,7 @@ public: static bool CheckRPath(std::string const& file, std::string const& newRPath); /** Remove a directory; repeat a few times in case of locked files. */ - static bool RepeatedRemoveDirectory(const char* dir); + static bool RepeatedRemoveDirectory(const std::string& dir); /** Tokenize a string */ static std::vector tokenize(const std::string& str, diff --git a/Source/cmTryRunCommand.cxx b/Source/cmTryRunCommand.cxx index d863339..da34bca 100644 --- a/Source/cmTryRunCommand.cxx +++ b/Source/cmTryRunCommand.cxx @@ -173,7 +173,7 @@ void cmTryRunCommand::RunExecutable(const std::string& runArgs, std::vector emulatorWithArgs; cmSystemTools::ExpandListArgument(emulator, emulatorWithArgs); finalCommand += - cmSystemTools::ConvertToRunCommandPath(emulatorWithArgs[0].c_str()); + cmSystemTools::ConvertToRunCommandPath(emulatorWithArgs[0]); finalCommand += " "; for (std::string const& arg : cmMakeRange(emulatorWithArgs).advance(1)) { finalCommand += "\""; @@ -182,8 +182,7 @@ void cmTryRunCommand::RunExecutable(const std::string& runArgs, finalCommand += " "; } } - finalCommand += - cmSystemTools::ConvertToRunCommandPath(this->OutputFile.c_str()); + finalCommand += cmSystemTools::ConvertToRunCommandPath(this->OutputFile); if (!runArgs.empty()) { finalCommand += runArgs; } -- cgit v0.12