cmSystemTools: More functions accept std::string params

This commit is contained in:
Vitaly Stakhovsky 2019-02-20 13:50:00 -05:00
parent b76b83efd3
commit 4e315e9449
22 changed files with 44 additions and 47 deletions

View File

@ -1255,9 +1255,8 @@ bool cmCPackGenerator::ConfigureFile(const std::string& inName,
int cmCPackGenerator::CleanTemporaryDirectory() int cmCPackGenerator::CleanTemporaryDirectory()
{ {
std::string tempInstallDirectoryWithPostfix = std::string tempInstallDirectory =
this->GetOption("CPACK_TEMPORARY_INSTALL_DIRECTORY"); this->GetOption("CPACK_TEMPORARY_INSTALL_DIRECTORY");
const char* tempInstallDirectory = tempInstallDirectoryWithPostfix.c_str();
if (cmsys::SystemTools::FileExists(tempInstallDirectory)) { if (cmsys::SystemTools::FileExists(tempInstallDirectory)) {
cmCPackLogger(cmCPackLog::LOG_OUTPUT, cmCPackLogger(cmCPackLog::LOG_OUTPUT,
"- Clean temporary : " << tempInstallDirectory << std::endl); "- Clean temporary : " << tempInstallDirectory << std::endl);

View File

@ -365,7 +365,7 @@ bool cmCTestBZR::UpdateImpl()
if (opts.empty()) { if (opts.empty()) {
opts = this->CTest->GetCTestConfiguration("BZRUpdateOptions"); opts = this->CTest->GetCTestConfiguration("BZRUpdateOptions");
} }
std::vector<std::string> args = cmSystemTools::ParseArguments(opts.c_str()); std::vector<std::string> args = cmSystemTools::ParseArguments(opts);
// TODO: if(this->CTest->GetTestModel() == cmCTest::NIGHTLY) // TODO: if(this->CTest->GetTestModel() == cmCTest::NIGHTLY)

View File

@ -418,8 +418,8 @@ int cmCTestBuildHandler::ProcessHandler()
int retVal = 0; int retVal = 0;
int res = cmsysProcess_State_Exited; int res = cmsysProcess_State_Exited;
if (!this->CTest->GetShowOnly()) { if (!this->CTest->GetShowOnly()) {
res = this->RunMakeCommand(makeCommand.c_str(), &retVal, res = this->RunMakeCommand(makeCommand, &retVal, buildDirectory.c_str(), 0,
buildDirectory.c_str(), 0, ofs); ofs);
} else { } else {
cmCTestOptionalLog(this->CTest, DEBUG, cmCTestOptionalLog(this->CTest, DEBUG,
"Build with command: " << makeCommand << std::endl, "Build with command: " << makeCommand << std::endl,
@ -766,9 +766,10 @@ void cmCTestBuildHandler::LaunchHelper::WriteScrapeMatchers(
} }
} }
int cmCTestBuildHandler::RunMakeCommand(const char* command, int* retVal, int cmCTestBuildHandler::RunMakeCommand(const std::string& command,
const char* dir, int timeout, int* retVal, const char* dir,
std::ostream& ofs, Encoding encoding) int timeout, std::ostream& ofs,
Encoding encoding)
{ {
// First generate the command and arguments // First generate the command and arguments
std::vector<std::string> args = cmSystemTools::ParseArguments(command); std::vector<std::string> args = cmSystemTools::ParseArguments(command);

View File

@ -52,7 +52,7 @@ private:
//! Run command specialized for make and configure. Returns process status //! Run command specialized for make and configure. Returns process status
// and retVal is return value or exception. // 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, int timeout, std::ostream& ofs,
Encoding encoding = cmProcessOutput::Auto); Encoding encoding = cmProcessOutput::Auto);

View File

@ -78,7 +78,7 @@ bool cmCTestCVS::UpdateImpl()
opts = "-dP"; opts = "-dP";
} }
} }
std::vector<std::string> args = cmSystemTools::ParseArguments(opts.c_str()); std::vector<std::string> args = cmSystemTools::ParseArguments(opts);
// Specify the start time for nightly testing. // Specify the start time for nightly testing.
if (this->CTest->GetTestModel() == cmCTest::NIGHTLY) { if (this->CTest->GetTestModel() == cmCTest::NIGHTLY) {

View File

@ -61,7 +61,7 @@ int cmCTestConfigureHandler::ProcessHandler()
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Configure with command: " << cCommand << std::endl, "Configure with command: " << cCommand << std::endl,
this->Quiet); this->Quiet);
res = this->CTest->RunMakeCommand(cCommand.c_str(), output, &retVal, res = this->CTest->RunMakeCommand(cCommand, output, &retVal,
buildDirectory.c_str(), buildDirectory.c_str(),
cmDuration::zero(), ofs); cmDuration::zero(), ofs);

View File

@ -1004,7 +1004,7 @@ int cmCTestCoverageHandler::HandleGCovCoverage(
static_cast<void>(locale_C); static_cast<void>(locale_C);
std::vector<std::string> basecovargs = std::vector<std::string> basecovargs =
cmSystemTools::ParseArguments(gcovExtraFlags.c_str()); cmSystemTools::ParseArguments(gcovExtraFlags);
basecovargs.insert(basecovargs.begin(), gcovCommand); basecovargs.insert(basecovargs.begin(), gcovCommand);
basecovargs.emplace_back("-o"); basecovargs.emplace_back("-o");
@ -1377,7 +1377,7 @@ int cmCTestCoverageHandler::HandleLCovCoverage(
static_cast<void>(locale_C); static_cast<void>(locale_C);
std::vector<std::string> covargs = std::vector<std::string> covargs =
cmSystemTools::ParseArguments(lcovExtraFlags.c_str()); cmSystemTools::ParseArguments(lcovExtraFlags);
covargs.insert(covargs.begin(), lcovCommand); covargs.insert(covargs.begin(), lcovCommand);
const std::string command = joinCommandLine(covargs); const std::string command = joinCommandLine(covargs);

View File

@ -162,7 +162,7 @@ bool cmCTestGIT::UpdateByFetchAndReset()
if (opts.empty()) { if (opts.empty()) {
opts = this->CTest->GetCTestConfiguration("GITUpdateOptions"); opts = this->CTest->GetCTestConfiguration("GITUpdateOptions");
} }
std::vector<std::string> args = cmSystemTools::ParseArguments(opts.c_str()); std::vector<std::string> args = cmSystemTools::ParseArguments(opts);
for (std::string const& arg : args) { for (std::string const& arg : args) {
git_fetch.push_back(arg.c_str()); git_fetch.push_back(arg.c_str());
} }

View File

@ -144,7 +144,7 @@ bool cmCTestHG::UpdateImpl()
if (opts.empty()) { if (opts.empty()) {
opts = this->CTest->GetCTestConfiguration("HGUpdateOptions"); opts = this->CTest->GetCTestConfiguration("HGUpdateOptions");
} }
std::vector<std::string> args = cmSystemTools::ParseArguments(opts.c_str()); std::vector<std::string> args = cmSystemTools::ParseArguments(opts);
for (std::string const& arg : args) { for (std::string const& arg : args) {
hg_update.push_back(arg.c_str()); hg_update.push_back(arg.c_str());
} }

View File

@ -520,7 +520,7 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking()
this->CTest->GetCTestConfiguration("ValgrindCommandOptions"); this->CTest->GetCTestConfiguration("ValgrindCommandOptions");
} }
this->MemoryTesterOptions = this->MemoryTesterOptions =
cmSystemTools::ParseArguments(memoryTesterOptions.c_str()); cmSystemTools::ParseArguments(memoryTesterOptions);
this->MemoryTesterOutputFile = this->MemoryTesterOutputFile =
this->CTest->GetBinaryDir() + "/Testing/Temporary/MemoryChecker.??.log"; this->CTest->GetBinaryDir() + "/Testing/Temporary/MemoryChecker.??.log";

View File

@ -324,8 +324,7 @@ void cmCTestP4::SetP4Options(std::vector<char const*>& CommandOptions)
// The CTEST_P4_OPTIONS variable adds additional Perforce command line // The CTEST_P4_OPTIONS variable adds additional Perforce command line
// options before the main command // options before the main command
std::string opts = this->CTest->GetCTestConfiguration("P4Options"); std::string opts = this->CTest->GetCTestConfiguration("P4Options");
std::vector<std::string> args = std::vector<std::string> args = cmSystemTools::ParseArguments(opts);
cmSystemTools::ParseArguments(opts.c_str());
P4Options.insert(P4Options.end(), args.begin(), args.end()); P4Options.insert(P4Options.end(), args.begin(), args.end());
} }
@ -501,7 +500,7 @@ bool cmCTestP4::UpdateImpl()
if (opts.empty()) { if (opts.empty()) {
opts = this->CTest->GetCTestConfiguration("P4UpdateOptions"); opts = this->CTest->GetCTestConfiguration("P4UpdateOptions");
} }
std::vector<std::string> args = cmSystemTools::ParseArguments(opts.c_str()); std::vector<std::string> args = cmSystemTools::ParseArguments(opts);
for (std::string const& arg : args) { for (std::string const& arg : args) {
p4_sync.push_back(arg.c_str()); p4_sync.push_back(arg.c_str());
} }

View File

@ -242,7 +242,7 @@ bool cmCTestSVN::UpdateImpl()
if (opts.empty()) { if (opts.empty()) {
opts = this->CTest->GetCTestConfiguration("SVNUpdateOptions"); opts = this->CTest->GetCTestConfiguration("SVNUpdateOptions");
} }
std::vector<std::string> args = cmSystemTools::ParseArguments(opts.c_str()); std::vector<std::string> args = cmSystemTools::ParseArguments(opts);
// Specify the start time for nightly testing. // Specify the start time for nightly testing.
if (this->CTest->GetTestModel() == cmCTest::NIGHTLY) { if (this->CTest->GetTestModel() == cmCTest::NIGHTLY) {
@ -277,7 +277,7 @@ bool cmCTestSVN::RunSVNCommand(std::vector<char const*> const& parameters,
std::string userOptions = this->CTest->GetCTestConfiguration("SVNOptions"); std::string userOptions = this->CTest->GetCTestConfiguration("SVNOptions");
std::vector<std::string> parsedUserOptions = std::vector<std::string> parsedUserOptions =
cmSystemTools::ParseArguments(userOptions.c_str()); cmSystemTools::ParseArguments(userOptions);
for (std::string const& opt : parsedUserOptions) { for (std::string const& opt : parsedUserOptions) {
args.push_back(opt.c_str()); args.push_back(opt.c_str());
} }

View File

@ -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, int* retVal, const char* dir, cmDuration timeout,
std::ostream& ofs, Encoding encoding) std::ostream& ofs, Encoding encoding)
{ {

View File

@ -280,8 +280,9 @@ public:
* Run command specialized for make and configure. Returns process status * Run command specialized for make and configure. Returns process status
* and retVal is return value or exception. * and retVal is return value or exception.
*/ */
int RunMakeCommand(const char* command, std::string& output, int* retVal, int RunMakeCommand(const std::string& command, std::string& output,
const char* dir, cmDuration timeout, std::ostream& ofs, int* retVal, const char* dir, cmDuration timeout,
std::ostream& ofs,
Encoding encoding = cmProcessOutput::Auto); Encoding encoding = cmProcessOutput::Auto);
/** Return the current tag */ /** Return the current tag */

View File

@ -1266,7 +1266,7 @@ void cmComputeLinkInformation::AddFrameworkItem(std::string const& item)
void cmComputeLinkInformation::AddDirectoryItem(std::string const& item) void cmComputeLinkInformation::AddDirectoryItem(std::string const& item)
{ {
if (this->Makefile->IsOn("APPLE") && if (this->Makefile->IsOn("APPLE") &&
cmSystemTools::IsPathToFramework(item.c_str())) { cmSystemTools::IsPathToFramework(item)) {
this->AddFrameworkItem(item); this->AddFrameworkItem(item);
} else { } else {
this->DropDirectoryItem(item); this->DropDirectoryItem(item);

View File

@ -67,7 +67,7 @@ bool cmExecProgramCommand::InitialPass(std::vector<std::string> const& args,
std::string command; std::string command;
if (!arguments.empty()) { if (!arguments.empty()) {
command = cmSystemTools::ConvertToRunCommandPath(args[0].c_str()); command = cmSystemTools::ConvertToRunCommandPath(args[0]);
command += " "; command += " ";
command += arguments; command += arguments;
} else { } else {

View File

@ -210,7 +210,7 @@ void cmGhsMultiTargetGenerator::WriteCompilerFlags(std::ostream& fout,
if (flagsByLangI != this->FlagsByLanguage.end()) { if (flagsByLangI != this->FlagsByLanguage.end()) {
if (!flagsByLangI->second.empty()) { if (!flagsByLangI->second.empty()) {
std::vector<std::string> ghsCompFlags = std::vector<std::string> ghsCompFlags =
cmSystemTools::ParseArguments(flagsByLangI->second.c_str()); cmSystemTools::ParseArguments(flagsByLangI->second);
for (auto& f : ghsCompFlags) { for (auto& f : ghsCompFlags) {
fout << " " << f << std::endl; fout << " " << f << std::endl;
} }
@ -265,16 +265,14 @@ void cmGhsMultiTargetGenerator::WriteTargetLinkLine(std::ostream& fout,
frameworkPath, linkPath, this->GeneratorTarget); frameworkPath, linkPath, this->GeneratorTarget);
// write out link options // write out link options
std::vector<std::string> lopts = std::vector<std::string> lopts = cmSystemTools::ParseArguments(linkFlags);
cmSystemTools::ParseArguments(linkFlags.c_str());
for (auto& l : lopts) { for (auto& l : lopts) {
fout << " " << l << std::endl; fout << " " << l << std::endl;
} }
// write out link search paths // write out link search paths
// must be quoted for paths that contain spaces // must be quoted for paths that contain spaces
std::vector<std::string> lpath = std::vector<std::string> lpath = cmSystemTools::ParseArguments(linkPath);
cmSystemTools::ParseArguments(linkPath.c_str());
for (auto& l : lpath) { for (auto& l : lpath) {
fout << " -L\"" << l << "\"" << std::endl; fout << " -L\"" << l << "\"" << std::endl;
} }
@ -284,7 +282,7 @@ void cmGhsMultiTargetGenerator::WriteTargetLinkLine(std::ostream& fout,
std::string cbd = this->LocalGenerator->GetCurrentBinaryDirectory(); std::string cbd = this->LocalGenerator->GetCurrentBinaryDirectory();
std::vector<std::string> llibs = std::vector<std::string> llibs =
cmSystemTools::ParseArguments(linkLibraries.c_str()); cmSystemTools::ParseArguments(linkLibraries);
for (auto& l : llibs) { for (auto& l : llibs) {
if (l.compare(0, 2, "-l") == 0) { if (l.compare(0, 2, "-l") == 0) {
fout << " \"" << l << "\"" << std::endl; fout << " \"" << l << "\"" << std::endl;

View File

@ -2200,7 +2200,7 @@ cmGeneratorTarget* cmGlobalGenerator::FindGeneratorTarget(
bool cmGlobalGenerator::NameResolvesToFramework( bool cmGlobalGenerator::NameResolvesToFramework(
const std::string& libname) const const std::string& libname) const
{ {
if (cmSystemTools::IsPathToFramework(libname.c_str())) { if (cmSystemTools::IsPathToFramework(libname)) {
return true; return true;
} }

View File

@ -776,7 +776,7 @@ std::string cmLocalGenerator::GetIncludeFlags(
#endif #endif
for (std::string const& i : includes) { for (std::string const& i : includes) {
if (fwSearchFlag && *fwSearchFlag && this->Makefile->IsOn("APPLE") && if (fwSearchFlag && *fwSearchFlag && this->Makefile->IsOn("APPLE") &&
cmSystemTools::IsPathToFramework(i.c_str())) { cmSystemTools::IsPathToFramework(i)) {
std::string frameworkDir = i; std::string frameworkDir = i;
frameworkDir += "/../"; frameworkDir += "/../";
frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir); frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir);

View File

@ -571,13 +571,14 @@ std::vector<std::string> cmSystemTools::HandleResponseFile(
return arg_full; return arg_full;
} }
std::vector<std::string> cmSystemTools::ParseArguments(const char* command) std::vector<std::string> cmSystemTools::ParseArguments(const std::string& cmd)
{ {
std::vector<std::string> args; std::vector<std::string> args;
std::string arg; std::string arg;
bool win_path = false; bool win_path = false;
const char* command = cmd.c_str();
if (command[0] && command[1] && if (command[0] && command[1] &&
((command[0] != '/' && command[1] == ':' && command[2] == '\\') || ((command[0] != '/' && command[1] == ':' && command[2] == '\\') ||
(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; outputflag = OUTPUT_NONE;
} }
std::vector<std::string> args = std::vector<std::string> args = cmSystemTools::ParseArguments(command);
cmSystemTools::ParseArguments(command.c_str());
if (args.empty()) { if (args.empty()) {
return false; return false;
@ -1411,7 +1411,7 @@ void cmSystemTools::ConvertToOutputSlashes(std::string& path)
#endif #endif
} }
std::string cmSystemTools::ConvertToRunCommandPath(const char* path) std::string cmSystemTools::ConvertToRunCommandPath(const std::string& path)
{ {
#if defined(_WIN32) && !defined(__CYGWIN__) #if defined(_WIN32) && !defined(__CYGWIN__)
return cmSystemTools::ConvertToWindowsOutputPath(path); return cmSystemTools::ConvertToWindowsOutputPath(path);
@ -1614,7 +1614,7 @@ void cmSystemTools::EnableVSConsoleOutput()
#endif #endif
} }
bool cmSystemTools::IsPathToFramework(const char* path) bool cmSystemTools::IsPathToFramework(const std::string& path)
{ {
return (cmSystemTools::FileIsFullPath(path) && return (cmSystemTools::FileIsFullPath(path) &&
cmHasLiteralSuffix(path, ".framework")); cmHasLiteralSuffix(path, ".framework"));
@ -3005,7 +3005,7 @@ bool cmSystemTools::CheckRPath(std::string const& file,
#endif #endif
} }
bool cmSystemTools::RepeatedRemoveDirectory(const char* dir) bool cmSystemTools::RepeatedRemoveDirectory(const std::string& dir)
{ {
// Windows sometimes locks files temporarily so try a few times. // Windows sometimes locks files temporarily so try a few times.
for (int i = 0; i < 10; ++i) { for (int i = 0; i < 10; ++i) {

View File

@ -141,7 +141,7 @@ public:
///! Return true if value is NOTFOUND or ends in -NOTFOUND. ///! Return true if value is NOTFOUND or ends in -NOTFOUND.
static bool IsNOTFOUND(const char* value); static bool IsNOTFOUND(const char* value);
///! Return true if the path is a framework ///! Return true if the path is a framework
static bool IsPathToFramework(const char* value); static bool IsPathToFramework(const std::string& value);
static bool DoesFileExistWithExtensions( static bool DoesFileExistWithExtensions(
const std::string& name, const std::vector<std::string>& sourceExts); const std::string& name, const std::vector<std::string>& sourceExts);
@ -242,7 +242,7 @@ public:
/** /**
* Parse arguments out of a single string command * Parse arguments out of a single string command
*/ */
static std::vector<std::string> ParseArguments(const char* command); static std::vector<std::string> ParseArguments(const std::string& command);
/** Parse arguments out of a windows command line string. */ /** Parse arguments out of a windows command line string. */
static void ParseWindowsCommandLine(const char* command, static void ParseWindowsCommandLine(const char* command,
@ -353,7 +353,7 @@ public:
// ConvertToRunCommandPath does not use s_ForceUnixPaths and should // ConvertToRunCommandPath does not use s_ForceUnixPaths and should
// be used when RunCommand is called from cmake, because the // be used when RunCommand is called from cmake, because the
// running cmake needs paths to be in its format // 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 /** compute the relative path from local to remote. local must
be a directory. remote can be a file or a directory. 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); static bool CheckRPath(std::string const& file, std::string const& newRPath);
/** Remove a directory; repeat a few times in case of locked files. */ /** 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 */ /** Tokenize a string */
static std::vector<std::string> tokenize(const std::string& str, static std::vector<std::string> tokenize(const std::string& str,

View File

@ -173,7 +173,7 @@ void cmTryRunCommand::RunExecutable(const std::string& runArgs,
std::vector<std::string> emulatorWithArgs; std::vector<std::string> emulatorWithArgs;
cmSystemTools::ExpandListArgument(emulator, emulatorWithArgs); cmSystemTools::ExpandListArgument(emulator, emulatorWithArgs);
finalCommand += finalCommand +=
cmSystemTools::ConvertToRunCommandPath(emulatorWithArgs[0].c_str()); cmSystemTools::ConvertToRunCommandPath(emulatorWithArgs[0]);
finalCommand += " "; finalCommand += " ";
for (std::string const& arg : cmMakeRange(emulatorWithArgs).advance(1)) { for (std::string const& arg : cmMakeRange(emulatorWithArgs).advance(1)) {
finalCommand += "\""; finalCommand += "\"";
@ -182,8 +182,7 @@ void cmTryRunCommand::RunExecutable(const std::string& runArgs,
finalCommand += " "; finalCommand += " ";
} }
} }
finalCommand += finalCommand += cmSystemTools::ConvertToRunCommandPath(this->OutputFile);
cmSystemTools::ConvertToRunCommandPath(this->OutputFile.c_str());
if (!runArgs.empty()) { if (!runArgs.empty()) {
finalCommand += runArgs; finalCommand += runArgs;
} }